2 // Mono.Posix/Syscall.cs
5 // Miguel de Icaza (miguel@novell.com)
6 // Jonathan Pryor (jonpryor@vt.edu)
8 // (C) 2003 Novell, Inc.
9 // (C) 2004 Jonathan Pryor
11 // This file implements the low-level syscall interface to the POSIX
14 // This file tries to stay close to the low-level API as much as possible
15 // using enumerations, structures and in a few cases, using existing .NET
18 // Implementation notes:
20 // Since the values for the various constants on the API changes
21 // from system to system (even Linux on different architectures will
22 // have different values), we define our own set of values, and we
23 // use a set of C helper routines to map from the constants we define
24 // to the values of the native OS.
26 // Bitfields are flagged with the [Map] attribute, and a helper program
27 // generates a set of routines that we can call to convert from our value
28 // definitions to the value definitions expected by the OS; see
29 // PosixConvert for the conversion routines.
31 // Methods that require tuning are bound as `private sys_NAME' methods
32 // and then a `NAME' method is exposed.
36 // Permission is hereby granted, free of charge, to any person obtaining
37 // a copy of this software and associated documentation files (the
38 // "Software"), to deal in the Software without restriction, including
39 // without limitation the rights to use, copy, modify, merge, publish,
40 // distribute, sublicense, and/or sell copies of the Software, and to
41 // permit persons to whom the Software is furnished to do so, subject to
42 // the following conditions:
44 // The above copyright notice and this permission notice shall be
45 // included in all copies or substantial portions of the Software.
47 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57 using System.Collections;
58 using System.Runtime.InteropServices;
62 [assembly:Mono.Posix.IncludeAttribute (
63 new string [] {"sys/types.h", "sys/stat.h", "sys/poll.h", "sys/wait.h", "sys/mount.h",
64 "unistd.h", "fcntl.h", "signal.h", "poll.h", "grp.h", "errno.h"},
65 new string [] {"_GNU_SOURCE", "_XOPEN_SOURCE"})]
67 namespace Mono.Posix {
70 public enum Error : int {
71 // errors & their values liberally copied from
72 // FC2 /usr/include/asm/errno.h
74 EPERM = 1, // Operation not permitted
75 ENOENT = 2, // No such file or directory
76 ESRCH = 3, // No such process
77 EINTR = 4, // Interrupted system call
79 ENXIO = 6, // No such device or address
80 E2BIG = 7, // Arg list too long
81 ENOEXEC = 8, // Exec format error
82 EBADF = 9, // Bad file number
83 ECHILD = 10, // No child processes
84 EAGAIN = 11, // Try again
85 ENOMEM = 12, // Out of memory
86 EACCES = 13, // Permission denied
87 EFAULT = 14, // Bad address
88 ENOTBLK = 15, // Block device required
89 EBUSY = 16, // Device or resource busy
90 EEXIST = 17, // File exists
91 EXDEV = 18, // Cross-device link
92 ENODEV = 19, // No such device
93 ENOTDIR = 20, // Not a directory
94 EISDIR = 21, // Is a directory
95 EINVAL = 22, // Invalid argument
96 ENFILE = 23, // File table overflow
97 EMFILE = 24, // Too many open files
98 ENOTTY = 25, // Not a typewriter
99 ETXTBSY = 26, // Text file busy
100 EFBIG = 27, // File too large
101 ENOSPC = 28, // No space left on device
102 ESPIPE = 29, // Illegal seek
103 EROFS = 30, // Read-only file system
104 EMLINK = 31, // Too many links
105 EPIPE = 32, // Broken pipe
106 EDOM = 33, // Math argument out of domain of func
107 ERANGE = 34, // Math result not representable
108 EDEADLK = 35, // Resource deadlock would occur
109 ENAMETOOLONG = 36, // File name too long
110 ENOLCK = 37, // No record locks available
111 ENOSYS = 38, // Function not implemented
112 ENOTEMPTY = 39, // Directory not empty
113 ELOOP = 40, // Too many symbolic links encountered
114 EWOULDBLOCK = EAGAIN, // Operation would block
115 ENOMSG = 42, // No message of desired type
116 EIDRM = 43, // Identifier removed
117 ECHRNG = 44, // Channel number out of range
118 EL2NSYNC = 45, // Level 2 not synchronized
119 EL3HLT = 46, // Level 3 halted
120 EL3RST = 47, // Level 3 reset
121 ELNRNG = 48, // Link number out of range
122 EUNATCH = 49, // Protocol driver not attached
123 ENOCSI = 50, // No CSI structure available
124 EL2HLT = 51, // Level 2 halted
125 EBADE = 52, // Invalid exchange
126 EBADR = 53, // Invalid request descriptor
127 EXFULL = 54, // Exchange full
128 ENOANO = 55, // No anode
129 EBADRQC = 56, // Invalid request code
130 EBADSLT = 57, // Invalid slot
134 EBFONT = 59, // Bad font file format
135 ENOSTR = 60, // Device not a stream
136 ENODATA = 61, // No data available
137 ETIME = 62, // Timer expired
138 ENOSR = 63, // Out of streams resources
139 ENONET = 64, // Machine is not on the network
140 ENOPKG = 65, // Package not installed
141 EREMOTE = 66, // Object is remote
142 ENOLINK = 67, // Link has been severed
143 EADV = 68, // Advertise error
144 ESRMNT = 69, // Srmount error
145 ECOMM = 70, // Communication error on send
146 EPROTO = 71, // Protocol error
147 EMULTIHOP = 72, // Multihop attempted
148 EDOTDOT = 73, // RFS specific error
149 EBADMSG = 74, // Not a data message
150 EOVERFLOW = 75, // Value too large for defined data type
151 ENOTUNIQ = 76, // Name not unique on network
152 EBADFD = 77, // File descriptor in bad state
153 EREMCHG = 78, // Remote address changed
154 ELIBACC = 79, // Can not access a needed shared library
155 ELIBBAD = 80, // Accessing a corrupted shared library
156 ELIBSCN = 81, // .lib section in a.out corrupted
157 ELIBMAX = 82, // Attempting to link in too many shared libraries
158 ELIBEXEC = 83, // Cannot exec a shared library directly
159 EILSEQ = 84, // Illegal byte sequence
160 ERESTART = 85, // Interrupted system call should be restarted
161 ESTRPIPE = 86, // Streams pipe error
162 EUSERS = 87, // Too many users
163 ENOTSOCK = 88, // Socket operation on non-socket
164 EDESTADDRREQ = 89, // Destination address required
165 EMSGSIZE = 90, // Message too long
166 EPROTOTYPE = 91, // Protocol wrong type for socket
167 ENOPROTOOPT = 92, // Protocol not available
168 EPROTONOSUPPORT = 93, // Protocol not supported
169 ESOCKTNOSUPPORT = 94, // Socket type not supported
170 EOPNOTSUPP = 95, // Operation not supported on transport endpoint
171 EPFNOSUPPORT = 96, // Protocol family not supported
172 EAFNOSUPPORT = 97, // Address family not supported by protocol
173 EADDRINUSE = 98, // Address already in use
174 EADDRNOTAVAIL = 99, // Cannot assign requested address
175 ENETDOWN = 100, // Network is down
176 ENETUNREACH = 101, // Network is unreachable
177 ENETRESET = 102, // Network dropped connection because of reset
178 ECONNABORTED = 103, // Software caused connection abort
179 ECONNRESET = 104, // Connection reset by peer
180 ENOBUFS = 105, // No buffer space available
181 EISCONN = 106, // Transport endpoint is already connected
182 ENOTCONN = 107, // Transport endpoint is not connected
183 ESHUTDOWN = 108, // Cannot send after transport endpoint shutdown
184 ETOOMANYREFS = 109, // Too many references: cannot splice
185 ETIMEDOUT = 110, // Connection timed out
186 ECONNREFUSED = 111, // Connection refused
187 EHOSTDOWN = 112, // Host is down
188 EHOSTUNREACH = 113, // No route to host
189 EALREADY = 114, // Operation already in progress
190 EINPROGRESS = 115, // Operation now in progress
191 ESTALE = 116, // Stale NFS file handle
192 EUCLEAN = 117, // Structure needs cleaning
193 ENOTNAM = 118, // Not a XENIX named type file
194 ENAVAIL = 119, // No XENIX semaphores available
195 EISNAM = 120, // Is a named type file
196 EREMOTEIO = 121, // Remote I/O error
197 EDQUOT = 122, // Quota exceeded
199 ENOMEDIUM = 123, // No medium found
200 EMEDIUMTYPE = 124, // Wrong medium type
204 public enum OpenFlags : int {
213 // Or-ed with zero or more of these
224 // These are non-Posix. Using them will result in errors/exceptions on
225 // non-supported platforms.
227 // (For example, "C-wrapped" system calls -- calls with implementation in
228 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
229 // calls will generate an exception in PosixConvert, as the value can't be
230 // converted on the target platform.)
242 public enum FilePermissions : uint {
243 S_ISUID = 0x0800, // Set user ID on execution
244 S_ISGID = 0x0400, // Set gorup ID on execution
245 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
246 S_IRUSR = 0x0100, // Read by owner
247 S_IWUSR = 0x0080, // Write by owner
248 S_IXUSR = 0x0040, // Execute by owner
249 S_IRGRP = 0x0020, // Read by group
250 S_IWGRP = 0x0010, // Write by group
251 S_IXGRP = 0x0008, // Execute by group
252 S_IROTH = 0x0004, // Read by other
253 S_IWOTH = 0x0002, // Write by other
254 S_IXOTH = 0x0001, // Execute by other
256 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
257 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
258 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
259 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
260 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
261 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
264 // Why these are held in "mode_t" is beyond me...
265 S_IFMT = 0xF000, // Bits which determine file type
266 S_IFDIR = 0x4000, // Directory
267 S_IFCHR = 0x2000, // Character device
268 S_IFBLK = 0x6000, // Block device
269 S_IFREG = 0x8000, // Regular file
270 S_IFIFO = 0x1000, // FIFO
271 S_IFLNK = 0xA000, // Symbolic link
272 S_IFSOCK = 0xC000, // Socket
275 public struct Flock {
276 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
277 public SeekFlags l_whence; // How to interpret l_start
278 public /* off_t */ long l_start; // Starting offset for lock
279 public /* off_t */ long l_len; // Number of bytes to lock
280 public /* pid_t */ int l_pid; // PID of process blocking our lock (F_GETLK only)
284 public enum FcntlCommand : int {
285 // Form /usr/include/bits/fcntl.h
286 F_DUPFD = 0, // Duplicate file descriptor.
287 F_GETFD = 1, // Get file descriptor flags.
288 F_SETFD = 2, // Set file descriptor flags.
289 F_GETFL = 3, // Get file status flags.
290 F_SETFL = 4, // Set file status flags.
291 F_GETLK = 12, // Get record locking info. [64]
292 F_SETLK = 13, // Set record locking info (non-blocking). [64]
293 F_SETLKW = 14, // Set record locking info (blocking). [64]
294 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
295 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
296 F_SETSIG = 10, // Set number of signal to be sent.
297 F_GETSIG = 11, // Get number of signal to be sent.
298 F_SETLEASE = 1024, // Set a lease.
299 F_GETLEASE = 1025, // Enquire what lease is active.
300 F_NOTIFY = 1026, // Required notifications on a directory
304 public enum LockType : short {
305 F_RDLCK = 0, // Read lock.
306 F_WRLCK = 1, // Write lock.
307 F_UNLCK = 2, // Remove lock.
311 public enum SeekFlags : short {
312 // values liberally copied from /usr/include/unistd.h
313 SEEK_SET = 0, // Seek from beginning of file.
314 SEEK_CUR = 1, // Seek from current position.
315 SEEK_END = 2, // Seek from end of file.
317 L_SET = SEEK_SET, // BSD alias for SEEK_SET
318 L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
319 L_XTND = SEEK_END, // BSD alias for SEEK_END
323 public enum DirectoryNotifyFlags : int {
324 // from /usr/include/bits/fcntl.h
325 DN_ACCESS = 0x00000001, // File accessed.
326 DN_MODIFY = 0x00000002, // File modified.
327 DN_CREATE = 0x00000004, // File created.
328 DN_DELETE = 0x00000008, // File removed.
329 DN_RENAME = 0x00000010, // File renamed.
330 DN_ATTRIB = 0x00000020, // File changed attributes.
331 DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
335 public enum PosixFadviseAdvice : int {
336 POSIX_FADV_NORMAL = 0, // No further special treatment.
337 POSIX_FADV_RANDOM = 1, // Expect random page references.
338 POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
339 POSIX_FADV_WILLNEED = 3, // Will need these pages.
340 POSIX_FADV_DONTNEED = 4, // Don't need these pages.
341 POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
345 public enum PosixMadviseAdvice : int {
346 POSIX_MADV_NORMAL = 0, // No further special treatment.
347 POSIX_MADV_RANDOM = 1, // Expect random page references.
348 POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
349 POSIX_MADV_WILLNEED = 3, // Will need these pages.
350 POSIX_MADV_DONTNEED = 4, // Don't need these pages.
354 public enum Signum : int {
355 SIGHUP = 1, // Hangup (POSIX).
356 SIGINT = 2, // Interrupt (ANSI).
357 SIGQUIT = 3, // Quit (POSIX).
358 SIGILL = 4, // Illegal instruction (ANSI).
359 SIGTRAP = 5, // Trace trap (POSIX).
360 SIGABRT = 6, // Abort (ANSI).
361 SIGIOT = 6, // IOT trap (4.2 BSD).
362 SIGBUS = 7, // BUS error (4.2 BSD).
363 SIGFPE = 8, // Floating-point exception (ANSI).
364 SIGKILL = 9, // Kill, unblockable (POSIX).
365 SIGUSR1 = 10, // User-defined signal 1 (POSIX).
366 SIGSEGV = 11, // Segmentation violation (ANSI).
367 SIGUSR2 = 12, // User-defined signal 2 (POSIX).
368 SIGPIPE = 13, // Broken pipe (POSIX).
369 SIGALRM = 14, // Alarm clock (POSIX).
370 SIGTERM = 15, // Termination (ANSI).
371 SIGSTKFLT = 16, // Stack fault.
372 SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
373 SIGCHLD = 17, // Child status has changed (POSIX).
374 SIGCONT = 18, // Continue (POSIX).
375 SIGSTOP = 19, // Stop, unblockable (POSIX).
376 SIGTSTP = 20, // Keyboard stop (POSIX).
377 SIGTTIN = 21, // Background read from tty (POSIX).
378 SIGTTOU = 22, // Background write to tty (POSIX).
379 SIGURG = 23, // Urgent condition on socket (4.2 BSD).
380 SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
381 SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
382 SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
383 SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
384 SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
385 SIGPOLL = SIGIO, // Pollable event occurred (System V).
386 SIGIO = 29, // I/O now possible (4.2 BSD).
387 SIGPWR = 30, // Power failure restart (System V).
388 SIGSYS = 31, // Bad system call.
393 public enum MountFlags : ulong {
394 MS_RDONLY = 1, // Mount read-only.
395 MS_NOSUID = 2, // Ignore suid and sgid bits.
396 MS_NODEV = 4, // Disallow access to device special files.
397 MS_NOEXEC = 8, // Disallow program execution.
398 MS_SYNCHRONOUS = 16, // Writes are synced at once.
399 MS_REMOUNT = 32, // Alter flags of a mounted FS.
400 MS_MANDLOCK = 64, // Allow mandatory locks on an FS.
401 S_WRITE = 128, // Write on file/directory/symlink.
402 S_APPEND = 256, // Append-only file.
403 S_IMMUTABLE = 512, // Immutable file.
404 MS_NOATIME = 1024, // Do not update access times.
405 MS_NODIRATIME = 2048, // Do not update directory access times.
406 MS_BIND = 4096, // Bind directory at different place.
407 MS_RMT_MASK = (MS_RDONLY | MS_MANDLOCK),
408 MS_MGC_VAL = 0xc0ed0000, // Magic flag number to indicate "new" flags
409 MS_MGC_MSK = 0xffff0000, // Magic flag number mask
413 public enum UmountFlags : int {
414 MNT_FORCE = 1, // Force unmount even if busy
415 MNT_DETACH, // Perform a lazy unmount.
419 public enum WaitOptions : int {
420 WNOHANG = 1, // Don't block waiting
421 WUNTRACED = 2, // Report status of stopped children
425 public enum AccessMode : int {
433 public enum PathConf : int {
440 _PC_CHOWN_RESTRICTED,
448 _PC_REC_INCR_XFER_SIZE,
449 _PC_REC_MAX_XFER_SIZE,
450 _PC_REC_MIN_XFER_SIZE,
458 public enum SysConf : int {
468 _SC_REALTIME_SIGNALS,
469 _SC_PRIORITY_SCHEDULING,
478 _SC_MEMORY_PROTECTION,
481 _SC_SHARED_MEMORY_OBJECTS,
484 _SC_AIO_PRIO_DELTA_MAX,
495 /* Values for the argument to `sysconf'
496 corresponding to _POSIX2_* symbols. */
501 _SC_COLL_WEIGHTS_MAX,
506 _SC_CHARCLASS_NAME_MAX,
522 _SC_IOV_MAX = _SC_UIO_MAXIOV,
523 _SC_PII_INTERNET_STREAM,
524 _SC_PII_INTERNET_DGRAM,
529 /* Values according to POSIX 1003.1c (POSIX threads). */
531 _SC_THREAD_SAFE_FUNCTIONS,
532 _SC_GETGR_R_SIZE_MAX,
533 _SC_GETPW_R_SIZE_MAX,
536 _SC_THREAD_DESTRUCTOR_ITERATIONS,
538 _SC_THREAD_STACK_MIN,
539 _SC_THREAD_THREADS_MAX,
540 _SC_THREAD_ATTR_STACKADDR,
541 _SC_THREAD_ATTR_STACKSIZE,
542 _SC_THREAD_PRIORITY_SCHEDULING,
543 _SC_THREAD_PRIO_INHERIT,
544 _SC_THREAD_PRIO_PROTECT,
545 _SC_THREAD_PROCESS_SHARED,
546 _SC_NPROCESSORS_CONF,
547 _SC_NPROCESSORS_ONLN,
553 _SC_XOPEN_XCU_VERSION,
588 _SC_XBS5_ILP32_OFF32,
589 _SC_XBS5_ILP32_OFFBIG,
591 _SC_XBS5_LPBIG_OFFBIG,
594 _SC_XOPEN_REALTIME_THREADS,
599 _SC_C_LANG_SUPPORT_R,
605 _SC_DEVICE_SPECIFIC_R,
616 _SC_READER_WRITER_LOCKS,
624 _SC_THREAD_SPORADIC_SERVER,
626 _SC_SYSTEM_DATABASE_R,
628 _SC_TYPED_MEMORY_OBJECTS,
632 _SC_2_PBS_ACCOUNTING,
638 _SC_2_PBS_CHECKPOINT,
645 _SC_TRACE_EVENT_FILTER,
648 _SC_LEVEL1_ICACHE_SIZE,
649 _SC_LEVEL1_ICACHE_ASSOC,
650 _SC_LEVEL1_ICACHE_LINESIZE,
651 _SC_LEVEL1_DCACHE_SIZE,
652 _SC_LEVEL1_DCACHE_ASSOC,
653 _SC_LEVEL1_DCACHE_LINESIZE,
654 _SC_LEVEL2_CACHE_SIZE,
655 _SC_LEVEL2_CACHE_ASSOC,
656 _SC_LEVEL2_CACHE_LINESIZE,
657 _SC_LEVEL3_CACHE_SIZE,
658 _SC_LEVEL3_CACHE_ASSOC,
659 _SC_LEVEL3_CACHE_LINESIZE,
660 _SC_LEVEL4_CACHE_SIZE,
661 _SC_LEVEL4_CACHE_ASSOC,
662 _SC_LEVEL4_CACHE_LINESIZE
666 public enum ConfStr : int {
667 _CS_PATH, /* The default search path. */
668 _CS_V6_WIDTH_RESTRICTED_ENVS,
669 _CS_GNU_LIBC_VERSION,
670 _CS_GNU_LIBPTHREAD_VERSION,
671 _CS_LFS_CFLAGS = 1000,
679 _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
680 _CS_XBS5_ILP32_OFF32_LDFLAGS,
681 _CS_XBS5_ILP32_OFF32_LIBS,
682 _CS_XBS5_ILP32_OFF32_LINTFLAGS,
683 _CS_XBS5_ILP32_OFFBIG_CFLAGS,
684 _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
685 _CS_XBS5_ILP32_OFFBIG_LIBS,
686 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
687 _CS_XBS5_LP64_OFF64_CFLAGS,
688 _CS_XBS5_LP64_OFF64_LDFLAGS,
689 _CS_XBS5_LP64_OFF64_LIBS,
690 _CS_XBS5_LP64_OFF64_LINTFLAGS,
691 _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
692 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
693 _CS_XBS5_LPBIG_OFFBIG_LIBS,
694 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
695 _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
696 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
697 _CS_POSIX_V6_ILP32_OFF32_LIBS,
698 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
699 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
700 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
701 _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
702 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
703 _CS_POSIX_V6_LP64_OFF64_CFLAGS,
704 _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
705 _CS_POSIX_V6_LP64_OFF64_LIBS,
706 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
707 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
708 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
709 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
710 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
714 public enum LockFlags : int {
715 F_ULOCK = 0, // Unlock a previously locked region.
716 F_LOCK = 1, // Lock a region for exclusive use.
717 F_TLOCK = 2, // Test and lock a region for exclusive use.
718 F_TEST = 3, // Test a region for other process locks.
722 public enum PollEvents : short {
723 POLLIN = 0x0001, // There is data to read
724 POLLPRI = 0x0002, // There is urgent data to read
725 POLLOUT = 0x0004, // Writing now will not block
726 POLLERR = 0x0008, // Error condition
727 POLLHUP = 0x0010, // Hung up
728 POLLNVAL = 0x0020, // Invalid request; fd not open
729 // XPG4.2 definitions (via _XOPEN_SOURCE)
730 POLLRDNORM = 0x0040, // Normal data bay be read
731 POLLRDBAND = 0x0080, // Priority data may be read
732 POLLWRNORM = 0x0100, // Writing now will not block
733 POLLWRBAND = 0x0200, // Priority data may be written
736 [StructLayout(LayoutKind.Sequential)]
737 public struct Pollfd {
739 public PollEvents events;
740 public PollEvents revents;
745 public /* ino_t */ ulong d_ino;
746 public /* off_t */ long d_off;
747 public ushort d_reclen;
749 public string d_name;
751 public override string ToString ()
759 public string gr_name;
760 public string gr_passwd;
761 public /* gid_t */ uint gr_gid;
762 public string[] gr_mem;
764 // Generate string in /etc/group format
765 public override string ToString ()
767 StringBuilder sb = new StringBuilder ();
768 sb.AppendFormat ("{0}:{1}:{2}:", gr_name, gr_passwd, gr_gid);
769 GetMembers (sb, gr_mem);
770 return sb.ToString ();
773 private static void GetMembers (StringBuilder sb, string[] members)
775 if (members.Length > 0)
776 sb.Append (members[0]);
777 for (int i = 1; i < members.Length; ++i) {
779 sb.Append (members[i]);
786 public string pw_name;
787 public string pw_passwd;
788 public /* uid_t */ uint pw_uid;
789 public /* gid_t */ uint pw_gid;
790 public string pw_gecos;
791 public string pw_dir;
792 public string pw_shell;
794 // Generate string in /etc/passwd format
795 public override string ToString ()
797 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
798 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
803 public /* dev_t */ ulong st_dev; // device
804 public /* ino_t */ ulong st_ino; // inode
805 public FilePermissions st_mode; // protection
806 private uint _padding_; // padding for structure alignment
807 public /* nlink_t */ ulong st_nlink; // number of hard links
808 public /* uid_t */ uint st_uid; // user ID of owner
809 public /* gid_t */ uint st_gid; // group ID of owner
810 public /* dev_t */ ulong st_rdev; // device type (if inode device)
811 public /* off_t */ long st_size; // total size, in bytes
812 public /* blksize_t */ long st_blksize; // blocksize for filesystem I/O
813 public /* blkcnt_t */ long st_blocks; // number of blocks allocated
814 public /* time_t */ long st_atime; // time of last access
815 public /* time_t */ long st_mtime; // time of last modification
816 public /* time_t */ long st_ctime; // time of last status change
819 public struct Timeval {
820 public /* time_t */ long tv_sec; // seconds
821 public /* suseconds_t */ long tv_usec; // microseconds
824 public struct Timezone {
825 public int tz_minuteswest; // minutes W of Greenwich
826 private int tz_dsttime; // type of dst correction (OBSOLETE)
829 public struct Utimbuf {
830 public /* time_t */ long actime; // access time
831 public /* time_t */ long modtime; // modification time
835 // Convention: Functions *not* part of the standard C library AND part of
836 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
838 // For example, the man page should be similar to:
840 // CONFORMING TO (or CONFORMS TO)
841 // XPG2, SUSv2, POSIX, etc.
843 // BSD- and GNU-specific exports can also be placed here.
845 // The only methods in here should be:
846 // (1) low-level functions
847 // (2) "Trivial" function overloads. For example, if the parameters to a
848 // function are related (e.g. getgroups(2))
849 // (3) The return type SHOULD NOT be changed. If you want to provide a
850 // convenient function with a nicer return type, place it into one of
851 // the Posix* wrapper classes, and give it a .NET-styled name.
852 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
853 // - If you're wrapping *broken* methods which make assumptions about
854 // input data, such as that an argument refers to N bytes of data.
855 // This is currently limited to cuserid(3) and encrypt(3).
856 // - If you call functions which themselves generate exceptions.
857 // This is the case for using PosixConvert, which will throw an
858 // exception if an invalid/unsupported value is used.
860 public sealed class Syscall : Stdlib
862 private const string LIBC = "libc";
863 private const string MPH = "MonoPosixHelper";
864 private const string CRYPT = "crypt";
866 private Syscall () {}
872 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
873 // aio_return(3), aio_suspend(3), aio_write(3)
875 // Then update PosixStream.BeginRead to use the aio* functions.
881 [DllImport (LIBC, SetLastError=true)]
882 public static extern IntPtr opendir (string name);
884 [DllImport (LIBC, SetLastError=true)]
885 public static extern int closedir (IntPtr dir);
888 // void seekdir (DIR *dir, off_t offset);
889 // Slight modification. Returns -1 on error, 0 on success.
890 [DllImport (MPH, SetLastError=true,
891 EntryPoint="Mono_Posix_Syscall_seekdir")]
892 public static extern int seekdir (IntPtr dir, long offset);
895 // off_t telldir(DIR *dir);
896 [DllImport (MPH, SetLastError=true,
897 EntryPoint="Mono_Posix_Syscall_telldir")]
898 public static extern long telldir (IntPtr dir);
900 [DllImport (LIBC, SetLastError=true)]
901 public static extern void rewinddir (IntPtr dir);
903 private struct _Dirent {
904 public /* ino_t */ ulong d_ino;
905 public /* off_t */ long d_off;
906 public ushort d_reclen;
908 public IntPtr d_name;
911 private static void CopyDirent (Dirent to, ref _Dirent from)
914 to.d_ino = from.d_ino;
915 to.d_off = from.d_off;
916 to.d_reclen = from.d_reclen;
917 to.d_type = from.d_type;
918 if (from.d_name != IntPtr.Zero)
919 to.d_name = PosixMarshal.PtrToString (from.d_name);
924 Stdlib.free (from.d_name);
925 from.d_name = IntPtr.Zero;
929 [DllImport (MPH, SetLastError=true,
930 EntryPoint="Mono_Posix_Syscall_readdir")]
931 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
933 public static Dirent readdir (IntPtr dir)
936 int r = sys_readdir (dir, out dentry);
939 Dirent d = new Dirent ();
940 CopyDirent (d, ref dentry);
944 [DllImport (MPH, SetLastError=true,
945 EntryPoint="Mono_Posix_Syscall_readdir_r")]
946 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
948 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
957 int r = sys_readdir_r (dirp, out _d, out result);
959 if (r == 0 && result != IntPtr.Zero) {
960 CopyDirent (entry, ref _d);
966 [DllImport (LIBC, SetLastError=true)]
967 public static extern int dirfd (IntPtr dir);
973 public static Error GetLastError ()
975 int errno = Marshal.GetLastWin32Error ();
976 return PosixConvert.ToError (errno);
979 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_SetLastError")]
980 private static extern void SetLastError (int error);
982 public static void SetLastError (Error error)
984 int _error = PosixConvert.FromError (error);
985 SetLastError (_error);
989 // int strerror_r(int errnum, char *buf, size_t n);
990 [DllImport (LIBC, SetLastError=true,
991 EntryPoint="Mono_Posix_Syscall_strerror_r")]
992 private static extern int sys_strerror_r (int errnum,
993 [Out] StringBuilder buf, ulong n);
995 public static int strerror_r (Error errnum, StringBuilder buf, ulong n)
997 int e = PosixConvert.FromError (errnum);
998 return sys_strerror_r (e, buf, n);
1001 public static int strerror_r (Error errnum, StringBuilder buf)
1003 return strerror_r (errnum, buf, (ulong) buf.Capacity);
1006 public static string strerror_r (Error errnum)
1008 StringBuilder buf = new StringBuilder (16);
1012 r = strerror_r (errnum, buf);
1013 } while (r == -1 && GetLastError() == Error.ERANGE);
1016 return "** Unknown error code: " + ((int) errnum) + "**";
1017 return buf.ToString();
1023 [DllImport (MPH, SetLastError=true,
1024 EntryPoint="Mono_Posix_Syscall_fcntl")]
1025 public static extern int fcntl (int fd, FcntlCommand cmd);
1027 [DllImport (MPH, SetLastError=true,
1028 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
1029 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
1031 [DllImport (MPH, SetLastError=true,
1032 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
1033 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
1035 [DllImport (MPH, SetLastError=true,
1036 EntryPoint="Mono_Posix_Syscall_open")]
1037 public static extern int open (string pathname, OpenFlags flags);
1039 [DllImport (MPH, SetLastError=true,
1040 EntryPoint="Mono_Posix_Syscall_open_mode")]
1041 public static extern int open (string pathname, OpenFlags flags, FilePermissions mode);
1043 [DllImport (MPH, SetLastError=true,
1044 EntryPoint="Mono_Posix_Syscall_creat")]
1045 public static extern int creat (string pathname, FilePermissions mode);
1048 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
1049 [DllImport (MPH, SetLastError=true,
1050 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
1051 public static extern int posix_fadvise (int fd, long offset,
1052 long len, PosixFadviseAdvice advice);
1054 // posix_fallocate(P)
1055 // int posix_fallocate(int fd, off_t offset, size_t len);
1056 [DllImport (MPH, SetLastError=true,
1057 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
1058 public static extern int posix_fallocate (int fd, long offset, long len);
1065 // int setgroups (size_t size, const gid_t *list);
1066 [DllImport (MPH, SetLastError=true,
1067 EntryPoint="Mono_Posix_Syscall_setgroups")]
1068 public static extern int setgroups (ulong size, uint[] list);
1070 public static int setgroups (uint [] list)
1072 return setgroups ((ulong) list.Length, list);
1075 private struct _Group
1077 public IntPtr gr_name;
1078 public IntPtr gr_passwd;
1079 public /* gid_t */ uint gr_gid;
1080 public int _gr_nmem_;
1081 public IntPtr gr_mem;
1082 public IntPtr _gr_buf_;
1085 private static void CopyGroup (Group to, ref _Group from)
1088 to.gr_gid = from.gr_gid;
1089 to.gr_name = PosixMarshal.PtrToString (from.gr_name);
1090 to.gr_passwd = PosixMarshal.PtrToString (from.gr_passwd);
1091 to.gr_mem = PosixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
1094 Stdlib.free (from.gr_mem);
1095 Stdlib.free (from._gr_buf_);
1096 from.gr_mem = IntPtr.Zero;
1097 from._gr_buf_ = IntPtr.Zero;
1101 [DllImport (MPH, SetLastError=true,
1102 EntryPoint="Mono_Posix_Syscall_getgrnam")]
1103 private static extern int sys_getgrnam (string name, out _Group group);
1105 public static Group getgrnam (string name)
1108 int r = sys_getgrnam (name, out group);
1111 Group gr = new Group ();
1112 CopyGroup (gr, ref group);
1117 // struct group *getgrgid(gid_t gid);
1118 [DllImport (MPH, SetLastError=true,
1119 EntryPoint="Mono_Posix_Syscall_getgrgid")]
1120 private static extern int sys_getgrgid (uint uid, out _Group group);
1122 public static Group getgrgid (uint uid)
1125 int r = sys_getgrgid (uid, out group);
1128 Group gr = new Group ();
1129 CopyGroup (gr, ref group);
1133 [DllImport (MPH, SetLastError=true,
1134 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
1135 private static extern int sys_getgrnam_r (string name, out _Group grbuf, out IntPtr grbufp);
1137 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
1142 int r = sys_getgrnam_r (name, out group, out _grbufp);
1143 if (r == 0 && _grbufp != IntPtr.Zero) {
1144 CopyGroup (grbuf, ref group);
1151 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
1152 // size_t buflen, struct group **gbufp);
1153 [DllImport (MPH, SetLastError=true,
1154 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
1155 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
1157 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
1162 int r = sys_getgrgid_r (uid, out group, out _grbufp);
1163 if (r == 0 && _grbufp != IntPtr.Zero) {
1164 CopyGroup (grbuf, ref group);
1170 [DllImport (MPH, SetLastError=true,
1171 EntryPoint="Mono_Posix_Syscall_getgrent")]
1172 private static extern int sys_getgrent (out _Group grbuf);
1174 public static Group getgrent ()
1177 int r = sys_getgrent (out group);
1180 Group gr = new Group();
1181 CopyGroup (gr, ref group);
1185 [DllImport (LIBC, SetLastError=true)]
1186 public static extern void setgrent ();
1188 [DllImport (LIBC, SetLastError=true)]
1189 public static extern void endgrent ();
1191 [DllImport (MPH, SetLastError=true,
1192 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
1193 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
1195 public static Group fgetgrent (IntPtr stream)
1198 int r = sys_fgetgrent (stream, out group);
1201 Group gr = new Group ();
1202 CopyGroup (gr, ref group);
1209 private struct _Passwd
1211 public IntPtr pw_name;
1212 public IntPtr pw_passwd;
1213 public /* uid_t */ uint pw_uid;
1214 public /* gid_t */ uint pw_gid;
1215 public IntPtr pw_gecos;
1216 public IntPtr pw_dir;
1217 public IntPtr pw_shell;
1218 public IntPtr _pw_buf_;
1221 private static void CopyPasswd (Passwd to, ref _Passwd from)
1224 to.pw_name = PosixMarshal.PtrToString (from.pw_name);
1225 to.pw_passwd = PosixMarshal.PtrToString (from.pw_passwd);
1226 to.pw_uid = from.pw_uid;
1227 to.pw_gid = from.pw_gid;
1228 to.pw_gecos = PosixMarshal.PtrToString (from.pw_gecos);
1229 to.pw_dir = PosixMarshal.PtrToString (from.pw_dir);
1230 to.pw_shell = PosixMarshal.PtrToString (from.pw_shell);
1233 Stdlib.free (from._pw_buf_);
1234 from._pw_buf_ = IntPtr.Zero;
1238 [DllImport (MPH, SetLastError=true,
1239 EntryPoint="Mono_Posix_Syscall_getpwnam")]
1240 private static extern int sys_getpwnam (string name, out _Passwd passwd);
1242 public static Passwd getpwnam (string name)
1245 int r = sys_getpwnam (name, out passwd);
1248 Passwd pw = new Passwd ();
1249 CopyPasswd (pw, ref passwd);
1254 // struct passwd *getpwnuid(uid_t uid);
1255 [DllImport (MPH, SetLastError=true,
1256 EntryPoint="Mono_Posix_Syscall_getpwuid")]
1257 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
1259 public static Passwd getpwuid (uint uid)
1262 int r = sys_getpwuid (uid, out passwd);
1265 Passwd pw = new Passwd ();
1266 CopyPasswd (pw, ref passwd);
1270 [DllImport (MPH, SetLastError=true,
1271 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
1272 private static extern int sys_getpwnam_r (string name, out _Passwd pwbuf, out IntPtr pwbufp);
1274 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
1279 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
1280 if (r == 0 && _pwbufp != IntPtr.Zero) {
1281 CopyPasswd (pwbuf, ref passwd);
1288 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
1289 // buflen, struct passwd **pwbufp);
1290 [DllImport (MPH, SetLastError=true,
1291 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
1292 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
1294 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
1299 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
1300 if (r == 0 && _pwbufp != IntPtr.Zero) {
1301 CopyPasswd (pwbuf, ref passwd);
1307 [DllImport (MPH, SetLastError=true,
1308 EntryPoint="Mono_Posix_Syscall_getpwent")]
1309 private static extern int sys_getpwent (out _Passwd pwbuf);
1311 public static Passwd getpwent ()
1314 int r = sys_getpwent (out passwd);
1317 Passwd pw = new Passwd ();
1318 CopyPasswd (pw, ref passwd);
1322 [DllImport (LIBC, SetLastError=true)]
1323 public static extern void setpwent ();
1325 [DllImport (LIBC, SetLastError=true)]
1326 public static extern void endpwent ();
1328 [DllImport (MPH, SetLastError=true,
1329 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
1330 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
1332 public static Passwd fgetpwent (IntPtr stream)
1335 int r = sys_fgetpwent (stream, out passwd);
1338 Passwd pw = new Passwd ();
1339 CopyPasswd (pw, ref passwd);
1346 [DllImport (LIBC, SetLastError=true)]
1347 private static extern void psignal (int sig, string s);
1349 public static void psignal (Signum sig, string s)
1351 int signum = PosixConvert.FromSignum (sig);
1352 psignal (signum, s);
1356 // int kill(pid_t pid, int sig);
1357 [DllImport (LIBC, SetLastError=true)]
1358 private static extern int sys_kill (int pid, int sig);
1360 public static int kill (int pid, Signum sig)
1362 int _sig = PosixConvert.FromSignum (sig);
1363 return sys_kill (pid, _sig);
1366 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
1367 private static extern IntPtr sys_strsignal (int sig);
1369 public static IntPtr sys_strsignal (Signum sig)
1371 int s = PosixConvert.FromSignum (sig);
1372 return sys_strsignal (s);
1375 public static string strsignal (Signum sig)
1377 IntPtr r = sys_strsignal (sig);
1378 return PosixMarshal.PtrToString (r);
1381 // TODO: sigaction(2)
1382 // TODO: sigsuspend(2)
1383 // TODO: sigpending(2)
1389 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
1390 private static extern int _L_ctermid ();
1392 public static readonly int L_ctermid = _L_ctermid ();
1394 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
1395 private static extern int _L_cuserid ();
1397 public static readonly int L_cuserid = _L_cuserid ();
1399 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
1400 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
1402 [Obsolete ("\"Nobody knows precisely what cuserid() does... DO NOT USE cuserid()." +
1403 "`string' must hold L_cuserid characters. Use Unistd.getlogin_r instead.")]
1404 public static string cuserid (StringBuilder @string)
1406 if (@string.Capacity < L_cuserid) {
1407 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
1409 IntPtr r = sys_cuserid (@string);
1410 return PosixMarshal.PtrToString (r);
1416 [DllImport (LIBC, SetLastError=true)]
1417 public static extern int ttyslot ();
1419 [DllImport (CRYPT, SetLastError=true)]
1420 public static extern void setkey (string key);
1427 // int posix_madvise(void *addr, size_t len, int advice);
1428 [DllImport (MPH, SetLastError=true,
1429 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
1430 public static extern int posix_madvise (IntPtr addr, ulong len,
1431 PosixMadviseAdvice advice);
1436 [DllImport (MPH, SetLastError=true,
1437 EntryPoint="Mono_Posix_Syscall_mount")]
1438 public static extern int mount (string source, string target,
1439 string filesystemtype, MountFlags mountflags, string data);
1441 [DllImport (MPH, SetLastError=true,
1442 EntryPoint="Mono_Posix_Syscall_umount")]
1443 public static extern int umount (string target);
1445 [DllImport (MPH, SetLastError=true,
1446 EntryPoint="Mono_Posix_Syscall_umount2")]
1447 private static extern int sys_umount2 (string target, int flags);
1449 public static int umount2 (string target, UmountFlags flags)
1451 int _flags = PosixConvert.FromUmountFlags (flags);
1452 return sys_umount2 (target, _flags);
1458 private struct _pollfd {
1460 public short events;
1461 public short revents;
1464 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
1465 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
1467 public static int poll (Pollfd [] fds, uint nfds, int timeout)
1469 if (fds.Length < nfds)
1470 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
1472 _pollfd[] send = new _pollfd[nfds];
1474 for (int i = 0; i < send.Length; i++) {
1475 send [i].fd = fds [i].fd;
1476 send [i].events = PosixConvert.FromPollEvents (fds [i].events);
1479 int r = sys_poll (send, nfds, timeout);
1481 for (int i = 0; i < send.Length; i++) {
1482 fds [i].revents = PosixConvert.ToPollEvents (send [i].revents);
1488 public static int poll (Pollfd [] fds, int timeout)
1490 return poll (fds, (uint) fds.Length, timeout);
1503 // TODO: setrlimit(2)
1504 // TODO: getrlimit(2)
1505 // TODO: getrusage(2)
1511 [DllImport (MPH, SetLastError=true,
1512 EntryPoint="Mono_Posix_Syscall_sendfile")]
1513 public static extern long sendfile (int out_fd, int in_fd,
1514 ref long offset, ulong count);
1519 [DllImport (MPH, SetLastError=true,
1520 EntryPoint="Mono_Posix_Syscall_stat")]
1521 public static extern int stat (string file_name, out Stat buf);
1523 [DllImport (MPH, SetLastError=true,
1524 EntryPoint="Mono_Posix_Syscall_fstat")]
1525 public static extern int fstat (int filedes, out Stat buf);
1527 [DllImport (MPH, SetLastError=true,
1528 EntryPoint="Mono_Posix_Syscall_lstat")]
1529 public static extern int lstat (string file_name, out Stat buf);
1531 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
1532 private static extern int sys_chmod (string path, uint mode);
1534 public static int chmod (string path, FilePermissions mode)
1536 uint _mode = PosixConvert.FromFilePermissions (mode);
1537 return sys_chmod (path, _mode);
1540 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
1541 private static extern int sys_fchmod (int filedes, uint mode);
1543 public static int fchmod (int filedes, FilePermissions mode)
1545 uint _mode = PosixConvert.FromFilePermissions (mode);
1546 return sys_fchmod (filedes, _mode);
1549 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
1550 private static extern int sys_umask (uint mask);
1552 public static int umask (FilePermissions mask)
1554 uint _mask = PosixConvert.FromFilePermissions (mask);
1555 return sys_umask (_mask);
1558 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
1559 public static extern int sys_mkdir (string oldpath, uint mode);
1561 public static int mkdir (string oldpath, FilePermissions mode)
1563 uint _mode = PosixConvert.FromFilePermissions (mode);
1564 return sys_mkdir (oldpath, _mode);
1568 // int mknod (const char *pathname, mode_t mode, dev_t dev);
1569 [DllImport (MPH, SetLastError=true,
1570 EntryPoint="Mono_Posix_Syscall_mknod")]
1571 public static extern int mknod (string pathname, FilePermissions mode, ulong dev);
1577 [DllImport (MPH, SetLastError=true,
1578 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1579 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
1581 [DllImport (MPH, SetLastError=true,
1582 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1583 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
1585 public static int gettimeofday (out Timeval tv)
1587 return gettimeofday (out tv, IntPtr.Zero);
1590 [DllImport (MPH, SetLastError=true,
1591 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1592 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
1594 public static int gettimeofday (out Timezone tz)
1596 return gettimeofday (IntPtr.Zero, out tz);
1599 [DllImport (MPH, SetLastError=true,
1600 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1601 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
1603 [DllImport (MPH, SetLastError=true,
1604 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1605 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
1607 public static int settimeofday (ref Timeval tv)
1609 return settimeofday (ref tv, IntPtr.Zero);
1629 // pid_t wait(int *status);
1630 [DllImport (LIBC, SetLastError=true)]
1631 public static extern int wait (out int status);
1634 // pid_t waitpid(pid_t pid, int *status, int options);
1635 [DllImport (LIBC, SetLastError=true)]
1636 private static extern int waitpid (int pid, out int status, int options);
1638 public static int waitpid (int pid, out int status, WaitOptions options)
1640 int _options = PosixConvert.FromWaitOptions (options);
1641 return waitpid (pid, out status, _options);
1644 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
1645 private static extern int _WIFEXITED (int status);
1647 public static bool WIFEXITED (int status)
1649 return _WIFEXITED (status) != 0;
1652 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
1653 public static extern int WEXITSTATUS (int status);
1655 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
1656 private static extern int _WIFSIGNALED (int status);
1658 public static bool WIFSIGNALED (int status)
1660 return _WIFSIGNALED (status) != 0;
1663 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
1664 private static extern int _WTERMSIG (int status);
1666 public static Signum WTERMSIG (int status)
1668 int r = _WTERMSIG (status);
1669 return PosixConvert.ToSignum (r);
1672 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
1673 private static extern int _WIFSTOPPED (int status);
1675 public static bool WIFSTOPPED (int status)
1677 return _WIFSTOPPED (status) != 0;
1680 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
1681 private static extern int _WSTOPSIG (int status);
1683 public static Signum WSTOPSIG (int status)
1685 int r = _WSTOPSIG (status);
1686 return PosixConvert.ToSignum (r);
1698 // int stime(time_t *t);
1699 [DllImport (MPH, SetLastError=true,
1700 EntryPoint="Mono_Posix_Syscall_stime")]
1701 public static extern int stime (ref long t);
1704 // time_t time(time_t *t);
1705 [DllImport (MPH, SetLastError=true,
1706 EntryPoint="Mono_Posix_Syscall_time")]
1707 public static extern long time (out long t);
1718 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
1719 private static extern int sys_access (string pathname, int mode);
1721 public static int access (string pathname, AccessMode mode)
1723 int _mode = PosixConvert.FromAccessMode (mode);
1724 return sys_access (pathname, _mode);
1728 // off_t lseek(int filedes, off_t offset, int whence);
1729 [DllImport (MPH, SetLastError=true,
1730 EntryPoint="Mono_Posix_Syscall_lseek")]
1731 public static extern long lseek (int fd, long offset, SeekFlags whence);
1733 [DllImport (LIBC, SetLastError=true)]
1734 public static extern int close (int fd);
1737 // ssize_t read(int fd, void *buf, size_t count);
1738 [DllImport (MPH, SetLastError=true,
1739 EntryPoint="Mono_Posix_Syscall_read")]
1740 public static extern long read (int fd, IntPtr buf, ulong count);
1742 public static unsafe long read (int fd, void *buf, ulong count)
1744 return read (fd, (IntPtr) buf, count);
1748 // ssize_t write(int fd, const void *buf, size_t count);
1749 [DllImport (MPH, SetLastError=true,
1750 EntryPoint="Mono_Posix_Syscall_write")]
1751 public static extern long write (int fd, IntPtr buf, ulong count);
1753 public static unsafe long write (int fd, void *buf, ulong count)
1755 return write (fd, (IntPtr) buf, count);
1759 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
1760 [DllImport (MPH, SetLastError=true,
1761 EntryPoint="Mono_Posix_Syscall_pread")]
1762 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
1764 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
1766 return pread (fd, (IntPtr) buf, count, offset);
1770 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
1771 [DllImport (MPH, SetLastError=true,
1772 EntryPoint="Mono_Posix_Syscall_pwrite")]
1773 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
1775 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
1777 return pwrite (fd, (IntPtr) buf, count, offset);
1780 [DllImport (MPH, SetLastError=true,
1781 EntryPoint="Mono_Posix_Syscall_pipe")]
1782 public static extern int pipe (out int reading, out int writing);
1784 public static int pipe (int[] filedes)
1786 if (filedes == null || filedes.Length != 2) {
1790 int reading, writing;
1791 int r = pipe (out reading, out writing);
1792 filedes[0] = reading;
1793 filedes[1] = writing;
1797 [DllImport (LIBC, SetLastError=true)]
1798 public static extern uint alarm (uint seconds);
1800 [DllImport (LIBC, SetLastError=true)]
1801 public static extern int sleep (uint seconds);
1803 [DllImport (LIBC, SetLastError=true)]
1804 public static extern uint ualarm (uint usecs, uint interval);
1806 [DllImport (LIBC, SetLastError=true)]
1807 public static extern int pause ();
1810 // int chown(const char *path, uid_t owner, gid_t group);
1811 [DllImport (LIBC, SetLastError=true)]
1812 public static extern int chown (string path, uint owner, uint group);
1815 // int fchown(int fd, uid_t owner, gid_t group);
1816 [DllImport (LIBC, SetLastError=true)]
1817 public static extern int fchown (int fd, uint owner, uint group);
1820 // int lchown(const char *path, uid_t owner, gid_t group);
1821 [DllImport (LIBC, SetLastError=true)]
1822 public static extern int lchown (string path, uint owner, uint group);
1824 [DllImport (LIBC, SetLastError=true)]
1825 public static extern int chdir (string path);
1827 [DllImport (LIBC, SetLastError=true)]
1828 public static extern int fchdir (int fd);
1831 // char *getcwd(char *buf, size_t size);
1832 [DllImport (MPH, SetLastError=true,
1833 EntryPoint="Mono_Posix_Syscall_getcwd")]
1834 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
1836 public static StringBuilder getcwd (StringBuilder buf)
1838 getcwd (buf, (ulong) buf.Capacity);
1842 // getwd(2) is deprecated; don't expose it.
1844 [DllImport (LIBC, SetLastError=true)]
1845 public static extern int dup (int fd);
1847 [DllImport (LIBC, SetLastError=true)]
1848 public static extern int dup2 (int fd, int fd2);
1850 // TODO: does Mono marshal arrays properly?
1851 [DllImport (LIBC, SetLastError=true)]
1852 public static extern int execve (string path, string[] argv, string[] envp);
1854 [DllImport (LIBC, SetLastError=true)]
1855 public static extern int execv (string path, string[] argv);
1857 // TODO: execle, execl
1858 [DllImport (LIBC, SetLastError=true)]
1859 public static extern int execvp (string path, string[] argv);
1861 [DllImport (LIBC, SetLastError=true)]
1862 public static extern int nice (int inc);
1864 [DllImport (LIBC, SetLastError=true)]
1865 public static extern int _exit (int status);
1867 [DllImport (MPH, SetLastError=true,
1868 EntryPoint="Mono_Posix_Syscall_fpathconf")]
1869 public static extern long fpathconf (int filedes, PathConf name);
1871 [DllImport (MPH, SetLastError=true,
1872 EntryPoint="Mono_Posix_Syscall_pathconf")]
1873 public static extern long pathconf (string path, PathConf name);
1875 [DllImport (MPH, SetLastError=true,
1876 EntryPoint="Mono_Posix_Syscall_sysconf")]
1877 public static extern long sysconf (SysConf name);
1880 // size_t confstr(int name, char *buf, size_t len);
1881 [DllImport (MPH, SetLastError=true,
1882 EntryPoint="Mono_Posix_Syscall_confstr")]
1883 public static extern ulong confstr (ConfStr name, [Out] StringBuilder buf, ulong len);
1886 // pid_t getpid(void);
1887 [DllImport (LIBC, SetLastError=true)]
1888 public static extern int getpid ();
1891 // int setpgid(pid_t pid, pid_t pgid);
1892 [DllImport (LIBC, SetLastError=true)]
1893 public static extern int setpgid (int pid, int pgid);
1896 // pid_t getpgid(pid_t pid);
1897 [DllImport (LIBC, SetLastError=true)]
1898 public static extern int getpgid (int pid);
1900 [DllImport (LIBC, SetLastError=true)]
1901 public static extern int setpgrp ();
1904 // pid_t getpgrp(void);
1905 [DllImport (LIBC, SetLastError=true)]
1906 public static extern int getpgrp ();
1909 // pid_t setsid(void);
1910 [DllImport (LIBC, SetLastError=true)]
1911 public static extern int setsid ();
1914 // pid_t getsid(pid_t pid);
1915 [DllImport (LIBC, SetLastError=true)]
1916 public static extern int getsid (int pid);
1919 // uid_t getuid(void);
1920 [DllImport (LIBC, SetLastError=true)]
1921 public static extern uint getuid ();
1924 // uid_t geteuid(void);
1925 [DllImport (LIBC, SetLastError=true)]
1926 public static extern uint geteuid ();
1929 // gid_t getgid(void);
1930 [DllImport (LIBC, SetLastError=true)]
1931 public static extern uint getgid ();
1934 // gid_t getgid(void);
1935 [DllImport (LIBC, SetLastError=true)]
1936 public static extern uint getegid ();
1939 // int getgroups(int size, gid_t list[]);
1940 [DllImport (LIBC, SetLastError=true)]
1941 public static extern int getgroups (int size, uint[] list);
1943 public static int getgroups (uint[] list)
1945 return getgroups (list.Length, list);
1949 // int setuid(uid_t uid);
1950 [DllImport (LIBC, SetLastError=true)]
1951 public static extern int setuid (uint uid);
1954 // int setreuid(uid_t ruid, uid_t euid);
1955 [DllImport (LIBC, SetLastError=true)]
1956 public static extern int setreuid (uint ruid, uint euid);
1959 // int setregid(gid_t ruid, gid_t euid);
1960 [DllImport (LIBC, SetLastError=true)]
1961 public static extern int setregid (uint rgid, uint egid);
1964 // int seteuid(uid_t euid);
1965 [DllImport (LIBC, SetLastError=true)]
1966 public static extern int seteuid (uint euid);
1969 // int setegid(gid_t euid);
1970 [DllImport (LIBC, SetLastError=true)]
1971 public static extern int setegid (uint uid);
1974 // int setgid(gid_t gid);
1975 [DllImport (LIBC, SetLastError=true)]
1976 public static extern int setgid (uint gid);
1979 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
1980 [DllImport (LIBC, SetLastError=true)]
1981 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
1984 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
1985 [DllImport (LIBC, SetLastError=true)]
1986 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
1989 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1990 [DllImport (LIBC, SetLastError=true)]
1991 public static extern int setresuid (uint ruid, uint euid, uint suid);
1994 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
1995 [DllImport (LIBC, SetLastError=true)]
1996 public static extern int setresgid (uint rgid, uint egid, uint sgid);
1999 // pid_t fork(void);
2000 [DllImport (LIBC, SetLastError=true)]
2001 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
2002 "shutdown code.\nUse System.Diagnostics.Process instead")]
2003 public static extern int fork ();
2006 // pid_t vfork(void);
2007 [DllImport (LIBC, SetLastError=true)]
2008 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
2009 "shutdown code.\nUse System.Diagnostics.Process instead")]
2010 public static extern int vfork ();
2012 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
2013 [Obsolete ("Not re-entrant. Use ttyname_r instead.")]
2014 public static extern IntPtr sys_ttyname (int fd);
2016 [Obsolete ("Not re-entrant. Use ttyname_r instead.")]
2017 public static string ttyname (int fd)
2019 IntPtr r = sys_ttyname (fd);
2020 return PosixMarshal.PtrToString (r);
2024 // int ttyname_r(int fd, char *buf, size_t buflen);
2025 [DllImport (MPH, SetLastError=true,
2026 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
2027 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
2029 public static int ttyname_r (int fd, StringBuilder buf)
2031 return ttyname_r (fd, buf, (ulong) buf.Capacity);
2034 [DllImport (LIBC, EntryPoint="isatty")]
2035 private static extern int sys_isatty (int fd);
2037 public static bool isatty (int fd)
2039 return sys_isatty (fd) == 1;
2042 [DllImport (LIBC, SetLastError=true)]
2043 public static extern int link (string oldpath, string newpath);
2045 [DllImport (LIBC, SetLastError=true)]
2046 public static extern int symlink (string oldpath, string newpath);
2049 // int readlink(const char *path, char *buf, size_t bufsize);
2050 [DllImport (MPH, SetLastError=true,
2051 EntryPoint="Mono_Posix_Syscall_readlink")]
2052 public static extern int readlink (string path, [Out] StringBuilder buf, ulong bufsiz);
2054 public static int readlink (string path, [Out] StringBuilder buf)
2056 return readlink (path, buf, (ulong) buf.Capacity);
2059 [DllImport (LIBC, SetLastError=true)]
2060 public static extern int unlink (string pathname);
2062 [DllImport (LIBC, SetLastError=true)]
2063 public static extern int rmdir (string pathname);
2066 // pid_t tcgetpgrp(int fd);
2067 [DllImport (LIBC, SetLastError=true)]
2068 public static extern int tcgetpgrp (int fd);
2071 // int tcsetpgrp(int fd, pid_t pgrp);
2072 [DllImport (LIBC, SetLastError=true)]
2073 public static extern int tcsetpgrp (int fd, int pgrp);
2075 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
2076 [Obsolete ("Not re-entrant. Use getlogin_r instead.")]
2077 public static extern IntPtr sys_getlogin ();
2079 [Obsolete ("Not re-entrant. Use getlogin_r instead.")]
2080 public static string getlogin ()
2082 IntPtr r = sys_getlogin ();
2083 return PosixMarshal.PtrToString (r);
2087 // int getlogin_r(char *buf, size_t bufsize);
2088 [DllImport (MPH, SetLastError=true,
2089 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
2090 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
2092 public static int getlogin_r (StringBuilder name)
2094 return getlogin_r (name, (ulong) name.Capacity);
2098 // int gethostname(char *name, size_t len);
2099 [DllImport (MPH, SetLastError=true,
2100 EntryPoint="Mono_Posix_Syscall_gethostname")]
2101 public static extern int gethostname ([Out] StringBuilder name, ulong len);
2103 public static int gethostname (StringBuilder name)
2105 return gethostname (name, (ulong) name.Capacity);
2109 // int gethostname(const char *name, size_t len);
2110 [DllImport (MPH, SetLastError=true,
2111 EntryPoint="Mono_Posix_Syscall_gethostname")]
2112 public static extern int sethostname (string name, ulong len);
2114 public static int sethostname (string name)
2116 return sethostname (name, (ulong) name.Length);
2119 [DllImport (MPH, SetLastError=true,
2120 EntryPoint="Mono_Posix_Syscall_gethostid")]
2121 public static extern long gethostid ();
2123 [DllImport (MPH, SetLastError=true,
2124 EntryPoint="Mono_Posix_Syscall_sethostid")]
2125 public static extern int sethostid (long hostid);
2128 // int getdomainname(char *name, size_t len);
2129 [DllImport (MPH, SetLastError=true,
2130 EntryPoint="Mono_Posix_Syscall_getdomainname")]
2131 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
2133 public static int getdomainname (StringBuilder name)
2135 return getdomainname (name, (ulong) name.Capacity);
2139 // int setdomainname(const char *name, size_t len);
2140 [DllImport (MPH, SetLastError=true,
2141 EntryPoint="Mono_Posix_Syscall_setdomainname")]
2142 public static extern int setdomainname (string name, ulong len);
2144 public static int setdomainname (string name)
2146 return setdomainname (name, (ulong) name.Length);
2149 [DllImport (LIBC, SetLastError=true)]
2150 public static extern int vhangup ();
2152 // Revoke doesn't appear to be POSIX. Include it?
2153 [DllImport (LIBC, SetLastError=true)]
2154 public static extern int revoke (string file);
2156 // TODO: profil? It's not POSIX.
2158 [DllImport (LIBC, SetLastError=true)]
2159 public static extern int acct (string filename);
2161 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
2162 public static extern IntPtr sys_getusershell ();
2164 public static string getusershell ()
2166 IntPtr r = sys_getusershell ();
2167 return PosixMarshal.PtrToString (r);
2170 [DllImport (LIBC, SetLastError=true)]
2171 public static extern void setusershell ();
2173 [DllImport (LIBC, SetLastError=true)]
2174 public static extern void endusershell ();
2176 [DllImport (LIBC, SetLastError=true)]
2177 private static extern int daemon (int nochdir, int noclose);
2179 public static int daemon (bool nochdir, bool noclose)
2181 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
2184 [DllImport (LIBC, SetLastError=true)]
2185 public static extern int chroot (string path);
2187 // skipping getpass(3) as the man page states:
2188 // This function is obsolete. Do not use it.
2190 [DllImport (LIBC, SetLastError=true)]
2191 public static extern int fsync (int fd);
2193 [DllImport (LIBC, SetLastError=true)]
2194 public static extern int fdatasync (int fd);
2196 [DllImport (LIBC, SetLastError=true)]
2197 public static extern void sync ();
2199 [DllImport (LIBC, SetLastError=true)]
2200 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
2201 "Use Unistd.sysconf (SysConf._SC_PAGESIZE).")]
2202 public static extern int getpagesize ();
2205 // int truncate(const char *path, off_t length);
2206 [DllImport (MPH, SetLastError=true,
2207 EntryPoint="Mono_Posix_Syscall_truncate")]
2208 public static extern int truncate (string path, long length);
2211 // int ftruncate(int fd, off_t length);
2212 [DllImport (MPH, SetLastError=true,
2213 EntryPoint="Mono_Posix_Syscall_ftruncate")]
2214 public static extern int ftruncate (int fd, long length);
2216 [DllImport (LIBC, SetLastError=true)]
2217 public static extern int getdtablesize ();
2219 [DllImport (LIBC, SetLastError=true)]
2220 public static extern int brk (IntPtr end_data_segment);
2222 [DllImport (LIBC, SetLastError=true)]
2223 public static extern IntPtr sbrk (IntPtr increment);
2225 // TODO: syscall(2)?
2226 // Probably safer to skip entirely.
2229 // int lockf(int fd, int cmd, off_t len);
2230 [DllImport (MPH, SetLastError=true,
2231 EntryPoint="Mono_Posix_Syscall_lockf")]
2232 public static extern int lockf (int fd, LockFlags cmd, long len);
2234 [DllImport (CRYPT, SetLastError=true, EntryPoint=CRYPT)]
2235 public static extern IntPtr sys_crypt (string key, string salt);
2237 public static string crypt (string key, string salt)
2239 IntPtr r = sys_crypt (key, salt);
2240 return PosixMarshal.PtrToString (r);
2243 [DllImport (CRYPT, SetLastError=true, EntryPoint="encrypt")]
2244 private static extern void sys_encrypt ([In, Out] byte[] block, int edflag);
2246 public static void encrypt (byte[] block, bool decode)
2248 if (block.Length < 64)
2249 throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
2250 sys_encrypt (block, decode ? 1 : 0);
2254 // void swab(const void *from, void *to, ssize_t n);
2255 [DllImport (MPH, SetLastError=true,
2256 EntryPoint="Mono_Posix_Syscall_swab")]
2257 public static extern void swab (IntPtr from, IntPtr to, long n);
2259 public static unsafe void swab (void* from, void* to, long n)
2261 swab ((IntPtr) from, (IntPtr) to, n);
2268 [DllImport (MPH, SetLastError=true,
2269 EntryPoint="Mono_Posix_Syscall_utime")]
2270 public static extern int utime (string filename, ref Utimbuf buf);
2272 [DllImport (MPH, SetLastError=true,
2273 EntryPoint="Mono_Posix_Syscall_utime")]
2274 private static extern int utime (string filename, IntPtr buf);
2276 public static int utime (string filename)
2278 return utime (filename, IntPtr.Zero);
2281 [DllImport (MPH, SetLastError=true,
2282 EntryPoint="Mono_Posix_Syscall_utimes")]
2283 public static extern int utimes (string filename, ref Timeval tvp);
2285 // Obsolete this after 1.2 is out:
2286 //[Obsolete ("Use Mono.Posix.Stdlib.strerror")]
2287 public static string strerror (int errnum)
2289 IntPtr r = Stdlib.sys_strerror (errnum);
2290 return PosixMarshal.PtrToString (r);