From c4337f7aecf5d5926f7eb8275985681372e05eca Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 26 Nov 2011 16:01:51 +0100 Subject: [PATCH] Factor mailbox_create() out of nat_reset() and files.c --- include/tel.h | 1 + src/lib/common/mailbox.c | 13 +++++++++++++ src/lib/common/nat.c | 6 +----- src/util/files.c | 7 ++----- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/tel.h b/include/tel.h index 497edb3c6..0fc9d6442 100644 --- a/include/tel.h +++ b/include/tel.h @@ -56,6 +56,7 @@ struct telstr { }; 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 *), diff --git a/src/lib/common/mailbox.c b/src/lib/common/mailbox.c index 6910327f0..c749eddd7 100644 --- a/src/lib/common/mailbox.c +++ b/src/lib/common/mailbox.c @@ -33,6 +33,9 @@ #include #include +#include +#include +#include #include "optlist.h" #include "tel.h" #include "prototypes.h" @@ -44,6 +47,16 @@ mailbox(char *buf, natid cn) 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. diff --git a/src/lib/common/nat.c b/src/lib/common/nat.c index 1f98b4691..666b4103a 100644 --- a/src/lib/common/nat.c +++ b/src/lib/common/nat.c @@ -34,10 +34,7 @@ #include -#include #include -#include -#include #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); } - 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; diff --git a/src/util/files.c b/src/util/files.c index 8cac575df..c5e78a845 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -36,7 +36,6 @@ #include #include -#include #include #include #include "file.h" @@ -71,7 +70,6 @@ int main(int argc, char *argv[]) { char buf[255]; - char *filename; struct natstr nat; int i; int opt; @@ -141,10 +139,9 @@ main(int argc, char *argv[]) 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); -- 2.43.0