9 date 93.08.25.17.31.30; author jromine; state Exp;
14 date 93.08.25.17.31.03; author jromine; state Exp;
25 @off_t fixes for BSD44
28 @/* uminc.c - uucp to mmdf inc */
30 static char Id[] = "@@(#)$Id:$";
35 #include "../mts/mts.h"
37 #include <sys/types.h>
41 static int mmdf = NOTOK;
42 static int uucp = NOTOK;
43 static char mmdfbox[LINESIZ];
44 static char uucpbox[LINESIZ];
61 sprintf (uucpbox, "%s/%s", UUCPDIR, UUCPFIL);
62 if (stat (uucpbox, &st1) == NOTOK || st1.st_size == 0L)
64 if ((uucp = lkopen (uucpbox, 0)) == NOTOK)
65 die ("unable to lock and open %s", uucpbox);
68 switch (fd = uucp2mmdf (uucp, fd, FALSE)) {
73 die ("internal error while filtering UUCP mail");
76 die ("no free file pointers -- you lose");
79 die ("i/o error while filtering UUCP mail");
84 fprintf (stderr, "UUCP mailbox in bad format, patched...\n");
88 sprintf (mmdfbox, "%s/%s", MAILDIR, MAILFIL);
89 mmdf = mbx_open (mmdfbox);
92 lkclose (mmdf, mmdfbox), mmdf = NOTOK;
94 if (stat (uucpbox, &st2) != NOTOK && st1.st_mtime != st2.st_mtime)
95 fprintf (stderr, "UUCP mailbox has been updated... (%s)\n",
96 "so it won't be removed");
98 if (unlink (uucpbox) == NOTOK)
99 if ((fd = creat (uucpbox, st1.st_mode & ~S_IFMT)) != NOTOK)
102 fprintf (stderr, "unable to remove or zero UUCP mailbox\n");
103 lkclose (uucp, uucpbox), uucp = NOTOK;
110 static int mbx_open (file)
119 for (clear = FALSE, count = 2; count > 0; count--)
120 if ((fd = lkopen (file, 6)) == NOTOK)
135 if (fstat (fd, &stbuf) == NOTOK)
136 die ("unable to stat MMDF mailbox '%s'", file);
137 clear = stbuf.st_size == 0L;
143 if (errno == ETXTBSY)
144 die ("your MMDF mailbox '%s' is busy", file);
146 die ("unable to open MMDF mailbox '%s'", file);
156 static mbx_create (file)
161 if ((fd = creat (file, MBXMODE)) == NOTOK)
162 die ("unable to create MMDF mailbox '%s'", file);
168 static mbx_chk (fd, file)
175 count = strlen (mmdlm2);
177 if (lseek (fd, (off_t) - count, 2) == (off_t) NOTOK
178 || read (fd, ldelim, count) != count)
179 die ("error reading MMDF mailbox '%s'", file);
180 ldelim[count] = NULL;
182 if (strcmp (ldelim, mmdlm2)) {
184 "MMDF mailbox '%s' has bad delimiter, patching...\n",
186 if (write (fd, mmdlm2, count) != count)
187 die ("error writing MMDF mailbox '%s'", file);
193 static mbx_copy (in, out)
200 lseek (in, (off_t)0, 0);
202 while ((i = read (in, buffer, sizeof buffer)) > 0)
203 if (write (out, buffer, i) != i)
204 die ("error writing MMDF mailbox");
206 die ("error reading temporary file");
214 static int tmp_open (mbx_fd)
218 char tmpfil[LINESIZ];
220 strcpy (tmpfil, "/tmp/umincXXXXXX");
221 unlink (mktemp (tmpfil));
222 if ((fd = creat (tmpfil, TMPMODE)) == NOTOK)
223 die ("unable to create temporary file '%s'", tmpfil);
226 if ((fd = open (tmpfil, 2)) == NOTOK)
227 die ("unable to create temporary file '%s'", tmpfil);
230 if ((*mbx_fd = dup (fd)) == NOTOK)
231 die ("unable to duplicate fd for temporary file '%s'", tmpfil);
238 static die (fmt, a, b, c, d)
245 lkclose (mmdf, mmdfbox), mmdf = NOTOK;
246 lkclose (uucp, uucpbox), uucp = NOTOK;
249 fprintf (stderr, fmt, a, b, c, d);
268 if (lseek (fd, (long) - count, 2) == (long) NOTOK