]> git.pond.sub.org Git - empserver/commitdiff
Factor mailbox_create() out of nat_reset() and files.c
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Nov 2011 15:01:51 +0000 (16:01 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 29 Dec 2011 10:47:07 +0000 (11:47 +0100)
include/tel.h
src/lib/common/mailbox.c
src/lib/common/nat.c
src/util/files.c

index 497edb3c6da12e1fe4a74a8799fa0d541e7e7d78..0fc9d6442992877f1dd1b6d43a6b468cb7cf63b2 100644 (file)
@@ -56,6 +56,7 @@ struct telstr {
 };
 
 extern char *mailbox(char *buf, natid cn);
 };
 
 extern char *mailbox(char *buf, natid cn);
+extern int mailbox_create(char *);
 extern int tel_read_header(FILE *, char *, struct telstr *);
 extern int tel_read_body(FILE *, char *, struct telstr *,
                         int (*sink)(char *, size_t, void *),
 extern int tel_read_header(FILE *, char *, struct telstr *);
 extern int tel_read_body(FILE *, char *, struct telstr *,
                         int (*sink)(char *, size_t, void *),
index 6910327f006b95364556b30aea642f549d9a2e77..c749eddd7bda635af6f3355483a05999e800023e 100644 (file)
@@ -33,6 +33,9 @@
 #include <config.h>
 
 #include <stdio.h>
 #include <config.h>
 
 #include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include "optlist.h"
 #include "tel.h"
 #include "prototypes.h"
 #include "optlist.h"
 #include "tel.h"
 #include "prototypes.h"
@@ -44,6 +47,16 @@ mailbox(char *buf, natid cn)
     return buf;
 }
 
     return buf;
 }
 
+/*
+ * Create an empty telegram file named MBOX.
+ */
+int
+mailbox_create(char *mbox)
+{
+    close(creat(mbox, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
+    return 0;
+}
+
 /*
  * Read telegram header from FP into TEL.
  * MBOX is the file name, it is used for logging errors.
 /*
  * Read telegram header from FP into TEL.
  * MBOX is the file name, it is used for logging errors.
index 1f98b469130a32af6b3119249fdf37a2755afce6..666b4103a53b473797f4f66cc519acab069676da 100644 (file)
 
 #include <config.h>
 
 
 #include <config.h>
 
-#include <fcntl.h>
 #include <string.h>
 #include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
 #include "file.h"
 #include "misc.h"
 #include "nat.h"
 #include "file.h"
 #include "misc.h"
 #include "nat.h"
@@ -208,8 +205,7 @@ nat_reset(struct natstr *natp, natid cnum, char *name, char *rep,
        ef_blank(EF_REALM, i + cnum * MAXNOR, &newrealm);
        putrealm(&newrealm);
     }
        ef_blank(EF_REALM, i + cnum * MAXNOR, &newrealm);
        putrealm(&newrealm);
     }
-    close(creat(mailbox(buf, cnum),
-               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
+    mailbox_create(mailbox(buf, cnum));
     /* FIXME natp->nat_ann = #annos */
     natp->nat_level[NAT_HLEV] = start_happiness;
     natp->nat_level[NAT_RLEV] = start_research;
     /* FIXME natp->nat_ann = #annos */
     natp->nat_level[NAT_HLEV] = start_happiness;
     natp->nat_level[NAT_RLEV] = start_research;
index 8cac575dfe0e4dca1db2f8611daf99954c3302a3..c5e78a845853b63e25ebdab95b1dec67638d4894 100644 (file)
@@ -36,7 +36,6 @@
 #include <config.h>
 
 #include <errno.h>
 #include <config.h>
 
 #include <errno.h>
-#include <fcntl.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include "file.h"
 #include <sys/stat.h>
 #include <unistd.h>
 #include "file.h"
@@ -71,7 +70,6 @@ int
 main(int argc, char *argv[])
 {
     char buf[255];
 main(int argc, char *argv[])
 {
     char buf[255];
-    char *filename;
     struct natstr nat;
     int i;
     int opt;
     struct natstr nat;
     int i;
     int opt;
@@ -141,10 +139,9 @@ main(int argc, char *argv[])
        exit(1);
     }
     for (i = 0; i < MAXNOC; i++) {
        exit(1);
     }
     for (i = 0; i < MAXNOC; i++) {
-       filename = mailbox(buf, i);
-       close(creat(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
+       mailbox_create(mailbox(buf, i));
     }
     }
-    close(creat(annfil, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
+    mailbox_create(annfil);
 
     nat_reset(&nat, 0, "POGO", "peter", STAT_GOD);
     putnat(&nat);
 
     nat_reset(&nat, 0, "POGO", "peter", STAT_GOD);
     putnat(&nat);