Advertisement
SteelCrow

DEBUG

Mar 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include "main.h"
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <stdarg.h>
  8. #include <string.h>
  9. #include <errno.h>
  10. #include <sys/socket.h>
  11.  
  12.  
  13. #define F_EXIT_FAILURE 1
  14. #define F_EXIT_SUCCESS 0
  15.  
  16. #define errno_s strerror(errno)
  17. void
  18. fatal(const char *fmt, ...)
  19. {
  20.     va_list vargs;
  21.  
  22.     va_start(vargs, fmt);
  23.     vfprintf(stderr, fmt, vargs);
  24.     fprintf(stderr, ".\n");
  25.     va_end(vargs);
  26.  
  27.     exit(EXIT_FAILURE);
  28. }
  29.  
  30. int appcore_debug = 0;
  31. void
  32. appcore_debug_internal(char *file, int line, const char *fmt, ...) {
  33.     va_list vargs;
  34.     char buf[2048];
  35.  
  36.     va_start(vargs, fmt);
  37.     vsnprintf(buf, sizeof(buf), fmt, vargs);
  38.     va_end(vargs);
  39.  
  40.     printf("%s:%d - %s\n", file, line, buf);
  41. }
  42. #define appcore_debug(...) \
  43.     if(appcore_debug) \
  44.         appcore_debug_internal(__FILE__, __LINE__, __VA_ARGS__)
  45.  
  46.  
  47. int
  48. main(int argc, char** argv)
  49. {
  50.     appcore_debug("%s : %s", "sf", "sfdsfd");
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement