1 /* 2 * 3 * Copyright (c) International Business Machines Corp., 2002 4 * 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 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /* 11/20/2002 Port to LTP robbiew (at) us.ibm.com */ 21 /* 06/30/2001 Port to Linux nsharoff (at) us.ibm.com */ 22 23 /* 24 * NAME 25 * confstr1.c - test for confstr(3C) - Get configuration-defined string 26 * values. 27 * 28 * CALLS 29 * confstr(3C) 30 * 31 * RESTRICTIONS 32 * MUST RUN AS ROOT 33 * 34 */ 35 36 #define _XOPEN_SOURCE 500 37 38 #include <unistd.h> 39 #include <stdio.h> 40 #include <sys/types.h> 41 #include <errno.h> 42 43 #include "test.h" 44 #include "safe_macros.h" 45 46 static struct test_case_t { 47 int value; 48 char *name; 49 } test_cases[] = { 50 {_CS_PATH, "PATH"}, 51 {_CS_XBS5_ILP32_OFF32_CFLAGS, "XBS5_ILP32_OFF32_CFLAGS"}, 52 {_CS_XBS5_ILP32_OFF32_LDFLAGS, "XBS5_ILP32_OFF32_LDFLAGS"}, 53 {_CS_XBS5_ILP32_OFF32_LIBS, "XBS5_ILP32_OFF32_LIBS"}, 54 {_CS_XBS5_ILP32_OFF32_LINTFLAGS, "XBS5_ILP32_OFF32_LINTFLAGS"}, 55 {_CS_XBS5_ILP32_OFFBIG_CFLAGS, "XBS5_ILP32_OFFBIG_CFLAGS"}, 56 {_CS_XBS5_ILP32_OFFBIG_LDFLAGS, "XBS5_ILP32_OFFBIG_LDFLAGS"}, 57 {_CS_XBS5_ILP32_OFFBIG_LIBS, "XBS5_ILP32_OFFBIG_LIBS"}, 58 {_CS_XBS5_ILP32_OFFBIG_LINTFLAGS, "XBS5_ILP32_OFFBIG_LINTFLAGS"}, 59 {_CS_XBS5_LP64_OFF64_CFLAGS, "XBS5_LP64_OFF64_CFLAGS"}, 60 {_CS_XBS5_LP64_OFF64_LDFLAGS, "XBS5_LP64_OFF64_LDFLAGS"}, 61 {_CS_XBS5_LP64_OFF64_LIBS, "XBS5_LP64_OFF64_LIBS"}, 62 {_CS_XBS5_LP64_OFF64_LINTFLAGS, "XBS5_LP64_OFF64_LINTFLAGS"}, 63 {_CS_XBS5_LPBIG_OFFBIG_CFLAGS, "XBS5_LPBIG_OFFBIG_CFLAGS"}, 64 {_CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "XBS5_LPBIG_OFFBIG_LDFLAGS"}, 65 {_CS_XBS5_LPBIG_OFFBIG_LIBS, "XBS5_LPBIG_OFFBIG_LIBS"}, 66 {_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "XBS5_LPBIG_OFFBIG_LINTFLAGS"}, 67 {_CS_GNU_LIBC_VERSION, "GNU_LIBC_VERSION"}, 68 {_CS_GNU_LIBPTHREAD_VERSION, "GNU_LIBPTHREAD_VERSION"}, 69 }; 70 71 char *TCID = "confstr01"; 72 int TST_TOTAL = ARRAY_SIZE(test_cases); 73 74 static void setup(void); 75 static void cleanup(void); 76 77 int main(int argc, char *argv[]) 78 { 79 int lc; 80 int i; 81 char *buf; 82 int len; 83 84 tst_parse_opts(argc, argv, NULL, NULL); 85 86 setup(); 87 88 for (lc = 0; TEST_LOOPING(lc); lc++) { 89 90 tst_count = 0; 91 92 for (i = 0; i < TST_TOTAL; i++) { 93 94 TEST(confstr(test_cases[i].value, NULL, (size_t)0)); 95 96 if (TEST_RETURN != 0) { 97 len = TEST_RETURN; 98 buf = SAFE_MALLOC(cleanup, len); 99 TEST(confstr(test_cases[i].value, buf, len)); 100 101 if (TEST_RETURN != len || buf[len-1] != '\0') { 102 tst_brkm(TBROK, cleanup, 103 "confstr :%s failed", 104 test_cases[i].name); 105 } else { 106 tst_resm(TPASS, "confstr %s = '%s'", 107 test_cases[i].name, buf); 108 } 109 free(buf); 110 } else { 111 if (TEST_ERRNO == EINVAL) { 112 tst_resm(TCONF, 113 "confstr %s not supported", 114 test_cases[i].name); 115 } else { 116 tst_resm(TFAIL, 117 "confstr %s failed", 118 test_cases[i].name); 119 } 120 } 121 } 122 } 123 124 cleanup(); 125 126 tst_exit(); 127 } 128 129 static void setup(void) 130 { 131 TEST_PAUSE; 132 } 133 134 static void cleanup(void) 135 { 136 } 137