muimaster.library: support Listview_List in List
[AROS.git] / compiler / posixc / open.c
blob2a01d136dc77b78e2ba59e11548c8c741425efe3
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 function open().
6 */
8 #include <stdarg.h>
9 #include "__fdesc.h"
11 /*****************************************************************************
13 NAME */
14 #include <fcntl.h>
16 int open (
18 /* SYNOPSIS */
19 const char * pathname,
20 int flags,
21 ...)
23 /* FUNCTION
24 Opens a file with the specified flags and name.
26 INPUTS
27 pathname - Path and filename of the file you want to open.
28 flags - Most be exactly one of: O_RDONLY, O_WRONLY or O_RDWR
29 to open a file for reading, writing or for reading and
30 writing.
32 The mode can be modified by or'ing the following bits in:
34 O_CREAT: Create the file if it doesn't exist (only for
35 O_WRONLY or O_RDWR). If this flag is set, then
36 open() will look for a third parameter mode. mode
37 must contain the access modes for the file
38 (mostly 0644).
39 O_EXCL: Only with O_CREAT. If the file does already exist,
40 then open() fails. See BUGS.
41 O_NOCTTY:
42 O_TRUNC: If the file exists, then it gets overwritten. This
43 is the default and the opposite to O_APPEND.
44 O_APPEND: If the file exists, then the startung position for
45 writes is the end of the file.
46 O_NONBLOCK or O_NDELAY: Opens the file in non-blocking mode.
47 If there is no data in the file, then read() on a
48 terminal will return immediately instead of waiting
49 until data arrives. Has no effect on write().
50 O_SYNC: The process will be stopped for each write() and the
51 data will be flushed before the write() returns.
52 This ensures that the data is physically written
53 when write() returns. If this flag is not specified,
54 the data is written into a buffer and flushed only
55 once in a while.
57 RESULT
58 -1 for error or a file descriptor for use with read(), write(), etc.
60 NOTES
61 If the filesystem doesn't allow to specify different access modes
62 for users, groups and others, then the user modes are used.
64 This function must not be used in a shared library or
65 in a threaded application.
68 EXAMPLE
70 BUGS
71 The flag O_EXCL is not very reliable if the file resides on a NFS
72 filesystem.
74 Most flags are not supported right now.
76 SEE ALSO
77 close(), read(), write(), fopen()
79 INTERNALS
81 ******************************************************************************/
83 mode_t mode = 0644;
85 if (flags & O_CREAT)
87 va_list ap;
89 va_start(ap, flags);
90 mode = va_arg(ap, int);
91 va_end(ap);
94 return __open(__getfirstfd(0), pathname, flags, mode);
95 } /* open */