File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sudo / include / missing.h
Revision 1.1.1.6 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Sun Jun 15 16:12:54 2014 UTC (10 years ago) by misho
Branches: sudo, MAIN
CVS tags: v1_8_10p3_0, v1_8_10p3, HEAD
sudo v 1.8.10p3

    1: /*
    2:  * Copyright (c) 1996, 1998-2005, 2008, 2009-2014
    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: #ifdef STDC_HEADERS
   27: # include <stddef.h>
   28: #endif
   29: #include <stdarg.h>
   30: 
   31: /*
   32:  * Macros and functions that may be missing on some operating systems.
   33:  */
   34: 
   35: #ifndef __GNUC_PREREQ__
   36: # ifdef __GNUC__
   37: #  define __GNUC_PREREQ__(ma, mi) \
   38: 	((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)))
   39: # else
   40: #  define __GNUC_PREREQ__(ma, mi)	0
   41: # endif
   42: #endif
   43: 
   44: /* Define away __attribute__ for non-gcc or old gcc */
   45: #if !defined(__attribute__) && !__GNUC_PREREQ__(2, 5)
   46: # define __attribute__(x)
   47: #endif
   48: 
   49: /* For catching format string mismatches */
   50: #ifndef __printflike
   51: # if __GNUC_PREREQ__(3, 3)
   52: #  define __printflike(f, v) 	__attribute__((__format__ (__printf__, f, v))) __attribute__((__nonnull__ (f)))
   53: # elif __GNUC_PREREQ__(2, 7)
   54: #  define __printflike(f, v) 	__attribute__((__format__ (__printf__, f, v)))
   55: # else
   56: #  define __printflike(f, v)
   57: # endif
   58: #endif
   59: #ifndef __printf0like
   60: # if __GNUC_PREREQ__(2, 7)
   61: #  define __printf0like(f, v) 	__attribute__((__format__ (__printf__, f, v)))
   62: # else
   63: #  define __printf0like(f, v)
   64: # endif
   65: #endif
   66: #ifndef __format_arg
   67: # if __GNUC_PREREQ__(2, 7)
   68: #  define __format_arg(f) 	__attribute__((__format_arg__ (f)))
   69: # else
   70: #  define __format_arg(f)
   71: # endif
   72: #endif
   73: 
   74: /* Hint to compiler that returned pointer is unique (malloc but not realloc). */
   75: #ifndef __malloc_like
   76: # if __GNUC_PREREQ__(2, 96)
   77: #  define __malloc_like 	__attribute__((__malloc__))
   78: # else
   79: #  define __malloc_like
   80: # endif
   81: #endif
   82: 
   83: /*
   84:  * Given the pointer x to the member m of the struct s, return
   85:  * a pointer to the containing structure.
   86:  */
   87: #ifndef __containerof
   88: # define __containerof(x, s, m)	((s *)((char *)(x) - offsetof(s, m)))
   89: #endif
   90: 
   91: #ifndef __dso_public
   92: # ifdef HAVE_DSO_VISIBILITY
   93: #  if defined(__GNUC__)
   94: #   define __dso_public	__attribute__((__visibility__("default")))
   95: #   define __dso_hidden	__attribute__((__visibility__("hidden")))
   96: #  elif defined(__SUNPRO_C)
   97: #   define __dso_public	__global
   98: #   define __dso_hidden __hidden
   99: #  else
  100: #   define __dso_public	__declspec(dllexport)
  101: #   define __dso_hidden
  102: #  endif
  103: # else
  104: #  define __dso_public
  105: #  define __dso_hidden
  106: # endif
  107: #endif
  108: 
  109: /*
  110:  * Pre-C99 compilers may lack a va_copy macro.
  111:  */
  112: #ifndef va_copy
  113: # ifdef __va_copy
  114: #  define va_copy(d, s) __va_copy(d, s)
  115: # else
  116: #  define va_copy(d, s) memcpy(&(d), &(s), sizeof(d));
  117: # endif
  118: #endif
  119: 
  120: /*
  121:  * Some systems lack full limit definitions.
  122:  */
  123: #ifndef OPEN_MAX
  124: # define OPEN_MAX	256
  125: #endif
  126: 
  127: #ifndef LLONG_MAX
  128: # if defined(QUAD_MAX)
  129: #  define LLONG_MAX	QUAD_MAX
  130: # else
  131: #  define LLONG_MAX	0x7fffffffffffffffLL
  132: # endif
  133: #endif
  134: 
  135: #ifndef LLONG_MIN
  136: # if defined(QUAD_MIN)
  137: #  define LLONG_MIN	QUAD_MIN
  138: # else
  139: #  define LLONG_MIN	(-0x7fffffffffffffffLL-1)
  140: # endif
  141: #endif
  142: 
  143: #ifndef ULLONG_MAX
  144: # if defined(UQUAD_MAX)
  145: #  define ULLONG_MAX	UQUAD_MAX
  146: # else
  147: #  define ULLONG_MAX	0xffffffffffffffffULL
  148: # endif
  149: #endif
  150: 
  151: #ifndef PATH_MAX
  152: # ifdef _POSIX_PATH_MAX
  153: #  define PATH_MAX		_POSIX_PATH_MAX
  154: # else
  155: #  define PATH_MAX		256
  156: # endif
  157: #endif
  158: 
  159: #ifndef HOST_NAME_MAX
  160: # ifdef _POSIX_HOST_NAME_MAX
  161: #  define HOST_NAME_MAX		_POSIX_HOST_NAME_MAX
  162: # else
  163: #  define HOST_NAME_MAX		255
  164: # endif
  165: #endif
  166: 
  167: /*
  168:  * Posix versions for those without...
  169:  */
  170: #ifndef _S_IFMT
  171: # define _S_IFMT		S_IFMT
  172: #endif /* _S_IFMT */
  173: #ifndef _S_IFREG
  174: # define _S_IFREG		S_IFREG
  175: #endif /* _S_IFREG */
  176: #ifndef _S_IFDIR
  177: # define _S_IFDIR		S_IFDIR
  178: #endif /* _S_IFDIR */
  179: #ifndef _S_IFLNK
  180: # define _S_IFLNK		S_IFLNK
  181: #endif /* _S_IFLNK */
  182: #ifndef S_ISREG
  183: # define S_ISREG(m)		(((m) & _S_IFMT) == _S_IFREG)
  184: #endif /* S_ISREG */
  185: #ifndef S_ISDIR
  186: # define S_ISDIR(m)		(((m) & _S_IFMT) == _S_IFDIR)
  187: #endif /* S_ISDIR */
  188: 
  189: /*
  190:  * Some OS's may not have this.
  191:  */
  192: #ifndef S_IRWXU
  193: # define S_IRWXU		0000700		/* rwx for owner */
  194: #endif /* S_IRWXU */
  195: 
  196: /*
  197:  * These should be defined in <unistd.h> but not everyone has them.
  198:  */
  199: #ifndef STDIN_FILENO
  200: # define	STDIN_FILENO	0
  201: #endif
  202: #ifndef STDOUT_FILENO
  203: # define	STDOUT_FILENO	1
  204: #endif
  205: #ifndef STDERR_FILENO
  206: # define	STDERR_FILENO	2
  207: #endif
  208: 
  209: /*
  210:  * BSD defines these in <sys/param.h> but we don't include that anymore.
  211:  */
  212: #ifndef MIN
  213: # define MIN(a,b) (((a)<(b))?(a):(b))
  214: #endif
  215: #ifndef MAX
  216: # define MAX(a,b) (((a)>(b))?(a):(b))
  217: #endif
  218: 
  219: /* Macros to set/clear/test flags. */
  220: #undef SET
  221: #define SET(t, f)	((t) |= (f))
  222: #undef CLR
  223: #define CLR(t, f)	((t) &= ~(f))
  224: #undef ISSET
  225: #define ISSET(t, f)     ((t) & (f))
  226: 
  227: /*
  228:  * Older systems may be missing stddef.h and/or offsetof macro
  229:  */
  230: #ifndef offsetof
  231: # ifdef __offsetof
  232: #  define offsetof(type, field) __offsetof(type, field)
  233: # else
  234: #  define offsetof(type, field) ((size_t)(&((type *)0)->field))
  235: # endif
  236: #endif
  237: 
  238: /*
  239:  * Simple isblank() macro and function for systems without it.
  240:  */
  241: #ifndef HAVE_ISBLANK
  242: int isblank(int);
  243: # define isblank(_x)	((_x) == ' ' || (_x) == '\t')
  244: #endif
  245: 
  246: /*
  247:  * NCR's SVr4 has _innetgr(3) instead of innetgr(3) for some reason.
  248:  */
  249: #ifdef HAVE__INNETGR
  250: # define innetgr(n, h, u, d)	(_innetgr(n, h, u, d))
  251: # define HAVE_INNETGR 1
  252: #endif /* HAVE__INNETGR */
  253: 
  254: /*
  255:  * On POSIX systems, O_NOCTTY is the default so some OS's may lack this define.
  256:  */
  257: #ifndef O_NOCTTY
  258: # define O_NOCTTY	0
  259: #endif /* O_NOCTTY */
  260: 
  261: /*
  262:  * Add IRIX-like sigaction_t for those without it.
  263:  * SA_RESTART is not required by POSIX; SunOS has SA_INTERRUPT instead.
  264:  */
  265: #ifndef HAVE_SIGACTION_T
  266: typedef struct sigaction sigaction_t;
  267: #endif
  268: #ifndef SA_INTERRUPT
  269: # define SA_INTERRUPT	0
  270: #endif
  271: #ifndef SA_RESTART
  272: # define SA_RESTART	0
  273: #endif
  274: 
  275: /*
  276:  * If dirfd() does not exists, hopefully dd_fd does.
  277:  */
  278: #if !defined(HAVE_DIRFD) && defined(HAVE_DD_FD)
  279: # define dirfd(_d)	((_d)->dd_fd)
  280: # define HAVE_DIRFD
  281: #endif
  282: 
  283: /*
  284:  * Define futimes() in terms of futimesat() if needed.
  285:  */
  286: #if !defined(HAVE_FUTIMES) && defined(HAVE_FUTIMESAT)
  287: # define futimes(_f, _tv)	futimesat(_f, NULL, _tv)
  288: # define HAVE_FUTIMES
  289: #endif
  290: 
  291: #if !defined(HAVE_KILLPG) && !defined(killpg)
  292: # define killpg(s)	kill(-(s))
  293: #endif
  294: 
  295: /*
  296:  * If we lack getprogname(), emulate with __progname if possible.
  297:  * Otherwise, add a prototype for use with our own getprogname.c.
  298:  */
  299: #ifndef HAVE_GETPROGNAME
  300: # ifdef HAVE___PROGNAME
  301: extern const char *__progname;
  302: #  define getprogname()		(__progname)
  303: # else
  304: const char *getprogname(void);
  305: # endif /* HAVE___PROGNAME */
  306: #endif /* !HAVE_GETPROGNAME */
  307: 
  308: /*
  309:  * Declare errno if errno.h doesn't do it for us.
  310:  */
  311: #if defined(HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
  312: extern int errno;
  313: #endif /* !HAVE_DECL_ERRNO */
  314: 
  315: /* Not all systems define NSIG in signal.h */
  316: #if !defined(NSIG)
  317: # if defined(_NSIG)
  318: #  define NSIG _NSIG
  319: # elif defined(__NSIG)
  320: #  define NSIG __NSIG
  321: # else
  322: #  define NSIG 64
  323: # endif
  324: #endif
  325: 
  326: /* For sig2str() */
  327: #ifndef SIG2STR_MAX
  328: # define SIG2STR_MAX 32
  329: #endif
  330: 
  331: #ifndef WCOREDUMP
  332: # define WCOREDUMP(x)	((x) & 0x80)
  333: #endif
  334: 
  335: #ifndef HAVE_SETEUID
  336: #  if defined(HAVE_SETRESUID)
  337: #    define seteuid(u)	setresuid(-1, (u), -1)
  338: #    define setegid(g)	setresgid(-1, (g), -1)
  339: #    define HAVE_SETEUID 1
  340: #  elif defined(HAVE_SETREUID)
  341: #    define seteuid(u)	setreuid(-1, (u))
  342: #    define setegid(g)	setregid(-1, (g))
  343: #    define HAVE_SETEUID 1
  344: #  endif
  345: #endif /* HAVE_SETEUID */
  346: 
  347: /*
  348:  * HP-UX does not declare innetgr() or getdomainname().
  349:  * Solaris does not declare getdomainname().
  350:  */
  351: #if defined(__hpux)
  352: int innetgr(const char *, const char *, const char *, const char *);
  353: #endif
  354: #if defined(__hpux) || defined(__sun)
  355: int getdomainname(char *, size_t);
  356: #endif
  357: 
  358: /* Functions "missing" from libc. */
  359: 
  360: struct timeval;
  361: struct timespec;
  362: 
  363: #ifndef HAVE_CLOSEFROM
  364: void closefrom(int);
  365: #endif
  366: #ifndef HAVE_GETCWD
  367: char *getcwd(char *, size_t size);
  368: #endif
  369: #ifndef HAVE_GETGROUPLIST
  370: int getgrouplist(const char *, gid_t, gid_t *, int *);
  371: #endif
  372: #ifndef HAVE_GETLINE
  373: ssize_t getline(char **, size_t *, FILE *);
  374: #endif
  375: #ifndef HAVE_UTIMES
  376: int utimes(const char *, const struct timeval *);
  377: #endif
  378: #ifdef HAVE_FUTIME
  379: int futimes(int, const struct timeval *);
  380: #endif
  381: #if !defined(HAVE_SNPRINTF) || defined(PREFER_PORTABLE_SNPRINTF)
  382: int rpl_snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
  383: # undef snprintf
  384: # define snprintf rpl_snprintf
  385: #endif
  386: #if !defined(HAVE_VSNPRINTF) || defined(PREFER_PORTABLE_SNPRINTF)
  387: int rpl_vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0);
  388: # undef vsnprintf
  389: # define vsnprintf rpl_vsnprintf
  390: #endif
  391: #if !defined(HAVE_ASPRINTF) || defined(PREFER_PORTABLE_SNPRINTF)
  392: int rpl_asprintf(char **, const char *, ...) __printflike(2, 3);
  393: # undef asprintf
  394: # define asprintf rpl_asprintf
  395: #endif
  396: #if !defined(HAVE_VASPRINTF) || defined(PREFER_PORTABLE_SNPRINTF)
  397: int rpl_vasprintf(char **, const char *, va_list) __printflike(2, 0);
  398: # undef vasprintf
  399: # define vasprintf rpl_vasprintf
  400: #endif
  401: #ifndef HAVE_STRLCAT
  402: size_t strlcat(char *, const char *, size_t);
  403: #endif
  404: #ifndef HAVE_STRLCPY
  405: size_t strlcpy(char *, const char *, size_t);
  406: #endif
  407: #ifndef HAVE_MEMRCHR
  408: void *memrchr(const void *, int, size_t);
  409: #endif
  410: #ifndef HAVE_MEMSET_S
  411: errno_t memset_s(void *, rsize_t, int, rsize_t);
  412: #endif
  413: #ifndef HAVE_MKDTEMP
  414: char *mkdtemp(char *);
  415: #endif
  416: #ifndef HAVE_MKSTEMPS
  417: int mkstemps(char *, int);
  418: #endif
  419: #ifndef HAVE_PW_DUP
  420: struct passwd *pw_dup(const struct passwd *);
  421: #endif
  422: #ifndef HAVE_SETENV
  423: int setenv(const char *, const char *, int);
  424: #endif
  425: #ifndef HAVE_UNSETENV
  426: int unsetenv(const char *);
  427: #endif
  428: #ifndef HAVE_STRSIGNAL
  429: char *strsignal(int);
  430: #endif
  431: #ifndef HAVE_SIG2STR
  432: int sig2str(int, char *);
  433: #endif
  434: #ifndef HAVE_STRTONUM
  435: long long rpl_strtonum(const char *, long long, long long, const char **);
  436: # undef strtonum
  437: # define strtonum rpl_strtonum
  438: #endif
  439: #ifndef HAVE_CLOCK_GETTIME
  440: # define CLOCK_REALTIME 0
  441: # ifdef __MACH__
  442: #  define CLOCK_MONOTONIC 1
  443: # endif
  444: int clock_gettime(clockid_t clock_id, struct timespec *tp);
  445: #endif
  446: #ifndef HAVE_INET_PTON
  447: int inet_pton(int af, const char *src, void *dst);
  448: #endif
  449: 
  450: #endif /* _SUDO_MISSING_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>