1
0
mirror of https://github.com/fumiama/simple-dict.git synced 2026-06-05 18:20:26 +08:00

skip null bytes

This commit is contained in:
fumiama
2022-02-06 15:14:46 +08:00
parent 14a9a02e31
commit d042193ef6

View File

@@ -170,11 +170,12 @@ static int send_all(THREADTIMER *timer) {
return re;
}
#define has_next(fp, ch) ((ch=getc(fp)),(feof(fp)?0:(ungetc(ch,fp),1)))
#define has_next(fp, ch) ((ch=getc(fp)),(feof(fp)?0:(ch?ungetc(ch,fp):1)))
static void init_dict_pool(FILE *fp) {
int ch;
while(has_next(fp, ch)) {
if(!ch) continue; // skip null bytes
SIMPLE_PB* spb = get_pb(fp);
DICT* d = (DICT*)spb->target;
DICT* dnew = (DICT*)malloc(sizeof(DICT));
@@ -219,6 +220,7 @@ static int s1_get(THREADTIMER *timer) {
}
while(has_next(fp, ch)) {
if(!ch) continue; // skip null bytes
SIMPLE_PB* spb = get_pb(fp);
DICT* d = (DICT*)spb->target;
if(!strcmp(timer->dat, d->key)) {
@@ -291,6 +293,7 @@ static int s3_set_data(THREADTIMER *timer) {
static void del(FILE *fp, char* key, int len, char ret[4]) {
int ch;
while(has_next(fp, ch)) {
if(!ch) continue; // skip null bytes
SIMPLE_PB* spb = get_pb(fp);
DICT* d = (DICT*)spb->target;
if(!memcmp(key, d->key, len)) {