--- parser3/src/main/pa_common.C 2001/04/10 10:32:10 1.44 +++ parser3/src/main/pa_common.C 2001/04/17 19:00:41 1.47 @@ -6,18 +6,10 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_common.C,v 1.44 2001/04/10 10:32:10 paf Exp $ + $Id: pa_common.C,v 1.47 2001/04/17 19:00:41 paf Exp $ */ #include "pa_config_includes.h" - -#include -#include -#include -#include -#include -#include - #include "pa_common.h" #include "pa_types.h" #include "pa_exception.h" @@ -27,6 +19,15 @@ #include "pa_hash.h" #include "pa_string.h" +#ifndef WIN32 +# ifndef _O_TEXT +# define _O_TEXT 0 +# endif +# ifndef _O_BINARY +# define _O_BINARY 0 +# endif +#endif + #if _MSC_VER int __vsnprintf(char *b, size_t s, const char *f, va_list l) { @@ -60,7 +61,7 @@ bool file_read(Pool& pool, const String& struct stat finfo; // first open, next stat: - // directory update of NTFS symbolic links performed on open. + // directory update of NTFS hard links performed on open. // ex: // a.html:^test[] and b.html hardlink to a.html // user inserts ! before ^test in a.html @@ -73,7 +74,14 @@ bool file_read(Pool& pool, const String& /*if(exclusive) flock(f, LOCK_EX);*/ size_t max_size=limit?min(offset+limit, finfo.st_size)-offset:finfo.st_size; + if(!max_size) { // eof + data=0; + read_size=0; + return true; + } 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);*/ @@ -81,7 +89,7 @@ bool file_read(Pool& pool, const String& if(read_size>=0 && read_size<=max_size) { if(as_text) - ((char *)data)[read_size]=0; + ((char*&)data)[read_size]=0; } else PTHROW(0, 0, &file_spec, @@ -93,7 +101,7 @@ bool file_read(Pool& pool, const String& if(fail_on_read_problem) PTHROW(0, 0, &file_spec, - "read failed: %s (#%d)", strerror(errno), errno); + "read failed: %s (%d)", strerror(errno), errno); return false; } @@ -131,14 +139,14 @@ void file_write(Pool& pool, } PTHROW(0, 0, &file_spec, - "write failed: %s (#%d)", strerror(errno), errno); + "write failed: %s (%d)", strerror(errno), errno); } void file_delete(Pool& pool, const String& file_spec) { if(unlink(file_spec.cstr(String::UL_FILE_NAME))!=0) PTHROW(0, 0, &file_spec, - "unlink failed: %s (#%d)", strerror(errno), errno); + "unlink failed: %s (%d)", strerror(errno), errno); } bool file_readable(const String& file_spec) { @@ -155,7 +163,7 @@ size_t file_size(const String& file_spec if(stat(fname, &finfo)!=0) PTHROW(0, 0, &file_spec, - "write failed: %s (#%d)", strerror(errno), errno); + "write failed: %s (%d)", strerror(errno), errno); return finfo.st_size; } @@ -283,8 +291,7 @@ static void append_attribute_subattribut Attributed_meaning_info& ami=*static_cast(info); // ...; charset=windows1251 - if(ami.header->size()) - ami.header->APPEND_CONST("; "); + ami.header->APPEND_CONST("; "); ami.header->append(akey, ami.lang, true); ami.header->APPEND_CONST("="); ami.header->append(static_cast(avalue)->as_string(),