2 * <fcntl.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004 Jonathan Pryor
14 #include <sys/types.h>
25 struct Mono_Posix_Flock
{
34 Mono_Posix_Syscall_fcntl (gint32 fd
, gint32 cmd
)
36 if (Mono_Posix_FromFcntlCommand (cmd
, &cmd
) == -1)
38 return fcntl (fd
, cmd
);
42 Mono_Posix_Syscall_fcntl_arg (gint32 fd
, gint32 cmd
, gint64 arg
)
47 mph_return_if_long_overflow (arg
);
50 if (cmd
== F_NOTIFY
) {
52 if (Mono_Posix_FromDirectoryNotifyFlags (arg
, &_argi
) == -1) {
61 if (Mono_Posix_FromFcntlCommand (cmd
, &_cmd
) == -1)
63 return fcntl (fd
, cmd
, _arg
);
67 Mono_Posix_Syscall_fcntl_lock (gint32 fd
, gint32 cmd
, struct Mono_Posix_Flock
*lock
)
77 mph_return_if_off_t_overflow (lock
->l_start
);
78 mph_return_if_off_t_overflow (lock
->l_len
);
80 if (Mono_Posix_FromLockType (lock
->l_type
, &lock
->l_type
) == -1)
82 _lock
.l_type
= lock
->l_type
;
83 _lock
.l_whence
= lock
->l_whence
;
84 _lock
.l_start
= lock
->l_start
;
85 _lock
.l_len
= lock
->l_len
;
86 _lock
.l_pid
= lock
->l_pid
;
88 r
= fcntl (fd
, cmd
, &_lock
);
90 if (Mono_Posix_ToLockType (_lock
.l_type
, &_lock
.l_type
) == -1)
92 lock
->l_type
= _lock
.l_type
;
93 lock
->l_whence
= _lock
.l_whence
;
94 lock
->l_start
= _lock
.l_start
;
95 lock
->l_len
= _lock
.l_len
;
96 lock
->l_pid
= _lock
.l_pid
;
102 Mono_Posix_Syscall_open (const char *pathname
, gint32 flags
)
104 if (Mono_Posix_FromOpenFlags (flags
, &flags
) == -1)
107 return open (pathname
, flags
);
111 Mono_Posix_Syscall_open_mode (const char *pathname
, gint32 flags
, guint32 mode
)
113 if (Mono_Posix_FromOpenFlags (flags
, &flags
) == -1)
115 if (Mono_Posix_FromFilePermissions (mode
, &mode
) == -1)
118 return open (pathname
, flags
, mode
);
122 Mono_Posix_Syscall_creat (const char *pathname
, guint32 mode
)
124 if (Mono_Posix_FromFilePermissions (mode
, &mode
) == -1)
127 return creat (pathname
, mode
);
130 #ifdef HAVE_POSIX_FADVISE
132 Mono_Posix_Syscall_posix_fadvise (gint32 fd
, mph_off_t offset
, mph_off_t len
,
135 mph_return_if_off_t_overflow (offset
);
136 mph_return_if_off_t_overflow (len
);
138 if (Mono_Posix_FromPosixFadviseAdvice (advice
, &advice
) == -1)
141 return posix_fadvise (fd
, (off_t
) offset
, (off_t
) len
, advice
);
143 #endif /* ndef HAVE_POSIX_FADVISE */
145 #ifdef HAVE_POSIX_FALLOCATE
147 Mono_Posix_Syscall_posix_fallocate (gint32 fd
, mph_off_t offset
, mph_size_t len
)
149 mph_return_if_off_t_overflow (offset
);
150 mph_return_if_size_t_overflow (len
);
152 return posix_fallocate (fd
, (off_t
) offset
, (size_t) len
);
154 #endif /* ndef HAVE_POSIX_FALLOCATE */