diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-12-07 19:48:42 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-12-07 19:48:42 +0800 |
commit | e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2 (patch) | |
tree | 6917e3ead4beec72534673b799b5e51add0a0519 /mbbsd/stuff.c | |
parent | f596ac6e290311dea6c2181816b7d096127696a8 (diff) | |
download | pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.gz pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.bz2 pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.lz pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.xz pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.zst pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.zip |
use open() instead of fopen() in log_file()
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1405 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
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 |