Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
30f4a9d22b6e76cfac66d0b9ea65788e24a66e59
[simgrid.git] / buildtools / Cmake / test_prog / prog_vsnprintf.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include <stdarg.h>
9
10 int my_vsnprintf (char *buf, const char *tmpl, ...)
11 {
12     int i;
13     va_list args;
14     va_start (args, tmpl);
15     i = vsnprintf (buf, 2, tmpl, args);
16     va_end (args);
17     return i;
18 }
19
20 int main(void)
21 {
22     char bufs[5] = { 'x', 'x', 'x', '\0', '\0' };
23     char bufd[5] = { 'x', 'x', 'x', '\0', '\0' };
24     int i;
25     i = my_vsnprintf (bufs, "%s", "111");
26     if (strcmp (bufs, "1")) exit (1);
27     if (i != 3) exit (1);
28     i = my_vsnprintf (bufd, "%d", 111);
29     if (strcmp (bufd, "1")) exit (1);
30     if (i != 3) exit (1);
31     exit(0);
32 }