nptl: Fix tst-cancel30 on sparc64
[glibc.git] / misc / tst-dirname.c
blob95c765ca82fdca9be2ee221b97315860272bd7b0
1 /* Test program for dirname function a la XPG.
2 Copyright (C) 1996-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #define _GNU_SOURCE 1
20 #include <libgen.h>
21 #include <stdio.h>
22 #include <string.h>
25 static int
26 test (const char *input, const char *result)
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;
39 static int
40 do_test (void)
42 int result = 0;
44 /* These are the examples given in XPG4.2. */
45 result |= test ("/usr/lib", "/usr");
46 result |= test ("/usr/", "/");
47 result |= test ("usr", ".");
48 result |= test ("/", "/");
49 result |= test (".", ".");
50 result |= test ("..", ".");
52 /* Some more tests. */
53 result |= test ("/usr/lib/", "/usr");
54 result |= test ("/usr", "/");
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 ("//", "//");
63 /* Other Unix implementations behave like this. */
64 result |= test ("x///y", "x");
65 result |= test ("x/////y", "x");
67 return result != 0;
70 #define TEST_FUNCTION do_test ()
71 #include "../test-skeleton.c"