tests.c (2976B)
1 #if TEST___PROGNAME 2 int 3 main(void) 4 { 5 extern char *__progname; 6 7 return !__progname; 8 } 9 #endif /* TEST___PROGNAME */ 10 #if TEST_ERR 11 /* 12 * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org> 13 * 14 * Permission to use, copy, modify, and distribute this software for any 15 * purpose with or without fee is hereby granted, provided that the above 16 * copyright notice and this permission notice appear in all copies. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 */ 26 27 #include <err.h> 28 29 int 30 main(void) 31 { 32 warnx("%d. warnx", 1); 33 warn("%d. warn", 2); 34 err(0, "%d. err", 3); 35 /* NOTREACHED */ 36 return 1; 37 } 38 #endif /* TEST_ERR */ 39 #if TEST_GETPROGNAME 40 #include <stdlib.h> 41 42 int 43 main(void) 44 { 45 const char * progname; 46 47 progname = getprogname(); 48 return progname == NULL; 49 } 50 #endif /* TEST_GETPROGNAME */ 51 #if TEST_PLEDGE 52 #include <unistd.h> 53 54 int 55 main(void) 56 { 57 return !!pledge("stdio", NULL); 58 } 59 #endif /* TEST_PLEDGE */ 60 #if TEST_PROGRAM_INVOCATION_SHORT_NAME 61 #define _GNU_SOURCE /* See feature_test_macros(7) */ 62 #include <errno.h> 63 64 int 65 main(void) 66 { 67 68 return !program_invocation_short_name; 69 } 70 #endif /* TEST_PROGRAM_INVOCATION_SHORT_NAME */ 71 #if TEST_REALLOCARRAY 72 #include <stdlib.h> 73 74 int 75 main(void) 76 { 77 return !reallocarray(NULL, 2, 2); 78 } 79 #endif /* TEST_REALLOCARRAY */ 80 #if TEST_STRTONUM 81 /* 82 * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org> 83 * 84 * Permission to use, copy, modify, and distribute this software for any 85 * purpose with or without fee is hereby granted, provided that the above 86 * copyright notice and this permission notice appear in all copies. 87 * 88 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 89 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 90 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 91 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 92 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 93 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 94 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 95 */ 96 97 #include <stdlib.h> 98 99 int 100 main(void) 101 { 102 const char *errstr; 103 104 if (strtonum("1", 0, 2, &errstr) != 1) 105 return 1; 106 if (errstr != NULL) 107 return 2; 108 if (strtonum("1x", 0, 2, &errstr) != 0) 109 return 3; 110 if (errstr == NULL) 111 return 4; 112 if (strtonum("2", 0, 1, &errstr) != 0) 113 return 5; 114 if (errstr == NULL) 115 return 6; 116 if (strtonum("0", 1, 2, &errstr) != 0) 117 return 7; 118 if (errstr == NULL) 119 return 8; 120 return 0; 121 } 122 #endif /* TEST_STRTONUM */