]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/zotnet/mf/muinc.c
1 /* muinc.c - mmdf to uucp inc */
3 static char Id
[] = "@(#)$Id: muinc.c,v 1.2 1993/08/25 17:30:36 jromine Exp $";
8 #include "../mts/mts.h"
10 #include <sys/types.h>
14 static int mmdf
= NOTOK
;
15 static int uucp
= NOTOK
;
16 static char mmdfbox
[LINESIZ
];
17 static char uucpbox
[LINESIZ
];
31 sprintf (mmdfbox
, "%s/%s", MAILDIR
, MAILFIL
);
32 if (stat (mmdfbox
, &st1
) == NOTOK
|| st1
.st_size
== 0L)
34 if ((mmdf
= lkopen (mmdfbox
, 0)) == NOTOK
)
35 die ("unable to lock and open %s", mmdfbox
);
38 switch (fd
= mmdf2uucp (mmdf
, fd
, FALSE
)) {
43 die ("internal error while filtering MMDF mail");
46 die ("no free file pointers -- you lose");
49 die ("i/o error while filtering MMDF mail");
54 fprintf (stderr
, "MMDF mailbox in bad format, patched...\n");
58 sprintf (uucpbox
, "%s/%s", UUCPDIR
, UUCPFIL
);
59 uucp
= mbx_open (uucpbox
);
62 lkclose (uucp
, uucpbox
), uucp
= NOTOK
;
64 if (stat (mmdfbox
, &st2
) != NOTOK
&& st1
.st_mtime
!= st2
.st_mtime
)
65 fprintf (stderr
, "MMDF mailbox has been updated... (%s)\n",
66 "so it won't be zero'd");
68 if ((fd
= creat (mmdfbox
, st1
.st_mode
& ~S_IFMT
)) != NOTOK
)
71 fprintf (stderr
, "unable to zero MMDF mailbox\n");
72 lkclose (mmdf
, mmdfbox
), mmdf
= NOTOK
;
79 static int mbx_open (file
)
86 for (count
= 2; count
> 0; count
--)
87 if ((fd
= lkopen (file
, 1)) == NOTOK
)
101 if (errno
== ETXTBSY
)
102 die ("your UUCP mailbox '%s' is busy", file
);
104 die ("unable to open UUCP mailbox '%s'", file
);
107 lseek (fd
, (off_t
)0, 2);
114 static mbx_create (file
)
119 if ((fd
= creat (file
, MBXMODE
)) == NOTOK
)
120 die ("unable to create UUCP mailbox '%s'", file
);
127 static mbx_copy (in
, out
)
134 lseek (in
, (off_t
)0, 0);
136 while ((i
= read (in
, buffer
, sizeof buffer
)) > 0)
137 if (write (out
, buffer
, i
) != i
)
138 die ("error writing UUCP mailbox");
140 die ("error reading temporary file");
145 static int tmp_open (mbx_fd
)
149 char tmpfil
[LINESIZ
];
151 strcpy (tmpfil
, "/tmp/muincXXXXXX");
152 unlink (mktemp (tmpfil
));
153 if ((fd
= creat (tmpfil
, TMPMODE
)) == NOTOK
)
154 die ("unable to create temporary file '%s'", tmpfil
);
157 if ((fd
= open (tmpfil
, 2)) == NOTOK
)
158 die ("unable to create temporary file '%s'", tmpfil
);
161 if ((*mbx_fd
= dup (fd
)) == NOTOK
)
162 die ("unable to duplicate fd for temporary file '%s'", tmpfil
);
169 static die (fmt
, a
, b
, c
, d
)
176 lkclose (mmdf
, mmdfbox
), mmdf
= NOTOK
;
177 lkclose (uucp
, uucpbox
), uucp
= NOTOK
;
180 fprintf (stderr
, fmt
, a
, b
, c
, d
);