Annotation of embedaddon/sudo/include/missing.h, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (c) 1996, 1998-2005, 2008, 2009-2010
3: * Todd C. Miller <Todd.Miller@courtesan.com>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: *
17: * Sponsored in part by the Defense Advanced Research Projects
18: * Agency (DARPA) and Air Force Research Laboratory, Air Force
19: * Materiel Command, USAF, under agreement number F39502-99-1-0512.
20: */
21:
22: #ifndef _SUDO_MISSING_H
23: #define _SUDO_MISSING_H
24:
25: #include <stdio.h>
26: #include <stdarg.h>
27:
28: /*
29: * Macros and functions that may be missing on some operating systems.
30: */
31:
32: /* Define away __attribute__ for non-gcc or old gcc */
33: #if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5
34: # define __attribute__(x)
35: #endif
36:
37: /* For silencing gcc warnings about rcsids */
38: #ifndef __unused
39: # if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 7)
40: # define __unused __attribute__((__unused__))
41: # else
42: # define __unused
43: # endif
44: #endif
45:
46: /* For catching format string mismatches */
47: #ifndef __printflike
48: # if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7)
49: # define __printflike(f, v) __attribute__((__format__ (__printf__, f, v)))
50: # else
51: # define __printflike(f, v)
52: # endif
53: #endif
54:
55: /*
56: * Some systems lack full limit definitions.
57: */
58: #ifndef OPEN_MAX
59: # define OPEN_MAX 256
60: #endif
61:
62: #ifndef INT_MAX
63: # define INT_MAX 0x7fffffff
64: #endif
65:
66: #ifndef PATH_MAX
67: # ifdef MAXPATHLEN
68: # define PATH_MAX MAXPATHLEN
69: # else
70: # ifdef _POSIX_PATH_MAX
71: # define PATH_MAX _POSIX_PATH_MAX
72: # else
73: # define PATH_MAX 1024
74: # endif
75: # endif
76: #endif
77:
78: #ifndef MAXHOSTNAMELEN
79: # define MAXHOSTNAMELEN 64
80: #endif
81:
82: /*
83: * Posix versions for those without...
84: */
85: #ifndef _S_IFMT
86: # define _S_IFMT S_IFMT
87: #endif /* _S_IFMT */
88: #ifndef _S_IFREG
89: # define _S_IFREG S_IFREG
90: #endif /* _S_IFREG */
91: #ifndef _S_IFDIR
92: # define _S_IFDIR S_IFDIR
93: #endif /* _S_IFDIR */
94: #ifndef _S_IFLNK
95: # define _S_IFLNK S_IFLNK
96: #endif /* _S_IFLNK */
97: #ifndef S_ISREG
98: # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
99: #endif /* S_ISREG */
100: #ifndef S_ISDIR
101: # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
102: #endif /* S_ISDIR */
103:
104: /*
105: * Some OS's may not have this.
106: */
107: #ifndef S_IRWXU
108: # define S_IRWXU 0000700 /* rwx for owner */
109: #endif /* S_IRWXU */
110:
111: /*
112: * These should be defined in <unistd.h> but not everyone has them.
113: */
114: #ifndef STDIN_FILENO
115: # define STDIN_FILENO 0
116: #endif
117: #ifndef STDOUT_FILENO
118: # define STDOUT_FILENO 1
119: #endif
120: #ifndef STDERR_FILENO
121: # define STDERR_FILENO 2
122: #endif
123:
124: /*
125: * BSD defines these in <sys/param.h> but others may not.
126: */
127: #ifndef MIN
128: # define MIN(a,b) (((a)<(b))?(a):(b))
129: #endif
130: #ifndef MAX
131: # define MAX(a,b) (((a)>(b))?(a):(b))
132: #endif
133:
134: /*
135: * Simple isblank() macro and function for systems without it.
136: */
137: #ifndef HAVE_ISBLANK
138: int isblank(int);
139: # define isblank(_x) ((_x) == ' ' || (_x) == '\t')
140: #endif
141:
142: /*
143: * NCR's SVr4 has _innetgr(3) instead of innetgr(3) for some reason.
144: */
145: #ifdef HAVE__INNETGR
146: # define innetgr(n, h, u, d) (_innetgr(n, h, u, d))
147: # define HAVE_INNETGR 1
148: #endif /* HAVE__INNETGR */
149:
150: /*
151: * On POSIX systems, O_NOCTTY is the default so some OS's may lack this define.
152: */
153: #ifndef O_NOCTTY
154: # define O_NOCTTY 0
155: #endif /* O_NOCTTY */
156:
157: /*
158: * Add IRIX-like sigaction_t for those without it.
159: * SA_RESTART is not required by POSIX; SunOS has SA_INTERRUPT instead.
160: */
161: #ifndef HAVE_SIGACTION_T
162: typedef struct sigaction sigaction_t;
163: #endif
164: #ifndef SA_INTERRUPT
165: # define SA_INTERRUPT 0
166: #endif
167: #ifndef SA_RESTART
168: # define SA_RESTART 0
169: #endif
170:
171: /*
172: * If dirfd() does not exists, hopefully dd_fd does.
173: */
174: #if !defined(HAVE_DIRFD) && defined(HAVE_DD_FD)
175: # define dirfd(_d) ((_d)->dd_fd)
176: # define HAVE_DIRFD
177: #endif
178:
179: /*
180: * Define futimes() in terms of futimesat() if needed.
181: */
182: #if !defined(HAVE_FUTIMES) && defined(HAVE_FUTIMESAT)
183: # define futimes(_f, _tv) futimesat(_f, NULL, _tv)
184: # define HAVE_FUTIMES
185: #endif
186:
187: #if !defined(HAVE_KILLPG) && !defined(killpg)
188: # define killpg(s) kill(-(s))
189: #endif
190:
191: /*
192: * If we lack getprogname(), emulate with __progname if possible.
193: * Otherwise, add a prototype for use with our own getprogname.c.
194: */
195: #ifndef HAVE_GETPROGNAME
196: # ifdef HAVE___PROGNAME
197: extern const char *__progname;
198: # define getprogname() (__progname)
199: # else
200: const char *getprogname(void);
201: void setprogname(const char *);
202: #endif /* HAVE___PROGNAME */
203: #endif /* !HAVE_GETPROGNAME */
204:
205: /*
206: * Declare errno if errno.h doesn't do it for us.
207: */
208: #if defined(HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
209: extern int errno;
210: #endif /* !HAVE_DECL_ERRNO */
211:
212: #ifndef timevalclear
213: # define timevalclear(tv) ((tv)->tv_sec = (tv)->tv_usec = 0)
214: #endif
215: #ifndef timevalisset
216: # define timevalisset(tv) ((tv)->tv_sec || (tv)->tv_usec)
217: #endif
218: #ifndef timevalcmp
219: # define timevalcmp(tv1, tv2, op) \
220: (((tv1)->tv_sec == (tv2)->tv_sec) ? \
221: ((tv1)->tv_usec op (tv2)->tv_usec) : \
222: ((tv1)->tv_sec op (tv2)->tv_sec))
223: #endif
224: #ifndef timevaladd
225: # define timevaladd(tv1, tv2) \
226: do { \
227: (tv1)->tv_sec += (tv2)->tv_sec; \
228: (tv1)->tv_usec += (tv2)->tv_usec; \
229: if ((tv1)->tv_usec >= 1000000) { \
230: (tv1)->tv_sec++; \
231: (tv1)->tv_usec -= 1000000; \
232: } \
233: } while (0)
234: #endif
235: #ifndef timevalsub
236: # define timevalsub(tv1, tv2) \
237: do { \
238: (tv1)->tv_sec -= (tv2)->tv_sec; \
239: (tv1)->tv_usec -= (tv2)->tv_usec; \
240: if ((tv1)->tv_usec < 0) { \
241: (tv1)->tv_sec--; \
242: (tv1)->tv_usec += 1000000; \
243: } \
244: } while (0)
245: #endif
246:
247: /* Not all systems define NSIG in signal.h */
248: #if !defined(NSIG)
249: # if defined(_NSIG)
250: # define NSIG _NSIG
251: # elif defined(__NSIG)
252: # define NSIG __NSIG
253: # else
254: # define NSIG 64
255: # endif
256: #endif
257:
258: #ifndef WCOREDUMP
259: # define WCOREDUMP(x) ((x) & 0x80)
260: #endif
261:
262: #ifndef HAVE_SETEUID
263: # if defined(HAVE_SETRESUID)
264: # define seteuid(u) setresuid(-1, (u), -1)
265: # define setegid(g) setresgid(-1, (g), -1)
266: # define HAVE_SETEUID 1
267: # elif defined(HAVE_SETREUID)
268: # define seteuid(u) setreuid(-1, (u))
269: # define setegid(g) setregid(-1, (g))
270: # define HAVE_SETEUID 1
271: # endif
272: #endif /* HAVE_SETEUID */
273:
274: /*
275: * HP-UX does not declare innetgr() or getdomainname().
276: * Solaris does not declare getdomainname().
277: */
278: #if defined(__hpux)
279: int innetgr(const char *, const char *, const char *, const char *);
280: #endif
281: #if defined(__hpux) || defined(__sun)
282: int getdomainname(char *, size_t);
283: #endif
284:
285: /* Functions "missing" from libc. */
286:
287: struct timeval;
288: struct timespec;
289:
290: #ifndef HAVE_CLOSEFROM
291: void closefrom(int);
292: #endif
293: #ifndef HAVE_GETCWD
294: char *getcwd(char *, size_t size);
295: #endif
296: #ifndef HAVE_GETGROUPLIST
297: int getgrouplist(const char *, gid_t, gid_t *, int *);
298: #endif
299: #ifndef HAVE_GETLINE
300: ssize_t getline(char **, size_t *, FILE *);
301: #endif
302: #ifndef HAVE_UTIMES
303: int utimes(const char *, const struct timeval *);
304: #endif
305: #ifdef HAVE_FUTIME
306: int futimes(int, const struct timeval *);
307: #endif
308: #ifndef HAVE_SNPRINTF
309: int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
310: #endif
311: #ifndef HAVE_VSNPRINTF
312: int vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0);
313: #endif
314: #ifndef HAVE_ASPRINTF
315: int asprintf(char **, const char *, ...) __printflike(2, 3);
316: #endif
317: #ifndef HAVE_VASPRINTF
318: int vasprintf(char **, const char *, va_list) __printflike(2, 0);
319: #endif
320: #ifndef HAVE_STRLCAT
321: size_t strlcat(char *, const char *, size_t);
322: #endif
323: #ifndef HAVE_STRLCPY
324: size_t strlcpy(char *, const char *, size_t);
325: #endif
326: #ifndef HAVE_MEMRCHR
327: void *memrchr(const void *, int, size_t);
328: #endif
329: #ifndef HAVE_MKDTEMP
330: char *mkdtemp(char *);
331: #endif
332: #ifndef HAVE_MKSTEMPS
333: int mkstemps(char *, int);
334: #endif
335: #ifndef HAVE_NANOSLEEP
336: int nanosleep(const struct timespec *, struct timespec *);
337: #endif
338: #ifndef HAVE_SETENV
339: int setenv(const char *, const char *, int);
340: #endif
341: #ifndef HAVE_UNSETENV
342: int unsetenv(const char *);
343: #endif
344: #ifndef HAVE_STRSIGNAL
345: char *strsignal(int);
346: #endif
347:
348: #endif /* _SUDO_MISSING_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>