Diff

Differences From Artifact [3db9c71bd5]:

To Artifact [6307d2f89c]:


   173    173   #define MAX_ATR_SIZE 1024
   174    174   #endif
   175    175   
   176    176   #ifdef CACKEY_DEBUG
   177    177   #  ifdef HAVE_TIME_H
   178    178   #    include <time.h>
   179    179   static time_t cackey_debug_start_time = 0;
   180         -#    define CACKEY_DEBUG_PRINTTIME { if (cackey_debug_start_time == 0) { cackey_debug_start_time = time(NULL); }; fprintf(cackey_debug_fd(), "[%lu]: ", (unsigned long) (time(NULL) - cackey_debug_start_time)); }
          180  +static unsigned long CACKEY_DEBUG_GETTIME(void) {
          181  +	if (cackey_debug_start_time == 0) {
          182  +		cackey_debug_start_time = time(NULL);
          183  +	}
          184  +
          185  +	return(time(NULL) - cackey_debug_start_time);
          186  +}
   181    187   #  else
   182         -#    define CACKEY_DEBUG_PRINTTIME /**/
          188  +static unsigned long CACKEY_DEBUG_GETTIME(void) {
          189  +	return(0);
          190  +}
   183    191   #  endif
   184    192   
   185         -#  define CACKEY_DEBUG_PRINTF(x...) { CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: ", __func__, __LINE__); fprintf(cackey_debug_fd(), x); fprintf(cackey_debug_fd(), "\n"); fflush(cackey_debug_fd()); }
   186         -#  define CACKEY_DEBUG_PRINTBUF(f, x, y) { unsigned char *TMPBUF; unsigned long idx; TMPBUF = (unsigned char *) (x); CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: %s  (%s/%lu = {%02x", __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0]); for (idx = 1; idx < (y); idx++) { fprintf(cackey_debug_fd(), ", %02x", TMPBUF[idx]); }; fprintf(cackey_debug_fd(), "})\n"); fflush(cackey_debug_fd()); }
   187         -#  define CACKEY_DEBUG_PERROR(x) { fprintf(cackey_debug_fd(), "%s():%i: ", __func__, __LINE__); CACKEY_DEBUG_PRINTTIME; perror(x); fflush(cackey_debug_fd()); }
          193  +#  define CACKEY_DEBUG_PRINTF(x...) { \
          194  +	static char buf_user[4096] = {0}; \
          195  +	snprintf(buf_user, sizeof(buf_user), x); \
          196  +	buf_user[sizeof(buf_user) - 1] = '\0'; \
          197  +	fprintf(cackey_debug_fd(), "[%lu]: %s():%i: %s\n", CACKEY_DEBUG_GETTIME(), __func__, __LINE__, buf_user); \
          198  +	fflush(cackey_debug_fd()); \
          199  +}
          200  +#  define CACKEY_DEBUG_PRINTBUF(f, x, y) { \
          201  +	static char buf_user[4096] = {0}, *buf_user_p; \
          202  +	unsigned long buf_user_size; \
          203  +	unsigned char *TMPBUF; \
          204  +	unsigned long idx; \
          205  +	int snprintf_ret; \
          206  +	TMPBUF = (unsigned char *) (x); \
          207  +	buf_user_p = buf_user; \
          208  +	buf_user_size = sizeof(buf_user); \
          209  +	for (idx = 1; idx < (y); idx++) { \
          210  +		if (buf_user_size <= 0) { \
          211  +			break; \
          212  +		}; \
          213  +		snprintf_ret = snprintf(buf_user_p, buf_user_size, ", %02x", TMPBUF[idx]); \
          214  +		if (snprintf_ret <= 0) { \
          215  +			break; \
          216  +		}; \
          217  +		buf_user_p += snprintf_ret; \
          218  +		buf_user_size -= snprintf_ret; \
          219  +	}; \
          220  +	buf_user[sizeof(buf_user) - 1] = '\0'; \
          221  +	fprintf(cackey_debug_fd(), "[%lu]: %s():%i: %s  (%s/%lu = {%02x%s})\n", CACKEY_DEBUG_GETTIME(), __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0], buf_user); \
          222  +	fflush(cackey_debug_fd()); \
          223  +}
   188    224   #  define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", (void *) x, #x); free(x); }
   189    225   
   190    226   static FILE *cackey_debug_fd(void) {
   191    227   	static FILE *fd = NULL;
   192    228   	char *logfile;
   193    229   
   194    230   	if (fd != NULL) {
................................................................................
   233    269   }
   234    270   
   235    271   static void *CACKEY_DEBUG_FUNC_MALLOC(size_t size, const char *func, int line) {
   236    272   	void *retval;
   237    273   
   238    274   	retval = malloc(size);
   239    275   
   240         -	CACKEY_DEBUG_PRINTTIME;
   241         -	fprintf(cackey_debug_fd(), "%s():%i: ", func, line);
   242         -	fprintf(cackey_debug_fd(), "MALLOC() = %p", retval);
   243         -	fprintf(cackey_debug_fd(), "\n");
          276  +	fprintf(cackey_debug_fd(), "[%lu]: %s():%i: MALLOC() = %p\n", CACKEY_DEBUG_GETTIME(), func, line, retval);
   244    277   	fflush(cackey_debug_fd());
   245    278   
   246    279   	return(retval);
   247    280   }
   248    281   
   249    282   static void *CACKEY_DEBUG_FUNC_REALLOC(void *ptr, size_t size, const char *func, int line) {
   250    283   	void *retval;
   251    284   
   252    285   	retval = realloc(ptr, size);
   253    286   
   254    287   	if (retval != ptr) {
   255         -		CACKEY_DEBUG_PRINTTIME;
   256         -		fprintf(cackey_debug_fd(), "%s():%i: ", func, line);
   257         -		fprintf(cackey_debug_fd(), "REALLOC(%p) = %p", ptr, retval);
   258         -		fprintf(cackey_debug_fd(), "\n");
          288  +		fprintf(cackey_debug_fd(), "[%lu]: %s():%i: REALLOC(%p) = %p\n", CACKEY_DEBUG_GETTIME(), func, line, ptr, retval);
   259    289   		fflush(cackey_debug_fd());
   260    290   	}
   261    291   
   262    292   	if (retval == NULL) {
   263    293   		CACKEY_DEBUG_PRINTF(" *** ERROR *** realloc returned NULL (size = %lu)", (unsigned long) size);
   264    294   	}
   265    295   
................................................................................
   267    297   }
   268    298   
   269    299   static char *CACKEY_DEBUG_FUNC_STRDUP(const char *ptr, const char *func, int line) {
   270    300   	char *retval;
   271    301   
   272    302   	retval = strdup(ptr);
   273    303   
   274         -	CACKEY_DEBUG_PRINTTIME;
   275         -	fprintf(cackey_debug_fd(), "%s():%i: ", func, line);
   276         -	fprintf(cackey_debug_fd(), "STRDUP_MALLOC() = %p", retval);
   277         -	fprintf(cackey_debug_fd(), "\n");
          304  +	fprintf(cackey_debug_fd(), "[%lu]: %s():%i: STRDUP_MALLOC() = %p\n", CACKEY_DEBUG_GETTIME(), func, line, retval);
   278    305   	fflush(cackey_debug_fd());
   279    306   
   280    307   	return(retval);
   281    308   }
   282    309   
   283    310   static const char *CACKEY_DEBUG_FUNC_TAG_TO_STR(unsigned char tag) {
   284    311   	switch (tag) {
................................................................................
   652    679   #  ifdef strdup
   653    680   #    undef strdup
   654    681   #  endif
   655    682   #  define strdup(x) CACKEY_DEBUG_FUNC_STRDUP(x, __func__, __LINE__)
   656    683   #else
   657    684   #  define CACKEY_DEBUG_PRINTF(x...) /**/
   658    685   #  define CACKEY_DEBUG_PRINTBUF(f, x, y) /**/
   659         -#  define CACKEY_DEBUG_PERROR(x) /**/
   660    686   #  define CACKEY_DEBUG_FUNC_TAG_TO_STR(x) "DEBUG_DISABLED"
   661    687   #  define CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(x) "DEBUG_DISABLED"
   662    688   #  define CACKEY_DEBUG_FUNC_OBJID_TO_STR(x) "DEBUG_DISABLED"
   663    689   #  define CACKEY_DEBUG_FUNC_APPTYPE_TO_STR(x) "DEBUG_DISABLED"
   664    690   #  define CACKEY_DEBUG_FUNC_ATTRIBUTE_TO_STR(x) "DEBUG_DISABLED"
   665    691   #endif
   666    692