Add missing {
[mono-project.git] / support / fcntl.c
blob85605d1bc21ddcedb5fdf3cd7a0aff2685cbd4cf
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 #include <unistd.h>
17 #include <fcntl.h>
18 #include <errno.h>
20 #include "map.h"
21 #include "mph.h"
23 G_BEGIN_DECLS
25 gint32
26 Mono_Posix_Syscall_fcntl (gint32 fd, gint32 cmd)
28 if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
29 return -1;
30 return fcntl (fd, cmd);
33 gint32
34 Mono_Posix_Syscall_fcntl_arg_int (gint32 fd, gint32 cmd, int arg)
36 if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
37 return -1;
38 return fcntl (fd, cmd, arg);
41 gint32
42 Mono_Posix_Syscall_fcntl_arg_ptr (gint32 fd, gint32 cmd, void *arg)
44 if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
45 return -1;
46 return fcntl (fd, cmd, arg);
49 gint32
50 Mono_Posix_Syscall_fcntl_arg (gint32 fd, gint32 cmd, gint64 arg)
52 long _arg;
53 gint32 _cmd;
55 mph_return_if_long_overflow (arg);
57 #ifdef F_NOTIFY
58 if (cmd == F_NOTIFY) {
59 int _argi;
60 if (Mono_Posix_FromDirectoryNotifyFlags (arg, &_argi) == -1) {
61 return -1;
63 _arg = _argi;
65 else
66 #endif
67 _arg = (long) arg;
69 if (Mono_Posix_FromFcntlCommand (cmd, &_cmd) == -1)
70 return -1;
71 return fcntl (fd, cmd, _arg);
74 gint32
75 Mono_Posix_Syscall_fcntl_lock (gint32 fd, gint32 cmd, struct Mono_Posix_Flock *lock)
77 struct flock _lock;
78 int r;
80 if (lock == NULL) {
81 errno = EFAULT;
82 return -1;
85 if (Mono_Posix_FromFlock (lock, &_lock) == -1)
86 return -1;
88 if (Mono_Posix_FromFcntlCommand (cmd, &cmd) == -1)
89 return -1;
91 r = fcntl (fd, cmd, &_lock);
93 if (Mono_Posix_ToFlock (&_lock, lock) == -1)
94 return -1;
96 return r;
99 gint32
100 Mono_Posix_Syscall_open (const char *pathname, gint32 flags)
102 if (Mono_Posix_FromOpenFlags (flags, &flags) == -1)
103 return -1;
105 return open (pathname, flags);
108 gint32
109 Mono_Posix_Syscall_open_mode (const char *pathname, gint32 flags, guint32 mode)
111 if (Mono_Posix_FromOpenFlags (flags, &flags) == -1)
112 return -1;
113 if (Mono_Posix_FromFilePermissions (mode, &mode) == -1)
114 return -1;
116 return open (pathname, flags, mode);
119 gint32
120 Mono_Posix_Syscall_get_at_fdcwd ()
122 #ifdef AT_FDCWD
123 return AT_FDCWD;
124 #else
125 return -1;
126 #endif
129 gint32
130 Mono_Posix_Syscall_creat (const char *pathname, guint32 mode)
132 if (Mono_Posix_FromFilePermissions (mode, &mode) == -1)
133 return -1;
135 return creat (pathname, mode);
138 #ifdef HAVE_POSIX_FADVISE
139 gint32
140 Mono_Posix_Syscall_posix_fadvise (gint32 fd, mph_off_t offset, mph_off_t len,
141 gint32 advice)
143 mph_return_if_off_t_overflow (offset);
144 mph_return_if_off_t_overflow (len);
146 if (Mono_Posix_FromPosixFadviseAdvice (advice, &advice) == -1)
147 return -1;
149 return posix_fadvise (fd, (off_t) offset, (off_t) len, advice);
151 #endif /* ndef HAVE_POSIX_FADVISE */
153 #ifdef HAVE_POSIX_FALLOCATE
154 gint32
155 Mono_Posix_Syscall_posix_fallocate (gint32 fd, mph_off_t offset, mph_size_t len)
157 mph_return_if_off_t_overflow (offset);
158 mph_return_if_size_t_overflow (len);
160 return posix_fallocate (fd, (off_t) offset, (size_t) len);
162 #endif /* ndef HAVE_POSIX_FALLOCATE */
164 G_END_DECLS
167 * vim: noexpandtab