sort: Replace GNU sort with NetBSD sort
[dragonfly.git] / gnu / usr.bin / sort / system.h
1 /* system-dependent definitions for textutils programs.
2    Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17 /*
18  * $DragonFly: src/gnu/usr.bin/sort/system.h,v 1.2 2003/11/09 11:41:16 eirikn Exp $
19  */
20 /* Include sys/types.h before this file.  */
21
22 #include <sys/stat.h>
23
24 #ifdef STAT_MACROS_BROKEN
25 #undef S_ISBLK
26 #undef S_ISCHR
27 #undef S_ISDIR
28 #undef S_ISFIFO
29 #undef S_ISLNK
30 #undef S_ISMPB
31 #undef S_ISMPC
32 #undef S_ISNWK
33 #undef S_ISREG
34 #undef S_ISSOCK
35 #endif /* STAT_MACROS_BROKEN.  */
36
37 #if !defined(S_ISBLK) && defined(S_IFBLK)
38 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
39 #endif
40 #if !defined(S_ISCHR) && defined(S_IFCHR)
41 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
42 #endif
43 #if !defined(S_ISDIR) && defined(S_IFDIR)
44 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
45 #endif
46 #if !defined(S_ISREG) && defined(S_IFREG)
47 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
48 #endif
49 #if !defined(S_ISFIFO) && defined(S_IFIFO)
50 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
51 #endif
52 #if !defined(S_ISLNK) && defined(S_IFLNK)
53 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
54 #endif
55 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
56 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
57 #endif
58 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
59 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
60 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
61 #endif
62 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
63 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
64 #endif
65 #if !defined(HAVE_MKFIFO)
66 #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
67 #endif
68
69 #ifdef HAVE_UNISTD_H
70 #include <unistd.h>
71 #endif
72
73 #ifndef _POSIX_VERSION
74 off_t lseek ();
75 #endif
76
77 #ifndef STDIN_FILENO
78 #define STDIN_FILENO 0
79 #endif
80
81 #ifndef STDOUT_FILENO
82 #define STDOUT_FILENO 1
83 #endif
84
85 #ifndef STDERR_FILENO
86 #define STDERR_FILENO 2
87 #endif
88
89 /* Don't use bcopy!  Use memmove if source and destination may overlap,
90    memcpy otherwise.  */
91
92 #ifdef HAVE_STRING_H
93 # if !STDC_HEADERS && HAVE_MEMORY_H
94 #  include <memory.h>
95 # endif
96 # include <string.h>
97 #else
98 # include <strings.h>
99 char *memchr ();
100 #endif
101
102 #include <errno.h>
103 #ifndef errno
104 extern int errno;
105 #endif
106
107 #ifdef STDC_HEADERS
108 #include <stdlib.h>
109 #else
110 char *getenv ();
111 #endif
112
113 #ifndef EXIT_FAILURE
114 # define EXIT_FAILURE 1
115 #endif
116
117 #ifndef EXIT_SUCCESS
118 # define EXIT_SUCCESS 0
119 #endif
120
121 #ifdef HAVE_FCNTL_H
122 #include <fcntl.h>
123 #else
124 #include <sys/file.h>
125 #endif
126
127 #if !defined(SEEK_SET)
128 #define SEEK_SET 0
129 #define SEEK_CUR 1
130 #define SEEK_END 2
131 #endif
132
133 #ifndef _POSIX_SOURCE
134 #include <sys/param.h>
135 #endif
136
137 /* Get or fake the disk device blocksize.
138    Usually defined by sys/param.h (if at all).  */
139 #if !defined(DEV_BSIZE) && defined(BSIZE)
140 #define DEV_BSIZE BSIZE
141 #endif
142 #if !defined(DEV_BSIZE) && defined(BBSIZE) /* SGI */
143 #define DEV_BSIZE BBSIZE
144 #endif
145 #ifndef DEV_BSIZE
146 #define DEV_BSIZE 4096
147 #endif
148
149 /* Extract or fake data from a `struct stat'.
150    ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes. */
151 #ifndef HAVE_ST_BLKSIZE
152 # define ST_BLKSIZE(statbuf) DEV_BSIZE
153 #else /* HAVE_ST_BLKSIZE */
154 /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
155 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
156                                ? (statbuf).st_blksize : DEV_BSIZE)
157 #endif /* HAVE_ST_BLKSIZE */
158
159 #ifndef S_ISLNK
160 #define lstat stat
161 #endif
162
163 #ifndef RETSIGTYPE
164 #define RETSIGTYPE void
165 #endif
166
167 #include <ctype.h>
168
169 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
170 #define ISASCII(c) 1
171 #else
172 #define ISASCII(c) isascii((unsigned char)c)
173 #endif
174
175 #ifdef isblank
176 #define ISBLANK(c) (ISASCII (c) && isblank ((unsigned char)c))
177 #else
178 #define ISBLANK(c) ((c) == ' ' || (c) == '\t')
179 #endif
180 #ifdef isgraph
181 #define ISGRAPH(c) (ISASCII (c) && isgraph ((unsigned char)c))
182 #else
183 #define ISGRAPH(c) (ISASCII (c) && isprint ((unsigned char)c) && !isspace ((unsigned char)c))
184 #endif
185
186 #define ISPRINT(c) (ISASCII (c) && isprint ((unsigned char)c))
187 #define ISDIGIT(c) (ISASCII (c) && isdigit ((unsigned char)c))
188 #define ISALNUM(c) (ISASCII (c) && isalnum ((unsigned char)c))
189 #define ISALPHA(c) (ISASCII (c) && isalpha ((unsigned char)c))
190 #define ISCNTRL(c) (ISASCII (c) && iscntrl ((unsigned char)c))
191 #define ISLOWER(c) (ISASCII (c) && islower ((unsigned char)c))
192 #define ISPUNCT(c) (ISASCII (c) && ispunct ((unsigned char)c))
193 #define ISSPACE(c) (ISASCII (c) && isspace ((unsigned char)c))
194 #define ISUPPER(c) (ISASCII (c) && isupper ((unsigned char)c))
195 #define ISXDIGIT(c) (ISASCII (c) && isxdigit ((unsigned char)c))
196
197 /* Disable string localization for the time being.  */
198 #undef _
199 #define _(String) String
200