Blame gl/filename.h

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