.
[coreutils.git] / src / sys2.h
blobe2d41594e8c33ac805fd3f6b3fed0c04a909dd5d
1 /* WARNING -- this file is temporary. It is shared between the
2 sh-utils, fileutils, and textutils packages. Once I find a little
3 more time, I'll merge the remaining things in system.h and everything
4 in this file will go back there. */
6 #ifndef RETSIGTYPE
7 # define RETSIGTYPE void
8 #endif
10 #ifndef __GNUC__
11 # ifdef HAVE_ALLOCA_H
12 # include <alloca.h>
13 # else
14 # ifdef _AIX
15 # pragma alloca
16 # else
17 # ifdef _WIN32
18 # include <malloc.h>
19 # include <io.h>
20 # else
21 # ifndef alloca
22 char *alloca ();
23 # endif
24 # endif
25 # endif
26 # endif
27 #endif
29 #include <ctype.h>
31 /* Jim Meyering writes:
33 "... Some ctype macros are valid only for character codes that
34 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
35 using /bin/cc or gcc but without giving an ansi option). So, all
36 ctype uses should be through macros like ISPRINT... If
37 STDC_HEADERS is defined, then autoconf has verified that the ctype
38 macros don't need to be guarded with references to isascii. ...
39 Defining isascii to 1 should let any compiler worth its salt
40 eliminate the && through constant folding."
42 Bruno Haible adds:
44 "... Furthermore, isupper(c) etc. have an undefined result if c is
45 outside the range -1 <= c <= 255. One is tempted to write isupper(c)
46 with c being of type `char', but this is wrong if c is an 8-bit
47 character >= 128 which gets sign-extended to a negative value.
48 The macro ISUPPER protects against this as well." */
50 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
51 # define IN_CTYPE_DOMAIN(c) 1
52 #else
53 # define IN_CTYPE_DOMAIN(c) isascii(c)
54 #endif
56 #ifdef isblank
57 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
58 #else
59 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
60 #endif
61 #ifdef isgraph
62 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
63 #else
64 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
65 #endif
67 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
68 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
69 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
70 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
71 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
72 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
73 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
74 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
75 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
76 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
78 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
79 - Its arg may be any int or unsigned int; it need not be an unsigned char.
80 - It's guaranteed to evaluate its argument exactly once.
81 - It's typically faster.
82 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
83 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
84 it's important to use the locale's definition of `digit' even when the
85 host does not conform to Posix. */
86 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
88 #ifndef PARAMS
89 # if PROTOTYPES
90 # define PARAMS(Args) Args
91 # else
92 # define PARAMS(Args) ()
93 # endif
94 #endif
96 /* Take care of NLS matters. */
98 #if HAVE_LOCALE_H
99 # include <locale.h>
100 #endif
101 #if !HAVE_SETLOCALE
102 # define setlocale(Category, Locale) /* empty */
103 #endif
105 #if ENABLE_NLS
106 # include <libintl.h>
107 # define _(Text) gettext (Text)
108 #else
109 # undef bindtextdomain
110 # define bindtextdomain(Domain, Directory) /* empty */
111 # undef textdomain
112 # define textdomain(Domain) /* empty */
113 # define _(Text) Text
114 #endif
115 #define N_(Text) Text
117 #define STREQ(a,b) (strcmp((a), (b)) == 0)
119 #ifndef HAVE_DECL_FREE
120 void free ();
121 #endif
123 #ifndef HAVE_DECL_MALLOC
124 char *malloc ();
125 #endif
127 #ifndef HAVE_DECL_MEMCHR
128 char *memchr ();
129 #endif
131 #ifndef HAVE_DECL_REALLOC
132 char *realloc ();
133 #endif
135 #ifndef HAVE_DECL_STPCPY
136 # ifndef stpcpy
137 char *stpcpy ();
138 # endif
139 #endif
141 #ifndef HAVE_DECL_STRSTR
142 char *strstr ();
143 #endif
145 #ifndef HAVE_DECL_GETENV
146 char *getenv ();
147 #endif
149 #ifndef HAVE_DECL_LSEEK
150 off_t lseek ();
151 #endif
153 #include "xalloc.h"
155 #ifndef HAVE_MEMPCPY
156 /* Be CAREFUL that there are no side effects in N. */
157 # define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
158 #endif