1/* uucp.h
2   Header file for the UUCP package.
3
4   Copyright (C) 1991, 1992, 1993, 1994, 1995, 2002 Ian Lance Taylor
5
6   This file is part of the Taylor UUCP package.
7
8   This program is free software; you can redistribute it and/or
9   modify it under the terms of the GNU General Public License as
10   published by the Free Software Foundation; either version 2 of the
11   License, or (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program; if not, write to the Free Software
20   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
21
22   The author of the program may be contacted at ian@airs.com.
23   */
24
25/* Get the system configuration parameters.  */
26#include "config.h"
27#include "policy.h"
28
29/* Get a definition for ANSI_C if we weren't given one.  */
30#ifndef ANSI_C
31#ifdef __STDC__
32#define ANSI_C 1
33#else /* ! defined (__STDC__) */
34#define ANSI_C 0
35#endif /* ! defined (__STDC__) */
36#endif /* ! defined (ANSI_C) */
37
38/* Pass this definition into uuconf.h.  */
39#define UUCONF_ANSI_C ANSI_C
40
41/* We always include some standard header files.  We need <signal.h>
42   to define sig_atomic_t.  */
43#include <stdio.h>
44#include <signal.h>
45#if HAVE_STDDEF_H
46#include <stddef.h>
47#endif
48
49/* On some systems we need <sys/types.h> to get sig_atomic_t or
50   size_t or time_t.  */
51#if ! HAVE_SIG_ATOMIC_T_IN_SIGNAL_H && HAVE_SIG_ATOMIC_T_IN_TYPES_H
52#define USE_TYPES_H 1
53#else
54#if ! HAVE_SIZE_T_IN_STDDEF_H && HAVE_SIZE_T_IN_TYPES_H
55#define USE_TYPES_H 1
56#else
57#if ! HAVE_TIME_T_IN_TIME_H && HAVE_TIME_T_IN_TYPES_H
58#define USE_TYPES_H 1
59#endif
60#endif
61#endif
62
63#ifndef USE_TYPES_H
64#define USE_TYPES_H 0
65#endif
66
67#if USE_TYPES_H
68#include <sys/types.h>
69#endif
70
71/* Make sure we have sig_atomic_t.  */
72#if ! HAVE_SIG_ATOMIC_T_IN_SIGNAL_H && ! HAVE_SIG_ATOMIC_T_IN_TYPES_H
73#ifndef SIG_ATOMIC_T
74/* There is no portable definition for sig_atomic_t.  */
75#define SIG_ATOMIC_T char
76#endif /* ! defined (SIG_ATOMIC_T) */
77typedef SIG_ATOMIC_T sig_atomic_t;
78#endif /* ! HAVE_SIG_ATOMIC_T_IN_SIGNAL_H && ! HAVE_SIG_ATOMIC_T_IN_TYPES_H */
79
80/* Make sure we have size_t.  */
81#if ! HAVE_SIZE_T_IN_STDDEF_H && ! HAVE_SIZE_T_IN_TYPES_H
82#ifndef SIZE_T
83#define SIZE_T unsigned
84#endif /* ! defined (SIZE_T) */
85typedef SIZE_T size_t;
86#endif /* ! HAVE_SIZE_T_IN_STDDEF_H && ! HAVE_SIZE_T_IN_TYPES_H */
87
88/* Make sure we have time_t.  We use long as the default.  We don't
89   bother to let conf.h override this, since on a system which doesn't
90   define time_t long must be correct.  */
91#if ! HAVE_TIME_T_IN_TIME_H && ! HAVE_TIME_T_IN_TYPES_H
92typedef long time_t;
93#endif
94
95/* Set up some definitions for both ANSI C and Classic C.
96
97   P() -- for function prototypes (e.g. extern int foo P((int)) ).
98   pointer -- for a generic pointer (i.e. void *).
99   constpointer -- for a generic pointer to constant data.
100   BUCHAR -- to convert a character to unsigned.  */
101#if ANSI_C
102#if ! HAVE_VOID || ! HAVE_UNSIGNED_CHAR || ! HAVE_PROTOTYPES
103 #error ANSI C compiler without void or unsigned char or prototypes
104#endif
105#define P(x) x
106typedef void *pointer;
107typedef const void *constpointer;
108#define BUCHAR(b) ((unsigned char) (b))
109#else /* ! ANSI_C */
110/* Handle uses of volatile and void in Classic C.  */
111#define volatile
112#if ! HAVE_VOID
113#define void int
114#endif
115#if HAVE_PROTOTYPES
116#define P(x) x
117#else
118#define P(x) ()
119#endif
120typedef char *pointer;
121typedef const char *constpointer;
122#if HAVE_UNSIGNED_CHAR
123#define BUCHAR(b) ((unsigned char) (b))
124#else /* ! HAVE_UNSIGNED_CHAR */
125/* This should work on most systems, but not necessarily all.  */
126#define BUCHAR(b) ((b) & 0xff)
127#endif /* ! HAVE_UNSIGNED_CHAR */
128#endif /* ! ANSI_C */
129
130/* Make sure we have a definition for offsetof.  */
131#ifndef offsetof
132#define offsetof(type, field) \
133  ((size_t) ((char *) &(((type *) 0)->field) - (char *) (type *) 0))
134#endif
135
136/* Only use inline with gcc.  */
137#ifndef __GNUC__
138#define __inline__
139#endif
140
141/* Some boilerplate code to permit using gcc attributes while
142   supporting older versions of gcc and also other compilers.  */
143
144/* This macro simplifies testing whether we are using gcc, and if it
145   is of a particular minimum version. (Both major & minor numbers are
146   significant.)  This macro will evaluate to 0 if we are not using
147   gcc at all.  */
148#ifndef GCC_VERSION
149#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
150#endif /* GCC_VERSION */
151
152/* Define macros for some gcc attributes.  This permits us to use the
153   macros freely, and know that they will come into play for the
154   version of gcc in which they are supported.  */
155
156#if (GCC_VERSION < 2007)
157# define __attribute__(x)
158#endif
159
160/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
161#ifndef ATTRIBUTE_MALLOC
162# if (GCC_VERSION >= 2096)
163#  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
164# else
165#  define ATTRIBUTE_MALLOC
166# endif /* GNUC >= 2.96 */
167#endif /* ATTRIBUTE_MALLOC */
168
169/* Attributes on labels were valid as of gcc 2.93. */
170#ifndef ATTRIBUTE_UNUSED_LABEL
171# if (GCC_VERSION >= 2093)
172#  define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
173# else
174#  define ATTRIBUTE_UNUSED_LABEL
175# endif /* GNUC >= 2.93 */
176#endif /* ATTRIBUTE_UNUSED_LABEL */
177
178#ifndef ATTRIBUTE_UNUSED
179#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
180#endif /* ATTRIBUTE_UNUSED */
181
182#ifndef ATTRIBUTE_NORETURN
183#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
184#endif /* ATTRIBUTE_NORETURN */
185
186#ifndef ATTRIBUTE_PRINTF
187#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
188#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
189#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
190#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
191#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
192#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
193#endif /* ATTRIBUTE_PRINTF */
194
195/* Get the string functions, which are used throughout the code.  */
196#if HAVE_MEMORY_H
197#include <memory.h>
198#else
199/* We really need a definition for memchr, and this should not
200   conflict with anything in <string.h>.  I hope.  */
201extern pointer memchr ();
202#endif
203
204#if HAVE_STRING_H
205#include <string.h>
206#else /* ! HAVE_STRING_H */
207#if HAVE_STRINGS_H
208#include <strings.h>
209#else /* ! HAVE_STRINGS_H */
210extern char *strcpy (), *strncpy (), *strchr (), *strrchr (), *strtok ();
211extern char *strcat (), *strerror (), *strstr ();
212extern size_t strlen (), strspn (), strcspn ();
213#if ! HAVE_MEMORY_H
214extern pointer memcpy (), memchr ();
215#endif /* ! HAVE_MEMORY_H */
216#endif /* ! HAVE_STRINGS_H */
217#endif /* ! HAVE_STRING_H */
218
219/* Get what we need from <stdlib.h>.  */
220#if HAVE_STDLIB_H
221#include <stdlib.h>
222#else /* ! HAVE_STDLIB_H */
223extern pointer malloc (), realloc (), bsearch ();
224extern long strtol ();
225extern unsigned long strtoul ();
226extern char *getenv ();
227#endif /* ! HAVE_STDLIB_H */
228
229/* NeXT uses <libc.h> to declare a bunch of functions.  */
230#if HAVE_LIBC_H
231#include <libc.h>
232#endif
233
234/* Make sure we have the EXIT_ macros.  */
235#ifndef EXIT_SUCCESS
236#define EXIT_SUCCESS (0)
237#endif
238#ifndef EXIT_FAILURE
239#define EXIT_FAILURE (1)
240#endif
241
242/* If we need to declare errno, do so.  I don't want to always do
243   this, because some system might theoretically have a different
244   declaration for errno.  On a POSIX system this is sure to work.  */
245#if ! HAVE_ERRNO_DECLARATION
246extern int errno;
247#endif
248
249/* If the system has the socket call, guess that we can compile the
250   TCP code.  */
251#define HAVE_TCP HAVE_SOCKET
252
253/* If the system has the t_open call, guess that we can compile the
254   TLI code.  */
255#define HAVE_TLI HAVE_T_OPEN
256
257/* The boolean type holds boolean values.  */
258typedef int boolean;
259#undef TRUE
260#undef FALSE
261#define TRUE (1)
262#define FALSE (0)
263
264/* The openfile_t type holds an open file.  This depends on whether we
265   are using stdio or not.  */
266#if USE_STDIO
267
268typedef FILE *openfile_t;
269#define EFILECLOSED ((FILE *) NULL)
270#define ffileisopen(e) ((e) != NULL)
271#define ffileeof(e) feof (e)
272#define cfileread(e, z, c) fread ((z), 1, (c), (e))
273#define cfilewrite(e, z, c) fwrite ((z), 1, (c), (e))
274#define ffileioerror(e, c) ferror (e)
275#ifdef SEEK_SET
276#define ffileseek(e, i) (fseek ((e), (long) (i), SEEK_SET) == 0)
277#define ffilerewind(e) (fseek ((e), (long) 0, SEEK_SET) == 0)
278#else
279#define ffileseek(e, i) (fseek ((e), (long) (i), 0) == 0)
280#define ffilerewind(e) (fseek ((e), (long) 0, 0) == 0)
281#endif
282#ifdef SEEK_END
283#define ffileseekend(e) (fseek ((e), (long) 0, SEEK_END) == 0)
284#else
285#define ffileseekend(e) (fseek ((e), (long) 0, 2) == 0)
286#endif
287#define ffileclose(e) (fclose (e) == 0)
288
289#define fstdiosync(e, z) (fsysdep_sync (e, z))
290
291#else /* ! USE_STDIO */
292
293#if ! USE_TYPES_H
294#undef USE_TYPES_H
295#define USE_TYPES_H 1
296#include <sys/types.h>
297#endif
298
299#if HAVE_UNISTD_H
300#include <unistd.h>
301#endif
302
303#ifdef OFF_T
304typedef OFF_T off_t;
305#undef OFF_T
306#endif
307
308typedef int openfile_t;
309#define EFILECLOSED (-1)
310#define ffileisopen(e) ((e) >= 0)
311#define ffileeof(e) (FALSE)
312#define cfileread(e, z, c) read ((e), (z), (c))
313#define cfilewrite(e, z, c) write ((e), (z), (c))
314#define ffileioerror(e, c) ((c) < 0)
315#ifdef SEEK_SET
316#define ffileseek(e, i) (lseek ((e), (off_t) i, SEEK_SET) >= 0)
317#define ffilerewind(e) (lseek ((e), (off_t) 0, SEEK_SET) >= 0)
318#else
319#define ffileseek(e, i) (lseek ((e), (off_t) i, 0) >= 0)
320#define ffilerewind(e) (lseek ((e), (off_t) 0, 0) >= 0)
321#endif
322#ifdef SEEK_END
323#define ffileseekend(e) (lseek ((e), (off_t) 0, SEEK_END) >= 0)
324#else
325#define ffileseekend(e) (lseek ((e), (off_t) 0, 2) >= 0)
326#endif
327#define ffileclose(e) (close (e) >= 0)
328
329#define fstdiosync(e, z) (fsysdep_sync (fileno (e), z))
330
331#endif /* ! USE_STDIO */
332
333/* A prototype for main to avoid warnings from gcc 2.0
334   -Wmissing-prototype option.  */
335extern int main P((int argc, char **argv));
336
337/* Some standard routines which we only define if they are not present
338   on the system we are compiling on.  */
339
340#if ! HAVE_GETLINE
341/* Read a line from a file.  */
342extern int getline P((char **pz, size_t *pc, FILE *e));
343#endif
344
345#if ! HAVE_REMOVE
346/* Erase a file.  */
347#undef remove
348extern int remove P((const char *zfile));
349#endif
350
351#if ! HAVE_STRDUP
352/* Copy a string into memory.  */
353extern char *strdup P((const char *z));
354#endif
355
356#if ! HAVE_STRSTR
357/* Look for one string within another.  */
358extern char *strstr P((const char *zouter, const char *zinner));
359#endif
360
361#if ! HAVE_STRCASECMP
362#if HAVE_STRICMP
363#define strcasecmp stricmp
364#else /* ! HAVE_STRICMP */
365/* Rename strcasecmp to avoid ANSI C name space.  */
366#define strcasecmp xstrcasecmp
367extern int strcasecmp P((const char *z1, const char *z2));
368#endif /* ! HAVE_STRICMP */
369#endif /* ! HAVE_STRCASECMP */
370
371#if ! HAVE_STRNCASECMP
372#if HAVE_STRNICMP
373#define strncasecmp strnicmp
374#else /* ! HAVE_STRNICMP */
375/* Rename strncasecmp to avoid ANSI C name space.  */
376#define strncasecmp xstrncasecmp
377extern int strncasecmp P((const char *z1, const char *z2, size_t clen));
378#endif /* ! HAVE_STRNICMP */
379#endif /* ! HAVE_STRNCASECMP */
380
381#if ! HAVE_STRERROR
382/* Get a string corresponding to an error message.  */
383#undef strerror
384extern char *strerror P((int ierr));
385#endif
386
387/* Get the appropriate definitions for memcmp, memcpy, memchr and
388   bzero.  */
389#if ! HAVE_MEMCMP
390#if HAVE_BCMP
391#define memcmp(p1, p2, c) bcmp ((p1), (p2), (c))
392#else /* ! HAVE_BCMP */
393extern int memcmp P((constpointer p1, constpointer p2, size_t c));
394#endif /* ! HAVE_BCMP */
395#endif /* ! HAVE_MEMCMP */
396
397#if ! HAVE_MEMCPY
398#if HAVE_BCOPY
399#define memcpy(pto, pfrom, c) bcopy ((pfrom), (pto), (c))
400#else /* ! HAVE_BCOPY */
401extern pointer memcpy P((pointer pto, constpointer pfrom, size_t c));
402#endif /* ! HAVE_BCOPY */
403#endif /* ! HAVE_MEMCPY */
404
405#if ! HAVE_MEMCHR
406extern pointer memchr P((constpointer p, int b, size_t c));
407#endif
408
409#if ! HAVE_BZERO
410#if HAVE_MEMSET
411#define bzero(p, c) memset ((p), 0, (c))
412#else /* ! HAVE_MEMSET */
413extern void bzero P((pointer p, int c));
414#endif /* ! HAVE_MEMSET */
415#endif /* ! HAVE_BZERO */
416
417/* Look up a character in a string.  */
418#if ! HAVE_STRCHR
419#if HAVE_INDEX
420#define strchr index
421extern char *index ();
422#else /* ! HAVE_INDEX */
423extern char *strchr P((const char *z, int b));
424#endif /* ! HAVE_INDEX */
425#endif /* ! HAVE_STRCHR */
426
427#if ! HAVE_STRRCHR
428#if HAVE_RINDEX
429#define strrchr rindex
430extern char *rindex ();
431#else /* ! HAVE_RINDEX */
432extern char *strrchr P((const char *z, int b));
433#endif /* ! HAVE_RINDEX */
434#endif /* ! HAVE_STRRCHR */
435
436/* Turn a string into a long integer.  */
437#if ! HAVE_STRTOL
438extern long strtol P((const char *, char **, int));
439#endif
440
441/* Turn a string into a long unsigned integer.  */
442#if ! HAVE_STRTOUL
443extern unsigned long strtoul P((const char *, char **, int));
444#endif
445
446/* Lookup a key in a sorted array.  */
447#if ! HAVE_BSEARCH
448extern pointer bsearch P((constpointer pkey, constpointer parray,
449			  size_t celes, size_t cbytes,
450			  int (*pficmp) P((constpointer, constpointer))));
451#endif
452