2
* Copyright (c) 2011 Jiri Zarevucky
3
* Copyright (c) 2011 Petr Koupy
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
10
* - Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* - Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
* - The name of the author may not be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
/** @addtogroup libposix
33
/** @file Miscellaneous standard definitions.
36
#ifndef POSIX_UNISTD_H_
37
#define POSIX_UNISTD_H_
39
#include "libc/unistd.h"
40
#include "sys/types.h"
42
/* Process Termination */
45
/* Option Arguments */
47
extern int optind, opterr, optopt;
48
extern int getopt(int, char * const [], const char *);
51
extern char **posix_environ;
53
/* Login Information */
54
extern char *posix_getlogin(void);
55
extern int posix_getlogin_r(char *name, size_t namesize);
57
/* Identifying Terminals */
58
extern int posix_isatty(int fd);
60
/* Working Directory */
61
extern char *posix_getcwd(char *buf, size_t size);
62
extern int posix_chdir(const char *path);
64
/* Query Memory Parameters */
65
extern int posix_getpagesize(void);
67
/* Process Identification */
68
extern posix_pid_t posix_getpid(void);
69
extern posix_uid_t posix_getuid(void);
70
extern posix_gid_t posix_getgid(void);
72
/* File Manipulation */
73
extern int posix_close(int fildes);
74
extern ssize_t posix_read(int fildes, void *buf, size_t nbyte);
75
extern ssize_t posix_write(int fildes, const void *buf, size_t nbyte);
76
extern int posix_fsync(int fildes);
77
extern int posix_ftruncate(int fildes, posix_off_t length);
78
extern int posix_rmdir(const char *path);
79
extern int posix_unlink(const char *path);
80
extern int posix_dup(int fildes);
81
extern int posix_dup2(int fildes, int fildes2);
83
/* Standard Streams */
85
#define STDIN_FILENO (fileno(stdin))
87
#define STDOUT_FILENO (fileno(stdout))
89
#define STDERR_FILENO (fileno(stderr))
91
/* File Accessibility */
96
#define F_OK 0 /* Test for existence. */
97
#define X_OK 1 /* Test for execute permission. */
98
#define W_OK 2 /* Test for write permission. */
99
#define R_OK 4 /* Test for read permission. */
100
extern int posix_access(const char *path, int amode);
102
/* System Parameters */
109
extern long posix_sysconf(int name);
111
/* Path Configuration Parameters */
116
_PC_CHOWN_RESTRICTED,
126
_PC_REC_INCR_XFER_SIZE,
127
_PC_REC_MIN_XFER_SIZE,
133
extern long posix_pathconf(const char *path, int name);
135
/* Creating a Process */
136
extern posix_pid_t posix_fork(void);
138
/* Executing a File */
139
extern int posix_execv(const char *path, char *const argv[]);
140
extern int posix_execvp(const char *file, char *const argv[]);
142
/* Creating a Pipe */
143
extern int posix_pipe(int fildes[2]);
145
#ifndef LIBPOSIX_INTERNAL
146
#define environ posix_environ
148
#define getlogin posix_getlogin
149
#define getlogin_r posix_getlogin_r
151
#define getcwd posix_getcwd
152
#define chdir posix_chdir
154
#define isatty posix_isatty
157
#define getpagesize posix_getpagesize
159
#define getpid posix_getpid
160
#define getuid posix_getuid
161
#define getgid posix_getgid
163
#define close posix_close
164
#define read posix_read
165
#define write posix_write
166
#define fsync posix_fsync
167
#define ftruncate posix_ftruncate
168
#define rmdir posix_rmdir
169
#define unlink posix_unlink
170
#define dup posix_dup
171
#define dup2 posix_dup2
173
#define access posix_access
175
#define sysconf posix_sysconf
177
#define pathconf posix_pathconf
179
#define fork posix_fork
181
#define execv posix_execv
182
#define execvp posix_execvp
184
#define pipe posix_pipe
187
#endif /* POSIX_UNISTD_H_ */