Mercurial > code
diff port/C/asprintf.c @ 548:f48bb09bccc7
Misc: huge cleanup, switch to spaces
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 15 Jun 2016 13:13:26 +0200 |
parents | dc1b5143c5e3 |
children | 266f32919d0a |
line wrap: on
line diff
--- a/port/C/asprintf.c Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/asprintf.c Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * asprintf.c -- basic port of asprintf / vsprintf functions * - * Copyright (c) 2011, 2012 David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -39,17 +39,17 @@ int vasprintf(char **res, const char *fmt, va_list ap) { - int total = _vscprintf(fmt, ap); + int total = _vscprintf(fmt, ap); - if (total < 0) { - *res = NULL; - return -1; - } + if (total < 0) { + *res = NULL; + return -1; + } - if ((*res = (char *)malloc(sizeof (total) + 1)) == NULL) - return -1; + if ((*res = (char *)malloc(sizeof (total) + 1)) == NULL) + return -1; - return vsprintf_s(*res, total + 1, fmt, ap); + return vsprintf_s(*res, total + 1, fmt, ap); } #elif __STDC_VERSION__ >= 199901L @@ -60,29 +60,29 @@ int vasprintf(char **res, const char *fmt, va_list ap) { - int total, nwritten; - va_list copy; + int total, nwritten; + va_list copy; - va_copy(copy, ap); - total = vsnprintf(NULL, 0, fmt, copy); - va_end(copy); + va_copy(copy, ap); + total = vsnprintf(NULL, 0, fmt, copy); + va_end(copy); - if (total < 0) { - *res = NULL; - return total; - } + if (total < 0) { + *res = NULL; + return total; + } - if ((*res = malloc(total + 1)) == NULL) - return -1; + if ((*res = malloc(total + 1)) == NULL) + return -1; - if ((nwritten = vsnprintf(*res, total + 1, fmt, ap)) < 0) { - free(*res); - *res = NULL; + if ((nwritten = vsnprintf(*res, total + 1, fmt, ap)) < 0) { + free(*res); + *res = NULL; - return -1; - } + return -1; + } - return nwritten; + return nwritten; } #else @@ -93,24 +93,24 @@ int vasprintf(char **res, const char *format, va_list ap) { - int rvalue, ok; - size_t base = 80; + int rvalue, ok; + size_t base = 80; - if ((*res = malloc(base)) == NULL) - return -1; + if ((*res = malloc(base)) == NULL) + return -1; - ok = 0; - do { - rvalue = vsnprintf(*res, base, format, ap); + ok = 0; + do { + rvalue = vsnprintf(*res, base, format, ap); - if ((signed int)base <= rvalue || rvalue < 0) { - *res = realloc(*res, base * 2); - base *= 2; - } else - ok = 1; - } while (!ok && *res != NULL); + if ((signed int)base <= rvalue || rvalue < 0) { + *res = realloc(*res, base * 2); + base *= 2; + } else + ok = 1; + } while (!ok && *res != NULL); - return rvalue; + return rvalue; } #endif @@ -118,12 +118,12 @@ int asprintf(char **res, const char *fmt, ...) { - va_list ap; - int rvalue; + va_list ap; + int rvalue; - va_start(ap, fmt); - rvalue = vasprintf(res, fmt, ap); - va_end(ap); + va_start(ap, fmt); + rvalue = vasprintf(res, fmt, ap); + va_end(ap); - return rvalue; + return rvalue; }