source: trunk/minix/lib/other/basename.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 383 bytes
Line 
1/*
2basename.c
3*/
4
5#include <libgen.h>
6#include <string.h>
7
8char *basename(path)
9char *path;
10{
11 size_t len;
12 char *cp;
13
14 if (path == NULL)
15 return ".";
16 len= strlen(path);
17 if (len == 0)
18 return ".";
19 while (path[len-1] == '/')
20 {
21 if (len == 1)
22 return path; /* just "/" */
23 len--;
24 path[len]= '\0';
25 }
26 cp= strrchr(path, '/');
27 if (cp != NULL)
28 return cp+1;
29 return path;
30}
Note: See TracBrowser for help on using the repository browser.