xref: /haiku/src/libs/stdc++/legacy/basename.c (revision 508f54795f39c3e7552d87c95aae9dd8ec6f505b)
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 char *
24 basename (name)
25      const char *name;
26 {
27   const char *base = name;
28 
29   while (*name)
30     {
31       if (*name++ == '/')
32 	{
33 	  base = name;
34 	}
35     }
36   return (char *) base;
37 }
38