Files
glibc/misc/tst-dirname.c
T

71 lines
2.1 KiB
C
Raw Normal View History

1996-11-06 04:24:40 +00:00
/* Test program for dirname function a la XPG.
2002-04-04 08:12:33 +00:00
Copyright (C) 1996, 2000, 2001, 2002 Free Software Foundation, Inc.
1996-11-06 04:24:40 +00:00
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
1996-11-06 04:24:40 +00:00
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2001-07-06 04:58:11 +00:00
Lesser General Public License for more details.
1996-11-06 04:24:40 +00:00
2001-07-06 04:58:11 +00:00
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
1996-11-06 04:24:40 +00:00
#define _GNU_SOURCE 1
#include <libgen.h>
#include <stdio.h>
#include <string.h>
2000-12-16 07:54:18 +00:00
static int
2000-05-23 08:43:26 +00:00
test (const char *input, const char *result)
1996-11-06 04:24:40 +00:00
{
int retval;
char *cp;
cp = strdupa (input);
cp = dirname (cp);
retval = strcmp (cp, result);
if (retval)
printf ("dirname(\"%s\") should be \"%s\", but is \"%s\"\n",
input, result, cp);
return retval;
}
int
2000-05-23 08:43:26 +00:00
main (void)
1996-11-06 04:24:40 +00:00
{
int result = 0;
/* These are the examples given in XPG4.2. */
result |= test ("/usr/lib", "/usr");
2000-12-16 07:54:18 +00:00
result |= test ("/usr/", "/");
1996-11-06 04:24:40 +00:00
result |= test ("usr", ".");
result |= test ("/", "/");
result |= test (".", ".");
result |= test ("..", ".");
2000-12-16 07:54:18 +00:00
/* Some more tests. */
result |= test ("/usr/lib/", "/usr");
result |= test ("/usr", "/");
2001-04-04 00:01:02 +00:00
result |= test ("a//", ".");
result |= test ("a////", ".");
result |= test ("////usr", "/");
result |= test ("////usr//", "/");
result |= test ("//usr", "//");
result |= test ("//usr//", "//");
result |= test ("//", "//");
2000-12-16 07:54:18 +00:00
2002-04-04 08:12:33 +00:00
/* Other Unix implementations behave like this. */
result |= test ("x///y", "x");
result |= test ("x/////y", "x");
1996-11-06 04:24:40 +00:00
return result != 0;
}