X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=basics.h;h=7449c1114009e0815b745685944e249fa39f5e8a;hb=235e3214904e390d2f101c5d5bf7def98745b132;hp=273aa1dfd545dd2149a51034096ca29a0123fa1b;hpb=aa6692a9fd2badf8e8e686b92075f041dc03bbef;p=SXSI%2FXMLTree.git diff --git a/basics.h b/basics.h index 273aa1d..7449c11 100644 --- a/basics.h +++ b/basics.h @@ -1,15 +1,21 @@ #ifndef BASICS_H #define BASICS_H +#include #include #include +#include // for memset +#include +#include +#include + 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"; + throw ("ufread I/O error" ); return; } @@ -30,6 +36,21 @@ inline void *urealloc(void *ptr, size_t size) throw std::bad_alloc(); return dest; } +// realloc and set to 0 +inline void *urecalloc(void *ptr, size_t o_size, size_t n_size) + { + if (o_size == n_size) + return ptr; + + void *dest = realloc(ptr,n_size); + //don't fail if we requested size 0 + if (dest == NULL && n_size > 0 ) + throw std::bad_alloc(); + // Initialize the new area with 0 + void * n_area_start = &(((char*) dest)[o_size]); + memset(n_area_start,0, n_size - o_size); + return dest; + } inline void *ucalloc(size_t nmemb, size_t size) {