- if (mapping)
- 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);
-
- return OK;
- }
-}
-
-
-int
-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 != NOTOK)
- close (fd);
- return NOTOK;
- }
-
- fseek (fp, start, SEEK_SET);
- for (i = 0, pos = stop - start; pos-- > 0; i++)
- if (fgetc (fp) == '\n')
- i++;
-
- fclose (fp);
- return i;
-}
-
-
-/*
- * Close and unlock file/maildrop.
- */
-
-int
-mbx_close (char *mailbox, int md)
-{
- lkclose (md, mailbox);
- return OK;
-}
-
-
-/*
- * This function is performed implicitly by getbbent.c:
- * bb->bb_map = map_name (bb->bb_file);
- */
-
-char *
-map_name (char *file)
-{
- register char *cp, *dp;
- static char buffer[BUFSIZ];
-
- if ((dp = strchr(cp = r1bindex (file, '/'), '.')) == NULL)
- dp = cp + strlen (cp);
- if (cp == file)
- snprintf (buffer, sizeof(buffer), ".%.*s%s", dp - cp, cp, ".map");
- else
- snprintf (buffer, sizeof(buffer), "%.*s.%.*s%s",
- cp - file, file, dp - cp, cp, ".map");
-
- return buffer;
-}
-
-
-int
-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 != NOTOK)
- close (md);
- return 0;
- }
-
- msgp = mp->d_id;
- dp = (struct drop *) calloc ((size_t) (msgp + 1), sizeof(*dp));
- if (dp == NULL) {
- 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)) {
- i = 0;
- free ((char *) dp);
- } else {
-#ifdef NTOHLSWAP
- register struct drop *tdp;
- int j;
-
- for (j = 0, tdp = dp; j < i / sizeof(*dp); j++, tdp++) {
- tdp->d_id = ntohl(tdp->d_id);
- tdp->d_size = ntohl(tdp->d_size);
- tdp->d_start = ntohl(tdp->d_start);
- tdp->d_stop = ntohl(tdp->d_stop);