Annotation of embedaddon/sudo/include/missing.h, revision 1.1.1.2
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 catching format string mismatches */
38: #ifndef __printflike
39: # if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7)
40: # define __printflike(f, v) __attribute__((__format__ (__printf__, f, v)))
41: # else
42: # define __printflike(f, v)
43: # endif
44: #endif
45:
46: /*
47: * Some systems lack full limit definitions.
48: */
49: #ifndef OPEN_MAX
50: # define OPEN_MAX 256
51: #endif
52:
53: #ifndef INT_MAX
54: # define INT_MAX 0x7fffffff
55: #endif
56:
57: #ifndef PATH_MAX
58: # ifdef MAXPATHLEN
59: # define PATH_MAX MAXPATHLEN
60: # else
61: # ifdef _POSIX_PATH_MAX
62: # define PATH_MAX _POSIX_PATH_MAX
63: # else
64: # define PATH_MAX 1024
65: # endif
66: # endif
67: #endif
68:
69: #ifndef MAXHOSTNAMELEN
70: # define MAXHOSTNAMELEN 64
71: #endif
72:
73: /*
74: * Posix versions for those without...
75: */
76: #ifndef _S_IFMT
77: # define _S_IFMT S_IFMT
78: #endif /* _S_IFMT */
79: #ifndef _S_IFREG
80: # define _S_IFREG S_IFREG
81: #endif /* _S_IFREG */
82: #ifndef _S_IFDIR
83: # define _S_IFDIR S_IFDIR
84: #endif /* _S_IFDIR */
85: #ifndef _S_IFLNK
86: # define _S_IFLNK S_IFLNK
87: #endif /* _S_IFLNK */
88: #ifndef S_ISREG
89: # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
90: #endif /* S_ISREG */
91: #ifndef S_ISDIR
92: # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
93: #endif /* S_ISDIR */
94:
95: /*
96: * Some OS's may not have this.
97: */
98: #ifndef S_IRWXU
99: # define S_IRWXU 0000700 /* rwx for owner */
100: #endif /* S_IRWXU */
101:
102: /*
103: * These should be defined in <unistd.h> but not everyone has them.
104: */
105: #ifndef STDIN_FILENO
106: # define STDIN_FILENO 0
107: #endif
108: #ifndef STDOUT_FILENO
109: # define STDOUT_FILENO 1
110: #endif
111: #ifndef STDERR_FILENO
112: # define STDERR_FILENO 2
113: #endif
114:
115: /*
116: * BSD defines these in <sys/param.h> but others may not.
117: */
118: #ifndef MIN
119: # define MIN(a,b) (((a)<(b))?(a):(b))
120: #endif
121: #ifndef MAX
122: # define MAX(a,b) (((a)>(b))?(a):(b))
123: #endif
124:
125: /*
1.1.1.2 ! misho 126: * Older systems may be missing stddef.h and/or offsetof macro
! 127: */
! 128: #ifndef offsetof
! 129: # ifdef __offsetof
! 130: # define offsetof(type, field) __offsetof(type, field)
! 131: # else
! 132: # define offsetof(type, field) ((size_t)(&((type *)0)->field))
! 133: # endif
! 134: #endif
! 135:
! 136: /*
1.1 misho 137: * Simple isblank() macro and function for systems without it.
138: */
139: #ifndef HAVE_ISBLANK
140: int isblank(int);
141: # define isblank(_x) ((_x) == ' ' || (_x) == '\t')
142: #endif
143:
144: /*
145: * NCR's SVr4 has _innetgr(3) instead of innetgr(3) for some reason.
146: */
147: #ifdef HAVE__INNETGR
148: # define innetgr(n, h, u, d) (_innetgr(n, h, u, d))
149: # define HAVE_INNETGR 1
150: #endif /* HAVE__INNETGR */
151:
152: /*
153: * On POSIX systems, O_NOCTTY is the default so some OS's may lack this define.
154: */
155: #ifndef O_NOCTTY
156: # define O_NOCTTY 0
157: #endif /* O_NOCTTY */
158:
159: /*
160: * Add IRIX-like sigaction_t for those without it.
161: * SA_RESTART is not required by POSIX; SunOS has SA_INTERRUPT instead.
162: */
163: #ifndef HAVE_SIGACTION_T
164: typedef struct sigaction sigaction_t;
165: #endif
166: #ifndef SA_INTERRUPT
167: # define SA_INTERRUPT 0
168: #endif
169: #ifndef SA_RESTART
170: # define SA_RESTART 0
171: #endif
172:
173: /*
174: * If dirfd() does not exists, hopefully dd_fd does.
175: */
176: #if !defined(HAVE_DIRFD) && defined(HAVE_DD_FD)
177: # define dirfd(_d) ((_d)->dd_fd)
178: # define HAVE_DIRFD
179: #endif
180:
181: /*
182: * Define futimes() in terms of futimesat() if needed.
183: */
184: #if !defined(HAVE_FUTIMES) && defined(HAVE_FUTIMESAT)
185: # define futimes(_f, _tv) futimesat(_f, NULL, _tv)
186: # define HAVE_FUTIMES
187: #endif
188:
189: #if !defined(HAVE_KILLPG) && !defined(killpg)
190: # define killpg(s) kill(-(s))
191: #endif
192:
193: /*
194: * If we lack getprogname(), emulate with __progname if possible.
195: * Otherwise, add a prototype for use with our own getprogname.c.
196: */
197: #ifndef HAVE_GETPROGNAME
198: # ifdef HAVE___PROGNAME
199: extern const char *__progname;
200: # define getprogname() (__progname)
201: # else
202: const char *getprogname(void);
203: void setprogname(const char *);
204: #endif /* HAVE___PROGNAME */
205: #endif /* !HAVE_GETPROGNAME */
206:
207: /*
208: * Declare errno if errno.h doesn't do it for us.
209: */
210: #if defined(HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
211: extern int errno;
212: #endif /* !HAVE_DECL_ERRNO */
213:
214: #ifndef timevalclear
215: # define timevalclear(tv) ((tv)->tv_sec = (tv)->tv_usec = 0)
216: #endif
217: #ifndef timevalisset
218: # define timevalisset(tv) ((tv)->tv_sec || (tv)->tv_usec)
219: #endif
220: #ifndef timevalcmp
221: # define timevalcmp(tv1, tv2, op) \
222: (((tv1)->tv_sec == (tv2)->tv_sec) ? \
223: ((tv1)->tv_usec op (tv2)->tv_usec) : \
224: ((tv1)->tv_sec op (tv2)->tv_sec))
225: #endif
226: #ifndef timevaladd
227: # define timevaladd(tv1, tv2) \
228: do { \
229: (tv1)->tv_sec += (tv2)->tv_sec; \
230: (tv1)->tv_usec += (tv2)->tv_usec; \
231: if ((tv1)->tv_usec >= 1000000) { \
232: (tv1)->tv_sec++; \
233: (tv1)->tv_usec -= 1000000; \
234: } \
235: } while (0)
236: #endif
237: #ifndef timevalsub
238: # define timevalsub(tv1, tv2) \
239: do { \
240: (tv1)->tv_sec -= (tv2)->tv_sec; \
241: (tv1)->tv_usec -= (tv2)->tv_usec; \
242: if ((tv1)->tv_usec < 0) { \
243: (tv1)->tv_sec--; \
244: (tv1)->tv_usec += 1000000; \
245: } \
246: } while (0)
247: #endif
248:
249: /* Not all systems define NSIG in signal.h */
250: #if !defined(NSIG)
251: # if defined(_NSIG)
252: # define NSIG _NSIG
253: # elif defined(__NSIG)
254: # define NSIG __NSIG
255: # else
256: # define NSIG 64
257: # endif
258: #endif
259:
260: #ifndef WCOREDUMP
261: # define WCOREDUMP(x) ((x) & 0x80)
262: #endif
263:
264: #ifndef HAVE_SETEUID
265: # if defined(HAVE_SETRESUID)
266: # define seteuid(u) setresuid(-1, (u), -1)
267: # define setegid(g) setresgid(-1, (g), -1)
268: # define HAVE_SETEUID 1
269: # elif defined(HAVE_SETREUID)
270: # define seteuid(u) setreuid(-1, (u))
271: # define setegid(g) setregid(-1, (g))
272: # define HAVE_SETEUID 1
273: # endif
274: #endif /* HAVE_SETEUID */
275:
276: /*
277: * HP-UX does not declare innetgr() or getdomainname().
278: * Solaris does not declare getdomainname().
279: */
280: #if defined(__hpux)
281: int innetgr(const char *, const char *, const char *, const char *);
282: #endif
283: #if defined(__hpux) || defined(__sun)
284: int getdomainname(char *, size_t);
285: #endif
286:
287: /* Functions "missing" from libc. */
288:
289: struct timeval;
290: struct timespec;
291:
292: #ifndef HAVE_CLOSEFROM
293: void closefrom(int);
294: #endif
295: #ifndef HAVE_GETCWD
296: char *getcwd(char *, size_t size);
297: #endif
298: #ifndef HAVE_GETGROUPLIST
299: int getgrouplist(const char *, gid_t, gid_t *, int *);
300: #endif
301: #ifndef HAVE_GETLINE
302: ssize_t getline(char **, size_t *, FILE *);
303: #endif
304: #ifndef HAVE_UTIMES
305: int utimes(const char *, const struct timeval *);
306: #endif
307: #ifdef HAVE_FUTIME
308: int futimes(int, const struct timeval *);
309: #endif
310: #ifndef HAVE_SNPRINTF
311: int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
312: #endif
313: #ifndef HAVE_VSNPRINTF
314: int vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0);
315: #endif
316: #ifndef HAVE_ASPRINTF
317: int asprintf(char **, const char *, ...) __printflike(2, 3);
318: #endif
319: #ifndef HAVE_VASPRINTF
320: int vasprintf(char **, const char *, va_list) __printflike(2, 0);
321: #endif
322: #ifndef HAVE_STRLCAT
323: size_t strlcat(char *, const char *, size_t);
324: #endif
325: #ifndef HAVE_STRLCPY
326: size_t strlcpy(char *, const char *, size_t);
327: #endif
328: #ifndef HAVE_MEMRCHR
329: void *memrchr(const void *, int, size_t);
330: #endif
331: #ifndef HAVE_MKDTEMP
332: char *mkdtemp(char *);
333: #endif
334: #ifndef HAVE_MKSTEMPS
335: int mkstemps(char *, int);
336: #endif
337: #ifndef HAVE_NANOSLEEP
338: int nanosleep(const struct timespec *, struct timespec *);
339: #endif
1.1.1.2 ! misho 340: #ifndef HAVE_PW_DUP
! 341: struct passwd *pw_dup(const struct passwd *);
! 342: #endif
1.1 misho 343: #ifndef HAVE_SETENV
344: int setenv(const char *, const char *, int);
345: #endif
346: #ifndef HAVE_UNSETENV
347: int unsetenv(const char *);
348: #endif
349: #ifndef HAVE_STRSIGNAL
350: char *strsignal(int);
351: #endif
352:
353: #endif /* _SUDO_MISSING_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>