diff options
Diffstat (limited to 'src/setmaillist.c')
-rw-r--r-- | src/setmaillist.c | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/src/setmaillist.c b/src/setmaillist.c index f7ac89b..a32e86b 100644 --- a/src/setmaillist.c +++ b/src/setmaillist.c @@ -1,19 +1,20 @@ -#include <unistd.h> #include <sys/stat.h> +#include <unistd.h> + #include "buffer.h" -#include "logmsg.h" -#include "stralloc.h" +#include "byte.h" #include "getln.h" +#include "logmsg.h" #include "open.h" -#include "byte.h" +#include "stralloc.h" #define WHO "setmaillist" -int rename(const char *,const char *); // stdio.h +int rename(const char *, const char *); // stdio.h void usage() { - logmsg(WHO,100,USAGE,"setmaillist list.bin list.tmp"); + logmsg(WHO, 100, USAGE, "setmaillist list.bin list.tmp"); } stralloc line = {0}; @@ -27,56 +28,52 @@ buffer bo; void writeerr() { - logmsg(WHO,111,FATAL,B("unable to write to: ",fntmp)); + logmsg(WHO, 111, FATAL, B("unable to write to: ", fntmp)); } -static void out(char *s,int len) +static void out(char *s, int len) { - if (buffer_put(&bo,s,len) == -1) writeerr(); + if (buffer_put(&bo, s, len) == -1) writeerr(); } -int main(int argc,char **argv) +int main(int argc, char **argv) { umask(033); - fnbin = argv[1]; if (!fnbin) usage(); - fntmp = argv[2]; if (!fntmp) usage(); + fnbin = argv[1]; + if (!fnbin) usage(); + fntmp = argv[2]; + if (!fntmp) usage(); fd = open_trunc(fntmp); - if (fd == -1) - logmsg(WHO,111,FATAL,B("unable to create: ",fntmp)); + if (fd == -1) logmsg(WHO, 111, FATAL, B("unable to create: ", fntmp)); - buffer_init(&bo,write,fd,buf,sizeof(buf)); + buffer_init(&bo, write, fd, buf, sizeof(buf)); do { - if (getln(buffer_0small,&line,&match,'\n') == -1) - logmsg(WHO,111,FATAL,"unable to read input: "); + if (getln(buffer_0small, &line, &match, '\n') == -1) + logmsg(WHO, 111, FATAL, "unable to read input: "); while (line.len) { if (line.s[line.len - 1] != '\n') if (line.s[line.len - 1] != ' ') - if (line.s[line.len - 1] != '\t') - break; + if (line.s[line.len - 1] != '\t') break; --line.len; } - if (byte_chr(line.s,line.len,'\0') != line.len) - logmsg(WHO,111,FATAL,"NUL in input"); + if (byte_chr(line.s, line.len, '\0') != line.len) logmsg(WHO, 111, FATAL, "NUL in input"); if (line.len) if (line.s[0] != '#') { if ((line.s[0] == '.') || (line.s[0] == '/')) { - out(line.s,line.len); - out("",1); - } - else { - if (line.len > 800) - logmsg(WHO,111,FATAL,"addresses must be under 800 bytes"); - if (line.s[0] != '&') - out("&",1); - out(line.s,line.len); - out("",1); + out(line.s, line.len); + out("", 1); + } else { + if (line.len > 800) logmsg(WHO, 111, FATAL, "addresses must be under 800 bytes"); + if (line.s[0] != '&') out("&", 1); + out(line.s, line.len); + out("", 1); } } @@ -86,8 +83,7 @@ int main(int argc,char **argv) if (fsync(fd) == -1) writeerr(); if (close(fd) == -1) writeerr(); /* NFS stupidity */ - if (rename(fntmp,fnbin) == -1) - logmsg(WHO,111,FATAL,B("unable to move ",fntmp," to: ",fnbin)); - + if (rename(fntmp, fnbin) == -1) logmsg(WHO, 111, FATAL, B("unable to move ", fntmp, " to: ", fnbin)); + _exit(0); } |