File: string-printf.c-expected

package info (click to toggle)
vala 0.56.18-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 57,520 kB
  • sloc: ansic: 581,293; sh: 5,357; makefile: 3,980; xml: 3,161; yacc: 1,219; lex: 374; javascript: 23
file content (74 lines) | stat: -rw-r--r-- 1,604 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* 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>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#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;
}