TizenRT Libs&Environment  v2.0 M2
unistd.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/unistd.h
20  *
21  * Copyright (C) 2007-2009, 2013-2014 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
60 
63 #ifndef __INCLUDE_UNISTD_H
64 #define __INCLUDE_UNISTD_H
65 
66 /****************************************************************************
67  * Included Files
68  ****************************************************************************/
69 
70 #include <sys/types.h>
71 #include <tinyara/compiler.h>
72 
73 /****************************************************************************
74  * Pre-processor Definitions
75  ****************************************************************************/
76 
77 /* Values for seeking */
78 
79 #define SEEK_SET 0 /* From the start of the file */
80 #define SEEK_CUR 1 /* From the current file offset */
81 #define SEEK_END 2 /* From the end of the file */
82 
83 /* Bit values for the second argument to access */
84 
85 #define F_OK 0 /* Test existence */
86 #define R_OK 1 /* Test read permission */
87 #define W_OK 2 /* Test write permission */
88 #define X_OK 4 /* Test execute permission */
89 
90 /* POSIX feature set macros */
91 
92 #define POSIX_VERSION
93 #undef _POSIX_SAVED_IDS
94 #undef _POSIX_JOB_CONTROL
95 #define _POSIX_REALTIME_SIGNALS 1
96 #define _POSIX_MESSAGE_PASSING 1
97 #undef _POSIX_MAPPED_FILES
98 #undef _POSIX_SHARED_MEMORY_OBJECTS
99 #define _POSIX_PRIORITY_SCHEDULING 1
100 #define _POSIX_TIMERS 1
101 #undef _POSIX_MEMLOCK
102 #undef _POSIX_MEMLOCK_RANGE
103 #undef _POSIX_FSYNC
104 #define _POSIX_SYNCHRONIZED_IO 1
105 #undef _POSIX_ASYNCHRONOUS_IO
106 #undef _POSIX_PRIORITIZED_IO
107 
108 /* Execution time constants (not supported) */
109 
110 #undef _POSIX_CHOWN_RESTRICTED
111 #undef _POSIX_NO_TRUNC
112 #undef _POSIX_VDISABLE
113 
114 #define _POSIX_SYNC_IO 1
115 #undef _POSIX_ASYNC_IO
116 #undef _POSIX_PRIO_IO
117 
118 #define fdatasync(f) fsync(f)
119 
120 /****************************************************************************
121  * Global Variables
122  ****************************************************************************/
123 
124 #undef EXTERN
125 #if defined(__cplusplus)
126 #define EXTERN extern "C"
127 extern "C" {
128 #else
129 #define EXTERN extern
130 #endif
131 
132 /* Used by getopt (obviously NOT thread safe!). These variables cannot be
133  * accessed directly by an external NXFLAT module. In that case, accessor
134  * functions must be used.
135  */
136 
137 #ifndef __NXFLAT__
138 EXTERN FAR char *optarg; /* Optional argument following option */
139 EXTERN int optind; /* Index into argv */
140 EXTERN int optopt; /* unrecognized option character */
141 #else
142 #define optarg (*(getoptargp()))
143 #define optind (*(getoptindp()))
144 #define optopt (*(getoptoptp()))
145 #endif
146 
147 /****************************************************************************
148  * Global Function Prototypes
149  ****************************************************************************/
150 
151 /* Task Control Interfaces */
152 
190 pid_t vfork(void);
201 pid_t getpid(void);
206 void _exit(int status) noreturn_function;
217 unsigned int sleep(unsigned int seconds);
229 int usleep(useconds_t usec);
237 int pause(void);
238 
239 /* File descriptor operations */
240 
252 int close(int fd);
260 int dup(int fd);
268 int dup2(int fd1, int fd2);
276 int fsync(int fd);
284 off_t lseek(int fd, off_t offset, int whence);
292 ssize_t read(int fd, FAR void *buf, size_t nbytes);
300 ssize_t write(int fd, FAR const void *buf, size_t nbytes);
308 ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset);
316 ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset);
317 
321 /* Memory management */
322 
323 #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_MM_PGALLOC) && \
324  defined(CONFIG_ARCH_USE_MMU)
325 
329 FAR void *sbrk(intptr_t incr);
333 #endif
334 
335 /* Special devices */
336 
345 int pipe(int fd[2]);
346 
347 /* Working directory operations */
348 
356 int chdir(FAR const char *path);
364 FAR char *getcwd(FAR char *buf, size_t size);
365 
366 /* File path operations */
374 int access(FAR const char *path, int amode);
383 int rmdir(FAR const char *pathname);
392 int unlink(FAR const char *pathname);
393 
394 /* Execution of programs from files */
395 
396 #ifdef CONFIG_LIBC_EXECFUNCS
397 
402 int execl(FAR const char *path, ...);
403 int execv(FAR const char *path, FAR char *const argv[]);
407 #endif
408 
409 /* Byte operations */
414 void swab(FAR const void *src, FAR void *dest, ssize_t nbytes);
419 /* getopt and friends */
427 int getopt(int argc, FAR char *const argv[], FAR const char *optstring);
428 
429 /* Accessor functions intended for use only by external NXFLAT
430  * modules. The global variables optarg, optind, and optopt cannot
431  * be referenced directly from external modules.
432  */
438 FAR char **getoptargp(void); /* Optional argument following option */
439 int *getoptindp(void); /* Index into argv */
440 int *getoptoptp(void); /* unrecognized option character */
444 #undef EXTERN
445 #if defined(__cplusplus)
446 }
447 #endif
448 
449 #endif /* __INCLUDE_UNISTD_H */
450 
unsigned int sleep(unsigned int seconds)
suspend execution for an interval of time
EXTERN int optopt
Definition: unistd.h:140
int dup(int fd)
duplicate an open file descriptor
int pipe(int fd[2])
create an interprocess channel
ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset)
read from a file
pid_t getpid(void)
get the process ID
int usleep(useconds_t usec)
suspend execution for microsecond intervals
ssize_t write(int fd, FAR const void *buf, size_t nbytes)
write to another user
int unlink(FAR const char *pathname)
call the unlink function
ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset)
write on a file
int rmdir(FAR const char *pathname)
remove a directory
int close(int fd)
close a file descriptor
off_t lseek(int fd, off_t offset, int whence)
move the read/write file offset
FAR char * getcwd(FAR char *buf, size_t size)
get the pathname of the current working directory
#define EXTERN
Definition: unistd.h:129
int chdir(FAR const char *path)
change working directory
ssize_t read(int fd, FAR void *buf, size_t nbytes)
read from a file
int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
command option parsing
int fsync(int fd)
synchronize changes to a file
int dup2(int fd1, int fd2)
duplicate an open file descriptor
EXTERN FAR char * optarg
Definition: unistd.h:138
int access(FAR const char *path, int amode)
determine accessibility of a file descriptor
int pause(void)
suspend the thread until a signal is received
EXTERN int optind
Definition: unistd.h:139