1 /* @(#)unistd.h 1.28 17/04/30 Copyright 1996-2017 J. Schilling */ 2 /* 3 * Definitions for unix system interface 4 * 5 * Copyright (c) 1996-2017 J. Schilling 6 */ 7 /* 8 * The contents of this file are subject to the terms of the 9 * Common Development and Distribution License, Version 1.0 only 10 * (the "License"). You may not use this file except in compliance 11 * with the License. 12 * 13 * See the file CDDL.Schily.txt in this distribution for details. 14 * A copy of the CDDL is also available via the Internet at 15 * http://www.opensource.org/licenses/cddl1.txt 16 * 17 * When distributing Covered Code, include this CDDL HEADER in each 18 * file and include the License file CDDL.Schily.txt from this distribution. 19 */ 20 21 #ifndef _SCHILY_UNISTD_H 22 #define _SCHILY_UNISTD_H 23 24 #ifndef _SCHILY_MCONFIG_H 25 #include <schily/mconfig.h> 26 #endif 27 28 /* 29 * unistd.h grants things like off_t to be typedef'd. 30 */ 31 #ifndef _SCHILY_TYPES_H 32 #include <schily/types.h> 33 #endif 34 35 /* 36 * inttypes.h grants things like Intptr_t to be typedef'd. 37 */ 38 #ifndef _SCHILY_INTTYPES_H 39 #include <schily/inttypes.h> 40 #endif 41 42 #ifdef HAVE_UNISTD_H 43 44 #ifndef _INCL_UNISTD_H 45 #include <unistd.h> 46 #define _INCL_UNISTD_H 47 #endif 48 49 #ifndef _SC_PAGESIZE 50 #ifdef _SC_PAGE_SIZE /* HP/UX & OSF */ 51 #define _SC_PAGESIZE _SC_PAGE_SIZE 52 #endif 53 #endif 54 55 #else /* !HAVE_UNISTD_H */ 56 #ifndef _SCHILY_STDLIB_H 57 #include <schily/stdlib.h> /* MSVC: no unistd.h environ is in stdlib.h */ 58 #endif 59 #endif /* !HAVE_UNISTD_H */ 60 61 /* 62 * MSVC has getcwd()/chdir()/mkdir()/rmdir() in direct.h 63 */ 64 #if defined(_MSC_VER) && defined(HAVE_DIRECT_H) 65 #ifndef _INCL_DIRECT_H 66 #include <direct.h> 67 #define _INCL_DIRECT_H 68 #endif 69 #endif 70 71 /* 72 * MSVC has size_t in stddef.h 73 */ 74 #ifdef HAVE_STDDEF_H 75 #ifndef _INCL_STDDEF_H 76 #include <stddef.h> 77 #define _INCL_STDDEF_H 78 #endif 79 #endif 80 81 #ifndef STDIN_FILENO 82 # ifdef JOS 83 # ifndef _SCHILY_JOS_IO_H 84 # include <schily/jos_io.h> 85 # endif 86 # else 87 # define STDIN_FILENO 0 88 # define STDOUT_FILENO 1 89 # define STDERR_FILENO 2 90 # endif 91 #endif 92 93 #ifndef R_OK 94 /* Symbolic constants for the "access" routine: */ 95 #define R_OK 4 /* Test for Read permission */ 96 #define W_OK 2 /* Test for Write permission */ 97 #define X_OK 1 /* Test for eXecute permission */ 98 #define F_OK 0 /* Test for existence of File */ 99 #endif 100 #ifndef E_OK 101 #ifdef HAVE_ACCESS_E_OK 102 #ifdef EFF_ONLY_OK 103 #define E_OK EFF_ONLY_OK /* Irix */ 104 #else 105 #ifdef EUID_OK 106 #define E_OK EUID_OK /* UNICOS (0400) */ 107 #else 108 #define E_OK 010 /* Test effective uids */ 109 #endif /* EUID_OK */ 110 #endif /* EFF_ONLY_OK */ 111 #else 112 #define E_OK 0 113 #endif /* HAVE_ACCESS_E_OK */ 114 #endif /* !E_OK */ 115 116 /* Symbolic constants for the "lseek" routine: */ 117 #ifndef SEEK_SET 118 #define SEEK_SET 0 /* Set file pointer to "offset" */ 119 #endif 120 #ifndef SEEK_CUR 121 #define SEEK_CUR 1 /* Set file pointer to current plus "offset" */ 122 #endif 123 #ifndef SEEK_END 124 #define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 125 #endif 126 127 #ifdef __cplusplus 128 extern "C" { 129 #endif 130 131 #ifndef HAVE_ENVIRON_DEF 132 extern char **environ; 133 #endif 134 135 #if !defined(HAVE_UNISTD_H) || !defined(_POSIX_VERSION) 136 /* 137 * Maybe we need a lot more definitions here... 138 * It is not clear whether we should have prototyped definitions. 139 */ 140 #if !defined(_MSC_VER) && !defined(__MINGW32__) 141 /* 142 * MS C comes with broken prototypes in wrong header files (in our case, the 143 * wrong prototype is in io.h). Avoid to redefine the broken MS stuff with 144 * correct prototypes. 145 */ 146 extern int access __PR((const char *, int)); 147 extern int close __PR((int)); 148 extern int dup __PR((int)); 149 extern int dup2 __PR((int, int)); 150 extern int link __PR((const char *, const char *)); 151 extern int read __PR((int, void *, size_t)); 152 extern int unlink __PR((const char *)); 153 extern int write __PR((int, const void *, size_t)); 154 #endif 155 #if !defined(_MSC_VER) && !defined(__MINGW32__) 156 /* 157 * MS C comes with broken prototypes in wrong header files (in our case, the 158 * wrong prototype is in stdlib.h). Avoid to redefine the broken MS stuff with 159 * correct prototypes. 160 */ 161 extern void _exit __PR((int)); 162 #endif 163 #endif 164 165 #if !defined(HAVE_PIPE) && defined(HAVE__PIPE) && defined(HAVE_IO_H) 166 #ifndef _SCHILY_LIMITS_H 167 #include <schily/limits.h> /* for PIPE_BUF */ 168 #endif 169 #ifndef _SCHILY_FCNTL_H 170 #include <schily/fcntl.h> /* for O_BINARY */ 171 #endif 172 #ifndef _SCHILY_IO_H 173 #include <schily/io.h> /* for _pipe() */ 174 #endif 175 176 #define pipe(pp) _pipe(pp, PIPE_BUF, O_BINARY) 177 #endif 178 179 #ifdef __cplusplus 180 } 181 #endif 182 183 #endif /* _SCHILY_UNISTD_H */ 184