projects
/
mmh
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
export MM_CHARSET in mhbuild test
[mmh]
/
uip
/
distsbr.c
diff --git
a/uip/distsbr.c
b/uip/distsbr.c
index
a9a52b1
..
a856dc7
100644
(file)
--- a/
uip/distsbr.c
+++ b/
uip/distsbr.c
@@
-9,6
+9,9
@@
#include <h/mh.h>
#include <fcntl.h>
#include <h/utils.h>
#include <h/mh.h>
#include <fcntl.h>
#include <h/utils.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <sys/stat.h>
static int hdrfd = NOTOK;
static int txtfd = NOTOK;
static int hdrfd = NOTOK;
static int txtfd = NOTOK;
@@
-16,31
+19,36
@@
static int txtfd = NOTOK;
/*
** static prototypes
*/
/*
** static prototypes
*/
-static void ready_msg(char *);
+static int ready_msg(char *);
int
distout(char *drft, char *msgnam, char *backup)
{
int state;
int
distout(char *drft, char *msgnam, char *backup)
{
int state;
- register unsigned char *dp;
- register char *resent;
+ unsigned char *dp;
+ char *resent;
char name[NAMESZ], buffer[BUFSIZ];
char name[NAMESZ], buffer[BUFSIZ];
- register FILE *ifp, *ofp;
+ FILE *ifp, *ofp;
strcpy(backup, m_mktemp(toabsdir(invo_name), NULL, NULL));
if (rename(drft, backup) == NOTOK) {
strcpy(backup, m_mktemp(toabsdir(invo_name), NULL, NULL));
if (rename(drft, backup) == NOTOK) {
- adios(backup, "unable to rename %s to",drft);
+ advise(backup, "unable to rename %s to",drft);
+ return NOTOK;
}
if (!(ifp = fopen(backup, "r"))) {
}
if (!(ifp = fopen(backup, "r"))) {
- adios(backup, "unable to read");
+ advise(backup, "unable to read");
+ return NOTOK;
}
if (!(ofp = fopen(drft, "w"))) {
}
if (!(ofp = fopen(drft, "w"))) {
- adios(drft, "unable to create temporary file");
+ advise(drft, "unable to create temporary file");
+ return NOTOK;
}
chmod(drft, m_gmprot());
}
chmod(drft, m_gmprot());
- ready_msg(msgnam);
+ if (ready_msg(msgnam) != OK) {
+ return NOTOK;
+ }
lseek(hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
cpydata(hdrfd, fileno(ofp), msgnam, drft);
lseek(hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
cpydata(hdrfd, fileno(ofp), msgnam, drft);
@@
-92,12
+100,13
@@
leave_bad: ;
fclose(ofp);
unlink(drft);
if (rename(backup, drft) == NOTOK) {
fclose(ofp);
unlink(drft);
if (rename(backup, drft) == NOTOK) {
- adios(drft, "unable to rename %s to", backup);
+ advise(drft, "unable to rename %s to", backup);
}
return NOTOK;
default:
}
return NOTOK;
default:
- adios(NULL, "getfld() returned %d", state);
+ advise(NULL, "getfld() returned %d", state);
+ return NOTOK;
}
}
}
}
@@
-110,7
+119,7
@@
process: ;
fclose(ofp);
unlink(drft);
if (rename(backup, drft) == NOTOK) {
fclose(ofp);
unlink(drft);
if (rename(backup, drft) == NOTOK) {
- adios(drft, "unable to rename %s to", backup);
+ advise(drft, "unable to rename %s to", backup);
}
return NOTOK;
}
}
return NOTOK;
}
@@
-127,12
+136,12
@@
process: ;
}
}
-static void
+static int
ready_msg(char *msgnam)
{
int state, out;
char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
ready_msg(char *msgnam)
{
int state, out;
char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
- register FILE *ifp, *ofp;
+ FILE *ifp, *ofp;
char *cp = NULL;
if (hdrfd != NOTOK) {
char *cp = NULL;
if (hdrfd != NOTOK) {
@@
-144,17
+153,20
@@
ready_msg(char *msgnam)
txtfd = NOTOK;
}
if (!(ifp = fopen(msgnam, "r"))) {
txtfd = NOTOK;
}
if (!(ifp = fopen(msgnam, "r"))) {
- adios(msgnam, "unable to open message");
+ advise(msgnam, "unable to open message");
+ return NOTOK;
}
cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
if (!cp) {
}
cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
if (!cp) {
- adios("distsbr", "unable to create temporary file");
+ advise("distsbr", "unable to create temporary file");
+ return NOTOK;
}
fchmod(hdrfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
if ((out = dup(hdrfd)) == NOTOK || !(ofp = fdopen(out, "w"))) {
}
fchmod(hdrfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
if ((out = dup(hdrfd)) == NOTOK || !(ofp = fdopen(out, "w"))) {
- adios(NULL, "no file descriptors -- you lose big");
+ advise(NULL, "no file descriptors -- you lose big");
+ return NOTOK;
}
unlink(tmpfil);
}
unlink(tmpfil);
@@
-185,13
+197,15
@@
ready_msg(char *msgnam)
cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
if (!cp) {
cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
if (!cp) {
- adios("distsbr", "unable to create temp file");
+ advise("distsbr", "unable to create temp file");
+ return NOTOK;
}
fchmod(txtfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
if ((out = dup(txtfd)) == NOTOK ||
!(ofp = fdopen(out, "w"))) {
}
fchmod(txtfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
if ((out = dup(txtfd)) == NOTOK ||
!(ofp = fdopen(out, "w"))) {
- adios(NULL, "no file descriptors -- you lose");
+ advise(NULL, "no file descriptors -- you lose");
+ return NOTOK;
}
unlink(tmpfil);
fprintf(ofp, "\n%s", buffer);
}
unlink(tmpfil);
fprintf(ofp, "\n%s", buffer);
@@
-205,13
+219,16
@@
ready_msg(char *msgnam)
case LENERR:
case FMTERR:
case LENERR:
case FMTERR:
- adios(NULL, "format error in message %s", msgnam);
+ advise(NULL, "format error in message %s", msgnam);
+ return NOTOK;
default:
default:
- adios(NULL, "getfld() returned %d", state);
+ advise(NULL, "getfld() returned %d", state);
+ return NOTOK;
}
}
process: ;
fclose(ifp);
fclose(ofp);
}
}
process: ;
fclose(ifp);
fclose(ofp);
+ return OK;
}
}