Sat, 07 May 2022 15:07:01 +0200
add util_asprintf and util_vasprintf
src/server/util/util.c | file | annotate | diff | comparison | revisions | |
src/server/util/util.h | file | annotate | diff | comparison | revisions |
--- a/src/server/util/util.c Sat May 07 14:14:20 2022 +0200 +++ b/src/server/util/util.c Sat May 07 15:07:01 2022 +0200 @@ -55,6 +55,7 @@ #include "../public/nsapi.h" #include <ucx/string.h> #include <ucx/mempool.h> +#include <ucx/utils.h> #include "pblock.h" #include "util.h" @@ -288,6 +289,24 @@ return vsnprintf(s, n, fmt, args); } +NSAPI_PUBLIC int util_vasprintf(pool_handle_t *pool, char **s, const char *fmt, + va_list args) +{ + UcxAllocator a = util_pool_allocator(pool); + va_list ap; + va_copy(ap, args); + sstr_t str = ucx_vasprintf(&a, fmt, ap); + *s = str.ptr; + return str.length; +} + +NSAPI_PUBLIC int util_asprintf(pool_handle_t *pool, char **s, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + return util_vasprintf(pool, s, fmt, args); +} + NSAPI_PUBLIC int util_vsprintf(char *s, register const char *fmt, va_list args) { return vsprintf(s, fmt, args); @@ -433,7 +452,7 @@ } NSAPI_PUBLIC char* util_parent_path(const char *path) { - char *name = util_resource_name((char*)path); + char *name = (char*)util_resource_name((char*)path); size_t namelen = strlen(name); size_t pathlen = strlen(path); size_t parentlen = pathlen - namelen;
--- a/src/server/util/util.h Sat May 07 14:14:20 2022 +0200 +++ b/src/server/util/util.h Sat May 07 15:07:01 2022 +0200 @@ -170,6 +170,11 @@ NSAPI_PUBLIC int INTutil_snprintf(char *s, int n, const char *fmt, ...); +NSAPI_PUBLIC int util_vasprintf(pool_handle_t *pool, char **s, const char *fmt, + va_list args); + +NSAPI_PUBLIC int util_asprintf(pool_handle_t *pool, char **s, const char *fmt, ...); + NSAPI_PUBLIC int util_strlftime(char *dst, size_t dstsize, const char *format, const struct tm *t); NSAPI_PUBLIC int INTutil_strftime(char *s, const char *format, const struct tm *t); @@ -331,6 +336,8 @@ #define util_sprintf INTutil_sprintf #define util_vsnprintf INTutil_vsnprintf #define util_snprintf INTutil_snprintf +#define util_vasprintf INTutil_vasprintf +#define util_asprintf INTutil_asprintf #define util_strftime INTutil_strftime #define util_strcasecmp INTutil_strcasecmp #define util_strncasecmp INTutil_strncasecmp