2 * <fcntl.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004, 2006 Jonathan Pryor
14 #include <sys/types.h>
22 #include <corecrt_io.h>
25 #include "mph.h" /* Don't remove or move after map.h! Works around issues with Android SDK unified headers */
32 Mono_Posix_Syscall_fcntl (gint32 fd
, gint32 cmd
)
34 if (Mono_Posix_FromFcntlCommand (cmd
, &cmd
) == -1)
36 return fcntl (fd
, cmd
);
40 Mono_Posix_Syscall_fcntl_arg_int (gint32 fd
, gint32 cmd
, int arg
)
42 if (Mono_Posix_FromFcntlCommand (cmd
, &cmd
) == -1)
44 return fcntl (fd
, cmd
, arg
);
48 Mono_Posix_Syscall_fcntl_arg_ptr (gint32 fd
, gint32 cmd
, void *arg
)
50 if (Mono_Posix_FromFcntlCommand (cmd
, &cmd
) == -1)
52 return fcntl (fd
, cmd
, arg
);
56 Mono_Posix_Syscall_fcntl_arg (gint32 fd
, gint32 cmd
, gint64 arg
)
61 mph_return_if_long_overflow (arg
);
64 if (cmd
== F_NOTIFY
) {
66 if (Mono_Posix_FromDirectoryNotifyFlags (arg
, &_argi
) == -1) {
75 if (Mono_Posix_FromFcntlCommand (cmd
, &_cmd
) == -1)
77 return fcntl (fd
, cmd
, _arg
);
81 Mono_Posix_Syscall_fcntl_lock (gint32 fd
, gint32 cmd
, struct Mono_Posix_Flock
*lock
)
91 if (Mono_Posix_FromFlock (lock
, &_lock
) == -1)
94 if (Mono_Posix_FromFcntlCommand (cmd
, &cmd
) == -1)
97 r
= fcntl (fd
, cmd
, &_lock
);
99 if (Mono_Posix_ToFlock (&_lock
, lock
) == -1)
107 Mono_Posix_Syscall_open (const char *pathname
, gint32 flags
)
109 if (Mono_Posix_FromOpenFlags (flags
, &flags
) == -1)
112 return open (pathname
, flags
);
116 Mono_Posix_Syscall_open_mode (const char *pathname
, gint32 flags
, guint32 mode
)
118 if (Mono_Posix_FromOpenFlags (flags
, &flags
) == -1)
120 if (Mono_Posix_FromFilePermissions (mode
, &mode
) == -1)
123 return open (pathname
, flags
, mode
);
127 Mono_Posix_Syscall_get_at_fdcwd ()
137 Mono_Posix_Syscall_creat (const char *pathname
, guint32 mode
)
139 if (Mono_Posix_FromFilePermissions (mode
, &mode
) == -1)
142 return creat (pathname
, mode
);
145 #ifdef HAVE_POSIX_FADVISE
147 Mono_Posix_Syscall_posix_fadvise (gint32 fd
, mph_off_t offset
, mph_off_t len
,
150 mph_return_if_off_t_overflow (offset
);
151 mph_return_if_off_t_overflow (len
);
153 if (Mono_Posix_FromPosixFadviseAdvice (advice
, &advice
) == -1)
156 return posix_fadvise (fd
, (off_t
) offset
, (off_t
) len
, advice
);
158 #endif /* ndef HAVE_POSIX_FADVISE */
160 #ifdef HAVE_POSIX_FALLOCATE
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 */