--- parser3/src/main/pa_common.C 2009/09/27 22:08:27 1.251 +++ parser3/src/main/pa_common.C 2009/10/06 12:12:51 1.255 @@ -26,7 +26,7 @@ * */ -static const char * const IDENT_COMMON_C="$Date: 2009/09/27 22:08:27 $"; +static const char * const IDENT_COMMON_C="$Date: 2009/10/06 12:12:51 $"; #include "pa_common.h" #include "pa_exception.h" @@ -67,7 +67,20 @@ const String file_status_name(FILE_STATU // functions +bool capitalized(const char* s){ + bool upper=true; + for(const char* c=s; *c; c++){ + if(*c != (upper ? toupper((unsigned char)*c) : tolower((unsigned char)*c))) + return false; + upper=strchr("-_ ", *c) != 0; + } + return true; +} + const char* capitalize(const char* s){ + if(!s || capitalized(s)) + return s; + char* result=pa_strdup(s); if(result){ bool upper=true; @@ -162,7 +175,7 @@ static void file_read_action( lseek(f, info.offset, SEEK_SET); *info.data=info.buf ? info.buf - : new(PointerFreeGC) char[to_read_size+(as_text?1:0)]; + : (char *)pa_malloc_atomic(to_read_size+1); *info.data_size=(size_t)read(f, *info.data, to_read_size); if(ssize_t(*info.data_size)<0 || *info.data_size>to_read_size) @@ -172,7 +185,7 @@ static void file_read_action( *info.data_size, to_read_size); } else { // empty file // for both, text and binary: for text we need that terminator, for binary we need nonzero pointer to be able to save such files - *info.data=new(PointerFreeGC) char[1]; + *info.data=(char *)pa_malloc_atomic(1); *(char*)(*info.data)=0; *info.data_size=0; return; @@ -293,7 +306,7 @@ bool file_read_action_under_lock(const S strerror(errno), errno, fname); struct stat finfo; - if(stat(fname, &finfo)!=0) + if(fstat(f, &finfo)!=0) throw Exception("file.missing", // hardly possible: we just opened it OK &file_spec, "stat failed: %s (%d), actual filename '%s'", @@ -362,7 +375,12 @@ bool file_write_action_under_lock( } try { - action(f, context); +#if (defined(HAVE_FCHMOD) && defined(PA_SAFE_MODE)) + struct stat finfo; + if(fstat(f, &finfo)==0 && finfo.st_mode & 0111) + fchmod(f, finfo.st_mode & 0666/*clear executable bits*/); // backward: ignore errors if any +#endif + action(f, context); } catch(...) { #ifdef HAVE_FTRUNCATE if(!do_append) @@ -993,6 +1011,9 @@ static char *base64_alphabet = * * Returns the number of bytes encoded. **/ + +#define BASE64_GROUPS_IN_LINE 19 + static size_t g_mime_utils_base64_encode_step (const unsigned char *in, size_t inlen, unsigned char *out, int *state, int *save) { @@ -1030,7 +1051,7 @@ g_mime_utils_base64_encode_step (const u *outptr++ = base64_alphabet [((c2 & 0x0f) << 2) | (c3 >> 6)]; *outptr++ = base64_alphabet [c3 & 0x3f]; /* this is a bit ugly ... */ - if ((++already) >= 19) { + if ((++already) >= BASE64_GROUPS_IN_LINE) { *outptr++ = '\n'; already = 0; } @@ -1196,9 +1217,9 @@ g_mime_utils_base64_decode_step (const u char* pa_base64_encode(const char *in, size_t in_size){ - size_t new_size=((in_size / 3 + 1) * 4); - new_size+=new_size / 76/*new lines*/ + 1/*zero terminator*/; - char* result=new(PointerFreeGC) char[new_size]; + size_t new_size = ((in_size / 3 + 1) * 4); + new_size += new_size / (BASE64_GROUPS_IN_LINE * 4)/*new lines*/ + 1/*zero terminator*/; + char* result = new(PointerFreeGC) char[new_size]; int state=0; int save=0; #ifndef NDEBUG