📄 dbz.pch
字号:
basef = NULL; pagf = NULL; if (fclose(dirf) == EOF) {****************** 809,820 **** if (!written) return(0); ! if (corepag != NULL) { if (putcore(corepag, bufpagf) < 0) { DEBUG(("dbzsync: putcore failed\n")); ret = -1; } } if (!conf.olddbz) if (putconf(dirf, &conf) < 0) ret = -1;--- 881,894 ---- if (!written) return(0); ! #ifndef MMAP! if (corepag != NULL && !writethrough) { if (putcore(corepag, bufpagf) < 0) { DEBUG(("dbzsync: putcore failed\n")); ret = -1; } }+ #endif if (!conf.olddbz) if (putconf(dirf, &conf) < 0) ret = -1;****************** 922,928 **** DEBUG(("fetch: seek failed\n")); return(output); }! if (fread(buffer, 1, keysize, basef) != keysize) { DEBUG(("fetch: read failed\n")); return(output); }--- 996,1002 ---- DEBUG(("fetch: seek failed\n")); return(output); }! if (fread((POINTER)buffer, 1, keysize, basef) != keysize) { DEBUG(("fetch: read failed\n")); return(output); }****************** 932,938 **** (void) mapcase(buffer, buffer, keysize); DEBUG(("fetch: buffer (%s) looking for (%s) size = %d\n", buffer, key.dptr, keysize));! if (memcmp(key.dptr, buffer, cmplen) == 0 && (*sepp == conf.fieldsep || *sepp == '\0')) { /* we found it */ output.dptr = (char *)&key_ptr;--- 1006,1012 ---- (void) mapcase(buffer, buffer, keysize); DEBUG(("fetch: buffer (%s) looking for (%s) size = %d\n", buffer, key.dptr, keysize));! if (memcmp((POINTER)key.dptr, (POINTER)buffer, cmplen) == 0 && (*sepp == conf.fieldsep || *sepp == '\0')) { /* we found it */ output.dptr = (char *)&key_ptr;****************** 965,976 **** DEBUG(("latebase: still can't open base\n")); } else { DEBUG(("latebase: late open succeeded\n"));! free(basefname); basefname = NULL; #ifdef _IOFBF (void) setvbuf(it, basebuf, _IOFBF, sizeof(basebuf)); #endif } return(it); } --- 1039,1052 ---- DEBUG(("latebase: still can't open base\n")); } else { DEBUG(("latebase: late open succeeded\n"));! free((POINTER)basefname); basefname = NULL; #ifdef _IOFBF (void) setvbuf(it, basebuf, _IOFBF, sizeof(basebuf)); #endif }+ if (it != NULL)+ CloseOnExec((int)fileno(it), 1); return(it); } ****************** 1034,1040 **** } /* copy the value in to ensure alignment */! (void) memcpy((char *)&value, data.dptr, SOF); DEBUG(("store: (%s, %ld)\n", key.dptr, (long)value)); if (!okayvalue(value)) { DEBUG(("store: reserved bit or overflow in 0x%lx\n", value));--- 1110,1116 ---- } /* copy the value in to ensure alignment */! (void) memcpy((POINTER)&value, (POINTER)data.dptr, SOF); DEBUG(("store: (%s, %ld)\n", key.dptr, (long)value)); if (!okayvalue(value)) { DEBUG(("store: reserved bit or overflow in 0x%lx\n", value));****************** 1062,1072 ****--- 1138,1188 ---- { register int old = incore; + #ifndef MMAP incore = value;+ #endif return(old); } /*+ - dbzwritethrough - write through the pag file in core+ */+ int /* old setting */+ dbzwritethrough(value)+ int value;+ {+ register int old = writethrough;+ + writethrough = value;+ return(old);+ }+ + /*+ - dbztagmask - calculate the correct tagmask for the given base file size+ */+ long+ dbztagmask(size)+ register long size;+ {+ register long m;+ register long tagmask;+ register int i;+ + if (size <= 0)+ return(0L); /* silly size */+ + for (m = 1, i = 0; m < size; i++, m <<= 1)+ continue;+ + if (m < (1 << TAGSHIFT))+ return(0L); /* not worth tagging */+ + tagmask = (~(unsigned long)0) >> (i + 1);+ tagmask = tagmask << i;+ return(tagmask);+ }+ + /* - getconf - get configuration from .dir file */ static int /* 0 success, -1 failure */****************** 1107,1113 **** if (getno(df, &err) != dbzversion) err = -1; cp->tsize = getno(df, &err);! cp->fieldsep = getno(df, &err); while ((c = getc(df)) == ' ') continue; cp->casemap = c;--- 1223,1229 ---- if (getno(df, &err) != dbzversion) err = -1; cp->tsize = getno(df, &err);! cp->fieldsep = (int)getno(df, &err); while ((c = getc(df)) == ' ') continue; cp->casemap = c;****************** 1124,1129 ****--- 1240,1246 ---- cp->bytemap[i] = getno(df, &err); if (getc(df) != '\n') err = -1;+ #ifdef DBZDEBUG DEBUG(("size %ld, sep %d, cmap %c, tags 0x%lx/0x%lx<<%d, ", cp->tsize, cp->fieldsep, cp->casemap, cp->tagenb, cp->tagmask, cp->tagshift));****************** 1132,1137 ****--- 1249,1255 ---- DEBUG((" %d", cp->bytemap[i])); } DEBUG(("\n"));+ #endif /* second line, the usages */ for (i = 0; i < NUSEDS; i++)****************** 1201,1214 **** DEBUG(("fseek failure in putconf\n")); ret = -1; }! fprintf(f, "dbz %d %ld %d %c %ld %ld %d %d", dbzversion, cp->tsize, cp->fieldsep, cp->casemap, cp->tagenb, cp->tagmask, cp->tagshift, cp->valuesize); for (i = 0; i < cp->valuesize; i++)! fprintf(f, " %d", cp->bytemap[i]);! fprintf(f, "\n"); for (i = 0; i < NUSEDS; i++)! fprintf(f, "%ld%c", cp->used[i], (i < NUSEDS-1) ? ' ' : '\n'); (void) fflush(f); if (ferror(f))--- 1319,1332 ---- DEBUG(("fseek failure in putconf\n")); ret = -1; }! (void) fprintf(f, "dbz %d %ld %d %c %ld %ld %d %d", dbzversion, cp->tsize, cp->fieldsep, cp->casemap, cp->tagenb, cp->tagmask, cp->tagshift, cp->valuesize); for (i = 0; i < cp->valuesize; i++)! (void) fprintf(f, " %d", cp->bytemap[i]);! (void) fprintf(f, "\n"); for (i = 0; i < NUSEDS; i++)! (void) fprintf(f, "%ld%c", cp->used[i], (i < NUSEDS-1) ? ' ' : '\n'); (void) fflush(f); if (ferror(f))****************** 1229,1235 ****--- 1347,1378 ---- register size_t i; register size_t nread; register char *it;+ #ifdef MMAP+ struct stat st; + if (fstat(fileno(f), &st) == -1) {+ DEBUG(("getcore: fstat failed\n"));+ return(NULL);+ }+ if (((size_t)conf.tsize * SOF) > st.st_size) {+ /* file too small; extend it */+ if (ftruncate((int)fileno(f), conf.tsize * SOF) == -1) {+ DEBUG(("getcore: ftruncate failed\n"));+ return(NULL);+ }+ }+ it = mmap((caddr_t)0, (size_t)conf.tsize * SOF, + pagronly ? PROT_READ : PROT_WRITE | PROT_READ, MAP__ARG,+ (int)fileno(f), (off_t)0);+ if (it == (char *)-1) {+ DEBUG(("getcore: mmap failed\n"));+ return(NULL);+ }+ #ifdef MC_ADVISE+ /* not present in all versions of mmap() */+ madvise(it, (size_t)conf.tsize * SOF, MADV_RANDOM);+ #endif+ #else it = malloc((size_t)conf.tsize * SOF); if (it == NULL) { DEBUG(("getcore: malloc failed\n"));****************** 1236,1255 **** return(NULL); } ! nread = fread(it, SOF, (size_t)conf.tsize, f); if (ferror(f)) { DEBUG(("getcore: read failed\n"));! free(it); return(NULL); } p = (of_t *)it + nread; i = (size_t)conf.tsize - nread; while (i-- > 0) *p++ = VACANT; return((of_t *)it); } /* - putcore - try to rewrite an in-core table */--- 1379,1402 ---- return(NULL); } ! nread = fread((POINTER)it, SOF, (size_t)conf.tsize, f); if (ferror(f)) { DEBUG(("getcore: read failed\n"));! free((POINTER)it); return(NULL); } + /* NOSTRICT *//* Possible pointer alignment problem */ p = (of_t *)it + nread; i = (size_t)conf.tsize - nread; while (i-- > 0) *p++ = VACANT;+ #endif+ /* NOSTRICT *//* Possible pointer alignment problem */ return((of_t *)it); } + #ifndef MMAP /* - putcore - try to rewrite an in-core table */****************** 1262,1271 **** DEBUG(("fseek failure in putcore\n")); return(-1); }! (void) fwrite((char *)tab, SOF, (size_t)conf.tsize, f); (void) fflush(f); return((ferror(f)) ? -1 : 0); } /* - start - set up to start or restart a search--- 1409,1419 ---- DEBUG(("fseek failure in putcore\n")); return(-1); }! (void) fwrite((POINTER)tab, SOF, (size_t)conf.tsize, f); (void) fflush(f); return((ferror(f)) ? -1 : 0); }+ #endif /* - start - set up to start or restart a search****************** 1343,1349 **** } /* read it */! if (fread((char *)&val, sizeof(val), 1, pagf) == 1) value = MAPIN(val); else if (ferror(pagf)) { DEBUG(("search: read failed\n"));--- 1491,1497 ---- } /* read it */! if (fread((POINTER)&val, sizeof(val), 1, pagf) == 1) value = MAPIN(val); else if (ferror(pagf)) { DEBUG(("search: read failed\n"));****************** 1425,1436 **** if (corepag != NULL && place < conf.tsize) { corepag[place] = value; DEBUG(("set: incore\n")); return(0); } /* seek to spot */ pagpos = -1; /* invalidate position memory */! if (fseek(pagf, place * SOF, SEEK_SET) != 0) { DEBUG(("set: seek failed\n")); sp->aborted = 1; return(-1);--- 1573,1589 ---- if (corepag != NULL && place < conf.tsize) { corepag[place] = value; DEBUG(("set: incore\n"));+ #ifdef MMAP return(0);+ #else+ if (!writethrough)+ return(0);+ #endif } /* seek to spot */ pagpos = -1; /* invalidate position memory */! if (fseek(pagf, (of_t)(place * SOF), SEEK_SET) != 0) { DEBUG(("set: seek failed\n")); sp->aborted = 1; return(-1);****************** 1437,1443 **** } /* write in data */! if (fwrite((char *)&value, SOF, 1, pagf) != 1) { DEBUG(("set: write failed\n")); sp->aborted = 1; return(-1);--- 1590,1596 ---- } /* write in data */! if (fwrite((POINTER)&value, SOF, 1, pagf) != 1) { DEBUG(("set: write failed\n")); sp->aborted = 1; return(-1);****************** 1474,1479 ****--- 1627,1633 ---- u.o = 1; for (ntodo = (int)SOF; ntodo > 0; ntodo--) { for (i = 0; i < SOF; i++)+ /* SUPPRESS 112 *//* Retrieving char where long is stored */ if (u.c[i] != 0) break; if (i == SOF) {****************** 1485,1490 ****--- 1639,1645 ---- } DEBUG(("mybytemap: byte %d\n", i)); *--mp = i;+ /* SUPPRESS 112 *//* Retrieving char where long is stored */ while (u.c[i] != 0) u.o <<= 1; }****************** 1728,1747 **** switch (conf.casemap) { case '0': /* unmapped, sensible */ return(NULL);- break; case 'C': /* C News, RFC 822 conformant (approx.) */! p = memchr(s, '@', siz); if (p == NULL) /* no local/domain split */ return(NULL); /* assume all local */! else if (p - (s+1) == plen && CISTREQN(s+1, post, plen)) { /* crazy -- "postmaster" is case-insensitive */ return(s);! } else! return(p);! break; case '=': /* 2.11, neither sensible nor conformant */ return(s); /* all case-insensitive */- break; } DEBUG(("cipoint: unknown case mapping `%c'\n", conf.casemap));--- 1883,1899 ---- switch (conf.casemap) { case '0': /* unmapped, sensible */ return(NULL); case 'C': /* C News, RFC 822 conformant (approx.) */! p = memchr((POINTER)s, '@', siz); if (p == NULL) /* no local/domain split */ return(NULL); /* assume all local */! if (p - (s+1) == plen && CISTREQN(s+1, post, plen)) { /* crazy -- "postmaster" is case-insensitive */ return(s);! }! return(p); case '=': /* 2.11, neither sensible nor conformant */ return(s); /* all case-insensitive */ } DEBUG(("cipoint: unknown case mapping `%c'\n", conf.casemap));****************** 1751,1766 **** /* - dbzdebug - control dbz debugging at run time */ int /* old value */ dbzdebug(value) int value; {- #ifdef DBZDEBUG register int old = debug; debug = value; return(old);- #else- return(-1);- #endif }--- 1903,1916 ---- /* - dbzdebug - control dbz debugging at run time */+ #ifdef DBZDEBUG int /* old value */ dbzdebug(value) int value; { register int old = debug; debug = value; return(old); }+ #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -