OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.git] / libiberty / basename.c
1 /* Return the basename of a pathname.
2    This file is in the public domain. */
3
4 /*
5 NAME
6         basename -- return pointer to last component of a pathname
7
8 SYNOPSIS
9         char *basename (const char *name)
10
11 DESCRIPTION
12         Given a pointer to a string containing a typical pathname
13         (/usr/src/cmd/ls/ls.c for example), returns a pointer to the
14         last component of the pathname ("ls.c" in this case).
15
16 BUGS
17         Presumes a UNIX style path with UNIX style separators.
18 */
19
20 #include "ansidecl.h"
21 #include "libiberty.h"
22
23 #include "config.h"
24
25 #ifdef NEED_basename
26
27 char *
28 basename (name)
29      const char *name;
30 {
31   const char *base = name;
32
33   while (*name)
34     {
35       if (*name++ == '/')
36         {
37           base = name;
38         }
39     }
40   return (char *) base;
41 }
42
43 #endif