diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-04 08:48:23 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-04 08:48:23 +0000 |
commit | b1fa75dfe08461c0f1349093266bcdc852bcd713 (patch) | |
tree | f9d3d7950c6e72d1c0d05d6ea4f0a6dff2346ab9 /src/httrack.h | |
parent | 4da59a639962cecf3599f19813b00f2ab065e089 (diff) |
Big cleanup in string primitives and abort functions
Diffstat (limited to 'src/httrack.h')
-rw-r--r-- | src/httrack.h | 159 |
1 files changed, 1 insertions, 158 deletions
diff --git a/src/httrack.h b/src/httrack.h index 360e472..da8e0f9 100644 --- a/src/httrack.h +++ b/src/httrack.h @@ -35,6 +35,7 @@ Please visit our Website: http://www.httrack.com #include "htsglobal.h" #include "htscore.h" +#include "htssafe.h"
#ifndef HTS_DEF_FWSTRUCT_t_StatsBuffer #define HTS_DEF_FWSTRUCT_t_StatsBuffer @@ -83,164 +84,6 @@ struct t_InpInfo { int main(int argc, char **argv); #endif -/* */ - -// Engine internal variables -typedef void (*htsErrorCallback) (char *msg, char *file, int line); -extern HTSEXT_API htsErrorCallback htsCallbackErr; -extern HTSEXT_API int htsMemoryFastXfr; - -/* */ extern HTSEXT_API hts_stat_struct HTS_STAT; extern int _DEBUG_HEAD; extern FILE *ioinfo; - -// from htsbase.h - -/* protected strcat, strncat and strcpy - definitely useful */ -#define strcatbuff(A, B) do { \ - assertf( (A) != NULL ); \ - assertf( (B) != NULL ); \ - if (htsMemoryFastXfr) { \ - if (sizeof(A) != sizeof(char*)) { \ - (A)[sizeof(A) - 1] = '\0'; \ - } \ - strcat(A, B); \ - if (sizeof(A) != sizeof(char*)) { \ - assertf((A)[sizeof(A) - 1] == '\0'); \ - } \ - } else { \ - unsigned int sz = (unsigned int) strlen(A); \ - unsigned int szf = (unsigned int) strlen(B); \ - if (sizeof(A) != sizeof(char*)) { \ - assertf(sz + szf + 1 < sizeof(A)); \ - if (szf > 0) { \ - if (sz + szf + 1 < sizeof(A)) { \ - memcpy((A) + sz, (B), szf + 1); \ - } \ - } \ - } else if (szf > 0) { \ - memcpybuff((A) + sz, (B), szf + 1); \ - } \ - } \ -} while(0) -#define strncatbuff(A, B, N) do { \ - assertf( (A) != NULL ); \ - assertf( (B) != NULL ); \ - if (htsMemoryFastXfr) { \ - if (sizeof(A) != sizeof(char*)) { \ - (A)[sizeof(A) - 1] = '\0'; \ - } \ - strncat(A, B, N); \ - if (sizeof(A) != sizeof(char*)) { \ - assertf((A)[sizeof(A) - 1] == '\0'); \ - } \ - } else { \ - unsigned int sz = (unsigned int) strlen(A); \ - unsigned int szf = (unsigned int) strlen(B); \ - if (szf > (unsigned int) (N)) szf = (unsigned int) (N); \ - if (sizeof(A) != sizeof(char*)) { \ - assertf(sz + szf + 1 < sizeof(A)); \ - if (szf > 0) { \ - if (sz + szf + 1 < sizeof(A)) { \ - memcpy((A) + sz, (B), szf); \ - * ( (A) + sz + szf) = '\0'; \ - } \ - } \ - } else if (szf > 0) { \ - memcpybuff((A) + sz, (B), szf); \ - * ( (A) + sz + szf) = '\0'; \ - } \ - } \ -} while(0) -#define strcpybuff(A, B) do { \ - assertf( (A) != NULL ); \ - assertf( (const char*) (B) != NULL ); \ - if (htsMemoryFastXfr) { \ - if (sizeof(A) != sizeof(char*)) { \ - (A)[sizeof(A) - 1] = '\0'; \ - } \ - strcpy(A, B); \ - if (sizeof(A) != sizeof(char*)) { \ - assertf((A)[sizeof(A) - 1] == '\0'); \ - } \ - } else { \ - unsigned int szf = (unsigned int) strlen(B); \ - if (sizeof(A) != sizeof(char*)) { \ - assertf(szf + 1 < sizeof(A)); \ - if (szf > 0) { \ - if (szf + 1 < sizeof(A)) { \ - memcpy((A), (B), szf + 1); \ - } else { \ - * (A) = '\0'; \ - } \ - } else { \ - * (A) = '\0'; \ - } \ - } else { \ - memcpybuff((A), (B), szf + 1); \ - } \ - } \ -} while(0) - -// emergency log -typedef void (*t_abortLog) (char *msg, char *file, int line); -extern HTSEXT_API t_abortLog abortLog__; - -#define abortLog(a) abortLog__(a, __FILE__, __LINE__) -#define abortLogFmt(a) do { \ - FILE* fp = fopen("CRASH.TXT", "wb"); \ - if (!fp) fp = fopen("/tmp/CRASH.TXT", "wb"); \ - if (!fp) fp = fopen("C:\\CRASH.TXT", "wb"); \ - if (fp) { \ - fprintf(fp, "HTTrack " HTTRACK_VERSIONID " closed at '" __FILE__ "', line %d\r\n", __LINE__); \ - fprintf(fp, "Reason:\r\n"); \ - fprintf(fp, a); \ - fprintf(fp, "\r\n"); \ - fflush(fp); \ - fclose(fp); \ - } \ -} while(0) - -#define _ , -#define abortLogFmt(a) do { \ - FILE* fp = fopen("CRASH.TXT", "wb"); \ - if (!fp) fp = fopen("/tmp/CRASH.TXT", "wb"); \ - if (!fp) fp = fopen("C:\\CRASH.TXT", "wb"); \ - if (fp) { \ - fprintf(fp, "HTTrack " HTTRACK_VERSIONID " closed at '" __FILE__ "', line %d\r\n", __LINE__); \ - fprintf(fp, "Reason:\r\n"); \ - fprintf(fp, a); \ - fprintf(fp, "\r\n"); \ - fflush(fp); \ - fclose(fp); \ - } \ -} while(0) -#define assertf(exp) do { \ - if (! ( exp ) ) { \ - abortLog("assert failed: " #exp); \ - if (htsCallbackErr != NULL) { \ - htsCallbackErr("assert failed: " #exp, __FILE__ , __LINE__ ); \ - } \ - assert(exp); \ - abort(); \ - } \ -} while(0) -/* non-fatal assert */ -#define assertnf(exp) do { \ - if (! ( exp ) ) { \ - abortLog("assert failed: " #exp); \ - if (htsCallbackErr != NULL) { \ - htsCallbackErr("assert failed: " #exp, __FILE__ , __LINE__ ); \ - } \ - } \ -} while(0) - -// - -#define malloct(A) malloc(A) -#define calloct(A,B) calloc((A), (B)) -#define freet(A) do { assertnf((A) != NULL); if ((A) != NULL) { free(A); (A) = NULL; } } while(0) -#define strdupt(A) strdup(A) -#define realloct(A,B) ( ((A) != NULL) ? realloc((A), (B)) : malloc(B) ) -#define memcpybuff(A, B, N) memcpy((A), (B), (N)) |