xref: /dragonfly/usr.bin/top/os.h (revision de78d61c)
1 /*
2  * Copyright (c) 1984 through 2008, William LeFebvre
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  *     * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  *     * Neither the name of William LeFebvre nor the names of other
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "config.h"
34 
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <stdio.h>
38 
39 #ifdef HAVE_LIMITS_H
40 #include <limits.h>
41 #endif
42 
43 #if TIME_WITH_SYS_TIME
44 # include <sys/time.h>
45 # include <time.h>
46 #else
47 # if HAVE_SYS_TIME_H
48 #  include <sys/time.h>
49 # else
50 #  include <time.h>
51 # endif
52 #endif
53 
54 #if STDC_HEADERS
55 #include <string.h>
56 #include <stdlib.h>
57 #define setbuffer(f, b, s)	setvbuf((f), (b), (b) ? _IOFBF : _IONBF, (s))
58 #define memzero(a, b)		memset((a), 0, (b))
59 #else /* !STDC_HEADERS */
60 #ifndef HAVE_STRCHR
61 #define strchr(a, b)		index((a), (b))
62 #define strrchr(a, b)		rindex((a), (b))
63 #endif /* HAVE_STRCHR */
64 #ifdef HAVE_MEMCPY
65 #define memzero(a, b)		memset((a), 0, (b))
66 #else
67 #define memcpy(a, b, c)		bcopy((b), (a), (c))
68 #define memzero(a, b)		bzero((a), (b))
69 #define memcmp(a, b, c)		bcmp((a), (b), (c))
70 #endif /* HAVE_MEMCPY */
71 #ifdef HAVE_STRINGS_H
72 #include <strings.h>
73 #else
74 #ifdef HAVE_STRING_H
75 #include <string.h>
76 #endif
77 #endif
78 char *getenv();
79 caddr_t malloc();
80 #endif /* STDC_HEADERS */
81 
82 /* If snprintf or vsnprintf aren't available, we substitute our own.
83    But we have to include stdarg in order to be able to define them.
84 */
85 #ifdef HAVE_STDARG_H
86 #include <stdarg.h>
87 #endif
88 
89 #if !HAVE_PID_T
90 typedef long pid_t;
91 #endif
92 #if !HAVE_TIME_T
93 typedef long time_t;
94 #endif
95 #if !HAVE_UID_T
96 typedef long uid_t;
97 #endif
98 
99 #ifndef INT_MAX
100 #define INT_MAX (0x7fffffff)
101 #endif
102 
103 #ifndef UINT_MAX
104 #define UINT_MAX (0xffffffffU)
105 #endif
106 
107 /* we must have both sighold and sigrelse to use them */
108 #if defined(HAVE_SIGHOLD) && !defined(HAVE_SIGRELSE)
109 #undef HAVE_SIGHOLD
110 #endif
111 
112 #ifdef HAVE_UNISTD_H
113 #include <unistd.h>
114 #endif
115 
116 #ifdef HAVE_SYSEXITS_H
117 #include <sysexits.h>
118 #else
119 #define EX_OK		0	/* successful termination */
120 #define EX_USAGE	64	/* command line usage error */
121 #define EX_DATAERR	65	/* data format error */
122 #define EX_NOINPUT	66	/* cannot open input */
123 #define EX_NOUSER	67	/* addressee unknown */
124 #define EX_NOHOST	68	/* host name unknown */
125 #define EX_UNAVAILABLE	69	/* service unavailable */
126 #define EX_SOFTWARE	70	/* internal software error */
127 #define EX_OSERR	71	/* system error (e.g., can't fork) */
128 #define EX_OSFILE	72	/* critical OS file missing */
129 #define EX_CANTCREAT	73	/* can't create (user) output file */
130 #define EX_IOERR	74	/* input/output error */
131 #define EX_TEMPFAIL	75	/* temp failure; user is invited to retry */
132 #define EX_PROTOCOL	76	/* remote error in protocol */
133 #define EX_NOPERM	77	/* permission denied */
134 #define EX_CONFIG	78	/* configuration error */
135 #endif
136