From: git Date: Mon, 20 Apr 2026 08:39:39 +0000 (-0400) Subject: minor asprintf refinement X-Git-Url: https://git.datadissipation.net/?a=commitdiff_plain;h=5db824c730835f1adbdf2d77f4676f6ab9266407;p=single-header-libcext.git minor asprintf refinement --- diff --git a/asprintf.h b/asprintf.h index 6d3341a..fc66ba5 100644 --- a/asprintf.h +++ b/asprintf.h @@ -29,59 +29,59 @@ #ifndef ASPRINTF_H_ #define ASPRINTF_H_ 1 - #ifdef ASPRINTF_INCLUDE_LIBC +#ifdef ASPRINTF_INCLUDE_LIBC #include #include #include - #endif /* ASPRINTF_INCLUDE_LIBC */ +#endif /* ASPRINTF_INCLUDE_LIBC */ - #ifndef HAVE_ASPRINTF +#ifndef HAVE_ASPRINTF #define HAVE_ASPRINTF 1 #define asprintf i_asprintf_ #define vasprintf i_vasprintf_ - int i_vasprintf_(char **restrict strp, const char *restrict fmt, va_list ap); - int i_asprintf_(char **restrict strp, const char *restrict fmt, ...); - #endif /* !HAVE_ASPRINTF */ + int i_vasprintf_(char **strp, const char *fmt, va_list ap); + int i_asprintf_(char **strp, const char *fmt, ...); +#endif /* !HAVE_ASPRINTF */ - #ifdef ASPRINTF_IMPLEMENTATION - int - i_vasprintf_(char **restrict strp, const char *restrict fmt, va_list ap) - { - int size, ret; - va_list tp; +#ifdef ASPRINTF_IMPLEMENTATION +int +i_vasprintf_(char **strp, const char *fmt, va_list ap) +{ + int size, ret; + va_list tp; - va_copy(tp, ap); - size = vsnprintf(NULL, 0, fmt, tp); - va_end(tp); + va_copy(tp, ap); + size = vsnprintf(NULL, 0, fmt, tp); + va_end(tp); - if (size < 0) { - return -1; - } - *strp = malloc(size + 1); - if (*strp == NULL) { - return -1; - } + if (size < 0) { + return -1; + } + *strp = malloc(size + 1); + if (*strp == NULL) { + return -1; + } - ret = vsnprintf(*strp, size + 1, fmt, ap); - if (ret < 0) { - free(*strp); - return -1; - } + ret = vsnprintf(*strp, size + 1, fmt, ap); + if (ret < 0) { + free(*strp); + return -1; + } - return ret; - } + return ret; +} - int - i_asprintf_(char **restrict strp, const char *restrict fmt, ...) - { - int ret; - va_list ap; +int +i_asprintf_(char **strp, const char *fmt, ...) +{ + int ret; + va_list ap; - va_start(ap, fmt); - ret = i_vasprintf_(strp, fmt, ap); - va_end(ap); + va_start(ap, fmt); + ret = i_vasprintf_(strp, fmt, ap); + va_end(ap); - return ret; - } - #endif /* ASPRINTF_IMPLEMENTATION */ + return ret; +} +#endif /* ASPRINTF_IMPLEMENTATION */ #endif /* !ASPRINTF_H_ */