Back to index

glibc  2.9
Defines | Functions
tst-dirname.c File Reference
#include <libgen.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Defines

#define _GNU_SOURCE   1

Functions

static int test (const char *input, const char *result)
int main (void)

Define Documentation

#define _GNU_SOURCE   1

Definition at line 21 of file tst-dirname.c.


Function Documentation

int main ( void  )

Definition at line 42 of file tst-dirname.c.

{
  int result = 0;

  /* These are the examples given in XPG4.2.  */
  result |= test ("/usr/lib", "/usr");
  result |= test ("/usr/", "/");
  result |= test ("usr", ".");
  result |= test ("/", "/");
  result |= test (".", ".");
  result |= test ("..", ".");

  /* Some more tests.   */
  result |= test ("/usr/lib/", "/usr");
  result |= test ("/usr", "/");
  result |= test ("a//", ".");
  result |= test ("a////", ".");
  result |= test ("////usr", "/");
  result |= test ("////usr//", "/");
  result |= test ("//usr", "//");
  result |= test ("//usr//", "//");
  result |= test ("//", "//");

  /* Other Unix implementations behave like this.  */
  result |= test ("x///y", "x");
  result |= test ("x/////y", "x");

  return result != 0;
}
static int test ( const char *  input,
const char *  result 
) [static]

Definition at line 28 of file tst-dirname.c.

{
  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;
}

Here is the call graph for this function: