Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/libbb/get_last_path_component.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 815 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 8  Line 8 
8   */   */
9    
10  #include "libbb.h"  #include "libbb.h"
11    /*
12  char *bb_get_last_path_component(char *path)   * "/"        -> "/"
13     * "abc"      -> "abc"
14     * "abc/def"  -> "def"
15     * "abc/def/" -> ""
16     */
17    char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path)
18  {  {
19   char *first = path;   char *slash = strrchr(path, '/');
  char *last;  
20    
21   last = path - 1;   if (!slash || (slash == path && !slash[1]))
22     return (char*)path;
23    
24     return slash + 1;
25    }
26    
27    /*
28     * "/"        -> "/"
29     * "abc"      -> "abc"
30     * "abc/def"  -> "def"
31     * "abc/def/" -> "def" !!
32     */
33    char* FAST_FUNC bb_get_last_path_component_strip(char *path)
34    {
35     char *slash = last_char_is(path, '/');
36    
37   while (*path) {   if (slash)
38   if ((*path != '/') && (path > ++last)) {   while (*slash == '/' && slash != path)
39   last = first = path;   *slash-- = '\0';
  }  
  ++path;  
  }  
   
  if (*first == '/') {  
  last = first;  
  }  
  last[1] = 0;  
40    
41   return first;   return bb_get_last_path_component_nostrip(path);
42  }  }

Legend:
Removed from v.815  
changed lines
  Added in v.816