diff options
Diffstat (limited to 'tests/posix/string-printf.c-expected')
-rw-r--r-- | tests/posix/string-printf.c-expected | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/posix/string-printf.c-expected b/tests/posix/string-printf.c-expected new file mode 100644 index 000000000..c63c6e0fe --- /dev/null +++ b/tests/posix/string-printf.c-expected @@ -0,0 +1,65 @@ +/* posix_string_printf.c generated by valac, the Vala compiler + * generated from posix_string_printf.vala, do not modify */ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <stdarg.h> +#include <assert.h> +#include <stddef.h> + +#define _free0(var) ((var == NULL) ? NULL : (var = (free (var), NULL))) + +static void _vala_main (void); +static char* string_printf (const char* format, + ...) __attribute__((__format__ (__printf__, 1, 2))) ; + +static char* +string_printf (const char* format, + ...) +{ + int length; + va_list ap; + char* result; + va_start (ap, format); + length = vsnprintf (NULL, 0, format, ap) + 1; + va_end (ap); + result = malloc (length); + va_start (ap, format); + vsnprintf (result, length, format, ap); + va_end (ap); + return result; +} + +static int +_strcmp0 (const void * s1, + const void * s2) +{ + if (!s1) { + return -(s1 != s2); + } + if (!s2) { + return s1 != s2; + } + return strcmp (s1, s2); +} + +static void +_vala_main (void) +{ + char* s = NULL; + char* _tmp0_; + _tmp0_ = string_printf ("%i %s %u %.4f", 42, "foo", 4711U, 3.1415); + s = _tmp0_; + assert (_strcmp0 (s, "42 foo 4711 3.1415") == 0); + _free0 (s); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + |