From e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 7 Dec 2003 11:48:42 +0000 Subject: use open() instead of fopen() in log_file() git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1405 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/stuff.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'mbbsd/stuff.c') 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 -- cgit v1.2.3