[mono-api-html] Render something for fields with marshalling info. (#10663)
[mono-project.git] / support / fcntl.c
blob1fd324e399f1a2b684b81ab99425096f9f3b181c
1 /*
2 * <fcntl.h> wrapper functions.
4 * Authors:
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004, 2006 Jonathan Pryor
8 */
10 #ifndef _GNU_SOURCE
11 #define _GNU_SOURCE
12 #endif
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #ifdef HAVE_UNISTD_H
17 #include <unistd.h>
18 #endif
19 #include <fcntl.h>
20 #include <errno.h>
21 #ifdef HOST_WIN32
22 #include <corecrt_io.h>
23 #endif
25 #include "mph.h" /* Don't remove or move after map.h! Works around issues with Android SDK unified headers */
26 #include "map.h"
28 G_BEGIN_DECLS
30 #ifndef HOST_WIN32
31 gint32
32 Mono_Posix_Syscall_fcntl (gint32 fd, gint32 cmd)
34 if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
35 return -1;
36 return fcntl (fd, cmd);
39 gint32
40 Mono_Posix_Syscall_fcntl_arg_int (gint32 fd, gint32 cmd, int arg)
42 if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
43 return -1;
44 return fcntl (fd, cmd, arg);
47 gint32
48 Mono_Posix_Syscall_fcntl_arg_ptr (gint32 fd, gint32 cmd, void *arg)
50 if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
51 return -1;
52 return fcntl (fd, cmd, arg);
55 gint32
56 Mono_Posix_Syscall_fcntl_arg (gint32 fd, gint32 cmd, gint64 arg)
58 long _arg;
59 gint32 _cmd;
61 mph_return_if_long_overflow (arg);
63 #ifdef F_NOTIFY
64 if (cmd == F_NOTIFY) {
65 int _argi;
66 if (Mono_Posix_FromDirectoryNotifyFlags (arg, &_argi) == -1) {
67 return -1;
69 _arg = _argi;
71 else
72 #endif
73 _arg = (long) arg;
75 if (Mono_Posix_FromFcntlCommand (cmd, &_cmd) == -1)
76 return -1;
77 return fcntl (fd, cmd, _arg);
80 gint32
81 Mono_Posix_Syscall_fcntl_lock (gint32 fd, gint32 cmd, struct Mono_Posix_Flock *lock)
83 struct flock _lock;
84 int r;
86 if (lock == NULL) {
87 errno = EFAULT;
88 return -1;
91 if (Mono_Posix_FromFlock (lock, &_lock) == -1)
92 return -1;
94 if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
95 return -1;
97 r = fcntl (fd, cmd, &_lock);
99 if (Mono_Posix_ToFlock (&_lock, lock) == -1)
100 return -1;
102 return r;
104 #endif
106 gint32
107 Mono_Posix_Syscall_open (const char *pathname, gint32 flags)
109 if (Mono_Posix_FromOpenFlags (flags, &flags) == -1)
110 return -1;
112 return open (pathname, flags);
115 gint32
116 Mono_Posix_Syscall_open_mode (const char *pathname, gint32 flags, guint32 mode)
118 if (Mono_Posix_FromOpenFlags (flags, &flags) == -1)
119 return -1;
120 if (Mono_Posix_FromFilePermissions (mode, &mode) == -1)
121 return -1;
123 return open (pathname, flags, mode);
126 gint32
127 Mono_Posix_Syscall_get_at_fdcwd ()
129 #ifdef AT_FDCWD
130 return AT_FDCWD;
131 #else
132 return -1;
133 #endif
136 gint32
137 Mono_Posix_Syscall_creat (const char *pathname, guint32 mode)
139 if (Mono_Posix_FromFilePermissions (mode, &mode) == -1)
140 return -1;
142 return creat (pathname, mode);
145 #ifdef HAVE_POSIX_FADVISE
146 gint32
147 Mono_Posix_Syscall_posix_fadvise (gint32 fd, mph_off_t offset, mph_off_t len,
148 gint32 advice)
150 mph_return_if_off_t_overflow (offset);
151 mph_return_if_off_t_overflow (len);
153 if (Mono_Posix_FromPosixFadviseAdvice (advice, &advice) == -1)
154 return -1;
156 return posix_fadvise (fd, (off_t) offset, (off_t) len, advice);
158 #endif /* ndef HAVE_POSIX_FADVISE */
160 #ifdef HAVE_POSIX_FALLOCATE
161 gint32
162 Mono_Posix_Syscall_posix_fallocate (gint32 fd, mph_off_t offset, mph_size_t len)
164 mph_return_if_off_t_overflow (offset);
165 mph_return_if_size_t_overflow (len);
167 return posix_fallocate (fd, (off_t) offset, (size_t) len);
169 #endif /* ndef HAVE_POSIX_FALLOCATE */
171 G_END_DECLS
174 * vim: noexpandtab