Convert codebase to C89 compatibility and update test scripts
This commit is contained in:
@@ -2,26 +2,45 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Portable va_copy fallback for pre-C99 or platforms without va_copy. */
|
||||
#ifndef va_copy
|
||||
# if defined(__va_copy)
|
||||
# define va_copy(dest, src) __va_copy(dest, src)
|
||||
# else
|
||||
# define va_copy(dest, src) ((dest) = (src))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
char* format_string_va(const char* fmt, va_list args) {
|
||||
if (!fmt) return NULL;
|
||||
/* Declarations first to satisfy -std=c89 */
|
||||
va_list args_copy;
|
||||
int needed;
|
||||
char* buf;
|
||||
|
||||
if (!fmt) return NULL;
|
||||
|
||||
va_copy(args_copy, args);
|
||||
int needed = vsnprintf(NULL, 0, fmt, args_copy);
|
||||
needed = vsnprintf(NULL, 0, fmt, args_copy);
|
||||
va_end(args_copy);
|
||||
if (needed < 0) return NULL;
|
||||
|
||||
char* buf = (char*)malloc((size_t)needed + 1);
|
||||
buf = (char*)malloc((size_t)needed + 1);
|
||||
if (!buf) return NULL;
|
||||
vsnprintf(buf, (size_t)needed + 1, fmt, args);
|
||||
return buf;
|
||||
}
|
||||
|
||||
char* format_string(const char* fmt, ...) {
|
||||
if (!fmt) return NULL;
|
||||
/* Declarations first to satisfy -std=c89 */
|
||||
va_list args;
|
||||
char* s;
|
||||
|
||||
if (!fmt) return NULL;
|
||||
|
||||
va_start(args, fmt);
|
||||
char* s = format_string_va(fmt, args);
|
||||
s = format_string_va(fmt, args);
|
||||
va_end(args);
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user