master xplshn/aruu / cmd / posix / sh / shell.h
  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#if defined(__linux__) || defined(__CYGWIN__)
 56#define tcsetsid(fd, pid) ioctl((fd), TIOCSCTTY, 0)
 57#endif
 58#endif
 59
 60#ifndef ALIGN
 61#define ALIGNBYTES (sizeof(void *) - 1)
 62#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
 63#endif
 64
 65#ifndef __dead2
 66#define __dead2 __attribute__((__noreturn__))
 67#endif
 68#ifndef __unused
 69#define __unused __attribute__((__unused__))
 70#endif
 71#ifndef __nonstring
 72#if defined(__has_attribute)
 73#if __has_attribute(__nonstring__)
 74#define __nonstring __attribute__((__nonstring__))
 75#elif __has_attribute(nonstring)
 76#define __nonstring __attribute__((nonstring))
 77#endif
 78#endif
 79#endif
 80#ifndef __nonstring
 81#define __nonstring
 82#endif
 83#ifndef __printf0like
 84#define __printf0like(n, m) __attribute__((__format__(__printf__, n, m)))
 85#endif
 86#ifndef __printflike
 87#define __printflike(n, m) __attribute__((__format__(__printf__, n, m)))
 88#endif
 89
 90#ifndef O_VERIFY
 91#define O_VERIFY 0
 92#endif
 93
 94#ifndef CLOCK_UPTIME
 95#define CLOCK_UPTIME CLOCK_MONOTONIC
 96#endif
 97
 98#ifndef timespecsub
 99#define timespecsub(a, b, result) \
100	do { \
101		(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
102		(result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
103		if ((result)->tv_nsec < 0) { \
104			--(result)->tv_sec; \
105			(result)->tv_nsec += 1000000000L; \
106		} \
107	} while (0)
108#endif
109
110#ifndef MAXLOGNAME
111#ifdef LOGIN_NAME_MAX
112#define MAXLOGNAME LOGIN_NAME_MAX
113#else
114#define MAXLOGNAME 32
115#endif
116#endif
117
118#ifndef __DECONST
119#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
120#endif
121
122#ifndef eaccess
123#ifdef AT_EACCESS
124#define eaccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_EACCESS)
125#else
126#define eaccess(path, mode) access((path), (mode))
127#endif
128#endif
129
130/*
131 * The follow should be set to reflect the type of system you have:
132 *	JOBS -> 1 if you have Berkeley job control, 0 otherwise.
133 *	define DEBUG=1 to compile in debugging (set global "debug" to turn on)
134 *	define DEBUG=2 to compile in and turn on debugging.
135 *
136 * When debugging is on, debugging info will be written to ./trace and
137 * a quit signal will generate a core dump.
138 */
139
140
141#define	JOBS 1
142/* #define DEBUG 1 */
143
144/*
145 * Type of used arithmetic. SUSv3 requires us to have at least signed long.
146 */
147typedef intmax_t arith_t;
148#define	ARITH_FORMAT_STR  "%" PRIdMAX
149#define	ARITH_MIN INTMAX_MIN
150#define	ARITH_MAX INTMAX_MAX
151
152typedef void *pointer;
153
154#if defined(__has_include)
155#if __has_include(<sys/cdefs.h>)
156#include <sys/cdefs.h>
157#endif
158#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
159#include <sys/cdefs.h>
160#endif
161
162extern char nullstr[1];		/* null string */
163
164#ifdef DEBUG
165#define TRACE(param)  sh_trace param
166#else
167#define TRACE(param)
168#endif
169
170#endif /* !SHELL_H_ */