From a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:52:39 +0200 Subject: format files --- src/qmail-newu.c | 72 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) (limited to 'src/qmail-newu.c') diff --git a/src/qmail-newu.c b/src/qmail-newu.c index d5e9baa..f2e33cd 100644 --- a/src/qmail-newu.c +++ b/src/qmail-newu.c @@ -1,52 +1,55 @@ -#include #include -#include // rename -#include "stralloc.h" -#include "getln.h" +#include + +#include // rename + #include "buffer.h" +#include "byte.h" +#include "case.h" #include "cdbmake.h" #include "exit.h" -#include "open.h" +#include "getln.h" #include "logmsg.h" -#include "case.h" -#include "byte.h" +#include "open.h" +#include "stralloc.h" + #include "auto_qmail.h" #define WHO "qmail-newu" -int rename(const char *,const char *); // stdio.h +int rename(const char *, const char *); // stdio.h void die_chdir() { - logmsg(WHO,110,ERROR,"unable to chdir"); + logmsg(WHO, 110, ERROR, "unable to chdir"); } void die_nomem() { - logmsg(WHO,111,FATAL,"fatal: out of memory"); + logmsg(WHO, 111, FATAL, "fatal: out of memory"); } void die_opena() { - logmsg(WHO,112,ERROR,"unable to open users/assign"); + logmsg(WHO, 112, ERROR, "unable to open users/assign"); } void die_reada() { - logmsg(WHO,110,ERROR,"unable to read users/assign"); + logmsg(WHO, 110, ERROR, "unable to read users/assign"); } void die_format() { - logmsg(WHO,112,ERROR,"bad format in users/assign"); + logmsg(WHO, 112, ERROR, "bad format in users/assign"); } void die_opent() { - logmsg(WHO,112,ERROR,"unable to open users/assign.cdb.tmp"); + logmsg(WHO, 112, ERROR, "unable to open users/assign.cdb.tmp"); } void die_writet() { - logmsg(WHO,112,ERROR,"unable to write users/assign.cdb.tmp"); + logmsg(WHO, 112, ERROR, "unable to write users/assign.cdb.tmp"); } void die_rename() { - logmsg(WHO,112,ERROR,"unable to move users/cdb.tmp to users/assign.cdb"); + logmsg(WHO, 112, ERROR, "unable to move users/cdb.tmp to users/assign.cdb"); } struct cdb_make cdb; @@ -75,39 +78,38 @@ int main() fd = open_read("users/assign"); if (fd == -1) die_opena(); - buffer_init(&bi,read,fd,inbuf,sizeof(inbuf)); + buffer_init(&bi, read, fd, inbuf, sizeof(inbuf)); fdtemp = open_trunc("users/assign.cdb.tmp"); if (fdtemp == -1) die_opent(); - if (cdb_make_start(&cdb,fdtemp) == -1) die_writet(); + if (cdb_make_start(&cdb, fdtemp) == -1) die_writet(); - if (!stralloc_copys(&wildchars,"")) die_nomem(); + if (!stralloc_copys(&wildchars, "")) die_nomem(); for (;;) { - if (getln(&bi,&line,&match,'\n') != 0) die_reada(); + if (getln(&bi, &line, &match, '\n') != 0) die_reada(); if (line.len && (line.s[0] == '.')) break; if (!match) die_format(); - if (byte_chr(line.s,line.len,'\0') < line.len) die_format(); - i = byte_chr(line.s,line.len,':'); + if (byte_chr(line.s, line.len, '\0') < line.len) die_format(); + i = byte_chr(line.s, line.len, ':'); if (i == line.len) die_format(); if (i == 0) die_format(); - if (!stralloc_copys(&key,"!")) die_nomem(); + if (!stralloc_copys(&key, "!")) die_nomem(); if (line.s[0] == '+') { - if (!stralloc_catb(&key,line.s + 1,i - 1)) die_nomem(); - case_lowerb(key.s,key.len); + if (!stralloc_catb(&key, line.s + 1, i - 1)) die_nomem(); + case_lowerb(key.s, key.len); if (i >= 2) - if (byte_chr(wildchars.s,wildchars.len,line.s[i - 1]) == wildchars.len) - if (!stralloc_append(&wildchars,line.s + i - 1)) die_nomem(); - } - else { - if (!stralloc_catb(&key,line.s + 1,i - 1)) die_nomem(); + if (byte_chr(wildchars.s, wildchars.len, line.s[i - 1]) == wildchars.len) + if (!stralloc_append(&wildchars, line.s + i - 1)) die_nomem(); + } else { + if (!stralloc_catb(&key, line.s + 1, i - 1)) die_nomem(); if (!stralloc_0(&key)) die_nomem(); - case_lowerb(key.s,key.len); + case_lowerb(key.s, key.len); } - if (!stralloc_copyb(&data,line.s + i + 1,line.len - i - 1)) die_nomem(); + if (!stralloc_copyb(&data, line.s + i + 1, line.len - i - 1)) die_nomem(); numcolons = 0; for (i = 0; i < data.len; ++i) @@ -118,15 +120,15 @@ int main() if (numcolons < 6) die_format(); data.len = i; - if (cdb_make_add(&cdb,key.s,key.len,data.s,data.len) == -1) die_writet(); + if (cdb_make_add(&cdb, key.s, key.len, data.s, data.len) == -1) die_writet(); } - if (cdb_make_add(&cdb,"",0,wildchars.s,wildchars.len) == -1) die_writet(); + if (cdb_make_add(&cdb, "", 0, wildchars.s, wildchars.len) == -1) die_writet(); if (cdb_make_finish(&cdb) == -1) die_writet(); if (fsync(fdtemp) == -1) die_writet(); if (close(fdtemp) == -1) die_writet(); /* NFS stupidity */ - if (rename("users/assign.cdb.tmp","users/assign.cdb") == -1) die_rename(); + if (rename("users/assign.cdb.tmp", "users/assign.cdb") == -1) die_rename(); _exit(0); } -- cgit v1.2.3