Annotation of embedaddon/sudo/include/missing.h, revision 1.1.1.5

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

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