Home | History | Annotate | Download | only in lib
      1 /*  Take file names apart into directory and base names.
      2 
      3     Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc.
      4 
      5     This program is free software: you can redistribute it and/or modify
      6     it under the terms of the GNU General Public License as published by
      7     the Free Software Foundation; either version 3 of the License, or
      8     (at your option) any later version.
      9 
     10     This program is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13     GNU General Public License for more details.
     14 
     15     You should have received a copy of the GNU General Public License
     16     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     17 
     18 #ifndef DIRNAME_H_
     19 # define DIRNAME_H_ 1
     20 
     21 # include <stdbool.h>
     22 # include <stddef.h>
     23 
     24 # ifndef DIRECTORY_SEPARATOR
     25 #  define DIRECTORY_SEPARATOR '/'
     26 # endif
     27 
     28 # ifndef ISSLASH
     29 #  define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
     30 # endif
     31 
     32 # ifndef FILE_SYSTEM_PREFIX_LEN
     33 #  if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
     34     /* This internal macro assumes ASCII, but all hosts that support drive
     35        letters use ASCII.  */
     36 #   define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
     37 				<= 'z' - 'a')
     38 #   define FILE_SYSTEM_PREFIX_LEN(Filename) \
     39 	   (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
     40 #  else
     41 #   define FILE_SYSTEM_PREFIX_LEN(Filename) 0
     42 #  endif
     43 # endif
     44 
     45 # ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
     46 #  define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
     47 # endif
     48 
     49 # ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
     50 #  define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
     51 # endif
     52 
     53 # if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
     54 #  define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
     55 # else
     56 #  define IS_ABSOLUTE_FILE_NAME(F) \
     57 	  (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
     58 # endif
     59 # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
     60 
     61 char *base_name (char const *file);
     62 char *dir_name (char const *file);
     63 size_t base_len (char const *file);
     64 size_t dir_len (char const *file);
     65 char *last_component (char const *file);
     66 
     67 bool strip_trailing_slashes (char *file);
     68 
     69 #endif /* not DIRNAME_H_ */
     70