1 /* 2 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25 #ifndef _DEFINES_H 26 #define _DEFINES_H 27 28 /* $Id: defines.h,v 1.181 2014/06/11 19:22:50 dtucker Exp $ */ 29 30 /* Constants */ 31 32 #ifndef PATH_MAX 33 # ifdef _POSIX_PATH_MAX 34 # define PATH_MAX _POSIX_PATH_MAX 35 # endif 36 #endif 37 38 /* 39 * Looks like ugly, but MAX_IMSGSIZE equals 16384, 40 * and if we don't care it will overflow for some struct 41 */ 42 #if PATH_MAX > 1024 43 # undef PATH_MAX 44 # define PATH_MAX 1024 45 #endif 46 47 #ifndef UID_MAX 48 #define UID_MAX UINT_MAX 49 #endif 50 #ifndef GID_MAX 51 #define GID_MAX UINT_MAX 52 #endif 53 54 #ifndef STDIN_FILENO 55 # define STDIN_FILENO 0 56 #endif 57 #ifndef STDOUT_FILENO 58 # define STDOUT_FILENO 1 59 #endif 60 #ifndef STDERR_FILENO 61 # define STDERR_FILENO 2 62 #endif 63 64 #if defined(HAVE_DECL_O_NONBLOCK) && HAVE_DECL_O_NONBLOCK == 0 65 # define O_NONBLOCK 00004 /* Non Blocking Open */ 66 #endif 67 68 #ifndef S_IXUSR 69 # define S_IXUSR 0000100 /* execute/search permission, */ 70 # define S_IXGRP 0000010 /* execute/search permission, */ 71 # define S_IXOTH 0000001 /* execute/search permission, */ 72 # define _S_IWUSR 0000200 /* write permission, */ 73 # define S_IWUSR _S_IWUSR /* write permission, owner */ 74 # define S_IWGRP 0000020 /* write permission, group */ 75 # define S_IWOTH 0000002 /* write permission, other */ 76 # define S_IRUSR 0000400 /* read permission, owner */ 77 # define S_IRGRP 0000040 /* read permission, group */ 78 # define S_IROTH 0000004 /* read permission, other */ 79 # define S_IRWXU 0000700 /* read, write, execute */ 80 # define S_IRWXG 0000070 /* read, write, execute */ 81 # define S_IRWXO 0000007 /* read, write, execute */ 82 #endif /* S_IXUSR */ 83 84 /* Types */ 85 86 #ifndef ULLONG_MAX 87 # define ULLONG_MAX ((unsigned long long)-1) 88 #endif 89 90 #ifndef SIZE_MAX 91 #define SIZE_MAX ((size_t)-1) 92 #endif 93 94 #if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS) 95 # define ss_family __ss_family 96 #endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */ 97 98 #ifndef HAVE_SYS_UN_H 99 struct sockaddr_un { 100 short sun_family; /* AF_UNIX */ 101 char sun_path[108]; /* path name (gag) */ 102 }; 103 #endif /* HAVE_SYS_UN_H */ 104 105 #ifndef HAVE_IN_ADDR_T 106 typedef uint32_t in_addr_t; 107 #endif 108 109 #ifndef HAVE_IN_PORT_T 110 typedef uint16_t in_port_t; 111 #endif 112 113 /* Macros */ 114 115 #ifndef MAX 116 # define MAX(a,b) (((a)>(b))?(a):(b)) 117 # define MIN(a,b) (((a)<(b))?(a):(b)) 118 #endif 119 120 #if !defined(__GNUC__) || (__GNUC__ < 2) 121 # define __attribute__(x) 122 #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ 123 124 #ifndef OSSH_ALIGNBYTES 125 #define OSSH_ALIGNBYTES (sizeof(int) - 1) 126 #endif 127 #ifndef __CMSG_ALIGN 128 #define __CMSG_ALIGN(p) (((unsigned int)(p) + OSSH_ALIGNBYTES) &~ OSSH_ALIGNBYTES) 129 #endif 130 131 /* Length of the contents of a control message of length len */ 132 #ifndef CMSG_LEN 133 #define CMSG_LEN(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) 134 #endif 135 136 /* Length of the space taken up by a padded control message of length len */ 137 #ifndef CMSG_SPACE 138 #define CMSG_SPACE(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(len)) 139 #endif 140 141 /* given pointer to struct cmsghdr, return pointer to data */ 142 #ifndef CMSG_DATA 143 #define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr))) 144 #endif /* CMSG_DATA */ 145 146 /* 147 * RFC 2292 requires to check msg_controllen, in case that the kernel returns 148 * an empty list for some reasons. 149 */ 150 #ifndef CMSG_FIRSTHDR 151 #define CMSG_FIRSTHDR(mhdr) \ 152 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ 153 (struct cmsghdr *)(mhdr)->msg_control : \ 154 (struct cmsghdr *)NULL) 155 #endif /* CMSG_FIRSTHDR */ 156 157 /* Set up BSD-style BYTE_ORDER definition if it isn't there already */ 158 /* XXX: doesn't try to cope with strange byte orders (PDP_ENDIAN) */ 159 #ifndef BYTE_ORDER 160 # ifndef LITTLE_ENDIAN 161 # define LITTLE_ENDIAN 1234 162 # endif /* LITTLE_ENDIAN */ 163 # ifndef BIG_ENDIAN 164 # define BIG_ENDIAN 4321 165 # endif /* BIG_ENDIAN */ 166 # ifdef WORDS_BIGENDIAN 167 # define BYTE_ORDER BIG_ENDIAN 168 # else /* WORDS_BIGENDIAN */ 169 # define BYTE_ORDER LITTLE_ENDIAN 170 # endif /* WORDS_BIGENDIAN */ 171 #endif /* BYTE_ORDER */ 172 173 #if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT) && \ 174 defined(SYSLOG_R_SAFE_IN_SIGHAND) 175 # define DO_LOG_SAFE_IN_SIGHAND 176 #endif 177 178 #ifndef IOV_MAX 179 # if defined(_XOPEN_IOV_MAX) 180 # define IOV_MAX _XOPEN_IOV_MAX 181 # elif defined(DEF_IOV_MAX) 182 # define IOV_MAX DEF_IOV_MAX 183 # else 184 # define IOV_MAX 16 185 # endif 186 #endif 187 188 /* OpenSMTPD-portable specific entries */ 189 190 /* From OpenNTPD portable */ 191 #if !defined(SA_LEN) 192 # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN) 193 # define SA_LEN(x) ((x)->sa_len) 194 # else 195 # define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \ 196 sizeof(struct sockaddr_in6) : \ 197 sizeof(struct sockaddr_in)) 198 # endif 199 #endif 200 201 /* EAI_NODATA is obsolete and may not be defined */ 202 #ifndef EAI_NODATA 203 #define EAI_NODATA EAI_NONAME 204 #endif 205 206 #endif /* _DEFINES_H */ 207