/gnu/usr.bin/grep/system.h

https://github.com/randy1/DragonFlyBSD · C Header · 207 lines · 165 code · 22 blank · 20 comment · 40 complexity · 81c0243a3243b1b27377827953ea99e7 MD5 · raw file

  1. /* Portability cruft. Include after config.h and sys/types.h.
  2. Copyright (C) 1996, 1998, 1999 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  14. 02111-1307, USA. */
  15. #undef PARAMS
  16. #if defined (__STDC__) && __STDC__
  17. # ifndef _PTR_T
  18. # define _PTR_T
  19. typedef void * ptr_t;
  20. # endif
  21. # define PARAMS(x) x
  22. #else
  23. # ifndef _PTR_T
  24. # define _PTR_T
  25. typedef char * ptr_t;
  26. # endif
  27. # define PARAMS(x) ()
  28. #endif
  29. #ifdef HAVE_UNISTD_H
  30. # include <fcntl.h>
  31. # include <unistd.h>
  32. #else
  33. # define O_RDONLY 0
  34. # define SEEK_SET 0
  35. # define SEEK_CUR 1
  36. int open(), read(), close();
  37. #endif
  38. #include <errno.h>
  39. #ifndef errno
  40. extern int errno;
  41. #endif
  42. #ifndef HAVE_STRERROR
  43. extern int sys_nerr;
  44. extern char *sys_errlist[];
  45. # define strerror(E) (0 <= (E) && (E) < sys_nerr ? _(sys_errlist[E]) : _("Unknown system error"))
  46. #endif
  47. /* Some operating systems treat text and binary files differently. */
  48. #if O_BINARY
  49. # include <io.h>
  50. # ifdef HAVE_SETMODE
  51. # define SET_BINARY(fd) setmode (fd, O_BINARY)
  52. # else
  53. # define SET_BINARY(fd) _setmode (fd, O_BINARY)
  54. # endif
  55. #else
  56. # ifndef O_BINARY
  57. # define O_BINARY 0
  58. # define SET_BINARY(fd) (void)0
  59. # endif
  60. #endif
  61. #ifdef HAVE_DOS_FILE_NAMES
  62. # define IS_SLASH(c) ((c) == '/' || (c) == '\\')
  63. # define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0)
  64. #endif
  65. #ifndef IS_SLASH
  66. # define IS_SLASH(c) ((c) == '/')
  67. #endif
  68. #ifndef FILESYSTEM_PREFIX_LEN
  69. # define FILESYSTEM_PREFIX_LEN(f) 0
  70. #endif
  71. /* This assumes _WIN32, like DJGPP, has D_OK. Does it? In what header? */
  72. #ifdef D_OK
  73. # ifdef EISDIR
  74. # define is_EISDIR(e, f) \
  75. ((e) == EISDIR \
  76. || ((e) == EACCES && access (f, D_OK) == 0 && ((e) = EISDIR, 1)))
  77. # else
  78. # define is_EISDIR(e, f) ((e) == EACCES && access (f, D_OK) == 0)
  79. # endif
  80. #endif
  81. #ifndef is_EISDIR
  82. # ifdef EISDIR
  83. # define is_EISDIR(e, f) ((e) == EISDIR)
  84. # else
  85. # define is_EISDIR(e, f) 0
  86. # endif
  87. #endif
  88. #if STAT_MACROS_BROKEN
  89. # undef S_ISDIR
  90. # undef S_ISREG
  91. #endif
  92. #if !defined(S_ISDIR) && defined(S_IFDIR)
  93. # define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
  94. #endif
  95. #if !defined(S_ISREG) && defined(S_IFREG)
  96. # define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
  97. #endif
  98. #ifdef STDC_HEADERS
  99. # include <stdlib.h>
  100. #else
  101. char *getenv ();
  102. ptr_t malloc(), realloc(), calloc();
  103. void free();
  104. #endif
  105. #if __STDC__
  106. # include <stddef.h>
  107. #endif
  108. #ifdef STDC_HEADERS
  109. # include <limits.h>
  110. #endif
  111. #ifndef CHAR_BIT
  112. # define CHAR_BIT 8
  113. #endif
  114. /* The extra casts work around common compiler bugs. */
  115. #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
  116. #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
  117. ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
  118. : (t) 0))
  119. #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
  120. #ifndef CHAR_MAX
  121. # define CHAR_MAX TYPE_MAXIMUM (char)
  122. #endif
  123. #ifndef INT_MAX
  124. # define INT_MAX TYPE_MAXIMUM (int)
  125. #endif
  126. #ifndef UCHAR_MAX
  127. # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
  128. #endif
  129. #if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H)
  130. # include <memory.h>
  131. #endif
  132. #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
  133. # include <string.h>
  134. #else
  135. # include <strings.h>
  136. # undef strchr
  137. # define strchr index
  138. # undef strrchr
  139. # define strrchr rindex
  140. # undef memcpy
  141. # define memcpy(d, s, n) bcopy (s, d, n)
  142. #endif
  143. #ifndef HAVE_MEMCHR
  144. ptr_t memchr();
  145. #endif
  146. #if ! defined HAVE_MEMMOVE && ! defined memmove
  147. # define memmove(d, s, n) bcopy (s, d, n)
  148. #endif
  149. #include <ctype.h>
  150. #ifndef isgraph
  151. # define isgraph(C) (isprint(C) && !isspace(C))
  152. #endif
  153. #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
  154. # define IN_CTYPE_DOMAIN(c) 1
  155. #else
  156. # define IN_CTYPE_DOMAIN(c) isascii(c)
  157. #endif
  158. #define ISALPHA(C) (IN_CTYPE_DOMAIN (C) && isalpha (C))
  159. #define ISUPPER(C) (IN_CTYPE_DOMAIN (C) && isupper (C))
  160. #define ISLOWER(C) (IN_CTYPE_DOMAIN (C) && islower (C))
  161. #define ISDIGIT(C) (IN_CTYPE_DOMAIN (C) && isdigit (C))
  162. #define ISXDIGIT(C) (IN_CTYPE_DOMAIN (C) && isxdigit (C))
  163. #define ISSPACE(C) (IN_CTYPE_DOMAIN (C) && isspace (C))
  164. #define ISPUNCT(C) (IN_CTYPE_DOMAIN (C) && ispunct (C))
  165. #define ISALNUM(C) (IN_CTYPE_DOMAIN (C) && isalnum (C))
  166. #define ISPRINT(C) (IN_CTYPE_DOMAIN (C) && isprint (C))
  167. #define ISGRAPH(C) (IN_CTYPE_DOMAIN (C) && isgraph (C))
  168. #define ISCNTRL(C) (IN_CTYPE_DOMAIN (C) && iscntrl (C))
  169. #define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C))
  170. #if ENABLE_NLS
  171. # include <libintl.h>
  172. # define _(String) gettext (String)
  173. #else
  174. # define _(String) String
  175. #endif
  176. #define N_(String) String
  177. #if HAVE_SETLOCALE
  178. # include <locale.h>
  179. #endif
  180. #ifndef initialize_main
  181. #define initialize_main(argcp, argvp)
  182. #endif