2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
16 * Test program for portab.h and friends ;-)
24 int allow_severity = 0, deny_severity = 0;
29 /* Oops, something failed!? */
30 fprintf(stderr, "Oops, test for %s failed!?\n", Reason);
39 snprintf(str, sizeof(str), "%s", "1234567890");
41 Panic("snprintf NULL byte");
43 Panic("snprintf string length");
51 ptr = strdup("1234567890");
55 Panic("strdup NULL byte");
56 if (strlen(ptr) != 10)
57 Panic("strdup string length");
66 ptr = strndup("1234567890", 5);
70 Panic("strndup NULL byte");
72 Panic("strndup string length");
81 if (strlcpy(str, "1234567890", sizeof(str)) != 10)
82 Panic("strlcpy return code");
84 Panic("strlcpy NULL byte");
86 Panic("strlcpy string length");
94 if (strlcpy(str, "12", sizeof(str)) != 2)
95 Panic("strlcpy for strlcat");
96 if (strlcat(str, "1234567890", sizeof(str)) != 12)
97 Panic("strlcat return code");
99 Panic("strlcat NULL byte");
100 if (strlen(str) != 4)
101 Panic("strlcat string length");
107 char *str, *ptr, *last;
109 ptr = strdup("12,abc");
112 ptr = strtok_r(ptr, ",", &last);
114 Panic("strtok_r result #1");
115 if (strcmp(ptr, "12") != 0)
116 Panic("strtok_r token #1");
118 ptr = strtok_r(NULL, ",", &last);
120 Panic("strtok_r result #2");
121 if (strcmp(ptr, "abc") != 0)
122 Panic("strtok_r token #2");
124 ptr = strtok_r(NULL, ",", &last);
126 Panic("strtok_r result #3");
133 Check_vsnprintf(const int Len, const char *Format, ...)
136 Check_vsnprintf(Len, Format, va_alist)
147 va_start(ap, Format);
151 r = vsnprintf(str, sizeof(str), Format, ap);
154 /* C99 states that vsnprintf() "returns the number of
155 * characters that would have been printed if the n were
156 * unlimited", but according to the Linux manual page "glibc
157 * until 2.0.6 would return -1 when the output was truncated",
158 * and other implementations (libUTIL on A/UX) even return the
159 * number of characters processed ... so we only test our own
160 * implementation and warn on errors otherwise :-/ */
161 #ifdef HAVE_VSNPRINTF
163 "\n ** WARNING: The vsnprintf() function of this system isn't standard\n");
165 " ** conformant and returns a WRONG result: %d (should be %d)! The test\n",
168 " ** result has been ignored but may lead to errors during execution!\n\n");
170 Panic("vsnprintf return code");
174 Panic("vsnprintf NULL byte");
175 if (strlen(str) != 4)
176 Panic("vsnprintf string length");
182 /* validate datatypes */
187 if (sizeof(UINT8) != 1)
189 if (sizeof(UINT16) != 2)
191 if (sizeof(UINT32) != 4)
194 /* check functions */
201 Check_vsnprintf(2+10, "%s%s", "ab", "1234567890");