Introduce {v,}asprintf for windows
We have now again two functions called h_platform_vasprintf and h_platform_asprintf. On windows they are implemented in terms of vsnprint and the like. On BSD/GNU libraries we use the supplied vasprintf and asprintf.
This commit is contained in:
parent
124b4c381b
commit
9557448ae6
5 changed files with 90 additions and 14 deletions
|
|
@ -1,5 +1,8 @@
|
|||
#define _GNU_SOURCE // to obtain asprintf/vasprintf
|
||||
#include "platform.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
@ -12,6 +15,20 @@
|
|||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
int h_platform_asprintf(char **strp, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int res = h_platform_vasprintf(strp, fmt, ap);
|
||||
va_end(ap);
|
||||
return res;
|
||||
}
|
||||
|
||||
int h_platform_vasprintf(char **strp, const char *fmt, va_list arg)
|
||||
{
|
||||
return vasprintf(strp, fmt, arg);
|
||||
}
|
||||
|
||||
void h_platform_errx(int err, const char* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
|
@ -62,5 +79,5 @@ int64_t h_platform_stopwatch_ns(struct HStopWatch* stopwatch) {
|
|||
|
||||
// time_diff is in ns
|
||||
return (ts_now.tv_sec - stopwatch->start.tv_sec) * 1000000000
|
||||
+ (ts_now.tv_nsec - stopwatch->start.tv_nsec);
|
||||
+ (ts_now.tv_nsec - stopwatch->start.tv_nsec);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue