kernel - Fix races created by a comedy of circumstansces (3)
[dragonfly.git] / contrib / top / os.h
blob5502df635a5bc5f3abc72e754174593282841079
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.
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.
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.
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.
33 #include "config.h"
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <stdio.h>
39 #ifdef HAVE_LIMITS_H
40 #include <limits.h>
41 #endif
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
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 */
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.
85 #ifdef HAVE_STDARG_H
86 #include <stdarg.h>
87 #ifndef HAVE_SNPRINTF
88 int ap_snprintf(char *buf, size_t len, const char *format,...);
89 #define snprintf ap_snprintf
90 #endif
91 #ifndef HAVE_VSNPRINTF
92 int ap_vsnprintf(char *buf, size_t len, const char *format,va_list ap);
93 #define vsnprintf ap_vsnprintf
94 #endif
95 #endif
97 #if !HAVE_PID_T
98 typedef long pid_t;
99 #endif
100 #if !HAVE_TIME_T
101 typedef long time_t;
102 #endif
103 #if !HAVE_UID_T
104 typedef long uid_t;
105 #endif
107 #ifndef INT_MAX
108 #define INT_MAX (0x7fffffff)
109 #endif
111 #ifndef UINT_MAX
112 #define UINT_MAX (0xffffffffU)
113 #endif
115 /* we must have both sighold and sigrelse to use them */
116 #if defined(HAVE_SIGHOLD) && !defined(HAVE_SIGRELSE)
117 #undef HAVE_SIGHOLD
118 #endif
120 #ifdef HAVE_UNISTD_H
121 #include <unistd.h>
122 #endif
124 #ifdef HAVE_SYSEXITS_H
125 #include <sysexits.h>
126 #else
127 #define EX_OK 0 /* successful termination */
128 #define EX_USAGE 64 /* command line usage error */
129 #define EX_DATAERR 65 /* data format error */
130 #define EX_NOINPUT 66 /* cannot open input */
131 #define EX_NOUSER 67 /* addressee unknown */
132 #define EX_NOHOST 68 /* host name unknown */
133 #define EX_UNAVAILABLE 69 /* service unavailable */
134 #define EX_SOFTWARE 70 /* internal software error */
135 #define EX_OSERR 71 /* system error (e.g., can't fork) */
136 #define EX_OSFILE 72 /* critical OS file missing */
137 #define EX_CANTCREAT 73 /* can't create (user) output file */
138 #define EX_IOERR 74 /* input/output error */
139 #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
140 #define EX_PROTOCOL 76 /* remote error in protocol */
141 #define EX_NOPERM 77 /* permission denied */
142 #define EX_CONFIG 78 /* configuration error */
143 #endif