[BACK]Return to compat.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / sudo

Annotation of src/usr.bin/sudo/compat.h, Revision 1.7

1.1       millert     1: /*
1.5       millert     2:  * Copyright (c) 1996, 1998-2003 Todd C. Miller <Todd.Miller@courtesan.com>
1.1       millert     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
                      7:  * are met:
                      8:  *
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  *
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * 3. The name of the author may not be used to endorse or promote products
                     17:  *    derived from this software without specific prior written permission.
                     18:  *
                     19:  * 4. Products derived from this software may not be called "Sudo" nor
                     20:  *    may "Sudo" appear in their names without specific prior written
                     21:  *    permission from the author.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     24:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     25:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
                     26:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     27:  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     28:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     29:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     30:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     31:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     32:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     33:  *
1.7     ! millert    34:  * Sponsored in part by the Defense Advanced Research Projects
        !            35:  * Agency (DARPA) and Air Force Research Laboratory, Air Force
        !            36:  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
        !            37:  *
        !            38:  * $Sudo: compat.h,v 1.67 2003/04/16 00:42:09 millert Exp $
1.1       millert    39:  */
                     40:
                     41: #ifndef _SUDO_COMPAT_H
                     42: #define _SUDO_COMPAT_H
                     43:
                     44: /*
                     45:  * Macros that may be missing on some Operating Systems
                     46:  */
                     47:
                     48: /* Deal with ANSI stuff reasonably.  */
                     49: #ifndef  __P
                     50: # if defined (__cplusplus) || defined (__STDC__)
                     51: #  define __P(args)            args
                     52: # else
                     53: #  define __P(args)            ()
                     54: # endif
                     55: #endif /* __P */
                     56:
                     57: /*
                     58:  * Some systems (ie ISC V/386) do not define MAXPATHLEN even in param.h
                     59:  */
                     60: #ifndef MAXPATHLEN
                     61: # define MAXPATHLEN            1024
                     62: #endif
                     63:
                     64: /*
                     65:  * Some systems do not define MAXHOSTNAMELEN.
                     66:  */
                     67: #ifndef MAXHOSTNAMELEN
                     68: # define MAXHOSTNAMELEN                64
                     69: #endif
                     70:
                     71: /*
                     72:  * 4.2BSD lacks FD_* macros (we only use FD_SET and FD_ZERO)
                     73:  */
                     74: #ifndef FD_SETSIZE
                     75: # define FD_SET(fd, fds)       ((fds) -> fds_bits[0] |= (1 << (fd)))
                     76: # define FD_ZERO(fds)          ((fds) -> fds_bits[0] = 0)
                     77: #endif /* !FD_SETSIZE */
                     78:
                     79: /*
                     80:  * Posix versions for those without...
                     81:  */
                     82: #ifndef _S_IFMT
                     83: # define _S_IFMT               S_IFMT
                     84: #endif /* _S_IFMT */
                     85: #ifndef _S_IFREG
                     86: # define _S_IFREG              S_IFREG
                     87: #endif /* _S_IFREG */
                     88: #ifndef _S_IFDIR
                     89: # define _S_IFDIR              S_IFDIR
                     90: #endif /* _S_IFDIR */
                     91: #ifndef _S_IFLNK
                     92: # define _S_IFLNK              S_IFLNK
                     93: #endif /* _S_IFLNK */
                     94: #ifndef S_ISREG
                     95: # define S_ISREG(m)            (((m) & _S_IFMT) == _S_IFREG)
                     96: #endif /* S_ISREG */
                     97: #ifndef S_ISDIR
                     98: # define S_ISDIR(m)            (((m) & _S_IFMT) == _S_IFDIR)
                     99: #endif /* S_ISDIR */
                    100:
                    101: /*
                    102:  * Some OS's may not have this.
                    103:  */
                    104: #ifndef S_IRWXU
                    105: # define S_IRWXU               0000700         /* rwx for owner */
                    106: #endif /* S_IRWXU */
                    107:
                    108: /*
                    109:  * In case this is not defined in <sys/types.h> or <sys/select.h>
                    110:  */
                    111: #ifndef howmany
                    112: # define howmany(x, y) (((x) + ((y) - 1)) / (y))
                    113: #endif
                    114:
                    115: /*
                    116:  * These should be defined in <unistd.h> but not everyone has them.
                    117:  */
                    118: #ifndef STDIN_FILENO
                    119: # define       STDIN_FILENO    0
                    120: #endif
                    121: #ifndef STDOUT_FILENO
                    122: # define       STDOUT_FILENO   1
                    123: #endif
                    124: #ifndef STDERR_FILENO
                    125: # define       STDERR_FILENO   2
                    126: #endif
                    127:
                    128: /*
                    129:  * These should be defined in <unistd.h> but not everyone has them.
                    130:  */
                    131: #ifndef SEEK_SET
                    132: # define       SEEK_SET        0
                    133: #endif
                    134: #ifndef SEEK_CUR
                    135: # define       SEEK_CUR        1
                    136: #endif
                    137: #ifndef SEEK_END
                    138: # define       SEEK_END        2
                    139: #endif
                    140:
                    141: /*
                    142:  * BSD defines these in <sys/param.h> but others may not.
                    143:  */
                    144: #ifndef MIN
                    145: # define MIN(a,b) (((a)<(b))?(a):(b))
                    146: #endif
                    147: #ifndef MAX
                    148: # define MAX(a,b) (((a)>(b))?(a):(b))
                    149: #endif
                    150:
                    151: /*
1.2       millert   152:  * Simple isblank() macro for systems without it.
                    153:  */
                    154: #ifndef HAVE_ISBLANK
                    155: # define isblank(_x)   ((_x) == ' ' || (_x) == '\t')
                    156: #endif
                    157:
                    158: /*
                    159:  * Old BSD systems lack strchr(), strrchr(), memset() and memcpy()
                    160:  */
                    161: #if !defined(HAVE_STRCHR) && !defined(strchr)
                    162: # define strchr(_s, _c)        index(_s, _c)
                    163: #endif
                    164: #if !defined(HAVE_STRRCHR) && !defined(strrchr)
                    165: # define strrchr(_s, _c)       rindex(_s, _c)
                    166: #endif
                    167: #if !defined(HAVE_MEMCPY) && !defined(memcpy)
                    168: # define memcpy(_d, _s, _n)    (bcopy(_s, _d, _n))
                    169: #endif
                    170: #if !defined(HAVE_MEMSET) && !defined(memset)
                    171: # define memset(_s, _x, _n)    (bzero(_s, _n))
                    172: #endif
                    173:
                    174: /*
                    175:  * NCR's SVr4 has _innetgr(3) instead of innetgr(3) for some reason.
                    176:  */
                    177: #ifdef HAVE__INNETGR
                    178: # define innetgr(n, h, u, d)   (_innetgr(n, h, u, d))
                    179: # define HAVE_INNETGR 1
                    180: #endif /* HAVE__INNETGR */
1.1       millert   181:
                    182: /*
                    183:  * On POSIX systems, O_NOCTTY is the default so some OS's may lack this define.
                    184:  */
                    185: #ifndef O_NOCTTY
                    186: # define O_NOCTTY      0
                    187: #endif /* O_NOCTTY */
1.2       millert   188:
                    189: /*
                    190:  * Emulate POSIX signals via sigvec(2)
                    191:  */
                    192: #ifndef HAVE_SIGACTION
                    193: # define SA_ONSTACK    SV_ONSTACK
                    194: # define SA_RESTART    SV_INTERRUPT            /* opposite effect */
                    195: # define SA_RESETHAND  SV_RESETHAND
                    196: # define sa_handler    sv_handler
                    197: # define sa_mask       sv_mask
                    198: # define sa_flags      sv_flags
                    199: typedef struct sigvec sigaction_t;
                    200: typedef int sigset_t;
                    201: int sigaction __P((int sig, const sigaction_t *act, sigaction_t *oact));
                    202: int sigemptyset __P((sigset_t *));
                    203: int sigfillset __P((sigset_t *));
                    204: int sigaddset __P((sigset_t *, int));
                    205: int sigdelset __P((sigset_t *, int));
                    206: int sigismember __P((sigset_t *, int));
                    207: int sigprocmask __P((int, const sigset_t *, sigset_t *));
                    208: #endif
                    209:
                    210: /*
                    211:  * Extra sugar for POSIX signals to deal with the above emulation
                    212:  * as well as the fact that SunOS has a SA_INTERRUPT flag.
                    213:  */
                    214: #ifdef HAVE_SIGACTION
                    215: # ifndef HAVE_SIGACTION_T
                    216: typedef struct sigaction sigaction_t;
                    217: # endif
1.7     ! millert   218: # ifndef SA_INTERRUPT
1.2       millert   219: #  define SA_INTERRUPT 0
                    220: # endif
1.7     ! millert   221: # ifndef SA_RESTART
1.2       millert   222: #  define SA_RESTART   0
                    223: # endif
1.4       millert   224: #endif
                    225:
                    226: /*
                    227:  * HP-UX 9.x has RLIMIT_* but no RLIM_INFINITY.
                    228:  * Using -1 works because we only check for RLIM_INFINITY and do not set it.
                    229:  */
                    230: #ifndef RLIM_INFINITY
                    231: # define RLIM_INFINITY (-1)
1.2       millert   232: #endif
1.6       millert   233:
                    234: /*
                    235:  * If we lack getprogname(), emulate with __progname if possible.
                    236:  * Otherwise, add a prototype for use with our own getprogname.c.
                    237:  */
                    238: #ifndef HAVE_GETPROGNAME
                    239: # ifdef HAVE___PROGNAME
                    240: extern const char *__progname;
                    241: #  define getprogname()          (__progname)
                    242: # else
                    243: const char *getprogname __P((void));
                    244: #endif /* HAVE___PROGNAME */
                    245: #endif /* !HAVE_GETPROGNAME */
1.1       millert   246:
                    247: #endif /* _SUDO_COMPAT_H */