1 /* $NetBSD: test.c,v 1.2 2003/07/26 19:38:45 salo Exp $ */
4 * Regression test for basename(3).
6 * Written by Jason R. Thorpe <thorpej@NetBSD.org>, Oct. 2002.
21 * The following are taken from the "Sample Input and Output Strings
22 * for basename()" table in IEEE Std 1003.1-2001.
24 { "/usr/lib", "lib" },
28 { "//usr//lib//", "lib" },
30 * IEEE Std 1003.1-2001:
32 * If path is a null pointer or points to an empty string,
33 * basename() shall return a pointer to the string "." .
38 * IEEE Std 1003.1-2001:
40 * If the string is exactly "//", it is implementation-defined
41 * whether "/" or "//" is returned.
43 * The NetBSD implementation returns "/".
50 int main(int argc
, char *argv
[]);
53 main(int argc
, char *argv
[])
55 char testbuf
[32], *base
;
58 for (i
= 0; test_table
[i
].output
!= NULL
; i
++) {
59 if (test_table
[i
].input
!= NULL
) {
60 assert(strlen(test_table
[i
].input
) < sizeof(testbuf
));
61 strcpy(testbuf
, test_table
[i
].input
);
62 base
= basename(testbuf
);
64 base
= basename(NULL
);
67 * basename(3) is allowed to modify the input buffer.
68 * However, that is considered hostile by some programs,
69 * and so we elect to consider this an error.
71 * This is not a problem, as basename(3) is also allowed
72 * to return a pointer to a statically-allocated buffer
73 * (it is explicitly not required to be reentrant).
75 if (test_table
[i
].input
!= NULL
&&
76 strcmp(test_table
[i
].input
, testbuf
) != 0) {
78 "Input buffer for \"%s\" was modified\n",
83 /* Make sure the result is correct. */
84 if (strcmp(test_table
[i
].output
, base
) != 0) {
86 "Input \"%s\", output \"%s\", expected \"%s\"\n",
87 test_table
[i
].input
== NULL
? "(null)"
88 : test_table
[i
].input
,
89 base
, test_table
[i
].output
);