| 1 |
/* Copyright 1993,1994 by Paul Vixie
|
| 2 |
* All rights reserved
|
| 3 |
*
|
| 4 |
* Distribute freely, except: don't remove my name from the source or
|
| 5 |
* documentation (don't take credit for my work), mark your changes (don't
|
| 6 |
* get me blamed for your possible bugs), don't alter or remove this
|
| 7 |
* notice. May be sold if buildable source is provided to buyer. No
|
| 8 |
* warrantee of any kind, express or implied, is included with this
|
| 9 |
* software; use at your own risk, responsibility for damages (if any) to
|
| 10 |
* anyone resulting from the use of this software rests entirely with the
|
| 11 |
* user.
|
| 12 |
*
|
| 13 |
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
|
| 14 |
* I'll try to keep a version up to date. I can be reached as follows:
|
| 15 |
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
|
| 16 |
*/
|
| 17 |
|
| 18 |
#if defined(POSIX) || defined(ATT)
|
| 19 |
# include <stdlib.h>
|
| 20 |
# include <unistd.h>
|
| 21 |
# include <string.h>
|
| 22 |
# include <dirent.h>
|
| 23 |
# include <errno.h>
|
| 24 |
# define DIR_T struct dirent
|
| 25 |
# define WAIT_T int
|
| 26 |
# define WAIT_IS_INT 1
|
| 27 |
extern char *tzname[2];
|
| 28 |
# define TZONE(tm) tzname[(tm).tm_isdst]
|
| 29 |
#endif
|
| 30 |
|
| 31 |
#if defined(UNIXPC)
|
| 32 |
# undef WAIT_T
|
| 33 |
# undef WAIT_IS_INT
|
| 34 |
# define WAIT_T union wait
|
| 35 |
#endif
|
| 36 |
|
| 37 |
#if defined(POSIX)
|
| 38 |
# define SIG_T sig_t
|
| 39 |
# define TIME_T time_t
|
| 40 |
# define PID_T pid_t
|
| 41 |
#endif
|
| 42 |
|
| 43 |
#if defined(ATT)
|
| 44 |
# define SIG_T void
|
| 45 |
# define TIME_T long
|
| 46 |
# define PID_T int
|
| 47 |
#endif
|
| 48 |
|
| 49 |
#if !defined(POSIX) && !defined(ATT)
|
| 50 |
/* classic BSD */
|
| 51 |
extern time_t time();
|
| 52 |
extern unsigned sleep();
|
| 53 |
extern struct tm *localtime();
|
| 54 |
extern struct passwd *getpwnam();
|
| 55 |
extern int errno;
|
| 56 |
extern void perror(), exit(), free();
|
| 57 |
extern char *getenv(), *strcpy(), *strchr(), *strtok();
|
| 58 |
extern void *malloc(), *realloc();
|
| 59 |
# define SIG_T void
|
| 60 |
# define TIME_T long
|
| 61 |
# define PID_T int
|
| 62 |
# define WAIT_T union wait
|
| 63 |
# define DIR_T struct direct
|
| 64 |
# include <sys/dir.h>
|
| 65 |
# define TZONE(tm) (tm).tm_zone
|
| 66 |
#endif
|
| 67 |
|
| 68 |
/* getopt() isn't part of POSIX. some systems define it in <stdlib.h> anyway.
|
| 69 |
* of those that do, some complain that our definition is different and some
|
| 70 |
* do not. to add to the misery and confusion, some systems define getopt()
|
| 71 |
* in ways that we cannot predict or comprehend, yet do not define the adjunct
|
| 72 |
* external variables needed for the interface.
|
| 73 |
*/
|
| 74 |
#if (!defined(BSD) || (BSD < 198911)) && !defined(ATT) && !defined(UNICOS)
|
| 75 |
int getopt __P((int, char * const *, const char *));
|
| 76 |
#endif
|
| 77 |
|
| 78 |
#if (!defined(BSD) || (BSD < 199103))
|
| 79 |
extern char *optarg;
|
| 80 |
extern int optind, opterr, optopt;
|
| 81 |
#endif
|
| 82 |
|
| 83 |
#if WAIT_IS_INT
|
| 84 |
# ifndef WEXITSTATUS
|
| 85 |
# define WEXITSTATUS(x) (((x) >> 8) & 0xff)
|
| 86 |
# endif
|
| 87 |
# ifndef WTERMSIG
|
| 88 |
# define WTERMSIG(x) ((x) & 0x7f)
|
| 89 |
# endif
|
| 90 |
# ifndef WCOREDUMP
|
| 91 |
# define WCOREDUMP(x) ((x) & 0x80)
|
| 92 |
# endif
|
| 93 |
#else /*WAIT_IS_INT*/
|
| 94 |
# ifndef WEXITSTATUS
|
| 95 |
# define WEXITSTATUS(x) ((x).w_retcode)
|
| 96 |
# endif
|
| 97 |
# ifndef WTERMSIG
|
| 98 |
# define WTERMSIG(x) ((x).w_termsig)
|
| 99 |
# endif
|
| 100 |
# ifndef WCOREDUMP
|
| 101 |
# define WCOREDUMP(x) ((x).w_coredump)
|
| 102 |
# endif
|
| 103 |
#endif /*WAIT_IS_INT*/
|
| 104 |
|
| 105 |
#ifndef WIFSIGNALED
|
| 106 |
#define WIFSIGNALED(x) (WTERMSIG(x) != 0)
|
| 107 |
#endif
|
| 108 |
#ifndef WIFEXITED
|
| 109 |
#define WIFEXITED(x) (WTERMSIG(x) == 0)
|
| 110 |
#endif
|
| 111 |
|
| 112 |
#ifdef NEED_STRCASECMP
|
| 113 |
extern int strcasecmp __P((char *, char *));
|
| 114 |
#endif
|
| 115 |
|
| 116 |
#ifdef NEED_STRDUP
|
| 117 |
extern char *strdup __P((char *));
|
| 118 |
#endif
|
| 119 |
|
| 120 |
#ifdef NEED_STRERROR
|
| 121 |
extern char *strerror __P((int));
|
| 122 |
#endif
|
| 123 |
|
| 124 |
#ifdef NEED_FLOCK
|
| 125 |
extern int flock __P((int, int));
|
| 126 |
# define LOCK_SH 1
|
| 127 |
# define LOCK_EX 2
|
| 128 |
# define LOCK_NB 4
|
| 129 |
# define LOCK_UN 8
|
| 130 |
#endif
|
| 131 |
|
| 132 |
#ifdef NEED_SETSID
|
| 133 |
extern int setsid __P((void));
|
| 134 |
#endif
|
| 135 |
|
| 136 |
#ifdef NEED_GETDTABLESIZE
|
| 137 |
extern int getdtablesize __P((void));
|
| 138 |
#endif
|
| 139 |
|
| 140 |
#ifdef NEED_SETENV
|
| 141 |
extern int setenv __P((char *, char *, int));
|
| 142 |
#endif
|
| 143 |
|
| 144 |
#ifdef NEED_VFORK
|
| 145 |
extern PID_T vfork __P((void));
|
| 146 |
#endif
|