X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fdropsbr.c;h=868127769329f388245b5af04025d5ce9e11984e;hb=d3ba09a465cb0e5fc9a74d0b152a7ed965f895cb;hp=0e3ce193060ca7299f22f302113029e394e508dc;hpb=a485ed478abbd599d8c9aab48934e7a26733ecb1;p=mmh diff --git a/uip/dropsbr.c b/uip/dropsbr.c index 0e3ce19..8681277 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -1,10 +1,10 @@ /* - * dropsbr.c -- create/read/manipulate mail drops - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ +** dropsbr.c -- create/read/manipulate mail drops +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ #include #include @@ -28,20 +28,20 @@ #include /* - * static prototypes - */ -static int mbx_chk_mbox (int); -static int mbx_chk_mmdf (int); -static int map_open (char *, int); +** static prototypes +*/ +static int mbx_chk_mbox(int); +static int mbx_chk_mmdf(int); +static int map_open(char *, int); /* - * Main entry point to open/create and lock - * a file or maildrop. - */ +** Main entry point to open/create and lock +** a file or maildrop. +*/ int -mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode) +mbx_open(char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode) { int j, count, fd; struct stat st; @@ -50,24 +50,25 @@ mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode) /* attempt to open and lock file */ for (count = 4; count > 0; count--) { - if ((fd = lkopen (file, O_RDWR | O_CREAT | O_NONBLOCK, mode)) == NOTOK) { + if ((fd = lkopen(file, O_RDWR | O_CREAT | O_NONBLOCK, mode)) + == NOTOK) { switch (errno) { #if defined(FCNTL_LOCKING) || defined(LOCKF_LOCKING) - case EACCES: - case EAGAIN: + case EACCES: + case EAGAIN: #endif #ifdef FLOCK_LOCKING - case EWOULDBLOCK: + case EWOULDBLOCK: #endif - case ETXTBSY: - j = errno; - sleep (5); - break; + case ETXTBSY: + j = errno; + sleep(5); + break; - default: - /* just return error */ - return NOTOK; + default: + /* just return error */ + return NOTOK; } } @@ -78,40 +79,40 @@ mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode) errno = j; /* - * Return if we still failed after 4 attempts, - * or we just want to skip the sanity checks. - */ + ** Return if we still failed after 4 attempts, + ** or we just want to skip the sanity checks. + */ if (fd == NOTOK || mbx_style == OTHER_FORMAT) return fd; /* - * Do sanity checks on maildrop. - */ - if (fstat (fd, &st) == NOTOK) { + ** Do sanity checks on maildrop. + */ + if (fstat(fd, &st) == NOTOK) { /* - * The stat failed. So we make sure file - * has right ownership/modes - */ - chown (file, uid, gid); - chmod (file, mode); + ** The stat failed. So we make sure file + ** has right ownership/modes + */ + chown(file, uid, gid); + chmod(file, mode); } else if (st.st_size > (off_t) 0) { int status; /* check the maildrop */ switch (mbx_style) { - case MMDF_FORMAT: - default: - status = mbx_chk_mmdf (fd); - break; + case MMDF_FORMAT: + default: + status = mbx_chk_mmdf(fd); + break; - case MBOX_FORMAT: - status = mbx_chk_mbox (fd); - break; + case MBOX_FORMAT: + status = mbx_chk_mbox(fd); + break; } /* if error, attempt to close it */ if (status == NOTOK) { - close (fd); + close(fd); return NOTOK; } } @@ -121,14 +122,14 @@ mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode) /* - * Check/prepare MBOX style maildrop for appending. - */ +** Check/prepare MBOX style maildrop for appending. +*/ static int -mbx_chk_mbox (int fd) +mbx_chk_mbox(int fd) { /* just seek to the end */ - if (lseek (fd, (off_t) 0, SEEK_END) == (off_t) NOTOK) + if (lseek(fd, (off_t) 0, SEEK_END) == (off_t) NOTOK) return NOTOK; return OK; @@ -136,28 +137,27 @@ mbx_chk_mbox (int fd) /* - * Check/prepare MMDF style maildrop for appending. - */ +** Check/prepare MMDF style maildrop for appending. +*/ static int -mbx_chk_mmdf (int fd) +mbx_chk_mmdf(int fd) { size_t count; char ldelim[BUFSIZ]; - count = strlen (mmdlm2); + count = strlen(mmdlm2); /* casting -count to off_t, seem to break FreeBSD 2.2.6 */ - if (lseek (fd, (long) (-count), SEEK_END) == (off_t) NOTOK) + if (lseek(fd, (long) (-count), SEEK_END) == (off_t) NOTOK) return NOTOK; - if (read (fd, ldelim, count) != count) + if (read(fd, ldelim, count) != count) return NOTOK; ldelim[count] = 0; - if (strcmp (ldelim, mmdlm2) - && write (fd, "\n", 1) != 1 - && write (fd, mmdlm2, count) != count) + if (strcmp(ldelim, mmdlm2)!=0 && write(fd, "\n", 1) != 1 + && write(fd, mmdlm2, count) != count) return NOTOK; return OK; @@ -165,7 +165,7 @@ mbx_chk_mmdf (int fd) int -mbx_read (FILE *fp, long pos, struct drop **drops, int noisy) +mbx_read(FILE *fp, long pos, struct drop **drops, int noisy) { register int len, size; register long ld1, ld2; @@ -173,33 +173,33 @@ mbx_read (FILE *fp, long pos, struct drop **drops, int noisy) char buffer[BUFSIZ]; register struct drop *cp, *dp, *ep, *pp; - pp = (struct drop *) calloc ((size_t) (len = MAXFOLDER), sizeof(*dp)); + pp = (struct drop *) calloc((size_t) (len = MAXFOLDER), sizeof(*dp)); if (pp == NULL) { if (noisy) - admonish (NULL, "unable to allocate drop storage"); + admonish(NULL, "unable to allocate drop storage"); return NOTOK; } - ld1 = (long) strlen (mmdlm1); - ld2 = (long) strlen (mmdlm2); + ld1 = (long) strlen(mmdlm1); + ld2 = (long) strlen(mmdlm2); - fseek (fp, pos, SEEK_SET); - for (ep = (dp = pp) + len - 1; fgets (buffer, sizeof(buffer), fp);) { + fseek(fp, pos, SEEK_SET); + for (ep = (dp = pp) + len - 1; fgets(buffer, sizeof(buffer), fp);) { size = 0; - if (strcmp (buffer, mmdlm1) == 0) + if (strcmp(buffer, mmdlm1) == 0) pos += ld1, dp->d_start = (long) pos; else { - dp->d_start = (long)pos , pos += (long) strlen (buffer); + dp->d_start = (long)pos , pos += (long) strlen(buffer); for (bp = buffer; *bp; bp++, size++) if (*bp == '\n') size++; } - while (fgets (buffer, sizeof(buffer), fp) != NULL) - if (strcmp (buffer, mmdlm2) == 0) + while (fgets(buffer, sizeof(buffer), fp) != NULL) + if (strcmp(buffer, mmdlm2) == 0) break; else { - pos += (long) strlen (buffer); + pos += (long) strlen(buffer); for (bp = buffer; *bp; bp++, size++) if (*bp == '\n') size++; @@ -216,17 +216,18 @@ mbx_read (FILE *fp, long pos, struct drop **drops, int noisy) if (dp >= ep) { register int curlen = dp - pp; - cp = (struct drop *) mh_xrealloc ((char *) pp, - (size_t) (len += MAXFOLDER) * sizeof(*pp)); + cp = (struct drop *) mh_xrealloc((char *) pp, + (size_t) (len += MAXFOLDER) * + sizeof(*pp)); dp = cp + curlen, ep = (pp = cp) + len - 1; } } if (dp == pp) - free ((char *) pp); + free((char *) pp); else *drops = pp; - return (dp - pp); + return(dp - pp); } @@ -240,21 +241,21 @@ mbx_write(char *mailbox, int md, FILE *fp, int id, long last, register char *cp; char buffer[BUFSIZ]; - off = (long) lseek (md, (off_t) 0, SEEK_CUR); - j = strlen (mmdlm1); - if (write (md, mmdlm1, j) != j) + off = (long) lseek(md, (off_t) 0, SEEK_CUR); + j = strlen(mmdlm1); + if (write(md, mmdlm1, j) != j) return NOTOK; - start = lseek (md, (off_t) 0, SEEK_CUR); + start = lseek(md, (off_t) 0, SEEK_CUR); size = 0; - fseek (fp, pos, SEEK_SET); - while (fgets (buffer, sizeof(buffer), fp) && (pos < stop)) { - i = strlen (buffer); - for (j = 0; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++) + fseek(fp, pos, SEEK_SET); + while (fgets(buffer, sizeof(buffer), fp) && (pos < stop)) { + i = strlen(buffer); + for (j = 0; (j = stringdex(mmdlm1, buffer)) >= 0; buffer[j]++) continue; - for (j = 0; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++) + for (j = 0; (j = stringdex(mmdlm2, buffer)) >= 0; buffer[j]++) continue; - if (write (md, buffer, i) != i) + if (write(md, buffer, i) != i) return NOTOK; pos += (long) i; if (mapping) @@ -263,24 +264,25 @@ mbx_write(char *mailbox, int md, FILE *fp, int id, long last, size++; } - stop = lseek (md, (off_t) 0, SEEK_CUR); - j = strlen (mmdlm2); - if (write (md, mmdlm2, j) != j) + stop = lseek(md, (off_t) 0, SEEK_CUR); + j = strlen(mmdlm2); + if (write(md, mmdlm2, j) != j) return NOTOK; if (mapping) - map_write (mailbox, md, id, last, start, stop, off, size, noisy); + map_write(mailbox, md, id, last, start, stop, off, size, + noisy); return OK; } /* - * Append message to end of file or maildrop. - */ +** Append message to end of file or maildrop. +*/ int -mbx_copy (char *mailbox, int mbx_style, int md, int fd, - int mapping, char *text, int noisy) +mbx_copy(char *mailbox, int mbx_style, int md, int fd, int mapping, + char *text, int noisy) { int i, j, size; off_t start, stop; @@ -288,241 +290,249 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, char *cp, buffer[BUFSIZ]; FILE *fp; - pos = (long) lseek (md, (off_t) 0, SEEK_CUR); + pos = (long) lseek(md, (off_t) 0, SEEK_CUR); size = 0; switch (mbx_style) { - case MMDF_FORMAT: - default: - j = strlen (mmdlm1); - if (write (md, mmdlm1, j) != j) - return NOTOK; - start = lseek (md, (off_t) 0, SEEK_CUR); - - if (text) { - i = strlen (text); - if (write (md, text, i) != i) - return NOTOK; - for (cp = text; *cp++; size++) - if (*cp == '\n') - size++; - } + case MMDF_FORMAT: + default: + j = strlen(mmdlm1); + if (write(md, mmdlm1, j) != j) + return NOTOK; + start = lseek(md, (off_t) 0, SEEK_CUR); - while ((i = read (fd, buffer, sizeof(buffer))) > 0) { - for (j = 0; - (j = stringdex (mmdlm1, buffer)) >= 0; - buffer[j]++) - continue; - for (j = 0; - (j = stringdex (mmdlm2, buffer)) >= 0; - buffer[j]++) - continue; - if (write (md, buffer, i) != i) - return NOTOK; - if (mapping) - for (cp = buffer; i-- > 0; size++) - if (*cp++ == '\n') - size++; - } + if (text) { + i = strlen(text); + if (write(md, text, i) != i) + return NOTOK; + for (cp = text; *cp++; size++) + if (*cp == '\n') + size++; + } - stop = lseek (md, (off_t) 0, SEEK_CUR); - j = strlen (mmdlm2); - if (write (md, mmdlm2, j) != j) + while ((i = read(fd, buffer, sizeof(buffer))) > 0) { + for (j = 0; (j = stringdex(mmdlm1, buffer)) >= 0; buffer[j]++) + continue; + for (j = 0; (j = stringdex(mmdlm2, buffer)) >= 0; buffer[j]++) + continue; + if (write(md, buffer, i) != i) return NOTOK; if (mapping) - map_write (mailbox, md, 0, (long) 0, start, stop, pos, size, noisy); + for (cp = buffer; i-- > 0; size++) + if (*cp++ == '\n') + size++; + } - return (i != NOTOK ? OK : NOTOK); + stop = lseek(md, (off_t) 0, SEEK_CUR); + j = strlen(mmdlm2); + if (write(md, mmdlm2, j) != j) + return NOTOK; + if (mapping) + map_write(mailbox, md, 0, (long) 0, start, stop, pos, + size, noisy); - case MBOX_FORMAT: - if ((j = dup (fd)) == NOTOK) - return NOTOK; - if ((fp = fdopen (j, "r")) == NULL) { - close (j); - return NOTOK; - } - start = lseek (md, (off_t) 0, SEEK_CUR); + return (i != NOTOK ? OK : NOTOK); - /* If text is given, we add it to top of message */ - if (text) { - i = strlen (text); - if (write (md, text, i) != i) - return NOTOK; - for (cp = text; *cp++; size++) - if (*cp == '\n') - size++; - } + case MBOX_FORMAT: + if ((j = dup(fd)) == NOTOK) + return NOTOK; + if ((fp = fdopen(j, "r")) == NULL) { + close(j); + return NOTOK; + } + start = lseek(md, (off_t) 0, SEEK_CUR); - for (j = 0; fgets (buffer, sizeof(buffer), fp) != NULL; j++) { + /* If text is given, we add it to top of message */ + if (text) { + i = strlen(text); + if (write(md, text, i) != i) + return NOTOK; + for (cp = text; *cp++; size++) + if (*cp == '\n') + size++; + } + for (j = 0; fgets(buffer, sizeof(buffer), fp) != NULL; j++) { + /* + ** Check the first line, and make some changes. + */ + if (j == 0 && !text) { /* - * Check the first line, and make some changes. - */ - if (j == 0 && !text) { + ** Change the "Return-Path:" field + ** (if in first line) back to "From ". + */ + if (strncmp(buffer, "Return-Path:", 12)==0) { + char tmpbuffer[BUFSIZ]; + char *tp, *ep, *fp; + + strncpy(tmpbuffer, buffer, + sizeof(tmpbuffer)); + ep = tmpbuffer + 13; + if (!(fp = strchr(ep + 1, ' '))) + fp = strchr(ep + 1, '\n'); + tp = dctime(dlocaltimenow()); + snprintf(buffer, sizeof(buffer), "From %.*s %s", (int)(fp - ep), ep, tp); + } else if (strncmp(buffer, "X-Envelope-From:", + 16)==0) { + /* + ** Change the "X-Envelope-From:" + ** field (if first line) back + ** to "From ". + */ + char tmpbuffer[BUFSIZ]; + char *ep; + + strncpy(tmpbuffer, buffer, + sizeof(tmpbuffer)); + ep = tmpbuffer + 17; + snprintf(buffer, sizeof(buffer), + "From %s", ep); + } else if (strncmp(buffer, "From ", 5)!=0) { /* - * Change the "Return-Path:" field (if in first line) - * back to "From ". - */ - if (!strncmp (buffer, "Return-Path:", 12)) { - char tmpbuffer[BUFSIZ]; - char *tp, *ep, *fp; - - strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); - ep = tmpbuffer + 13; - if (!(fp = strchr(ep + 1, ' '))) - fp = strchr(ep + 1, '\n'); - tp = dctime(dlocaltimenow()); - snprintf (buffer, sizeof(buffer), "From %.*s %s", - (int)(fp - ep), ep, tp); - } else if (!strncmp (buffer, "X-Envelope-From:", 16)) { - /* - * Change the "X-Envelope-From:" field - * (if first line) back to "From ". - */ - char tmpbuffer[BUFSIZ]; - char *ep; - - strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); - ep = tmpbuffer + 17; - snprintf (buffer, sizeof(buffer), "From %s", ep); - } else if (strncmp (buffer, "From ", 5)) { - /* - * If there is already a "From " line, - * then leave it alone. Else we add one. - */ - char tmpbuffer[BUFSIZ]; - char *tp, *ep; - - strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); - ep = "nobody@nowhere"; - tp = dctime(dlocaltimenow()); - snprintf (buffer, sizeof(buffer), "From %s %s%s", ep, tp, tmpbuffer); - } + ** If there is already a "From " + ** line, then leave it alone. + ** Else we add one. + */ + char tmpbuffer[BUFSIZ]; + char *tp, *ep; + + strncpy(tmpbuffer, buffer, + sizeof(tmpbuffer)); + ep = "nobody@nowhere"; + tp = dctime(dlocaltimenow()); + snprintf(buffer, sizeof(buffer), + "From %s %s%s", + ep, tp, tmpbuffer); } + } - /* - * If this is not first line, and begins with - * "From ", then prepend line with ">". - */ - if (j != 0 && strncmp (buffer, "From ", 5) == 0) { - write (md, ">", 1); - size++; - } - i = strlen (buffer); - if (write (md, buffer, i) != i) { - fclose (fp); - return NOTOK; - } - if (mapping) - for (cp = buffer; i-- > 0; size++) - if (*cp++ == '\n') - size++; + /* + ** If this is not first line, and begins with + ** "From ", then prepend line with ">". + */ + if (j != 0 && strncmp(buffer, "From ", 5) == 0) { + write(md, ">", 1); + size++; } - if (write (md, "\n", 1) != 1) { - fclose (fp); + i = strlen(buffer); + if (write(md, buffer, i) != i) { + fclose(fp); return NOTOK; } if (mapping) - size += 2; + for (cp = buffer; i-- > 0; size++) + if (*cp++ == '\n') + size++; + } + if (write(md, "\n", 1) != 1) { + fclose(fp); + return NOTOK; + } + if (mapping) + size += 2; - fclose (fp); - lseek (fd, (off_t) 0, SEEK_END); - stop = lseek (md, (off_t) 0, SEEK_CUR); - if (mapping) - map_write (mailbox, md, 0, (long) 0, start, stop, pos, size, noisy); + fclose(fp); + lseek(fd, (off_t) 0, SEEK_END); + stop = lseek(md, (off_t) 0, SEEK_CUR); + if (mapping) + map_write(mailbox, md, 0, (long) 0, start, stop, pos, + size, noisy); - return OK; + return OK; } } int -mbx_size (int md, off_t start, off_t stop) +mbx_size(int md, off_t start, off_t stop) { register int i, fd; register long pos; register FILE *fp; - if ((fd = dup (md)) == NOTOK || (fp = fdopen (fd, "r")) == NULL) { + if ((fd = dup(md)) == NOTOK || (fp = fdopen(fd, "r")) == NULL) { if (fd != NOTOK) - close (fd); + close(fd); return NOTOK; } - fseek (fp, start, SEEK_SET); + fseek(fp, start, SEEK_SET); for (i = 0, pos = stop - start; pos-- > 0; i++) - if (fgetc (fp) == '\n') + if (fgetc(fp) == '\n') i++; - fclose (fp); + fclose(fp); return i; } /* - * Close and unlock file/maildrop. - */ +** Close and unlock file/maildrop. +*/ int -mbx_close (char *mailbox, int md) +mbx_close(char *mailbox, int md) { - if (lkclose (md, mailbox) == 0) + if (lkclose(md, mailbox) == 0) return OK; return NOTOK; } /* - * This function is performed implicitly by getbbent.c: - * bb->bb_map = map_name (bb->bb_file); - */ +** This function is performed implicitly by getbbent.c: +** bb->bb_map = map_name(bb->bb_file); +*/ char * -map_name (char *file) +map_name(char *file) { register char *cp, *dp; static char buffer[BUFSIZ]; - if ((dp = strchr(cp = r1bindex (file, '/'), '.')) == NULL) - dp = cp + strlen (cp); + if ((dp = strchr(cp = mhbasename(file), '.')) == NULL) + dp = cp + strlen(cp); if (cp == file) - snprintf (buffer, sizeof(buffer), ".%.*s%s", (int)(dp - cp), cp, ".map"); + snprintf(buffer, sizeof(buffer), ".%.*s%s", + (int)(dp - cp), cp, ".map"); else snprintf (buffer, sizeof(buffer), "%.*s.%.*s%s", - (int)(cp - file), file, (int)(dp - cp), cp, ".map"); + (int)(cp - file), file, (int)(dp - cp), + cp, ".map"); return buffer; } int -map_read (char *file, long pos, struct drop **drops, int noisy) +map_read(char *file, long pos, struct drop **drops, int noisy) { register int i, md, msgp; register char *cp; struct drop d; register struct drop *mp, *dp; - if ((md = open (cp = map_name (file), O_RDONLY)) == NOTOK - || map_chk (cp, md, mp = &d, pos, noisy)) { + if ((md = open(cp = map_name(file), O_RDONLY)) == NOTOK + || map_chk(cp, md, mp = &d, pos, noisy)) { if (md != NOTOK) - close (md); + close(md); return 0; } msgp = mp->d_id; - dp = (struct drop *) calloc ((size_t) (msgp + 1), sizeof(*dp)); + dp = (struct drop *) calloc((size_t) (msgp + 1), sizeof(*dp)); if (dp == NULL) { - close (md); + close(md); return 0; } memcpy((char *) dp, (char *) mp, sizeof(*dp)); - lseek (md, (off_t) sizeof(*mp), SEEK_SET); - if ((i = read (md, (char *) (dp + 1), msgp * sizeof(*dp))) < sizeof(*dp)) { + lseek(md, (off_t) sizeof(*mp), SEEK_SET); + if ((i = read(md, (char *) (dp + 1), msgp * sizeof(*dp))) < + sizeof(*dp)) { i = 0; - free ((char *) dp); + free((char *) dp); } else { #ifdef NTOHLSWAP register struct drop *tdp; @@ -538,14 +548,14 @@ map_read (char *file, long pos, struct drop **drops, int noisy) *drops = dp; } - close (md); + close(md); return (i / sizeof(*dp)); } int -map_write (char *mailbox, int md, int id, long last, off_t start, +map_write(char *mailbox, int md, int id, long last, off_t start, off_t stop, long pos, int size, int noisy) { register int i; @@ -556,74 +566,76 @@ map_write (char *mailbox, int md, int id, long last, off_t start, register FILE *fp; struct stat st; - if ((fd = map_open (file = map_name (mailbox), md)) == NOTOK) + if ((fd = map_open(file = map_name(mailbox), md)) == NOTOK) return NOTOK; - if ((fstat (fd, &st) == OK) && (st.st_size > 0)) + if ((fstat(fd, &st) == OK) && (st.st_size > 0)) clear = 0; else clear = 1; - if (!clear && map_chk (file, fd, &d1, pos, noisy)) { - unlink (file); - mbx_close (file, fd); - if ((fd = map_open (file, md)) == NOTOK) + if (!clear && map_chk(file, fd, &d1, pos, noisy)) { + unlink(file); + mbx_close(file, fd); + if ((fd = map_open(file, md)) == NOTOK) return NOTOK; clear++; } if (clear) { - if ((td = dup (md)) == NOTOK || (fp = fdopen (td, "r")) == NULL) { + if ((td = dup(md)) == NOTOK || + (fp = fdopen(td, "r")) == NULL) { if (noisy) - admonish (file, "unable to %s", td != NOTOK ? "fdopen" : "dup"); + admonish(file, "unable to %s", td != NOTOK ? + "fdopen" : "dup"); if (td != NOTOK) - close (td); - mbx_close (file, fd); + close(td); + mbx_close(file, fd); return NOTOK; } - switch (i = mbx_read (fp, 0, &rp, noisy)) { - case NOTOK: - fclose (fp); - mbx_close (file, fd); - return NOTOK; + switch (i = mbx_read(fp, 0, &rp, noisy)) { + case NOTOK: + fclose(fp); + mbx_close(file, fd); + return NOTOK; - case OK: - fclose (fp); - break; + case OK: + fclose(fp); + break; - default: - d1.d_id = 0; - for (dp = rp; i-- >0; dp++) { - if (dp->d_start == start) - dp->d_id = id; - lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); - if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { - if (noisy) - admonish (file, "write error"); - mbx_close (file, fd); - fclose (fp); - return NOTOK; - } + default: + d1.d_id = 0; + for (dp = rp; i-- >0; dp++) { + if (dp->d_start == start) + dp->d_id = id; + lseek(fd, (off_t) (++d1.d_id * sizeof(*dp)), + SEEK_SET); + if (write(fd, (char *)dp, sizeof(*dp)) != sizeof(*dp)) { + if (noisy) + admonish(file, "write error"); + mbx_close(file, fd); + fclose(fp); + return NOTOK; } - free ((char *) rp); - fclose (fp); - break; + } + free((char *) rp); + fclose(fp); + break; } - } - else { + } else { if (last == 0) last = d1.d_start; dp = &d2; dp->d_id = id; - dp->d_size = (long) (size ? size : mbx_size (fd, start, stop)); + dp->d_size = (long) (size ? size : mbx_size(fd, start, stop)); dp->d_start = start; dp->d_stop = stop; - lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); - if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { + lseek(fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); + if (write(fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { if (noisy) - admonish (file, "write error"); - mbx_close (file, fd); + admonish(file, "write error"); + mbx_close(file, fd); return NOTOK; } } @@ -631,43 +643,44 @@ map_write (char *mailbox, int md, int id, long last, off_t start, dp = &d1; dp->d_size = DRVRSN; dp->d_start = (long) last; - dp->d_stop = lseek (md, (off_t) 0, SEEK_CUR); + dp->d_stop = lseek(md, (off_t) 0, SEEK_CUR); - lseek (fd, (off_t) 0, SEEK_SET); - if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { + lseek(fd, (off_t) 0, SEEK_SET); + if (write(fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { if (noisy) - admonish (file, "write error"); - mbx_close (file, fd); + admonish(file, "write error"); + mbx_close(file, fd); return NOTOK; } - mbx_close (file, fd); + mbx_close(file, fd); return OK; } static int -map_open (char *file, int md) +map_open(char *file, int md) { mode_t mode; struct stat st; - mode = fstat (md, &st) != NOTOK ? (mode_t) (st.st_mode & 0777) : m_gmprot (); - return mbx_open (file, OTHER_FORMAT, st.st_uid, st.st_gid, mode); + mode = fstat(md, &st) != NOTOK ? + (mode_t) (st.st_mode & 0777) : m_gmprot(); + return mbx_open(file, OTHER_FORMAT, st.st_uid, st.st_gid, mode); } int -map_chk (char *file, int fd, struct drop *dp, long pos, int noisy) +map_chk(char *file, int fd, struct drop *dp, long pos, int noisy) { long count; struct drop d, tmpd; register struct drop *dl; - if (read (fd, (char *) &tmpd, sizeof(*dp)) != sizeof(*dp)) { + if (read(fd, (char *) &tmpd, sizeof(*dp)) != sizeof(*dp)) { #ifdef notdef - admonish (NULL, "%s: missing or partial index", file); + admonish(NULL, "%s: missing or partial index", file); #endif /* notdef */ return NOTOK; } @@ -682,33 +695,31 @@ map_chk (char *file, int fd, struct drop *dp, long pos, int noisy) if (dp->d_size != DRVRSN) { if (noisy) - admonish (NULL, "%s: version mismatch (%d != %d)", - file, dp->d_size, DRVRSN); + admonish(NULL, "%s: version mismatch (%d != %d)", + file, dp->d_size, DRVRSN); return NOTOK; } if (dp->d_stop != pos) { if (noisy && pos != (long) 0) - admonish (NULL, - "%s: pointer mismatch or incomplete index (%ld!=%ld)", - file, dp->d_stop, (long) pos); + admonish(NULL, "%s: pointer mismatch or incomplete index (%ld!=%ld)", file, dp->d_stop, (long) pos); return NOTOK; } - if ((long) ((dp->d_id + 1) * sizeof(*dp)) != (long) lseek (fd, (off_t) 0, SEEK_END)) { + if ((long) ((dp->d_id + 1) * sizeof(*dp)) != (long) lseek(fd, (off_t) 0, SEEK_END)) { if (noisy) - admonish (NULL, "%s: corrupt index(1)", file); + admonish(NULL, "%s: corrupt index(1)", file); return NOTOK; } dl = &d; - count = (long) strlen (mmdlm2); - lseek (fd, (off_t) (dp->d_id * sizeof(*dp)), SEEK_SET); - if (read (fd, (char *) dl, sizeof(*dl)) != sizeof(*dl) + count = (long) strlen(mmdlm2); + lseek(fd, (off_t) (dp->d_id * sizeof(*dp)), SEEK_SET); + if (read(fd, (char *) dl, sizeof(*dl)) != sizeof(*dl) || (ntohl(dl->d_stop) != dp->d_stop && ntohl(dl->d_stop) + count != dp->d_stop)) { if (noisy) - admonish (NULL, "%s: corrupt index(2)", file); + admonish(NULL, "%s: corrupt index(2)", file); return NOTOK; }