--- parser3/src/main/pa_common.C 2001/07/11 15:02:09 1.58 +++ parser3/src/main/pa_common.C 2001/07/24 09:45:27 1.60 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) */ -static const char *RCSId="$Id: pa_common.C,v 1.58 2001/07/11 15:02:09 parser Exp $"; +static const char *RCSId="$Id: pa_common.C,v 1.60 2001/07/24 09:45:27 parser Exp $"; #include "pa_common.h" #include "pa_types.h" @@ -74,15 +74,17 @@ bool file_read(Pool& pool, const String& if(!max_size) { // eof data=0; read_size=0; - return true; + } else { + data=pool.malloc(max_size+(as_text?1:0)); + if(offset) + lseek(f, offset, SEEK_SET); + read_size=read(f, data, max_size); } - data=pool.malloc(max_size+(as_text?1:0)); - if(offset) - lseek(f, offset, SEEK_SET); - read_size=read(f, data, max_size); /*if(exclusive) flock(f, LOCK_UN);*/ close(f); + if(!max_size) // eof + return true; if(read_size>=0 && read_size<=max_size) { if(as_text) @@ -164,6 +166,15 @@ void file_delete(Pool& pool, const Strin rmdir(file_spec, 1); } +void file_move(Pool& pool, const String& old_spec, const String& new_spec) { + const char *old_spec_cstr=old_spec.cstr(String::UL_FILE_NAME); + const char *new_spec_cstr=new_spec.cstr(String::UL_FILE_NAME); + if(rename(old_spec_cstr, new_spec_cstr)!=0) + PTHROW(0, 0, + &old_spec, + "rename failed: %s (%d), actual filename '%s' to '%s'", + strerror(errno), errno, old_spec_cstr, new_spec_cstr); +} static bool entry_readable(const String& file_spec, bool need_dir) {