--- parser3/src/main/pa_common.C 2002/02/07 17:41:36 1.99 +++ parser3/src/main/pa_common.C 2002/02/13 12:05:17 1.104 @@ -1,10 +1,10 @@ /** @file Parser: commonly functions. - Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) + Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) - $Id: pa_common.C,v 1.99 2002/02/07 17:41:36 paf Exp $ + $Id: pa_common.C,v 1.104 2002/02/13 12:05:17 paf Exp $ */ #include "pa_common.h" @@ -78,6 +78,10 @@ static int unlock(int fd) { FLOCK(F_TLOC #endif static char *strnchr(char *buf, size_t size, char c) { + // sanity check + if(!buf) + return 0; + for(; size-->0; buf++) { if(*buf==c) return buf; @@ -208,7 +212,7 @@ bool file_write_action_under_lock( if((f=open(fname, O_CREAT|O_RDWR |(as_text?_O_TEXT:_O_BINARY) - |(do_append?O_APPEND:0), 0664))>=0) { + |(do_append?O_APPEND:O_TRUNC), 0664))>=0) { if((do_block?lock_exclusive_blocking(f):lock_exclusive_nonblocking(f))!=0) { close(f); return false; @@ -218,7 +222,8 @@ bool file_write_action_under_lock( action(f, context); } catch(...) { #if O_TRUNC==0 - ftruncate(f, tell(f)); + if(!do_append) + ftruncate(f, tell(f)); #endif unlock(f); close(f); @@ -226,7 +231,8 @@ bool file_write_action_under_lock( } #if O_TRUNC==0 - ftruncate(f, tell(f)); + if(!do_append) + ftruncate(f, tell(f)); #endif unlock(f); close(f);