1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*
* <fcntl.h> wrapper functions.
*
* Authors:
* Jonathan Pryor (jonpryor@vt.edu)
*
* Copyright (C) 2004, 2006 Jonathan Pryor
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <fcntl.h>
#include <errno.h>
#ifdef HOST_WIN32
#include <corecrt_io.h>
#endif
#include "mph.h" /* Don't remove or move after map.h! Works around issues with Android SDK unified headers */
#include "map.h"
G_BEGIN_DECLS
#ifndef HOST_WIN32
gint32
Mono_Posix_Syscall_fcntl (gint32 fd, gint32 cmd)
{
if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
return -1;
return fcntl (fd, cmd);
}
gint32
Mono_Posix_Syscall_fcntl_arg_int (gint32 fd, gint32 cmd, int arg)
{
if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
return -1;
return fcntl (fd, cmd, arg);
}
gint32
Mono_Posix_Syscall_fcntl_arg_ptr (gint32 fd, gint32 cmd, void *arg)
{
if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
return -1;
return fcntl (fd, cmd, arg);
}
gint32
Mono_Posix_Syscall_fcntl_arg (gint32 fd, gint32 cmd, gint64 arg)
{
long _arg;
gint32 _cmd;
mph_return_if_long_overflow (arg);
#ifdef F_NOTIFY
if (cmd == F_NOTIFY) {
int _argi;
if (Mono_Posix_FromDirectoryNotifyFlags (arg, &_argi) == -1) {
return -1;
}
_arg = _argi;
}
else
#endif
_arg = (long) arg;
if (Mono_Posix_FromFcntlCommand (cmd, &_cmd) == -1)
return -1;
return fcntl (fd, cmd, _arg);
}
gint32
Mono_Posix_Syscall_fcntl_lock (gint32 fd, gint32 cmd, struct Mono_Posix_Flock *lock)
{
struct flock _lock;
int r;
if (lock == NULL) {
errno = EFAULT;
return -1;
}
if (Mono_Posix_FromFlock (lock, &_lock) == -1)
return -1;
if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
return -1;
r = fcntl (fd, cmd, &_lock);
if (Mono_Posix_ToFlock (&_lock, lock) == -1)
return -1;
return r;
}
#endif
gint32
Mono_Posix_Syscall_open (const char *pathname, gint32 flags)
{
if (Mono_Posix_FromOpenFlags (flags, &flags) == -1)
return -1;
return open (pathname, flags);
}
gint32
Mono_Posix_Syscall_open_mode (const char *pathname, gint32 flags, guint32 mode)
{
if (Mono_Posix_FromOpenFlags (flags, &flags) == -1)
return -1;
if (Mono_Posix_FromFilePermissions (mode, &mode) == -1)
return -1;
return open (pathname, flags, mode);
}
gint32
Mono_Posix_Syscall_get_at_fdcwd ()
{
#ifdef AT_FDCWD
return AT_FDCWD;
#else
return -1;
#endif
}
gint32
Mono_Posix_Syscall_creat (const char *pathname, guint32 mode)
{
if (Mono_Posix_FromFilePermissions (mode, &mode) == -1)
return -1;
return creat (pathname, mode);
}
#ifdef HAVE_POSIX_FADVISE
gint32
Mono_Posix_Syscall_posix_fadvise (gint32 fd, mph_off_t offset, mph_off_t len,
gint32 advice)
{
mph_return_if_off_t_overflow (offset);
mph_return_if_off_t_overflow (len);
if (Mono_Posix_FromPosixFadviseAdvice (advice, &advice) == -1)
return -1;
return posix_fadvise (fd, (off_t) offset, (off_t) len, advice);
}
#endif /* ndef HAVE_POSIX_FADVISE */
#ifdef HAVE_POSIX_FALLOCATE
gint32
Mono_Posix_Syscall_posix_fallocate (gint32 fd, mph_off_t offset, mph_size_t len)
{
mph_return_if_off_t_overflow (offset);
mph_return_if_size_t_overflow (len);
return posix_fallocate (fd, (off_t) offset, (size_t) len);
}
#endif /* ndef HAVE_POSIX_FALLOCATE */
G_END_DECLS
/*
* vim: noexpandtab
*/
|