Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/netbsd-tests/lib/libc/gen/t_basedirname.c
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | if (test_basename_table[i].input != NULL) { | ||||
if (strlen(test_basename_table[i].input) >= | if (strlen(test_basename_table[i].input) >= | ||||
sizeof(testbuf)) | sizeof(testbuf)) | ||||
atf_tc_skip("Testbuf too small!"); | atf_tc_skip("Testbuf too small!"); | ||||
strcpy(testbuf, test_basename_table[i].input); | strcpy(testbuf, test_basename_table[i].input); | ||||
base = basename(testbuf); | base = basename(testbuf); | ||||
} else | } else | ||||
base = basename(NULL); | base = basename(NULL); | ||||
#ifdef __NetBSD__ | |||||
/* | /* | ||||
* basename(3) is allowed to modify the input buffer. | * basename(3) is allowed to modify the input buffer. | ||||
* However, that is considered hostile by some programs, | * However, that is considered hostile by some programs, | ||||
* and so we elect to consider this an error. | * and so we elect to consider this an error. | ||||
* | * | ||||
* This is not a problem, as basename(3) is also allowed | * This is not a problem, as basename(3) is also allowed | ||||
* to return a pointer to a statically-allocated buffer | * to return a pointer to a statically-allocated buffer | ||||
* (it is explicitly not required to be reentrant). | * (it is explicitly not required to be reentrant). | ||||
*/ | */ | ||||
if (test_basename_table[i].input != NULL && | if (test_basename_table[i].input != NULL && | ||||
strcmp(test_basename_table[i].input, testbuf) != 0) { | strcmp(test_basename_table[i].input, testbuf) != 0) { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"Input buffer for \"%s\" was modified\n", | "Input buffer for \"%s\" was modified\n", | ||||
test_basename_table[i].input); | test_basename_table[i].input); | ||||
atf_tc_fail("Input buffer was modified."); | atf_tc_fail("Input buffer was modified."); | ||||
} | } | ||||
#endif | |||||
/* Make sure the result is correct. */ | /* Make sure the result is correct. */ | ||||
if (strcmp(test_basename_table[i].output, base) != 0) { | if (strcmp(test_basename_table[i].output, base) != 0) { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"Input \"%s\", output \"%s\", expected \"%s\"\n", | "Input \"%s\", output \"%s\", expected \"%s\"\n", | ||||
test_basename_table[i].input == | test_basename_table[i].input == | ||||
NULL ? "(null)" : test_basename_table[i].input, | NULL ? "(null)" : test_basename_table[i].input, | ||||
base, test_basename_table[i].output); | base, test_basename_table[i].output); | ||||
Show All 19 Lines | if (test_dirname_table[i].input != NULL) { | ||||
if (strlen(test_dirname_table[i].input) >= | if (strlen(test_dirname_table[i].input) >= | ||||
sizeof(testbuf)) | sizeof(testbuf)) | ||||
atf_tc_skip("Testbuf too small!"); | atf_tc_skip("Testbuf too small!"); | ||||
strcpy(testbuf, test_dirname_table[i].input); | strcpy(testbuf, test_dirname_table[i].input); | ||||
base = dirname(testbuf); | base = dirname(testbuf); | ||||
} else | } else | ||||
base = dirname(NULL); | base = dirname(NULL); | ||||
#ifdef __NetBSD__ | |||||
/* | /* | ||||
* dirname(3) is allowed to modify the input buffer. | * dirname(3) is allowed to modify the input buffer. | ||||
* However, that is considered hostile by some programs, | * However, that is considered hostile by some programs, | ||||
* and so we elect to consider this an error. | * and so we elect to consider this an error. | ||||
* | * | ||||
* This is not a problem, as dirname(3) is also allowed | * This is not a problem, as dirname(3) is also allowed | ||||
* to return a pointer to a statically-allocated buffer | * to return a pointer to a statically-allocated buffer | ||||
* (it is explicitly not required to be reentrant). | * (it is explicitly not required to be reentrant). | ||||
*/ | */ | ||||
if (test_dirname_table[i].input != NULL && | if (test_dirname_table[i].input != NULL && | ||||
strcmp(test_dirname_table[i].input, testbuf) != 0) { | strcmp(test_dirname_table[i].input, testbuf) != 0) { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"Input buffer for \"%s\" was modified\n", | "Input buffer for \"%s\" was modified\n", | ||||
test_dirname_table[i].input); | test_dirname_table[i].input); | ||||
atf_tc_fail("Input buffer was modified."); | atf_tc_fail("Input buffer was modified."); | ||||
} | } | ||||
#endif | |||||
/* Make sure the result is correct. */ | /* Make sure the result is correct. */ | ||||
if (strcmp(test_dirname_table[i].output, base) != 0) { | if (strcmp(test_dirname_table[i].output, base) != 0) { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"Input \"%s\", output \"%s\", expected \"%s\"\n", | "Input \"%s\", output \"%s\", expected \"%s\"\n", | ||||
test_dirname_table[i].input == | test_dirname_table[i].input == | ||||
NULL ? "(null)" : test_dirname_table[i].input, | NULL ? "(null)" : test_dirname_table[i].input, | ||||
base, test_dirname_table[i].output); | base, test_dirname_table[i].output); | ||||
Show All 12 Lines |