Blame src/gl/filename.h

Packit Service 991b93
/* Basic filename support macros.
Packit Service 991b93
   Copyright (C) 2001-2004, 2007-2020 Free Software Foundation, Inc.
Packit Service 991b93
Packit Service 991b93
   This program is free software: you can redistribute it and/or modify
Packit Service 991b93
   it under the terms of the GNU General Public License as published by
Packit Service 991b93
   the Free Software Foundation; either version 3 of the License, or
Packit Service 991b93
   (at your option) any later version.
Packit Service 991b93
Packit Service 991b93
   This program is distributed in the hope that it will be useful,
Packit Service 991b93
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 991b93
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 991b93
   GNU General Public License for more details.
Packit Service 991b93
Packit Service 991b93
   You should have received a copy of the GNU General Public License
Packit Service 991b93
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service 991b93
Packit Service 991b93
/* From Paul Eggert and Jim Meyering.  */
Packit Service 991b93
Packit Service 991b93
#ifndef _FILENAME_H
Packit Service 991b93
#define _FILENAME_H
Packit Service 991b93
Packit Service 991b93
#include <string.h>
Packit Service 991b93
Packit Service 991b93
#ifdef __cplusplus
Packit Service 991b93
extern "C" {
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
/* Filename support.
Packit Service 991b93
   ISSLASH(C)                  tests whether C is a directory separator
Packit Service 991b93
                               character.
Packit Service 991b93
   HAS_DEVICE(Filename)        tests whether Filename contains a device
Packit Service 991b93
                               specification.
Packit Service 991b93
   FILE_SYSTEM_PREFIX_LEN(Filename)  length of the device specification
Packit Service 991b93
                                     at the beginning of Filename,
Packit Service 991b93
                                     index of the part consisting of
Packit Service 991b93
                                     alternating components and slashes.
Packit Service 991b93
   FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
Packit Service 991b93
                               1 when a non-empty device specification
Packit Service 991b93
                               can be followed by an empty or relative
Packit Service 991b93
                               part,
Packit Service 991b93
                               0 when a non-empty device specification
Packit Service 991b93
                               must be followed by a slash,
Packit Service 991b93
                               0 when device specification don't exist.
Packit Service 991b93
   IS_ABSOLUTE_FILE_NAME(Filename)
Packit Service 991b93
                               tests whether Filename is independent of
Packit Service 991b93
                               any notion of "current directory".
Packit Service 991b93
   IS_RELATIVE_FILE_NAME(Filename)
Packit Service 991b93
                               tests whether Filename may be concatenated
Packit Service 991b93
                               to a directory filename.
Packit Service 991b93
   Note: On native Windows, OS/2, DOS, "c:" is neither an absolute nor a
Packit Service 991b93
   relative file name!
Packit Service 991b93
   IS_FILE_NAME_WITH_DIR(Filename)  tests whether Filename contains a device
Packit Service 991b93
                                    or directory specification.
Packit Service 991b93
 */
Packit Service 991b93
#if defined _WIN32 || defined __CYGWIN__ \
Packit Service 991b93
    || defined __EMX__ || defined __MSDOS__ || defined __DJGPP__
Packit Service 991b93
  /* Native Windows, Cygwin, OS/2, DOS */
Packit Service 991b93
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
Packit Service 991b93
  /* Internal macro: Tests whether a character is a drive letter.  */
Packit Service 991b93
# define _IS_DRIVE_LETTER(C) \
Packit Service 991b93
    (((C) >= 'A' && (C) <= 'Z') || ((C) >= 'a' && (C) <= 'z'))
Packit Service 991b93
  /* Help the compiler optimizing it.  This assumes ASCII.  */
Packit Service 991b93
# undef _IS_DRIVE_LETTER
Packit Service 991b93
# define _IS_DRIVE_LETTER(C) \
Packit Service 991b93
    (((unsigned int) (C) | ('a' - 'A')) - 'a' <= 'z' - 'a')
Packit Service 991b93
# define HAS_DEVICE(Filename) \
Packit Service 991b93
    (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':')
Packit Service 991b93
# define FILE_SYSTEM_PREFIX_LEN(Filename) (HAS_DEVICE (Filename) ? 2 : 0)
Packit Service 991b93
# ifdef __CYGWIN__
Packit Service 991b93
#  define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
Packit Service 991b93
# else
Packit Service 991b93
   /* On native Windows, OS/2, DOS, the system has the notion of a
Packit Service 991b93
      "current directory" on each drive.  */
Packit Service 991b93
#  define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
Packit Service 991b93
# endif
Packit Service 991b93
# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
Packit Service 991b93
#  define IS_ABSOLUTE_FILE_NAME(Filename) \
Packit Service 991b93
     ISSLASH ((Filename)[FILE_SYSTEM_PREFIX_LEN (Filename)])
Packit Service 991b93
# else
Packit Service 991b93
#  define IS_ABSOLUTE_FILE_NAME(Filename) \
Packit Service 991b93
     (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename))
Packit Service 991b93
# endif
Packit Service 991b93
# define IS_RELATIVE_FILE_NAME(Filename) \
Packit Service 991b93
    (! (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename)))
Packit Service 991b93
# define IS_FILE_NAME_WITH_DIR(Filename) \
Packit Service 991b93
    (strchr ((Filename), '/') != NULL || strchr ((Filename), '\\') != NULL \
Packit Service 991b93
     || HAS_DEVICE (Filename))
Packit Service 991b93
#else
Packit Service 991b93
  /* Unix */
Packit Service 991b93
# define ISSLASH(C) ((C) == '/')
Packit Service 991b93
# define HAS_DEVICE(Filename) ((void) (Filename), 0)
Packit Service 991b93
# define FILE_SYSTEM_PREFIX_LEN(Filename) ((void) (Filename), 0)
Packit Service 991b93
# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
Packit Service 991b93
# define IS_ABSOLUTE_FILE_NAME(Filename) ISSLASH ((Filename)[0])
Packit Service 991b93
# define IS_RELATIVE_FILE_NAME(Filename) (! ISSLASH ((Filename)[0]))
Packit Service 991b93
# define IS_FILE_NAME_WITH_DIR(Filename) (strchr ((Filename), '/') != NULL)
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Deprecated macros.  For backward compatibility with old users of the
Packit Service 991b93
   'filename' module.  */
Packit Service 991b93
#define IS_ABSOLUTE_PATH IS_ABSOLUTE_FILE_NAME
Packit Service 991b93
#define IS_PATH_WITH_DIR IS_FILE_NAME_WITH_DIR
Packit Service 991b93
Packit Service 991b93
Packit Service 991b93
#ifdef __cplusplus
Packit Service 991b93
}
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
#endif /* _FILENAME_H */