leafnode  1.12.0
About: Leafnode is a store & forward NNTP proxy for small (dialup) sites.
  Fossies Dox: leafnode-1.12.0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xsnprintf.c
Go to the documentation of this file.
1/* override *snprintf if needed */
2#ifndef RUN_FROM_CONFIGURE
3#include "leafnode.h"
4#endif
5
6#include <string.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <stdarg.h>
10
11static int rc = EXIT_SUCCESS;
12
13static void complain(const char *t, int r, const char *s, int er, const char *es) {
14 fprintf(stderr, "test %s returned %d, string: \"%s\", wanted %d/\"%s\"\n", t, r, s, er, es);
15 rc = EXIT_FAILURE;
16}
17
18static void test(const char *t, int er, const char *es, int siz,
19 const char *f, ...) {
20 va_list ap;
21 int r;
22
23 char s[40];
24 const char init[40] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
25 va_start(ap, f);
26 strcpy(s, init);
27 r = vsnprintf(s, siz, f, ap);
28 va_end(ap);
29 if (r != er || strcmp(s, es))
30 complain(t, r, s, er, es);
31}
32
33int main(void)
34{
35 test ("1a", 1, "", 1, "1");
36 test ("1b", 1, "1", 2, "%d", 1);
37 test ("1c", 2, "1", 2, "%d", 11);
38 test ("2", 1, "1", 2, "1");
39 test ("3a", 1, "1", 2, "%s", "1");
40 test ("3b", 1, "1", 2, "%c", '1');
41 test ("3c", 1, "1", 2, "%d", 1);
42 test ("3d", 1, "1", 2, "%ld", 1l);
43 test ("3e", 1, "1", 2, "%u", 1);
44 test ("3f", 1, "1", 2, "%lu", 1l);
45 test ("4", 0, "", 1, "");
46 test ("5", 5, "64738", 10, "%u", 64738);
47 test ("6a", 3, "003", 4, "%03lu", 3l);
48 test ("6b", 3, " 3", 4, "%3lu", 3l);
49 test ("6c", 3, "", 1, "%3lu", 3l);
50 test ("7a", 3, "22", 3, "%3d", 222);
51 test ("7b", 3, "222", 4, "%3d", 222);
52 test ("7c", 4, "2222", 6, "%3d", 2222);
53 test ("8a", 3, "+02", 5, "%+03d", 2);
54 test ("8b", 5, "+0042", 6, "%+05d", 42);
55 test ("8c", 5, " +42", 6, "%+5d", 42);
56 test ("9", 5, "1", 2, "12345");
57 return rc;
58}
#define vsnprintf
Definition: leafnode.h:75
static void test(const char *t, int er, const char *es, int siz, const char *f,...)
Definition: xsnprintf.c:18
int main(void)
Definition: xsnprintf.c:33
static void complain(const char *t, int r, const char *s, int er, const char *es)
Definition: xsnprintf.c:13
static int rc
Definition: xsnprintf.c:11