source: mainline/uspace/lib/posix/include/posix/unistd.h@ bc56f30

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bc56f30 was bc56f30, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Make some libc and libposix headers usable in C++

These headers either get included from standard C++ headers,
or are standard themselves, which means any unnamespaced nonstandard
identifiers are a problem. This commit attempts to fix those
issues, and removes hacks previously used in libcpp to work around it.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Zarevucky
3 * Copyright (c) 2011 Petr Koupy
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
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.
17 *
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.
28 */
29
30/** @addtogroup libposix
31 * @{
32 */
33/** @file Miscellaneous standard definitions.
34 */
35
36#ifndef POSIX_UNISTD_H_
37#define POSIX_UNISTD_H_
38
39#include <stddef.h>
40#include <sys/types.h>
41
42#define SEEK_SET 0
43#define SEEK_CUR 1
44#define SEEK_END 2
45
46/* Process Termination */
47#define _exit exit
48
49/* Standard Streams */
50#define STDIN_FILENO (fileno(stdin))
51#define STDOUT_FILENO (fileno(stdout))
52#define STDERR_FILENO (fileno(stderr))
53
54#define F_OK 0 /* Test for existence. */
55#define X_OK 1 /* Test for execute permission. */
56#define W_OK 2 /* Test for write permission. */
57#define R_OK 4 /* Test for read permission. */
58
59__C_DECLS_BEGIN;
60
61extern char *optarg;
62extern int optind, opterr, optopt;
63extern int getopt(int, char *const [], const char *);
64
65/* Environment */
66extern char **environ;
67
68/* Sleeping */
69extern unsigned int sleep(unsigned int);
70
71/* Login Information */
72extern char *getlogin(void);
73extern int getlogin_r(char *name, size_t namesize);
74
75/* Identifying Terminals */
76extern int isatty(int fd);
77
78/* Working Directory */
79extern char *getcwd(char *buf, size_t size);
80extern int chdir(const char *path);
81
82/* Query Memory Parameters */
83extern int getpagesize(void);
84
85/* Process Identification */
86extern pid_t getpid(void);
87extern uid_t getuid(void);
88extern gid_t getgid(void);
89
90/* File Manipulation */
91extern int close(int fildes);
92extern ssize_t read(int fildes, void *buf, size_t nbyte);
93extern ssize_t write(int fildes, const void *buf, size_t nbyte);
94extern int fsync(int fildes);
95extern int rmdir(const char *path);
96extern int unlink(const char *path);
97extern int dup(int fildes);
98extern int dup2(int fildes, int fildes2);
99
100#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
101extern off64_t lseek64(int fildes, off64_t offset, int whence);
102extern int ftruncate64(int fildes, off64_t length);
103#endif
104
105#if _FILE_OFFSET_BITS == 64 && LONG_MAX == INT_MAX
106#ifdef __GNUC__
107extern off_t lseek(int fildes, off_t offset, int whence) __asm__("lseek64");
108extern int ftruncate(int fildes, off_t length) __asm__("ftruncate64");
109#else
110extern off_t lseek64(int fildes, off_t offset, int whence);
111extern int ftruncate64(int fildes, off_t length);
112#define lseek lseek64
113#define ftruncate ftruncate64
114#endif
115#else
116extern off_t lseek(int fildes, off_t offset, int whence);
117extern int ftruncate(int fildes, off_t length);
118#endif
119
120/* File Accessibility */
121extern int access(const char *path, int amode);
122
123/* System Parameters */
124enum {
125 _SC_PHYS_PAGES,
126 _SC_AVPHYS_PAGES,
127 _SC_PAGESIZE,
128 _SC_CLK_TCK
129};
130extern long sysconf(int name);
131
132/* Path Configuration Parameters */
133enum {
134 _PC_2_SYMLINKS,
135 _PC_ALLOC_SIZE_MIN,
136 _PC_ASYNC_IO,
137 _PC_CHOWN_RESTRICTED,
138 _PC_FILESIZEBITS,
139 _PC_LINK_MAX,
140 _PC_MAX_CANON,
141 _PC_MAX_INPUT,
142 _PC_NAME_MAX,
143 _PC_NO_TRUNC,
144 _PC_PATH_MAX,
145 _PC_PIPE_BUF,
146 _PC_PRIO_IO,
147 _PC_REC_INCR_XFER_SIZE,
148 _PC_REC_MIN_XFER_SIZE,
149 _PC_REC_XFER_ALIGN,
150 _PC_SYMLINK_MAX,
151 _PC_SYNC_IO,
152 _PC_VDISABLE
153};
154extern long pathconf(const char *path, int name);
155
156/* Creating a Process */
157extern pid_t fork(void);
158
159/* Executing a File */
160extern int execv(const char *path, char *const argv[]);
161extern int execvp(const char *file, char *const argv[]);
162
163/* Creating a Pipe */
164extern int pipe(int fildes[2]);
165
166/* Issue alarm signal. */
167extern unsigned int alarm(unsigned int);
168
169__C_DECLS_END;
170
171#endif /* POSIX_UNISTD_H_ */
172
173/** @}
174 */
Note: See TracBrowser for help on using the repository browser.