diff options
Diffstat (limited to 'mbbsd/stuff.c')
-rw-r--r-- | mbbsd/stuff.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 0970e58c..90294609 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -600,19 +600,17 @@ printdash(char *mesg) outch('\n'); } -int -log_file(char *filename, char *buf) +int log_file(char *fn, char *buf, int ifcreate) { - FILE *fp; - - if ((fp = fopen(filename, "a")) != NULL) { - fputs(buf, fp); - if (!strchr(buf, '\n')) - fputc('\n', fp); - fclose(fp); - return 0; - } else + int fd; + if( (fd = open(fn, O_APPEND | O_WRONLY | (ifcreate ? O_CREAT : 0))) < 0 ) + return -1; + if( write(fd, buf, strlen(buf)) < 0 ){ + close(fd); return -1; + } + close(fd); + return 0; } void |