Factor mailbox_create() out of nat_reset() and files.c

This commit is contained in:
Markus Armbruster 2011-11-26 16:01:51 +01:00
parent 8b7591f5d7
commit c4337f7aec
4 changed files with 17 additions and 10 deletions

View 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_header(FILE *, char *, struct telstr *);
extern int tel_read_body(FILE *, char *, struct telstr *, extern int tel_read_body(FILE *, char *, struct telstr *,
int (*sink)(char *, size_t, void *), int (*sink)(char *, size_t, void *),

View file

@ -33,6 +33,9 @@
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include "optlist.h" #include "optlist.h"
#include "tel.h" #include "tel.h"
#include "prototypes.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. * Read telegram header from FP into TEL.
* MBOX is the file name, it is used for logging errors. * MBOX is the file name, it is used for logging errors.

View file

@ -34,10 +34,7 @@
#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 "file.h"
#include "misc.h" #include "misc.h"
#include "nat.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); ef_blank(EF_REALM, i + cnum * MAXNOR, &newrealm);
putrealm(&newrealm); putrealm(&newrealm);
} }
close(creat(mailbox(buf, cnum), mailbox_create(mailbox(buf, cnum));
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
/* FIXME natp->nat_ann = #annos */ /* FIXME natp->nat_ann = #annos */
natp->nat_level[NAT_HLEV] = start_happiness; natp->nat_level[NAT_HLEV] = start_happiness;
natp->nat_level[NAT_RLEV] = start_research; natp->nat_level[NAT_RLEV] = start_research;

View file

@ -36,7 +36,6 @@
#include <config.h> #include <config.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "file.h" #include "file.h"
@ -71,7 +70,6 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char buf[255]; char buf[255];
char *filename;
struct natstr nat; struct natstr nat;
int i; int i;
int opt; int opt;
@ -141,10 +139,9 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
for (i = 0; i < MAXNOC; i++) { for (i = 0; i < MAXNOC; i++) {
filename = mailbox(buf, i); mailbox_create(mailbox(buf, i));
close(creat(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
} }
close(creat(annfil, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)); mailbox_create(annfil);
nat_reset(&nat, 0, "POGO", "peter", STAT_GOD); nat_reset(&nat, 0, "POGO", "peter", STAT_GOD);
putnat(&nat); putnat(&nat);