Advertisement
bueddl

Untitled

Apr 9th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1.  
  2. #if __STDC_VERSION__ < 199901L
  3.  
  4. #define STATIC_ALLOC(var, size) char *var = (char*)malloc(size);
  5. #define STATIC_FREE(var) free(var);
  6. int _expand_format_str(char *buffer, const char *format);
  7.  
  8. #else
  9.  
  10. #define STATIC_ALLOC(var, size) char var[size];
  11. #define STATIC_FREE(var)
  12. int _expand_format_str(char *restrict buffer, const char *restrict format);
  13.  
  14. #endif
  15.  
  16. /* ----------------------- Wrapping up standard io  ----------------------- */
  17.  
  18. #if __STDC_VERSION__ < 199901L
  19. int cprintf(const char *format, ...)
  20. #else
  21. int cprintf(const char *restrict format, ...)
  22. #endif
  23. {
  24.     va_list args;
  25.     int ret;
  26.     STATIC_ALLOC(format_expanded, _expand_format_str(NULL, format));
  27.  
  28.     va_start(args, format);
  29.     _expand_format_str(format_expanded, format);
  30.     ret = vprintf(format_expanded, args);
  31.     va_end(args);
  32.    
  33.     STATIC_FREE(format_expanded);
  34.     return ret;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement