Add getopt implementation from OpenBSD

This commit is contained in:
Micke Prag 2012-01-18 11:21:42 +01:00
parent 44b60a20ec
commit 848f65803c
8 changed files with 1731 additions and 0 deletions

View file

@ -0,0 +1,9 @@
#include <windows.h>
#include <stdio.h>
__inline void warnx(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}

View file

@ -0,0 +1,78 @@
/* $OpenBSD: getopt.h,v 1.2 2008/06/26 05:42:04 ray Exp $ */
/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Dieter Baron and Thomas Klausner.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GETOPT_H_
#define _GETOPT_H_
#include <sys/cdefs.h>
/*
* GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions
*/
#define no_argument 0
#define required_argument 1
#define optional_argument 2
struct option {
/* name of long option */
const char *name;
/*
* one of no_argument, required_argument, and optional_argument:
* whether option takes an argument
*/
int has_arg;
/* if not NULL, set *flag to val when option found */
int *flag;
/* if flag not NULL, value to set *flag to; else return value */
int val;
};
__BEGIN_DECLS
int getopt_long(int, char * const *, const char *,
const struct option *, int *);
int getopt_long_only(int, char * const *, const char *,
const struct option *, int *);
#ifndef _GETOPT_DEFINED_
#define _GETOPT_DEFINED_
int getopt(int, char * const *, const char *);
int getsubopt(char **, char * const *, char **);
extern char *optarg; /* getopt(3) external variables */
extern int opterr;
extern int optind;
extern int optopt;
extern int optreset;
extern char *suboptarg; /* getsubopt(3) external variable */
#endif
__END_DECLS
#endif /* !_GETOPT_H_ */

View file

@ -0,0 +1,511 @@
/* $OpenBSD: getopt_long.c,v 1.25 2011/03/05 22:10:11 guenther Exp $ */
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
/*
* Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Sponsored in part by the Defense Advanced Research Projects
* Agency (DARPA) and Air Force Research Laboratory, Air Force
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Dieter Baron and Thomas Klausner.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = '?'; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */
#define PRINT_ERROR ((opterr) && (*options != ':'))
#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
/* return values */
#define BADCH (int)'?'
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
#define INORDER (int)1
#define EMSG ""
static int getopt_internal(int, char * const *, const char *,
const struct option *, int *, int);
static int parse_long_options(char * const *, const char *,
const struct option *, int *, int);
static int gcd(int, int);
static void permute_args(int, int, int, char * const *);
static char *place = EMSG; /* option letter processing */
/* XXX: set optreset to 1 rather than these two */
static int nonopt_start = -1; /* first non option argument (for permute) */
static int nonopt_end = -1; /* first option after non options (for permute) */
/* Error messages */
static const char recargchar[] = "option requires an argument -- %c";
static const char recargstring[] = "option requires an argument -- %s";
static const char ambig[] = "ambiguous option -- %.*s";
static const char noarg[] = "option doesn't take an argument -- %.*s";
static const char illoptchar[] = "unknown option -- %c";
static const char illoptstring[] = "unknown option -- %s";
/*
* Compute the greatest common divisor of a and b.
*/
static int
gcd(int a, int b)
{
int c;
c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return (b);
}
/*
* Exchange the block from nonopt_start to nonopt_end with the block
* from nonopt_end to opt_end (keeping the same order of arguments
* in each block).
*/
static void
permute_args(int panonopt_start, int panonopt_end, int opt_end,
char * const *nargv)
{
int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
char *swap;
/*
* compute lengths of blocks and number and size of cycles
*/
nnonopts = panonopt_end - panonopt_start;
nopts = opt_end - panonopt_end;
ncycle = gcd(nnonopts, nopts);
cyclelen = (opt_end - panonopt_start) / ncycle;
for (i = 0; i < ncycle; i++) {
cstart = panonopt_end+i;
pos = cstart;
for (j = 0; j < cyclelen; j++) {
if (pos >= panonopt_end)
pos -= nnonopts;
else
pos += nopts;
swap = nargv[pos];
/* LINTED const cast */
((char **) nargv)[pos] = nargv[cstart];
/* LINTED const cast */
((char **)nargv)[cstart] = swap;
}
}
}
/*
* parse_long_options --
* Parse long options in argc/argv argument vector.
* Returns -1 if short_too is set and the option does not match long_options.
*/
static int
parse_long_options(char * const *nargv, const char *options,
const struct option *long_options, int *idx, int short_too)
{
char *current_argv, *has_equal;
size_t current_argv_len;
int i, match;
current_argv = place;
match = -1;
optind++;
if ((has_equal = strchr(current_argv, '=')) != NULL) {
/* argument found (--option=arg) */
current_argv_len = has_equal - current_argv;
has_equal++;
} else
current_argv_len = strlen(current_argv);
for (i = 0; long_options[i].name; i++) {
/* find matching long option */
if (strncmp(current_argv, long_options[i].name,
current_argv_len))
continue;
if (strlen(long_options[i].name) == current_argv_len) {
/* exact match */
match = i;
break;
}
/*
* If this is a known short option, don't allow
* a partial match of a single character.
*/
if (short_too && current_argv_len == 1)
continue;
if (match == -1) /* partial match */
match = i;
else {
/* ambiguous abbreviation */
if (PRINT_ERROR)
warnx(ambig, (int)current_argv_len,
current_argv);
optopt = 0;
return (BADCH);
}
}
if (match != -1) { /* option found */
if (long_options[match].has_arg == no_argument
&& has_equal) {
if (PRINT_ERROR)
warnx(noarg, (int)current_argv_len,
current_argv);
/*
* XXX: GNU sets optopt to val regardless of flag
*/
if (long_options[match].flag == NULL)
optopt = long_options[match].val;
else
optopt = 0;
return (BADARG);
}
if (long_options[match].has_arg == required_argument ||
long_options[match].has_arg == optional_argument) {
if (has_equal)
optarg = has_equal;
else if (long_options[match].has_arg ==
required_argument) {
/*
* optional argument doesn't use next nargv
*/
optarg = nargv[optind++];
}
}
if ((long_options[match].has_arg == required_argument)
&& (optarg == NULL)) {
/*
* Missing argument; leading ':' indicates no error
* should be generated.
*/
if (PRINT_ERROR)
warnx(recargstring,
current_argv);
/*
* XXX: GNU sets optopt to val regardless of flag
*/
if (long_options[match].flag == NULL)
optopt = long_options[match].val;
else
optopt = 0;
--optind;
return (BADARG);
}
} else { /* unknown option */
if (short_too) {
--optind;
return (-1);
}
if (PRINT_ERROR)
warnx(illoptstring, current_argv);
optopt = 0;
return (BADCH);
}
if (idx)
*idx = match;
if (long_options[match].flag) {
*long_options[match].flag = long_options[match].val;
return (0);
} else
return (long_options[match].val);
}
/*
* getopt_internal --
* Parse argc/argv argument vector. Called by user level routines.
*/
static int
getopt_internal(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx, int flags)
{
char *oli; /* option letter list index */
int optchar, short_too;
static int posixly_correct = -1;
if (options == NULL)
return (-1);
/*
* XXX Some GNU programs (like cvs) set optind to 0 instead of
* XXX using optreset. Work around this braindamage.
*/
if (optind == 0)
optind = optreset = 1;
/*
* Disable GNU extensions if POSIXLY_CORRECT is set or options
* string begins with a '+'.
*/
if (posixly_correct == -1 || optreset)
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
if (*options == '-')
flags |= FLAG_ALLARGS;
else if (posixly_correct || *options == '+')
flags &= ~FLAG_PERMUTE;
if (*options == '+' || *options == '-')
options++;
optarg = NULL;
if (optreset)
nonopt_start = nonopt_end = -1;
start:
if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc) { /* end of argument vector */
place = EMSG;
if (nonopt_end != -1) {
/* do permutation, if we have to */
permute_args(nonopt_start, nonopt_end,
optind, nargv);
optind -= nonopt_end - nonopt_start;
}
else if (nonopt_start != -1) {
/*
* If we skipped non-options, set optind
* to the first of them.
*/
optind = nonopt_start;
}
nonopt_start = nonopt_end = -1;
return (-1);
}
if (*(place = nargv[optind]) != '-' ||
(place[1] == '\0' && strchr(options, '-') == NULL)) {
place = EMSG; /* found non-option */
if (flags & FLAG_ALLARGS) {
/*
* GNU extension:
* return non-option as argument to option 1
*/
optarg = nargv[optind++];
return (INORDER);
}
if (!(flags & FLAG_PERMUTE)) {
/*
* If no permutation wanted, stop parsing
* at first non-option.
*/
return (-1);
}
/* do permutation */
if (nonopt_start == -1)
nonopt_start = optind;
else if (nonopt_end != -1) {
permute_args(nonopt_start, nonopt_end,
optind, nargv);
nonopt_start = optind -
(nonopt_end - nonopt_start);
nonopt_end = -1;
}
optind++;
/* process next argument */
goto start;
}
if (nonopt_start != -1 && nonopt_end == -1)
nonopt_end = optind;
/*
* If we have "-" do nothing, if "--" we are done.
*/
if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
optind++;
place = EMSG;
/*
* We found an option (--), so if we skipped
* non-options, we have to permute.
*/
if (nonopt_end != -1) {
permute_args(nonopt_start, nonopt_end,
optind, nargv);
optind -= nonopt_end - nonopt_start;
}
nonopt_start = nonopt_end = -1;
return (-1);
}
}
/*
* Check long options if:
* 1) we were passed some
* 2) the arg is not just "-"
* 3) either the arg starts with -- we are getopt_long_only()
*/
if (long_options != NULL && place != nargv[optind] &&
(*place == '-' || (flags & FLAG_LONGONLY))) {
short_too = 0;
if (*place == '-')
place++; /* --foo long option */
else if (*place != ':' && strchr(options, *place) != NULL)
short_too = 1; /* could be short option too */
optchar = parse_long_options(nargv, options, long_options,
idx, short_too);
if (optchar != -1) {
place = EMSG;
return (optchar);
}
}
if ((optchar = (int)*place++) == (int)':' ||
(optchar == (int)'-' && *place != '\0') ||
(oli = strchr(options, optchar)) == NULL) {
/*
* If the user specified "-" and '-' isn't listed in
* options, return -1 (non-option) as per POSIX.
* Otherwise, it is an unknown option character (or ':').
*/
if (optchar == (int)'-' && *place == '\0')
return (-1);
if (!*place)
++optind;
if (PRINT_ERROR)
warnx(illoptchar, optchar);
optopt = optchar;
return (BADCH);
}
if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
/* -W long-option */
if (*place) /* no space */
/* NOTHING */;
else if (++optind >= nargc) { /* no arg */
place = EMSG;
if (PRINT_ERROR)
warnx(recargchar, optchar);
optopt = optchar;
return (BADARG);
} else /* white space */
place = nargv[optind];
optchar = parse_long_options(nargv, options, long_options,
idx, 0);
place = EMSG;
return (optchar);
}
if (*++oli != ':') { /* doesn't take argument */
if (!*place)
++optind;
} else { /* takes (optional) argument */
optarg = NULL;
if (*place) /* no white space */
optarg = place;
else if (oli[1] != ':') { /* arg not optional */
if (++optind >= nargc) { /* no arg */
place = EMSG;
if (PRINT_ERROR)
warnx(recargchar, optchar);
optopt = optchar;
return (BADARG);
} else
optarg = nargv[optind];
}
place = EMSG;
++optind;
}
/* dump back option letter */
return (optchar);
}
/*
* getopt --
* Parse argc/argv argument vector.
*
* [eventually this will replace the BSD getopt]
*/
int
getopt(int nargc, char * const *nargv, const char *options)
{
/*
* We don't pass FLAG_PERMUTE to getopt_internal() since
* the BSD getopt(3) (unlike GNU) has never done this.
*
* Furthermore, since many privileged programs call getopt()
* before dropping privileges it makes sense to keep things
* as simple (and bug-free) as possible.
*/
return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
}
/*
* getopt_long --
* Parse argc/argv argument vector.
*/
int
getopt_long(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx)
{
return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE));
}
/*
* getopt_long_only --
* Parse argc/argv argument vector.
*/
int
getopt_long_only(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx)
{
return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE|FLAG_LONGONLY));
}

View file

@ -0,0 +1,71 @@
/* $OpenBSD: _types.h,v 1.2 2008/03/16 19:42:57 otto Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)types.h 8.3 (Berkeley) 1/5/94
*/
#ifndef _SYS__TYPES_H_
#define _SYS__TYPES_H_
#include <machine/_types.h>
typedef unsigned long __cpuid_t; /* CPU id */
typedef __int32_t __dev_t; /* device number */
typedef __uint32_t __fixpt_t; /* fixed point number */
typedef __uint32_t __gid_t; /* group id */
typedef __uint32_t __id_t; /* may contain pid, uid or gid */
typedef __uint32_t __in_addr_t; /* base type for internet address */
typedef __uint16_t __in_port_t; /* IP port type */
typedef __uint32_t __ino_t; /* inode number */
typedef long __key_t; /* IPC key (for Sys V IPC) */
typedef __uint32_t __mode_t; /* permissions */
typedef __uint32_t __nlink_t; /* link count */
typedef __int32_t __pid_t; /* process id */
typedef __uint64_t __rlim_t; /* resource limit */
typedef __uint8_t __sa_family_t; /* sockaddr address family type */
typedef __int32_t __segsz_t; /* segment size */
typedef __uint32_t __socklen_t; /* length type for network syscalls */
typedef __int32_t __swblk_t; /* swap offset */
typedef __uint32_t __uid_t; /* user id */
typedef __uint32_t __useconds_t; /* microseconds */
typedef __int32_t __suseconds_t; /* microseconds (signed) */
typedef __uint64_t __fsblkcnt_t; /* file system block count */
typedef __uint64_t __fsfilcnt_t; /* file system file count */
/*
* mbstate_t is an opaque object to keep conversion state, during multibyte
* stream conversions. The content must not be referenced by user programs.
*/
typedef union {
char __mbstate8[128];
__int64_t __mbstateL; /* for alignment */
} __mbstate_t;
#endif /* !_SYS__TYPES_H_ */

View file

@ -0,0 +1,386 @@
/* $OpenBSD: cdefs.h,v 1.32 2012/01/03 16:56:58 kettenis Exp $ */
/* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Berkeley Software Design, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)cdefs.h 8.7 (Berkeley) 1/21/94
*/
#ifndef _SYS_CDEFS_H_
#define _SYS_CDEFS_H_
#include <machine/cdefs.h>
#if defined(__cplusplus)
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS }
#else
#define __BEGIN_DECLS
#define __END_DECLS
#endif
/*
* Macro to test if we're using a specific version of gcc or later.
*/
#ifdef __GNUC__
#define __GNUC_PREREQ__(ma, mi) \
((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)))
#else
#define __GNUC_PREREQ__(ma, mi) 0
#endif
/*
* The __CONCAT macro is used to concatenate parts of symbol names, e.g.
* with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
* The __CONCAT macro is a bit tricky -- make sure you don't put spaces
* in between its arguments. __CONCAT can also concatenate double-quoted
* strings produced by the __STRING macro, but this only works with ANSI C.
*/
#if defined(__STDC__) || defined(__cplusplus)
#define __P(protos) protos /* full-blown ANSI C */
#define __CONCAT(x,y) x ## y
#define __STRING(x) #x
#define __const const /* define reserved names to standard */
#define __signed signed
#define __volatile volatile
#if defined(__cplusplus) || defined(__PCC__)
#define __inline inline /* convert to C++ keyword */
#else
#if !defined(__GNUC__) && !defined(lint)
#define __inline /* delete GCC keyword */
#endif /* !__GNUC__ && !lint */
#endif /* !__cplusplus */
#else /* !(__STDC__ || __cplusplus) */
#define __P(protos) () /* traditional C preprocessor */
#define __CONCAT(x,y) x/**/y
#define __STRING(x) "x"
#if !defined(__GNUC__) && !defined(lint)
#define __const /* delete pseudo-ANSI C keywords */
#define __inline
#define __signed
#define __volatile
#endif /* !__GNUC__ && !lint */
/*
* In non-ANSI C environments, new programs will want ANSI-only C keywords
* deleted from the program and old programs will want them left alone.
* Programs using the ANSI C keywords const, inline etc. as normal
* identifiers should define -DNO_ANSI_KEYWORDS.
*/
#ifndef NO_ANSI_KEYWORDS
#define const __const /* convert ANSI C keywords */
#define inline __inline
#define signed __signed
#define volatile __volatile
#endif /* !NO_ANSI_KEYWORDS */
#endif /* !(__STDC__ || __cplusplus) */
/*
* GCC1 and some versions of GCC2 declare dead (non-returning) and
* pure (no side effects) functions using "volatile" and "const";
* unfortunately, these then cause warnings under "-ansi -pedantic".
* GCC >= 2.5 uses the __attribute__((attrs)) style. All of these
* work for GNU C++ (modulo a slight glitch in the C++ grammar in
* the distribution version of 2.5.5).
*/
#if !__GNUC_PREREQ__(2, 5) && !defined(__PCC__)
#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __dead __volatile
#define __pure __const
#elif defined(lint)
#define __dead /* NORETURN */
#endif
#elif !defined(__STRICT_ANSI__)
#define __dead __attribute__((__noreturn__))
#define __pure __attribute__((__const__))
#endif
#if __GNUC_PREREQ__(2, 7)
#define __unused __attribute__((__unused__))
#else
#define __unused /* delete */
#endif
#if __GNUC_PREREQ__(3, 1)
#define __used __attribute__((__used__))
#else
#define __used __unused /* suppress -Wunused warnings */
#endif
/*
* __returns_twice makes the compiler not assume the function
* only returns once. This affects registerisation of variables:
* even local variables need to be in memory across such a call.
* Example: setjmp()
*/
#if __GNUC_PREREQ__(4, 1)
#define __returns_twice __attribute__((returns_twice))
#else
#define __returns_twice
#endif
/*
* __only_inline makes the compiler only use this function definition
* for inlining; references that can't be inlined will be left as
* external references instead of generating a local copy. The
* matching library should include a simple extern definition for
* the function to handle those references. c.f. ctype.h
*/
#ifdef __GNUC__
# if __GNUC_PREREQ__(4, 2)
#define __only_inline extern __inline __attribute__((__gnu_inline__))
# else
#define __only_inline extern __inline
# endif
#else
#define __only_inline static __inline
#endif
/*
* GNU C version 2.96 adds explicit branch prediction so that
* the CPU back-end can hint the processor and also so that
* code blocks can be reordered such that the predicted path
* sees a more linear flow, thus improving cache behavior, etc.
*
* The following two macros provide us with a way to utilize this
* compiler feature. Use __predict_true() if you expect the expression
* to evaluate to true, and __predict_false() if you expect the
* expression to evaluate to false.
*
* A few notes about usage:
*
* * Generally, __predict_false() error condition checks (unless
* you have some _strong_ reason to do otherwise, in which case
* document it), and/or __predict_true() `no-error' condition
* checks, assuming you want to optimize for the no-error case.
*
* * Other than that, if you don't know the likelihood of a test
* succeeding from empirical or other `hard' evidence, don't
* make predictions.
*
* * These are meant to be used in places that are run `a lot'.
* It is wasteful to make predictions in code that is run
* seldomly (e.g. at subsystem initialization time) as the
* basic block reordering that this affects can often generate
* larger code.
*/
#if __GNUC_PREREQ__(2, 96)
#define __predict_true(exp) __builtin_expect(((exp) != 0), 1)
#define __predict_false(exp) __builtin_expect(((exp) != 0), 0)
#else
#define __predict_true(exp) ((exp) != 0)
#define __predict_false(exp) ((exp) != 0)
#endif
/* Delete pseudo-keywords wherever they are not available or needed. */
#ifndef __dead
#define __dead
#define __pure
#endif
#if __GNUC_PREREQ__(2, 7) || defined(__PCC__)
#define __packed __attribute__((__packed__))
#elif defined(lint)
#define __packed
#endif
#if !__GNUC_PREREQ__(2, 8)
#define __extension__
#endif
#if __GNUC_PREREQ__(2, 8) || defined(__PCC__)
#define __statement(x) __extension__(x)
#elif defined(lint)
#define __statement(x) (0)
#else
#define __statement(x) (x)
#endif
#if __GNUC_PREREQ__(3, 0)
#define __malloc __attribute__((__malloc__))
#else
#define __malloc
#endif
/*
* "The nice thing about standards is that there are so many to choose from."
* There are a number of "feature test macros" specified by (different)
* standards that determine which interfaces and types the header files
* should expose.
*
* Because of inconsistencies in these macros, we define our own
* set in the private name space that end in _VISIBLE. These are
* always defined and so headers can test their values easily.
* Things can get tricky when multiple feature macros are defined.
* We try to take the union of all the features requested.
*
* The following macros are guaranteed to have a value after cdefs.h
* has been included:
* __POSIX_VISIBLE
* __XPG_VISIBLE
* __ISO_C_VISIBLE
* __BSD_VISIBLE
*/
/*
* X/Open Portability Guides and Single Unix Specifications.
* _XOPEN_SOURCE XPG3
* _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4
* _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2
* _XOPEN_SOURCE == 500 XPG5
* _XOPEN_SOURCE == 520 XPG5v2
* _XOPEN_SOURCE == 600 POSIX 1003.1-2001 with XSI
* _XOPEN_SOURCE == 700 POSIX 1003.1-2008 with XSI
*
* The XPG spec implies a specific value for _POSIX_C_SOURCE.
*/
#ifdef _XOPEN_SOURCE
# if (_XOPEN_SOURCE - 0 >= 700)
# define __XPG_VISIBLE 700
# undef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 200809L
# elif (_XOPEN_SOURCE - 0 >= 600)
# define __XPG_VISIBLE 600
# undef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 200112L
# elif (_XOPEN_SOURCE - 0 >= 520)
# define __XPG_VISIBLE 520
# undef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 199506L
# elif (_XOPEN_SOURCE - 0 >= 500)
# define __XPG_VISIBLE 500
# undef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 199506L
# elif (_XOPEN_SOURCE_EXTENDED - 0 == 1)
# define __XPG_VISIBLE 420
# elif (_XOPEN_VERSION - 0 >= 4)
# define __XPG_VISIBLE 400
# else
# define __XPG_VISIBLE 300
# endif
#endif
/*
* POSIX macros, these checks must follow the XOPEN ones above.
*
* _POSIX_SOURCE == 1 1003.1-1988 (superseded by _POSIX_C_SOURCE)
* _POSIX_C_SOURCE == 1 1003.1-1990
* _POSIX_C_SOURCE == 2 1003.2-1992
* _POSIX_C_SOURCE == 199309L 1003.1b-1993
* _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995,
* and the omnibus ISO/IEC 9945-1:1996
* _POSIX_C_SOURCE == 200112L 1003.1-2001
* _POSIX_C_SOURCE == 200809L 1003.1-2008
*
* The POSIX spec implies a specific value for __ISO_C_VISIBLE, though
* this may be overridden by the _ISOC99_SOURCE macro later.
*/
#ifdef _POSIX_C_SOURCE
# if (_POSIX_C_SOURCE - 0 >= 200809)
# define __POSIX_VISIBLE 200809
# define __ISO_C_VISIBLE 1999
# elif (_POSIX_C_SOURCE - 0 >= 200112)
# define __POSIX_VISIBLE 200112
# define __ISO_C_VISIBLE 1999
# elif (_POSIX_C_SOURCE - 0 >= 199506)
# define __POSIX_VISIBLE 199506
# define __ISO_C_VISIBLE 1990
# elif (_POSIX_C_SOURCE - 0 >= 199309)
# define __POSIX_VISIBLE 199309
# define __ISO_C_VISIBLE 1990
# elif (_POSIX_C_SOURCE - 0 >= 2)
# define __POSIX_VISIBLE 199209
# define __ISO_C_VISIBLE 1990
# else
# define __POSIX_VISIBLE 199009
# define __ISO_C_VISIBLE 1990
# endif
#elif defined(_POSIX_SOURCE)
# define __POSIX_VISIBLE 198808
# define __ISO_C_VISIBLE 0
#endif
/*
* _ANSI_SOURCE means to expose ANSI C89 interfaces only.
* If the user defines it in addition to one of the POSIX or XOPEN
* macros, assume the POSIX/XOPEN macro(s) should take precedence.
*/
#if defined(_ANSI_SOURCE) && !defined(__POSIX_VISIBLE) && \
!defined(__XPG_VISIBLE)
# define __POSIX_VISIBLE 0
# define __XPG_VISIBLE 0
# define __ISO_C_VISIBLE 1990
#endif
/*
* _ISOC99_SOURCE and __STDC_VERSION__ override any of the other macros since
* they are non-exclusive.
*/
#if defined(_ISOC99_SOURCE) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) || \
(defined(__cplusplus) && __cplusplus >= 201103)
# undef __ISO_C_VISIBLE
# define __ISO_C_VISIBLE 1999
#endif
/*
* Finally deal with BSD-specific interfaces that are not covered
* by any standards. We expose these when none of the POSIX or XPG
* macros is defined or if the user explicitly asks for them.
*/
#if !defined(_BSD_SOURCE) && \
(defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE))
# define __BSD_VISIBLE 0
#endif
/*
* Default values.
*/
#ifndef __XPG_VISIBLE
# define __XPG_VISIBLE 700
#endif
#ifndef __POSIX_VISIBLE
# define __POSIX_VISIBLE 200809
#endif
#ifndef __ISO_C_VISIBLE
# define __ISO_C_VISIBLE 1999
#endif
#ifndef __BSD_VISIBLE
# define __BSD_VISIBLE 1
#endif
#endif /* !_SYS_CDEFS_H_ */

View file

@ -0,0 +1,243 @@
/* $OpenBSD: types.h,v 1.32 2011/03/19 18:26:06 deraadt Exp $ */
/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */
/*-
* Copyright (c) 1982, 1986, 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)types.h 8.4 (Berkeley) 1/21/94
*/
#ifndef _SYS_TYPES_H_
#define _SYS_TYPES_H_
#include <sys/cdefs.h>
#include <sys/_types.h>
#include <machine/endian.h>
#if __BSD_VISIBLE
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
typedef unsigned char unchar; /* Sys V compatibility */
typedef unsigned short ushort; /* Sys V compatibility */
typedef unsigned int uint; /* Sys V compatibility */
typedef unsigned long ulong; /* Sys V compatibility */
typedef __cpuid_t cpuid_t; /* CPU id */
typedef __register_t register_t; /* register-sized type */
#endif /* __BSD_VISIBLE */
/*
* XXX The exact-width bit types should only be exposed if __BSD_VISIBLE
* but the rest of the includes are not ready for that yet.
*/
#ifndef __BIT_TYPES_DEFINED__
#define __BIT_TYPES_DEFINED__
#endif
#ifndef _INT8_T_DEFINED_
#define _INT8_T_DEFINED_
typedef __int8_t int8_t;
#endif
#ifndef _UINT8_T_DEFINED_
#define _UINT8_T_DEFINED_
typedef __uint8_t uint8_t;
#endif
#ifndef _INT16_T_DEFINED_
#define _INT16_T_DEFINED_
typedef __int16_t int16_t;
#endif
#ifndef _UINT16_T_DEFINED_
#define _UINT16_T_DEFINED_
typedef __uint16_t uint16_t;
#endif
#ifndef _INT32_T_DEFINED_
#define _INT32_T_DEFINED_
typedef __int32_t int32_t;
#endif
#ifndef _UINT32_T_DEFINED_
#define _UINT32_T_DEFINED_
typedef __uint32_t uint32_t;
#endif
#ifndef _INT64_T_DEFINED_
#define _INT64_T_DEFINED_
typedef __int64_t int64_t;
#endif
#ifndef _UINT64_T_DEFINED_
#define _UINT64_T_DEFINED_
typedef __uint64_t uint64_t;
#endif
/* BSD-style unsigned bits types */
typedef __uint8_t u_int8_t;
typedef __uint16_t u_int16_t;
typedef __uint32_t u_int32_t;
typedef __uint64_t u_int64_t;
/* quads, deprecated in favor of 64 bit int types */
typedef __int64_t quad_t;
typedef __uint64_t u_quad_t;
typedef quad_t * qaddr_t;
#if __BSD_VISIBLE
/* VM system types */
typedef __vaddr_t vaddr_t;
typedef __paddr_t paddr_t;
typedef __vsize_t vsize_t;
typedef __psize_t psize_t;
#endif /* __BSD_VISIBLE */
/* Standard system types */
typedef char * caddr_t; /* core address */
typedef __int32_t daddr32_t; /* 32-bit disk address */
typedef __int64_t daddr_t; /* 64-bit disk address */
typedef __int64_t daddr64_t; /* 64-bit disk address */
typedef __dev_t dev_t; /* device number */
typedef __fixpt_t fixpt_t; /* fixed point number */
typedef __gid_t gid_t; /* group id */
typedef __id_t id_t; /* may contain pid, uid or gid */
typedef __ino_t ino_t; /* inode number */
typedef __key_t key_t; /* IPC key (for Sys V IPC) */
typedef __mode_t mode_t; /* permissions */
typedef __nlink_t nlink_t; /* link count */
typedef __pid_t pid_t; /* process id */
typedef __rlim_t rlim_t; /* resource limit */
typedef __segsz_t segsz_t; /* segment size */
typedef __swblk_t swblk_t; /* swap offset */
typedef __uid_t uid_t; /* user id */
typedef __useconds_t useconds_t; /* microseconds */
typedef __suseconds_t suseconds_t; /* microseconds (signed) */
typedef __fsblkcnt_t fsblkcnt_t; /* file system block count */
typedef __fsfilcnt_t fsfilcnt_t; /* file system file count */
/*
* XPG4.2 states that inclusion of <netinet/in.h> must pull these
* in and that inclusion of <sys/socket.h> must pull in sa_family_t.
* We put these here because there are other headers that require
* these types and <sys/socket.h> and <netinet/in.h> will indirectly
* include <sys/types.h>.
* XXX - now that we have protected versions these should move.
*/
typedef __in_addr_t in_addr_t; /* base type for internet address */
typedef __in_port_t in_port_t; /* IP port type */
typedef __sa_family_t sa_family_t; /* sockaddr address family type */
typedef __socklen_t socklen_t; /* length type for network syscalls */
/*
* The following types may be defined in multiple header files.
*/
#ifndef _CLOCK_T_DEFINED_
#define _CLOCK_T_DEFINED_
typedef __clock_t clock_t;
#endif
#ifndef _CLOCKID_T_DEFINED_
#define _CLOCKID_T_DEFINED_
typedef __clockid_t clockid_t;
#endif
#ifndef _SIZE_T_DEFINED_
#define _SIZE_T_DEFINED_
typedef __size_t size_t;
#endif
#ifndef _SSIZE_T_DEFINED_
#define _SSIZE_T_DEFINED_
typedef __ssize_t ssize_t;
#endif
#ifndef _TIME_T_DEFINED_
#define _TIME_T_DEFINED_
typedef __time_t time_t;
#endif
#ifndef _TIMER_T_DEFINED_
#define _TIMER_T_DEFINED_
typedef __timer_t timer_t;
#endif
#ifndef _OFF_T_DEFINED_
#define _OFF_T_DEFINED_
typedef __off_t off_t;
#endif
/*
* These belong in unistd.h, but are placed here too to ensure that
* long arguments will be promoted to off_t if the program fails to
* include that header or explicitly cast them to off_t.
*/
#if __BSD_VISIBLE && !defined(_KERNEL)
__BEGIN_DECLS
off_t lseek(int, off_t, int);
int ftruncate(int, off_t);
int truncate(const char *, off_t);
__END_DECLS
#endif /* __BSD_VISIBLE && !_KERNEL */
#if __BSD_VISIBLE
/* Major, minor numbers, dev_t's. */
#define major(x) ((int32_t)(((u_int32_t)(x) >> 8) & 0xff))
#define minor(x) ((int32_t)((x) & 0xff) | (((x) & 0xffff0000) >> 8))
#define makedev(x,y) ((dev_t)((((x) & 0xff) << 8) | ((y) & 0xff) | (((y) & 0xffff00) << 8)))
#endif
#if __BSD_VISIBLE
#include <sys/select.h> /* must be after type declarations */
#endif
#if defined(__STDC__) && defined(_KERNEL)
/*
* Forward structure declarations for function prototypes. We include the
* common structures that cross subsystem boundaries here; others are mostly
* used in the same place that the structure is defined.
*/
struct proc;
struct pgrp;
struct ucred;
struct rusage;
struct file;
struct buf;
struct tty;
struct uio;
#endif
#endif /* !_SYS_TYPES_H_ */

View file

@ -0,0 +1,159 @@
/* $OpenBSD: unistd.h,v 1.19 2011/10/15 23:35:29 guenther Exp $ */
/* $NetBSD: unistd.h,v 1.10 1994/06/29 06:46:06 cgd Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)unistd.h 8.2 (Berkeley) 1/7/94
*/
#ifndef _SYS_UNISTD_H_
#define _SYS_UNISTD_H_
#include <sys/cdefs.h>
/* compile-time symbolic constants */
/* implementation supports job control */
#define _POSIX_JOB_CONTROL 1
/* saved set-user-ID and set-group-ID */
#define _POSIX_SAVED_IDS 1
#define _POSIX_VERSION 199009L
#define _POSIX2_VERSION 199212L
/* execution-time symbolic constants */
/* chown requires appropriate privileges */
#define _POSIX_CHOWN_RESTRICTED 1
/* too-long path components generate errors */
#define _POSIX_NO_TRUNC 1
/* may disable terminal special characters */
#define _POSIX_VDISABLE (0377)
/* file synchronization is available */
#define _POSIX_FSYNC 1
/* access function */
#define F_OK 0 /* test for existence of file */
#define X_OK 0x01 /* test for execute or search permission */
#define W_OK 0x02 /* test for write permission */
#define R_OK 0x04 /* test for read permission */
/* whence values for lseek(2) */
#define SEEK_SET 0 /* set file offset to offset */
#define SEEK_CUR 1 /* set file offset to current plus offset */
#define SEEK_END 2 /* set file offset to EOF plus offset */
#if __BSD_VISIBLE
/* old BSD whence values for lseek(2); renamed by POSIX 1003.1 */
#define L_SET SEEK_SET
#define L_INCR SEEK_CUR
#define L_XTND SEEK_END
/* the parameters argument passed to the __tfork() syscall */
struct __tfork {
void *tf_tcb;
pid_t *tf_tid;
int tf_flags;
};
#endif
/* configurable pathname variables */
#define _PC_LINK_MAX 1
#define _PC_MAX_CANON 2
#define _PC_MAX_INPUT 3
#define _PC_NAME_MAX 4
#define _PC_PATH_MAX 5
#define _PC_PIPE_BUF 6
#define _PC_CHOWN_RESTRICTED 7
#define _PC_NO_TRUNC 8
#define _PC_VDISABLE 9
/* configurable system variables */
#define _SC_ARG_MAX 1
#define _SC_CHILD_MAX 2
#define _SC_CLK_TCK 3
#define _SC_NGROUPS_MAX 4
#define _SC_OPEN_MAX 5
#define _SC_JOB_CONTROL 6
#define _SC_SAVED_IDS 7
#define _SC_VERSION 8
#define _SC_BC_BASE_MAX 9
#define _SC_BC_DIM_MAX 10
#define _SC_BC_SCALE_MAX 11
#define _SC_BC_STRING_MAX 12
#define _SC_COLL_WEIGHTS_MAX 13
#define _SC_EXPR_NEST_MAX 14
#define _SC_LINE_MAX 15
#define _SC_RE_DUP_MAX 16
#define _SC_2_VERSION 17
#define _SC_2_C_BIND 18
#define _SC_2_C_DEV 19
#define _SC_2_CHAR_TERM 20
#define _SC_2_FORT_DEV 21
#define _SC_2_FORT_RUN 22
#define _SC_2_LOCALEDEF 23
#define _SC_2_SW_DEV 24
#define _SC_2_UPE 25
#define _SC_STREAM_MAX 26
#define _SC_TZNAME_MAX 27
#define _SC_PAGESIZE 28
#define _SC_PAGE_SIZE _SC_PAGESIZE /* 1170 compatibility */
#define _SC_FSYNC 29
#define _SC_XOPEN_SHM 30
#define _SC_SEM_NSEMS_MAX 31
#define _SC_SEM_VALUE_MAX 32
#define _SC_HOST_NAME_MAX 33
/* P1003.1c */
#define _SC_GETGR_R_SIZE_MAX 100
#define _SC_GETPW_R_SIZE_MAX 101
#define _SC_LOGIN_NAME_MAX 102
#define _SC_THREAD_SAFE_FUNCTIONS 103
#ifdef notyet
#define _SC_THREAD_DESTRUCTOR_ITERATIONS
#define _SC_THREAD_KEYS_MAX
#define _SC_THREAD_STACK_MIN
#define _SC_THREAD_THREADS_MAX
#define _SC_TTY_NAME_MAX
#define _SC_THREADS
#define _SC_THREAD_ATTR_STACKADDR
#define _SC_THREAD_ATTR_STACKSIZE
#define _SC_THREAD_PRIORITY_SCHEDULING
#define _SC_THREAD_PRIO_INHERIT
#define _SC_THREAD_PRIO_PROTECT
#define _SC_THREAD_PROCESS_SHARED
#endif
#define _SC_PHYS_PAGES 500
#define _SC_AVPHYS_PAGES 501
#define _SC_NPROCESSORS_CONF 502
#define _SC_NPROCESSORS_ONLN 503
/* configurable system strings */
#define _CS_PATH 1
#endif /* !_SYS_UNISTD_H_ */

View file

@ -0,0 +1,274 @@
/* $OpenBSD: unistd.h,v 1.67 2012/01/13 13:16:44 nigel Exp $ */
/* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)unistd.h 5.13 (Berkeley) 6/17/91
*/
#ifndef _UNISTD_H_
#define _UNISTD_H_
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/unistd.h>
#define STDIN_FILENO 0 /* standard input file descriptor */
#define STDOUT_FILENO 1 /* standard output file descriptor */
#define STDERR_FILENO 2 /* standard error file descriptor */
#if __XPG_VISIBLE || __POSIX_VISIBLE >= 200112
#define F_ULOCK 0 /* unlock locked section */
#define F_LOCK 1 /* lock a section for exclusive use */
#define F_TLOCK 2 /* test and lock a section for exclusive use */
#define F_TEST 3 /* test a section for locks by other procs */
#endif
#if __POSIX_VISIBLE
#define _POSIX_REENTRANT_FUNCTIONS 1
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
#endif
#ifndef NULL
#ifdef __GNUG__
#define NULL __null
#elif defined(__cplusplus)
#define NULL 0L
#else
#define NULL ((void *)0)
#endif
#endif
__BEGIN_DECLS
__dead void _exit(int);
int access(const char *, int);
unsigned int alarm(unsigned int);
int chdir(const char *);
int chown(const char *, uid_t, gid_t);
int close(int);
int dup(int);
int dup2(int, int);
int execl(const char *, const char *, ...)
__attribute__((sentinel));
int execle(const char *, const char *, ...);
int execlp(const char *, const char *, ...)
__attribute__((sentinel));
int execv(const char *, char * const *);
int execve(const char *, char * const *, char * const *);
int execvp(const char *, char * const *);
pid_t fork(void);
long fpathconf(int, int);
char *getcwd(char *, size_t)
__attribute__((__bounded__(__string__,1,2)));
gid_t getegid(void);
uid_t geteuid(void);
gid_t getgid(void);
int getgroups(int, gid_t *);
char *getlogin(void);
pid_t getpgrp(void);
pid_t getpid(void);
pid_t getppid(void);
uid_t getuid(void);
int isatty(int);
int link(const char *, const char *);
off_t lseek(int, off_t, int);
long pathconf(const char *, int);
int pause(void);
int pipe(int *);
ssize_t read(int, void *, size_t)
__attribute__((__bounded__(__buffer__,2,3)));
int rmdir(const char *);
int setgid(gid_t);
int setuid(uid_t);
unsigned int sleep(unsigned int);
long sysconf(int);
pid_t tcgetpgrp(int);
int tcsetpgrp(int, pid_t);
char *ttyname(int);
int unlink(const char *);
ssize_t write(int, const void *, size_t)
__attribute__((__bounded__(__buffer__,2,3)));
#if __POSIX_VISIBLE || __XPG_VISIBLE >= 300
pid_t setsid(void);
int setpgid(pid_t, pid_t);
#endif
#if __POSIX_VISIBLE >= 199209 || __XPG_VISIBLE
size_t confstr(int, char *, size_t)
__attribute__((__bounded__(__string__,2,3)));
#ifndef _GETOPT_DEFINED_
#define _GETOPT_DEFINED_
int getopt(int, char * const *, const char *);
extern char *optarg; /* getopt(3) external variables */
extern int opterr, optind, optopt, optreset;
/* XXX - getsubopt does not belong here */
int getsubopt(char **, char * const *, char **);
extern char *suboptarg; /* getsubopt(3) external variable */
#endif /* _GETOPT_DEFINED_ */
#endif
#if __POSIX_VISIBLE >= 199506 || __XPG_VISIBLE
int fsync(int);
int ftruncate(int, off_t);
int getlogin_r(char *, size_t)
__attribute__((__bounded__(__string__,1,2)));
#endif
#if __XPG_VISIBLE || __BSD_VISIBLE
char *crypt(const char *, const char *);
int encrypt(char *, int);
int fchdir(int);
int fchown(int, uid_t, gid_t);
long gethostid(void);
char *getwd(char *)
__attribute__ ((__bounded__(__minbytes__,1,1024)));
int lchown(const char *, uid_t, gid_t);
int mkstemp(char *);
char *mktemp(char *);
int nice(int);
int readlink(const char *, char *, size_t)
__attribute__ ((__bounded__(__string__,2,3)));
int setkey(const char *);
int setpgrp(pid_t pid, pid_t pgrp); /* obsoleted by setpgid() */
int setregid(gid_t, gid_t);
int setreuid(uid_t, uid_t);
void swab(const void *, void *, size_t);
void sync(void);
int truncate(const char *, off_t);
unsigned int ualarm(unsigned int, unsigned int);
int usleep(useconds_t);
pid_t vfork(void);
#endif
#if __XPG_VISIBLE >= 420
pid_t getpgid(pid_t);
pid_t getsid(pid_t);
#endif
#if __XPG_VISIBLE >= 500
ssize_t pread(int, void *, size_t, off_t);
ssize_t pwrite(int, const void *, size_t, off_t);
int ttyname_r(int, char *, size_t)
__attribute__((__bounded__(__string__,2,3)));
#endif
#if __BSD_VISIBLE || __XPG_VISIBLE <= 500
/* Interfaces withdrawn by X/Open Issue 5 Version 0 */
int brk(void *);
int chroot(const char *);
int getdtablesize(void);
int getpagesize(void);
char *getpass(const char *);
void *sbrk(int);
#endif
#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 420
int lockf(int, int, off_t);
#endif
#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 420 || __BSD_VISIBLE
int symlink(const char *, const char *);
int gethostname(char *, size_t)
__attribute__ ((__bounded__(__string__,1,2)));
int setegid(gid_t);
int seteuid(uid_t);
#endif
#if __POSIX_VISIBLE >= 200809
int faccessat(int, const char *, int, int);
int fchownat(int, const char *, uid_t, gid_t, int);
int linkat(int, const char *, int, const char *, int);
ssize_t readlinkat(int, const char *, char *, size_t);
int symlinkat(const char *, int, const char *);
int unlinkat(int, const char *, int);
#endif
#if __BSD_VISIBLE
int acct(const char *);
int closefrom(int);
int des_cipher(const char *, char *, int32_t, int);
int des_setkey(const char *);
void endusershell(void);
int exect(const char *, char * const *, char * const *);
char *fflagstostr(u_int32_t);
int getdomainname(char *, size_t)
__attribute__ ((__bounded__(__string__,1,2)));
int getgrouplist(const char *, gid_t, gid_t *, int *);
mode_t getmode(const void *, mode_t);
int getresgid(gid_t *, gid_t *, gid_t *);
int getresuid(uid_t *, uid_t *, uid_t *);
char *getusershell(void);
int initgroups(const char *, gid_t);
int iruserok(u_int32_t, int, const char *, const char *);
int iruserok_sa(const void *, int, int, const char *, const char *);
int issetugid(void);
char *mkdtemp(char *);
int mkstemps(char *, int);
int nfssvc(int, void *);
int profil(char *, size_t, unsigned long, unsigned int)
__attribute__ ((__bounded__(__string__,1,2)));
int quotactl(const char *, int, int, char *);
int rcmd(char **, int, const char *,
const char *, const char *, int *);
int rcmd_af(char **, int, const char *,
const char *, const char *, int *, int);
int rcmdsh(char **, int, const char *,
const char *, const char *, char *);
char *re_comp(const char *);
int re_exec(const char *);
int reboot(int);
int revoke(const char *);
int rfork(int opts);
int rresvport(int *);
int rresvport_af(int *, int);
int ruserok(const char *, int, const char *, const char *);
#ifndef _SELECT_DEFINED_
#define _SELECT_DEFINED_
struct timeval;
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
#endif
int setdomainname(const char *, size_t);
int setgroups(int, const gid_t *);
int sethostid(long);
int sethostname(const char *, size_t);
int setlogin(const char *);
void *setmode(const char *);
int setresgid(gid_t, gid_t, gid_t);
int setresuid(uid_t, uid_t, uid_t);
int setrgid(gid_t);
int setruid(uid_t);
void setusershell(void);
int strtofflags(char **, u_int32_t *, u_int32_t *);
int swapctl(int cmd, const void *arg, int misc);
int syscall(int, ...);
#endif /* __BSD_VISIBLE */
__END_DECLS
#endif /* !_UNISTD_H_ */