X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=basics.h;h=97cbec1589083aa06dd1b01093105f8df71e2160;hb=e38bc834442d5369a523ba47d74865e48995ace4;hp=7449c1114009e0815b745685944e249fa39f5e8a;hpb=235e3214904e390d2f101c5d5bf7def98745b132;p=SXSI%2FXMLTree.git diff --git a/basics.h b/basics.h index 7449c11..97cbec1 100644 --- a/basics.h +++ b/basics.h @@ -1,21 +1,21 @@ -#ifndef BASICS_H -#define BASICS_H +#ifndef BASICS_H_ +#define BASICS_H_ + -#include #include #include -#include // for memset +//#include // for memset #include #include #include - +#define B_ERROR(msg) do { fprintf(stderr,"%s\n", msg); exit(1); } while (0) inline void ufread(void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t res; res = fread(ptr,size,nmemb,stream); if (res < nmemb) - throw ("ufread I/O error" ); + B_ERROR ("ufread I/O error" ); return; } @@ -24,7 +24,7 @@ inline void ufwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) size_t res; res = fwrite(ptr,size,nmemb,stream); if (res < nmemb) - throw "ufwrite I/O error"; + B_ERROR("ufwrite I/O error"); return; } @@ -33,7 +33,7 @@ inline void *urealloc(void *ptr, size_t size) void *dest = realloc(ptr,size); //don't fail if we requested size 0 if (dest == NULL && size > 0 ) - throw std::bad_alloc(); + B_ERROR("urealoc error"); return dest; } // realloc and set to 0 @@ -45,10 +45,12 @@ inline void *urecalloc(void *ptr, size_t o_size, size_t n_size) void *dest = realloc(ptr,n_size); //don't fail if we requested size 0 if (dest == NULL && n_size > 0 ) - throw std::bad_alloc(); + B_ERROR("urecalloc error"); // Initialize the new area with 0 void * n_area_start = &(((char*) dest)[o_size]); - memset(n_area_start,0, n_size - o_size); + // memset(n_area_start,0, n_size - o_size); + for(size_t i = 0; i < n_size - o_size;i++) + ((char *) n_area_start)[i] = 0; return dest; } @@ -57,7 +59,7 @@ inline void *ucalloc(size_t nmemb, size_t size) void * dest = calloc(nmemb,size); //don't fail if we requested size 0 if (dest == NULL && nmemb > 0 && size > 0 ) - throw std::bad_alloc(); + B_ERROR("ucalloc error"); return dest; } @@ -65,7 +67,7 @@ inline void *umalloc(size_t size) { void * dest = malloc(size); if (dest == NULL && size > 0) - throw std::bad_alloc(); + B_ERROR("umaloc error"); return dest; }