9 date 93.08.25.17.30.36; author jromine; state Exp;
14 date 93.08.25.17.30.10; author jromine; state Exp;
25 @off_t fixes for BSD44
28 @/* muinc.c - mmdf to uucp 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];
58 sprintf (mmdfbox, "%s/%s", MAILDIR, MAILFIL);
59 if (stat (mmdfbox, &st1) == NOTOK || st1.st_size == 0L)
61 if ((mmdf = lkopen (mmdfbox, 0)) == NOTOK)
62 die ("unable to lock and open %s", mmdfbox);
65 switch (fd = mmdf2uucp (mmdf, fd, FALSE)) {
70 die ("internal error while filtering MMDF mail");
73 die ("no free file pointers -- you lose");
76 die ("i/o error while filtering MMDF mail");
81 fprintf (stderr, "MMDF mailbox in bad format, patched...\n");
85 sprintf (uucpbox, "%s/%s", UUCPDIR, UUCPFIL);
86 uucp = mbx_open (uucpbox);
89 lkclose (uucp, uucpbox), uucp = NOTOK;
91 if (stat (mmdfbox, &st2) != NOTOK && st1.st_mtime != st2.st_mtime)
92 fprintf (stderr, "MMDF mailbox has been updated... (%s)\n",
93 "so it won't be zero'd");
95 if ((fd = creat (mmdfbox, st1.st_mode & ~S_IFMT)) != NOTOK)
98 fprintf (stderr, "unable to zero MMDF mailbox\n");
99 lkclose (mmdf, mmdfbox), mmdf = NOTOK;
106 static int mbx_open (file)
113 for (count = 2; count > 0; count--)
114 if ((fd = lkopen (file, 1)) == NOTOK)
128 if (errno == ETXTBSY)
129 die ("your UUCP mailbox '%s' is busy", file);
131 die ("unable to open UUCP mailbox '%s'", file);
134 lseek (fd, (off_t)0, 2);
141 static mbx_create (file)
146 if ((fd = creat (file, MBXMODE)) == NOTOK)
147 die ("unable to create UUCP mailbox '%s'", file);
154 static mbx_copy (in, out)
161 lseek (in, (off_t)0, 0);
163 while ((i = read (in, buffer, sizeof buffer)) > 0)
164 if (write (out, buffer, i) != i)
165 die ("error writing UUCP mailbox");
167 die ("error reading temporary file");
172 static int tmp_open (mbx_fd)
176 char tmpfil[LINESIZ];
178 strcpy (tmpfil, "/tmp/muincXXXXXX");
179 unlink (mktemp (tmpfil));
180 if ((fd = creat (tmpfil, TMPMODE)) == NOTOK)
181 die ("unable to create temporary file '%s'", tmpfil);
184 if ((fd = open (tmpfil, 2)) == NOTOK)
185 die ("unable to create temporary file '%s'", tmpfil);
188 if ((*mbx_fd = dup (fd)) == NOTOK)
189 die ("unable to duplicate fd for temporary file '%s'", tmpfil);
196 static die (fmt, a, b, c, d)
203 lkclose (mmdf, mmdfbox), mmdf = NOTOK;
204 lkclose (uucp, uucpbox), uucp = NOTOK;
207 fprintf (stderr, fmt, a, b, c, d);