]>
Commit | Line | Data |
---|---|---|
2c6fe0bd | 1 | /* Test program for dirname function a la XPG. |
6d7e8eda | 2 | Copyright (C) 1996-2023 Free Software Foundation, Inc. |
2c6fe0bd | 3 | This file is part of the GNU C Library. |
2c6fe0bd UD |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
2c6fe0bd UD |
9 | |
10 | The GNU C Library 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 the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
2c6fe0bd | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
2c6fe0bd UD |
18 | |
19 | #define _GNU_SOURCE 1 | |
20 | #include <libgen.h> | |
21 | #include <stdio.h> | |
22 | #include <string.h> | |
23 | ||
24 | ||
887e7ab6 | 25 | static int |
bcaad6ee | 26 | test (const char *input, const char *result) |
2c6fe0bd UD |
27 | { |
28 | int retval; | |
29 | char *cp; | |
30 | cp = strdupa (input); | |
31 | cp = dirname (cp); | |
32 | retval = strcmp (cp, result); | |
33 | if (retval) | |
34 | printf ("dirname(\"%s\") should be \"%s\", but is \"%s\"\n", | |
35 | input, result, cp); | |
36 | return retval; | |
37 | } | |
38 | ||
29955b5d AS |
39 | static int |
40 | do_test (void) | |
2c6fe0bd UD |
41 | { |
42 | int result = 0; | |
43 | ||
44 | /* These are the examples given in XPG4.2. */ | |
45 | result |= test ("/usr/lib", "/usr"); | |
887e7ab6 | 46 | result |= test ("/usr/", "/"); |
2c6fe0bd UD |
47 | result |= test ("usr", "."); |
48 | result |= test ("/", "/"); | |
49 | result |= test (".", "."); | |
50 | result |= test ("..", "."); | |
51 | ||
887e7ab6 UD |
52 | /* Some more tests. */ |
53 | result |= test ("/usr/lib/", "/usr"); | |
54 | result |= test ("/usr", "/"); | |
c891b2df UD |
55 | result |= test ("a//", "."); |
56 | result |= test ("a////", "."); | |
57 | result |= test ("////usr", "/"); | |
58 | result |= test ("////usr//", "/"); | |
59 | result |= test ("//usr", "//"); | |
60 | result |= test ("//usr//", "//"); | |
61 | result |= test ("//", "//"); | |
887e7ab6 | 62 | |
d3d48616 UD |
63 | /* Other Unix implementations behave like this. */ |
64 | result |= test ("x///y", "x"); | |
65 | result |= test ("x/////y", "x"); | |
66 | ||
2c6fe0bd UD |
67 | return result != 0; |
68 | } | |
29955b5d AS |
69 | |
70 | #define TEST_FUNCTION do_test () | |
71 | #include "../test-skeleton.c" |