Back to index

nagios-plugins  1.4.16
dirname.h
Go to the documentation of this file.
00001 /*  Take file names apart into directory and base names.
00002 
00003     Copyright (C) 1998, 2001, 2003-2006, 2009-2010 Free Software Foundation,
00004     Inc.
00005 
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00018 
00019 #ifndef DIRNAME_H_
00020 # define DIRNAME_H_ 1
00021 
00022 # include <stdbool.h>
00023 # include <stddef.h>
00024 
00025 # ifndef DIRECTORY_SEPARATOR
00026 #  define DIRECTORY_SEPARATOR '/'
00027 # endif
00028 
00029 # ifndef ISSLASH
00030 #  define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
00031 # endif
00032 
00033 # ifndef FILE_SYSTEM_PREFIX_LEN
00034 #  if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
00035     /* This internal macro assumes ASCII, but all hosts that support drive
00036        letters use ASCII.  */
00037 #   define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
00038                                 <= 'z' - 'a')
00039 #   define FILE_SYSTEM_PREFIX_LEN(Filename) \
00040            (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
00041 #  else
00042 #   define FILE_SYSTEM_PREFIX_LEN(Filename) 0
00043 #  endif
00044 # endif
00045 
00046 # ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
00047 #  define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
00048 # endif
00049 
00050 # ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
00051 #  define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
00052 # endif
00053 
00054 # if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
00055 #  define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
00056 # else
00057 #  define IS_ABSOLUTE_FILE_NAME(F) \
00058           (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
00059 # endif
00060 # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
00061 
00062 # if GNULIB_DIRNAME
00063 char *base_name (char const *file);
00064 char *dir_name (char const *file);
00065 # endif
00066 
00067 char *mdir_name (char const *file);
00068 size_t base_len (char const *file);
00069 size_t dir_len (char const *file);
00070 char *last_component (char const *file);
00071 
00072 bool strip_trailing_slashes (char *file);
00073 
00074 #endif /* not DIRNAME_H_ */