shell.h (5176B)
1 /* - 2 * spdx-license-identifier: bsd-3-clause 3 * 4 * copyright (c) 1991, 1993 5 * the regents of the university of california. all rights reserved 6 * 7 * this code is derived from software contributed to berkeley by 8 * kenneth almquist 9 * 10 * redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer 15 * 2. redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution 18 * 3. neither the name of the university nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR a PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE 33 */ 34 35 #ifndef SHELL_H_ 36 #define SHELL_H_ 37 38 #if !defined(FEATURE_SH_HISTEDIT) || !FEATURE_SH_HISTEDIT 39 #ifndef NO_HISTORY 40 #define NO_HISTORY 41 #endif 42 #endif 43 44 #include "sig.h" 45 46 #include <fcntl.h> 47 #include <inttypes.h> 48 #include <stdint.h> 49 #include <sys/ioctl.h> 50 #include <sys/stat.h> 51 #include <sys/types.h> 52 #include <unistd.h> 53 54 #ifndef tcsetsid 55 #define tcsetsid(fd, pid) ioctl((fd), TIOCSCTTY, 0) 56 #endif 57 58 #ifndef ALIGN 59 #define ALIGNBYTES (sizeof(void *) - 1) 60 #define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES) 61 #endif 62 63 #ifndef __dead2 64 #define __dead2 __attribute__((__noreturn__)) 65 #endif 66 #ifndef __unused 67 #define __unused __attribute__((__unused__)) 68 #endif 69 #ifndef __nonstring 70 #if defined(__has_attribute) 71 #if __has_attribute(__nonstring__) 72 #define __nonstring __attribute__((__nonstring__)) 73 #elif __has_attribute(nonstring) 74 #define __nonstring __attribute__((nonstring)) 75 #endif 76 #endif 77 #endif 78 #ifndef __nonstring 79 #define __nonstring 80 #endif 81 #ifndef __printf0like 82 #define __printf0like(n, m) __attribute__((__format__(__printf__, n, m))) 83 #endif 84 #ifndef __printflike 85 #define __printflike(n, m) __attribute__((__format__(__printf__, n, m))) 86 #endif 87 88 #ifndef O_VERIFY 89 #define O_VERIFY 0 90 #endif 91 92 #ifndef CLOCK_UPTIME 93 #define CLOCK_UPTIME CLOCK_MONOTONIC 94 #endif 95 96 #ifndef timespecsub 97 #define timespecsub(a, b, result) \ 98 do { \ 99 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 100 (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \ 101 if ((result)->tv_nsec < 0) { \ 102 --(result)->tv_sec; \ 103 (result)->tv_nsec += 1000000000L; \ 104 } \ 105 } while (0) 106 #endif 107 108 #ifndef MAXLOGNAME 109 #ifdef LOGIN_NAME_MAX 110 #define MAXLOGNAME LOGIN_NAME_MAX 111 #else 112 #define MAXLOGNAME 32 113 #endif 114 #endif 115 116 #ifndef __DECONST 117 #define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 118 #endif 119 120 #ifndef eaccess 121 #ifdef AT_EACCESS 122 #define eaccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_EACCESS) 123 #else 124 #define eaccess(path, mode) access((path), (mode)) 125 #endif 126 #endif 127 128 /* 129 * the follow should be set to reflect the type of system you have: 130 * JOBS -> 1 if you have berkeley job control, 0 otherwise 131 * define DEBUG=1 to compile in debugging (set global "debug" to turn on) 132 * define DEBUG=2 to compile in and turn on debugging 133 * 134 * when debugging is on, debugging info will be written to ./trace and 135 * a quit signal will generate a core dump 136 */ 137 138 #define JOBS 1 139 /* #define DEBUG 1 */ 140 141 /* 142 * type of used arithmetic. susv3 requires us to have at least signed long 143 */ 144 typedef intmax_t arith_t; 145 #define ARITH_FORMAT_STR "%" PRIdMAX 146 #define ARITH_MIN INTMAX_MIN 147 #define ARITH_MAX INTMAX_MAX 148 149 #ifndef _SH_POINTER_TYPEDEF 150 #define _SH_POINTER_TYPEDEF 151 typedef void *pointer; 152 #endif 153 154 #if defined(__has_include) 155 #if __has_include(<sys/cdefs.h>) 156 #include <sys/cdefs.h> 157 #endif 158 #endif 159 160 extern char nullstr[1]; /* null string */ 161 162 #ifdef DEBUG 163 #define TRACE(param) sh_trace param 164 #else 165 #define TRACE(param) 166 #endif 167 168 #endif /* !SHELL_H_ */