Back to index

nagios-plugins  1.4.16
basename.c File Reference
#include <config.h>
#include "dirname.h"
#include <string.h>
#include "xalloc.h"
#include "xstrndup.h"

Go to the source code of this file.


char * base_name (char const *name)

Function Documentation

char* base_name ( char const name)

Definition at line 28 of file basename.c.

  char const *base = last_component (name);
  size_t length;

  /* If there is no last component, then name is a file system root or the
     empty string.  */
  if (! *base)
    return xstrndup (name, base_len (name));

  /* Collapse a sequence of trailing slashes into one.  */
  length = base_len (base);
  if (ISSLASH (base[length]))

  /* On systems with drive letters, `a/b:c' must return `./b:c' rather
     than `b:c' to avoid confusion with a drive letter.  On systems
     with pure POSIX semantics, this is not an issue.  */
      char *p = xmalloc (length + 3);
      p[0] = '.';
      p[1] = '/';
      memcpy (p + 2, base, length);
      p[length + 2] = '\0';
      return p;

  /* Finally, copy the basename.  */
  return xstrndup (base, length);

Here is the call graph for this function:

Here is the caller graph for this function: