fb2ebbfe582fb0fc14e44ffbf2f5126aa9d29630
[mono.git] / mcs / class / Mono.Posix / Mono.Posix / Syscall.cs
1 //
2 // Mono.Posix/Syscall.cs
3 //
4 // Authors:
5 //   Miguel de Icaza (miguel@novell.com)
6 //   Jonathan Pryor (jonpryor@vt.edu)
7 //
8 // (C) 2003 Novell, Inc.
9 // (C) 2004 Jonathan Pryor
10 //
11 // This file implements the low-level syscall interface to the POSIX
12 // subsystem.
13 //
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
16 // data types.
17 //
18 // Implementation notes:
19 //
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.
25 //
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.
30 //
31 //    Methods that require tuning are bound as `private sys_NAME' methods
32 //    and then a `NAME' method is exposed.
33 //
34
35 //
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:
43 // 
44 // The above copyright notice and this permission notice shall be
45 // included in all copies or substantial portions of the Software.
46 // 
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.
54 //
55
56 using System;
57 using System.Collections;
58 using System.Runtime.InteropServices;
59 using System.Text;
60 using Mono.Posix;
61
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"})]
66
67 namespace Mono.Posix {
68
69         [Map]
70         public enum Error : int {
71                 // errors & their values liberally copied from
72                 // FC2 /usr/include/asm/errno.h
73                 
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 
78                 EIO             =   5, // I/O error 
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 
131                       
132                 EDEADLOCK             =  EDEADLK,
133                       
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 
198
199                 ENOMEDIUM       = 123, // No medium found 
200                 EMEDIUMTYPE     = 124, // Wrong medium type 
201         }
202
203         [Map][Flags]
204         public enum OpenFlags : int {
205                 //
206                 // One of these
207                 //
208                 O_RDONLY    = 0,
209                 O_WRONLY    = 1,
210                 O_RDWR      = 2,
211
212                 //
213                 // Or-ed with zero or more of these
214                 //
215                 O_CREAT     = 4,
216                 O_EXCL      = 8,
217                 O_NOCTTY    = 16,
218                 O_TRUNC     = 32,
219                 O_APPEND    = 64,
220                 O_NONBLOCK  = 128,
221                 O_SYNC      = 256,
222
223                 //
224                 // These are non-Posix.  Using them will result in errors/exceptions on
225                 // non-supported platforms.
226                 //
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.)
231                 //
232                 
233                 O_NOFOLLOW  = 512,
234                 O_DIRECTORY = 1024,
235                 O_DIRECT    = 2048,
236                 O_ASYNC     = 4096,
237                 O_LARGEFILE = 8192
238         }
239         
240         // mode_t
241         [Flags][Map]
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
255
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
262
263                 // Device types
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
273         }
274
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)
281         }
282
283         [Map]
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
301         }
302
303         [Map]
304         public enum LockType : short {
305                 F_RDLCK = 0, // Read lock.
306                 F_WRLCK = 1, // Write lock.
307                 F_UNLCK = 2, // Remove lock.
308         }
309
310         [Map]
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.
316
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
320         }
321         
322         [Map, Flags]
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
332         }
333
334         [Map]
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.
342         }
343
344         [Map]
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.
351         }
352
353         [Map]
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.
389                 SIGUNUSED = 31
390         }
391
392         [Map][Flags]
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
410         }
411
412         [Map][Flags]
413         public enum UmountFlags : int {
414                 MNT_FORCE  = 1, // Force unmount even if busy
415                 MNT_DETACH,     // Perform a lazy unmount.
416         }
417
418         [Flags][Map]
419         public enum WaitOptions : int {
420                 WNOHANG   = 1,  // Don't block waiting
421                 WUNTRACED = 2,  // Report status of stopped children
422         }
423
424   [Flags][Map]
425         public enum AccessMode : int {
426                 R_OK = 1,
427                 W_OK = 2,
428                 X_OK = 4,
429                 F_OK = 8,
430         }
431
432         [Map]
433         public enum PathConf : int {
434                 _PC_LINK_MAX,
435                 _PC_MAX_CANON,
436                 _PC_MAX_INPUT,
437                 _PC_NAME_MAX,
438                 _PC_PATH_MAX,
439                 _PC_PIPE_BUF,
440                 _PC_CHOWN_RESTRICTED,
441                 _PC_NO_TRUNC,
442                 _PC_VDISABLE,
443                 _PC_SYNC_IO,
444                 _PC_ASYNC_IO,
445                 _PC_PRIO_IO,
446                 _PC_SOCK_MAXBUF,
447                 _PC_FILESIZEBITS,
448                 _PC_REC_INCR_XFER_SIZE,
449                 _PC_REC_MAX_XFER_SIZE,
450                 _PC_REC_MIN_XFER_SIZE,
451                 _PC_REC_XFER_ALIGN,
452                 _PC_ALLOC_SIZE_MIN,
453                 _PC_SYMLINK_MAX,
454                 _PC_2_SYMLINKS
455         }
456
457         [Map]
458         public enum SysConf : int {
459                 _SC_ARG_MAX,
460                 _SC_CHILD_MAX,
461                 _SC_CLK_TCK,
462                 _SC_NGROUPS_MAX,
463                 _SC_OPEN_MAX,
464                 _SC_STREAM_MAX,
465                 _SC_TZNAME_MAX,
466                 _SC_JOB_CONTROL,
467                 _SC_SAVED_IDS,
468                 _SC_REALTIME_SIGNALS,
469                 _SC_PRIORITY_SCHEDULING,
470                 _SC_TIMERS,
471                 _SC_ASYNCHRONOUS_IO,
472                 _SC_PRIORITIZED_IO,
473                 _SC_SYNCHRONIZED_IO,
474                 _SC_FSYNC,
475                 _SC_MAPPED_FILES,
476                 _SC_MEMLOCK,
477                 _SC_MEMLOCK_RANGE,
478                 _SC_MEMORY_PROTECTION,
479                 _SC_MESSAGE_PASSING,
480                 _SC_SEMAPHORES,
481                 _SC_SHARED_MEMORY_OBJECTS,
482                 _SC_AIO_LISTIO_MAX,
483                 _SC_AIO_MAX,
484                 _SC_AIO_PRIO_DELTA_MAX,
485                 _SC_DELAYTIMER_MAX,
486                 _SC_MQ_OPEN_MAX,
487                 _SC_MQ_PRIO_MAX,
488                 _SC_VERSION,
489                 _SC_PAGESIZE,
490                 _SC_RTSIG_MAX,
491                 _SC_SEM_NSEMS_MAX,
492                 _SC_SEM_VALUE_MAX,
493                 _SC_SIGQUEUE_MAX,
494                 _SC_TIMER_MAX,
495                 /* Values for the argument to `sysconf'
496                          corresponding to _POSIX2_* symbols.  */
497                 _SC_BC_BASE_MAX,
498                 _SC_BC_DIM_MAX,
499                 _SC_BC_SCALE_MAX,
500                 _SC_BC_STRING_MAX,
501                 _SC_COLL_WEIGHTS_MAX,
502                 _SC_EQUIV_CLASS_MAX,
503                 _SC_EXPR_NEST_MAX,
504                 _SC_LINE_MAX,
505                 _SC_RE_DUP_MAX,
506                 _SC_CHARCLASS_NAME_MAX,
507                 _SC_2_VERSION,
508                 _SC_2_C_BIND,
509                 _SC_2_C_DEV,
510                 _SC_2_FORT_DEV,
511                 _SC_2_FORT_RUN,
512                 _SC_2_SW_DEV,
513                 _SC_2_LOCALEDEF,
514                 _SC_PII,
515                 _SC_PII_XTI,
516                 _SC_PII_SOCKET,
517                 _SC_PII_INTERNET,
518                 _SC_PII_OSI,
519                 _SC_POLL,
520                 _SC_SELECT,
521                 _SC_UIO_MAXIOV,
522                 _SC_IOV_MAX = _SC_UIO_MAXIOV,
523                 _SC_PII_INTERNET_STREAM,
524                 _SC_PII_INTERNET_DGRAM,
525                 _SC_PII_OSI_COTS,
526                 _SC_PII_OSI_CLTS,
527                 _SC_PII_OSI_M,
528                 _SC_T_IOV_MAX,
529                 /* Values according to POSIX 1003.1c (POSIX threads).  */
530                 _SC_THREADS,
531                 _SC_THREAD_SAFE_FUNCTIONS,
532                 _SC_GETGR_R_SIZE_MAX,
533                 _SC_GETPW_R_SIZE_MAX,
534                 _SC_LOGIN_NAME_MAX,
535                 _SC_TTY_NAME_MAX,
536                 _SC_THREAD_DESTRUCTOR_ITERATIONS,
537                 _SC_THREAD_KEYS_MAX,
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,
548                 _SC_PHYS_PAGES,
549                 _SC_AVPHYS_PAGES,
550                 _SC_ATEXIT_MAX,
551                 _SC_PASS_MAX,
552                 _SC_XOPEN_VERSION,
553                 _SC_XOPEN_XCU_VERSION,
554                 _SC_XOPEN_UNIX,
555                 _SC_XOPEN_CRYPT,
556                 _SC_XOPEN_ENH_I18N,
557                 _SC_XOPEN_SHM,
558                 _SC_2_CHAR_TERM,
559                 _SC_2_C_VERSION,
560                 _SC_2_UPE,
561                 _SC_XOPEN_XPG2,
562                 _SC_XOPEN_XPG3,
563                 _SC_XOPEN_XPG4,
564                 _SC_CHAR_BIT,
565                 _SC_CHAR_MAX,
566                 _SC_CHAR_MIN,
567                 _SC_INT_MAX,
568                 _SC_INT_MIN,
569                 _SC_LONG_BIT,
570                 _SC_WORD_BIT,
571                 _SC_MB_LEN_MAX,
572                 _SC_NZERO,
573                 _SC_SSIZE_MAX,
574                 _SC_SCHAR_MAX,
575                 _SC_SCHAR_MIN,
576                 _SC_SHRT_MAX,
577                 _SC_SHRT_MIN,
578                 _SC_UCHAR_MAX,
579                 _SC_UINT_MAX,
580                 _SC_ULONG_MAX,
581                 _SC_USHRT_MAX,
582                 _SC_NL_ARGMAX,
583                 _SC_NL_LANGMAX,
584                 _SC_NL_MSGMAX,
585                 _SC_NL_NMAX,
586                 _SC_NL_SETMAX,
587                 _SC_NL_TEXTMAX,
588                 _SC_XBS5_ILP32_OFF32,
589                 _SC_XBS5_ILP32_OFFBIG,
590                 _SC_XBS5_LP64_OFF64,
591                 _SC_XBS5_LPBIG_OFFBIG,
592                 _SC_XOPEN_LEGACY,
593                 _SC_XOPEN_REALTIME,
594                 _SC_XOPEN_REALTIME_THREADS,
595                 _SC_ADVISORY_INFO,
596                 _SC_BARRIERS,
597                 _SC_BASE,
598                 _SC_C_LANG_SUPPORT,
599                 _SC_C_LANG_SUPPORT_R,
600                 _SC_CLOCK_SELECTION,
601                 _SC_CPUTIME,
602                 _SC_THREAD_CPUTIME,
603                 _SC_DEVICE_IO,
604                 _SC_DEVICE_SPECIFIC,
605                 _SC_DEVICE_SPECIFIC_R,
606                 _SC_FD_MGMT,
607                 _SC_FIFO,
608                 _SC_PIPE,
609                 _SC_FILE_ATTRIBUTES,
610                 _SC_FILE_LOCKING,
611                 _SC_FILE_SYSTEM,
612                 _SC_MONOTONIC_CLOCK,
613                 _SC_MULTI_PROCESS,
614                 _SC_SINGLE_PROCESS,
615                 _SC_NETWORKING,
616                 _SC_READER_WRITER_LOCKS,
617                 _SC_SPIN_LOCKS,
618                 _SC_REGEXP,
619                 _SC_REGEX_VERSION,
620                 _SC_SHELL,
621                 _SC_SIGNALS,
622                 _SC_SPAWN,
623                 _SC_SPORADIC_SERVER,
624                 _SC_THREAD_SPORADIC_SERVER,
625                 _SC_SYSTEM_DATABASE,
626                 _SC_SYSTEM_DATABASE_R,
627                 _SC_TIMEOUTS,
628                 _SC_TYPED_MEMORY_OBJECTS,
629                 _SC_USER_GROUPS,
630                 _SC_USER_GROUPS_R,
631                 _SC_2_PBS,
632                 _SC_2_PBS_ACCOUNTING,
633                 _SC_2_PBS_LOCATE,
634                 _SC_2_PBS_MESSAGE,
635                 _SC_2_PBS_TRACK,
636                 _SC_SYMLOOP_MAX,
637                 _SC_STREAMS,
638                 _SC_2_PBS_CHECKPOINT,
639                 _SC_V6_ILP32_OFF32,
640                 _SC_V6_ILP32_OFFBIG,
641                 _SC_V6_LP64_OFF64,
642                 _SC_V6_LPBIG_OFFBIG,
643                 _SC_HOST_NAME_MAX,
644                 _SC_TRACE,
645                 _SC_TRACE_EVENT_FILTER,
646                 _SC_TRACE_INHERIT,
647                 _SC_TRACE_LOG,
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
663         }
664
665         [Map]
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,
672                 _CS_LFS_LDFLAGS,
673                 _CS_LFS_LIBS,
674                 _CS_LFS_LINTFLAGS,
675                 _CS_LFS64_CFLAGS,
676                 _CS_LFS64_LDFLAGS,
677                 _CS_LFS64_LIBS,
678                 _CS_LFS64_LINTFLAGS,
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
711         }
712
713         [Map]
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.
719         }
720
721         [Map][Flags]
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
734         }
735
736         [StructLayout(LayoutKind.Sequential)]
737         public struct Pollfd {
738                 public int fd;
739                 public PollEvents events;
740                 public PollEvents revents;
741         }
742
743         public class Dirent
744         {
745                 public /* ino_t */ ulong  d_ino;
746                 public /* off_t */ long   d_off;
747                 public ushort             d_reclen;
748                 public byte               d_type;
749                 public string             d_name;
750
751                 public override string ToString ()
752                 {
753                         return d_name;
754                 }
755         }
756
757         public class Group
758         {
759                 public string           gr_name;
760                 public string           gr_passwd;
761                 public /* gid_t */ uint gr_gid;
762                 public string[]         gr_mem;
763
764                 // Generate string in /etc/group format
765                 public override string ToString ()
766                 {
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 ();
771                 }
772
773                 private static void GetMembers (StringBuilder sb, string[] members)
774                 {
775                         if (members.Length > 0)
776                                 sb.Append (members[0]);
777                         for (int i = 1; i < members.Length; ++i) {
778                                 sb.Append (",");
779                                 sb.Append (members[i]);
780                         }
781                 }
782         }
783
784         public class Passwd
785         {
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;
793
794                 // Generate string in /etc/passwd format
795                 public override string ToString ()
796                 {
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);
799                 }
800         }
801
802         public struct Stat {
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
817         }
818
819         public struct Timeval {
820                 public  /* time_t */      long    tv_sec;   // seconds
821                 public  /* suseconds_t */ long    tv_usec;  // microseconds
822         }
823
824         public struct Timezone {
825                 public  int tz_minuteswest; // minutes W of Greenwich
826                 private int tz_dsttime;     // type of dst correction (OBSOLETE)
827         }
828
829         public struct Utimbuf {
830                 public  /* time_t */      long    actime;   // access time
831                 public  /* time_t */      long    modtime;  // modification time
832         }
833
834         //
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.
837         //
838         // For example, the man page should be similar to:
839         //
840         //    CONFORMING TO (or CONFORMS TO)
841         //           XPG2, SUSv2, POSIX, etc.
842         //
843         // BSD- and GNU-specific exports can also be placed here.
844         //
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.
859         //
860         public sealed class Syscall : Stdlib
861         {
862                 private const string LIBC = "libc";
863                 private const string MPH = "MonoPosixHelper";
864                 private const string CRYPT = "crypt";
865
866                 private Syscall () {}
867
868                 //
869                 // <aio.h>
870                 //
871
872                 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3), 
873                 // aio_return(3), aio_suspend(3), aio_write(3)
874                 //
875                 // Then update PosixStream.BeginRead to use the aio* functions.
876
877                 //
878                 // <dirent.h>
879                 //
880
881                 [DllImport (LIBC, SetLastError=true)]
882                 public static extern IntPtr opendir (string name);
883
884                 [DllImport (LIBC, SetLastError=true)]
885                 public static extern int closedir (IntPtr dir);
886
887                 // seekdir(3):
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);
893
894                 // telldir(3)
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);
899
900                 [DllImport (LIBC, SetLastError=true)]
901                 public static extern void rewinddir (IntPtr dir);
902
903                 private struct _Dirent {
904                         public /* ino_t */ ulong  d_ino;
905                         public /* off_t */ long   d_off;
906                         public ushort             d_reclen;
907                         public byte               d_type;
908                         public IntPtr             d_name;
909                 }
910
911                 private static void CopyDirent (Dirent to, ref _Dirent from)
912                 {
913                         try {
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);
920                                 else 
921                                         to.d_name = null;
922                         }
923                         finally {
924                                 Stdlib.free (from.d_name);
925                                 from.d_name = IntPtr.Zero;
926                         }
927                 }
928
929                 [DllImport (MPH, SetLastError=true,
930                                 EntryPoint="Mono_Posix_Syscall_readdir")]
931                 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
932
933                 public static Dirent readdir (IntPtr dir)
934                 {
935                         _Dirent dentry;
936                         int r = sys_readdir (dir, out dentry);
937                         if (r != 0)
938                                 return null;
939                         Dirent d = new Dirent ();
940                         CopyDirent (d, ref dentry);
941                         return d;
942                 }
943
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);
947
948                 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
949                 {
950                         entry.d_ino    = 0;
951                         entry.d_off    = 0;
952                         entry.d_reclen = 0;
953                         entry.d_type   = 0;
954                         entry.d_name   = null;
955
956                         _Dirent _d;
957                         int r = sys_readdir_r (dirp, out _d, out result);
958
959                         if (r == 0 && result != IntPtr.Zero) {
960                                 CopyDirent (entry, ref _d);
961                         }
962
963                         return r;
964                 }
965
966                 [DllImport (LIBC, SetLastError=true)]
967                 public static extern int dirfd (IntPtr dir);
968
969                 //
970                 // <errno.h>
971                 //
972
973                 public static Error GetLastError ()
974                 {
975                         int errno = Marshal.GetLastWin32Error ();
976                         return PosixConvert.ToError (errno);
977                 }
978
979                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_SetLastError")]
980                 private static extern void SetLastError (int error);
981
982                 public static void SetLastError (Error error)
983                 {
984                         int _error = PosixConvert.FromError (error);
985                         SetLastError (_error);
986                 }
987
988                 // strerror_r(3)
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);
994
995                 public static int strerror_r (Error errnum, StringBuilder buf, ulong n)
996                 {
997                         int e = PosixConvert.FromError (errnum);
998                         return sys_strerror_r (e, buf, n);
999                 }
1000
1001                 public static int strerror_r (Error errnum, StringBuilder buf)
1002                 {
1003                         return strerror_r (errnum, buf, (ulong) buf.Capacity);
1004                 }
1005
1006                 public static string strerror_r (Error errnum)
1007                 {
1008                         StringBuilder buf = new StringBuilder (16);
1009                         int r = 0;
1010                         do {
1011                                 buf.Capacity *= 2;
1012                                 r = strerror_r (errnum, buf);
1013                         } while (r == -1 && GetLastError() == Error.ERANGE);
1014
1015                         if (r == -1)
1016                                 return "** Unknown error code: " + ((int) errnum) + "**";
1017                         return buf.ToString();
1018                 }
1019
1020                 //
1021                 // <fcntl.h>
1022                 //
1023                 [DllImport (MPH, SetLastError=true, 
1024                                 EntryPoint="Mono_Posix_Syscall_fcntl")]
1025                 public static extern int fcntl (int fd, FcntlCommand cmd);
1026
1027                 [DllImport (MPH, SetLastError=true, 
1028                                 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
1029                 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
1030
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);
1034
1035                 [DllImport (MPH, SetLastError=true, 
1036                                 EntryPoint="Mono_Posix_Syscall_open")]
1037                 public static extern int open (string pathname, OpenFlags flags);
1038
1039                 [DllImport (MPH, SetLastError=true, 
1040                                 EntryPoint="Mono_Posix_Syscall_open_mode")]
1041                 public static extern int open (string pathname, OpenFlags flags, FilePermissions mode);
1042
1043                 [DllImport (MPH, SetLastError=true, 
1044                                 EntryPoint="Mono_Posix_Syscall_creat")]
1045                 public static extern int creat (string pathname, FilePermissions mode);
1046
1047                 // posix_fadvise(2)
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);
1053
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);
1059
1060                 //
1061                 // <grp.h>
1062                 //
1063
1064                 // setgroups(2)
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);
1069
1070                 public static int setgroups (uint [] list)
1071                 {
1072                         return setgroups ((ulong) list.Length, list);
1073                 }
1074
1075                 private struct _Group
1076                 {
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_;
1083                 }
1084
1085                 private static void CopyGroup (Group to, ref _Group from)
1086                 {
1087                         try {
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);
1092                         }
1093                         finally {
1094                                 Stdlib.free (from.gr_mem);
1095                                 Stdlib.free (from._gr_buf_);
1096                                 from.gr_mem   = IntPtr.Zero;
1097                                 from._gr_buf_ = IntPtr.Zero;
1098                         }
1099                 }
1100
1101                 [DllImport (MPH, SetLastError=true,
1102                                 EntryPoint="Mono_Posix_Syscall_getgrnam")]
1103                 private static extern int sys_getgrnam (string name, out _Group group);
1104
1105                 public static Group getgrnam (string name)
1106                 {
1107                         _Group group;
1108                         int r = sys_getgrnam (name, out group);
1109                         if (r != 0)
1110                                 return null;
1111                         Group gr = new Group ();
1112                         CopyGroup (gr, ref group);
1113                         return gr;
1114                 }
1115
1116                 // getgrgid(3)
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);
1121
1122                 public static Group getgrgid (uint uid)
1123                 {
1124                         _Group group;
1125                         int r = sys_getgrgid (uid, out group);
1126                         if (r != 0)
1127                                 return null;
1128                         Group gr = new Group ();
1129                         CopyGroup (gr, ref group);
1130                         return gr;
1131                 }
1132
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);
1136
1137                 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
1138                 {
1139                         grbufp = null;
1140                         _Group group;
1141                         IntPtr _grbufp;
1142                         int r = sys_getgrnam_r (name, out group, out _grbufp);
1143                         if (r == 0 && _grbufp != IntPtr.Zero) {
1144                                 CopyGroup (grbuf, ref group);
1145                                 grbufp = grbuf;
1146                         }
1147                         return r;
1148                 }
1149
1150                 // getgrgid_r(3)
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);
1156
1157                 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
1158                 {
1159                         grbufp = null;
1160                         _Group group;
1161                         IntPtr _grbufp;
1162                         int r = sys_getgrgid_r (uid, out group, out _grbufp);
1163                         if (r == 0 && _grbufp != IntPtr.Zero) {
1164                                 CopyGroup (grbuf, ref group);
1165                                 grbufp = grbuf;
1166                         }
1167                         return r;
1168                 }
1169
1170                 [DllImport (MPH, SetLastError=true,
1171                                 EntryPoint="Mono_Posix_Syscall_getgrent")]
1172                 private static extern int sys_getgrent (out _Group grbuf);
1173
1174                 public static Group getgrent ()
1175                 {
1176                         _Group group;
1177                         int r = sys_getgrent (out group);
1178                         if (r != 0)
1179                                 return null;
1180                         Group gr = new Group();
1181                         CopyGroup (gr, ref group);
1182                         return gr;
1183                 }
1184
1185                 [DllImport (LIBC, SetLastError=true)]
1186                 public static extern void setgrent ();
1187
1188                 [DllImport (LIBC, SetLastError=true)]
1189                 public static extern void endgrent ();
1190
1191                 [DllImport (MPH, SetLastError=true,
1192                                 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
1193                 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
1194
1195                 public static Group fgetgrent (IntPtr stream)
1196                 {
1197                         _Group group;
1198                         int r = sys_fgetgrent (stream, out group);
1199                         if (r != 0)
1200                                 return null;
1201                         Group gr = new Group ();
1202                         CopyGroup (gr, ref group);
1203                         return gr;
1204                 }
1205
1206                 //
1207                 // <pwd.h>
1208                 //
1209                 private struct _Passwd
1210                 {
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_;
1219                 }
1220
1221                 private static void CopyPasswd (Passwd to, ref _Passwd from)
1222                 {
1223                         try {
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);
1231                         }
1232                         finally {
1233                                 Stdlib.free (from._pw_buf_);
1234                                 from._pw_buf_ = IntPtr.Zero;
1235                         }
1236                 }
1237
1238                 [DllImport (MPH, SetLastError=true,
1239                                 EntryPoint="Mono_Posix_Syscall_getpwnam")]
1240                 private static extern int sys_getpwnam (string name, out _Passwd passwd);
1241
1242                 public static Passwd getpwnam (string name)
1243                 {
1244                         _Passwd passwd;
1245                         int r = sys_getpwnam (name, out passwd);
1246                         if (r != 0)
1247                                 return null;
1248                         Passwd pw = new Passwd ();
1249                         CopyPasswd (pw, ref passwd);
1250                         return pw;
1251                 }
1252
1253                 // getpwuid(3)
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);
1258
1259                 public static Passwd getpwuid (uint uid)
1260                 {
1261                         _Passwd passwd;
1262                         int r = sys_getpwuid (uid, out passwd);
1263                         if (r != 0)
1264                                 return null;
1265                         Passwd pw = new Passwd ();
1266                         CopyPasswd (pw, ref passwd);
1267                         return pw;
1268                 }
1269
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);
1273
1274                 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
1275                 {
1276                         pwbufp = null;
1277                         _Passwd passwd;
1278                         IntPtr _pwbufp;
1279                         int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
1280                         if (r == 0 && _pwbufp != IntPtr.Zero) {
1281                                 CopyPasswd (pwbuf, ref passwd);
1282                                 pwbufp = pwbuf;
1283                         }
1284                         return r;
1285                 }
1286
1287                 // getpwuid_r(3)
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);
1293
1294                 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
1295                 {
1296                         pwbufp = null;
1297                         _Passwd passwd;
1298                         IntPtr _pwbufp;
1299                         int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
1300                         if (r == 0 && _pwbufp != IntPtr.Zero) {
1301                                 CopyPasswd (pwbuf, ref passwd);
1302                                 pwbufp = pwbuf;
1303                         }
1304                         return r;
1305                 }
1306
1307                 [DllImport (MPH, SetLastError=true,
1308                                 EntryPoint="Mono_Posix_Syscall_getpwent")]
1309                 private static extern int sys_getpwent (out _Passwd pwbuf);
1310
1311                 public static Passwd getpwent ()
1312                 {
1313                         _Passwd passwd;
1314                         int r = sys_getpwent (out passwd);
1315                         if (r != 0)
1316                                 return null;
1317                         Passwd pw = new Passwd ();
1318                         CopyPasswd (pw, ref passwd);
1319                         return pw;
1320                 }
1321
1322                 [DllImport (LIBC, SetLastError=true)]
1323                 public static extern void setpwent ();
1324
1325                 [DllImport (LIBC, SetLastError=true)]
1326                 public static extern void endpwent ();
1327
1328                 [DllImport (MPH, SetLastError=true,
1329                                 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
1330                 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
1331
1332                 public static Passwd fgetpwent (IntPtr stream)
1333                 {
1334                         _Passwd passwd;
1335                         int r = sys_fgetpwent (stream, out passwd);
1336                         if (r != 0)
1337                                 return null;
1338                         Passwd pw = new Passwd ();
1339                         CopyPasswd (pw, ref passwd);
1340                         return pw;
1341                 }
1342
1343                 //
1344                 // <signal.h>
1345                 //
1346                 [DllImport (LIBC, SetLastError=true)]
1347                 private static extern void psignal (int sig, string s);
1348
1349                 public static void psignal (Signum sig, string s)
1350                 {
1351                         int signum = PosixConvert.FromSignum (sig);
1352                         psignal (signum, s);
1353                 }
1354
1355                 // kill(2)
1356                 //    int kill(pid_t pid, int sig);
1357                 [DllImport (LIBC, SetLastError=true)]
1358                 private static extern int sys_kill (int pid, int sig);
1359
1360                 public static int kill (int pid, Signum sig)
1361                 {
1362                         int _sig = PosixConvert.FromSignum (sig);
1363                         return sys_kill (pid, _sig);
1364                 }
1365
1366                 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
1367                 private static extern IntPtr sys_strsignal (int sig);
1368
1369                 public static IntPtr sys_strsignal (Signum sig)
1370                 {
1371                         int s = PosixConvert.FromSignum (sig);
1372                         return sys_strsignal (s);
1373                 }
1374
1375                 public static string strsignal (Signum sig)
1376                 {
1377                         IntPtr r = sys_strsignal (sig);
1378                         return PosixMarshal.PtrToString (r);
1379                 }
1380
1381                 // TODO: sigaction(2)
1382                 // TODO: sigsuspend(2)
1383                 // TODO: sigpending(2)
1384
1385
1386                 //
1387                 // <stdio.h>
1388                 //
1389                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
1390                 private static extern int _L_ctermid ();
1391
1392                 public static readonly int L_ctermid = _L_ctermid ();
1393
1394                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
1395                 private static extern int _L_cuserid ();
1396
1397                 public static readonly int L_cuserid = _L_cuserid ();
1398
1399                 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
1400                 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
1401
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)
1405                 {
1406                         if (@string.Capacity < L_cuserid) {
1407                                 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
1408                         }
1409                         IntPtr r = sys_cuserid (@string);
1410                         return PosixMarshal.PtrToString (r);
1411                 }
1412
1413                 //
1414                 // <stdlib.h>
1415                 //
1416                 [DllImport (LIBC, SetLastError=true)]
1417                 public static extern int ttyslot ();
1418
1419                 [DllImport (CRYPT, SetLastError=true)]
1420                 public static extern void setkey (string key);
1421
1422                 //
1423                 // <sys/mman.h>
1424                 //
1425
1426                 // posix_madvise(P)
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);
1432
1433                 //
1434                 // <sys/mount.h>
1435                 //
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);
1440
1441                 [DllImport (MPH, SetLastError=true, 
1442                                 EntryPoint="Mono_Posix_Syscall_umount")]
1443                 public static extern int umount (string target);
1444
1445                 [DllImport (MPH, SetLastError=true, 
1446                                 EntryPoint="Mono_Posix_Syscall_umount2")]
1447                 private static extern int sys_umount2 (string target, int flags);
1448
1449                 public static int umount2 (string target, UmountFlags flags)
1450                 {
1451                         int _flags = PosixConvert.FromUmountFlags (flags);
1452                         return sys_umount2 (target, _flags);
1453                 }
1454
1455                 //
1456                 // <sys/poll.h>
1457                 //
1458                 private struct _pollfd {
1459                         public int fd;
1460                         public short events;
1461                         public short revents;
1462                 }
1463
1464                 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
1465                 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
1466
1467                 public static int poll (Pollfd [] fds, uint nfds, int timeout)
1468                 {
1469                         if (fds.Length < nfds)
1470                                 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
1471
1472                         _pollfd[] send = new _pollfd[nfds];
1473
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);
1477                         }
1478
1479                         int r = sys_poll (send, nfds, timeout);
1480
1481                         for (int i = 0; i < send.Length; i++) {
1482                                 fds [i].revents = PosixConvert.ToPollEvents (send [i].revents);
1483                         }
1484
1485                         return r;
1486                 }
1487
1488                 public static int poll (Pollfd [] fds, int timeout)
1489                 {
1490                         return poll (fds, (uint) fds.Length, timeout);
1491                 }
1492
1493                 //
1494                 // <sys/ptrace.h>
1495                 //
1496
1497                 // TODO: ptrace(2)
1498
1499                 //
1500                 // <sys/resource.h>
1501                 //
1502
1503                 // TODO: setrlimit(2)
1504                 // TODO: getrlimit(2)
1505                 // TODO: getrusage(2)
1506
1507                 //
1508                 // <sys/sendfile.h>
1509                 //
1510
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);
1515
1516                 //
1517                 // <sys/stat.h>
1518                 //
1519                 [DllImport (MPH, SetLastError=true, 
1520                                 EntryPoint="Mono_Posix_Syscall_stat")]
1521                 public static extern int stat (string file_name, out Stat buf);
1522
1523                 [DllImport (MPH, SetLastError=true, 
1524                                 EntryPoint="Mono_Posix_Syscall_fstat")]
1525                 public static extern int fstat (int filedes, out Stat buf);
1526
1527                 [DllImport (MPH, SetLastError=true, 
1528                                 EntryPoint="Mono_Posix_Syscall_lstat")]
1529                 public static extern int lstat (string file_name, out Stat buf);
1530
1531                 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
1532                 private static extern int sys_chmod (string path, uint mode);
1533
1534                 public static int chmod (string path, FilePermissions mode)
1535                 {
1536                         uint _mode = PosixConvert.FromFilePermissions (mode);
1537                         return sys_chmod (path, _mode);
1538                 }
1539
1540                 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
1541                 private static extern int sys_fchmod (int filedes, uint mode);
1542
1543                 public static int fchmod (int filedes, FilePermissions mode)
1544                 {
1545                         uint _mode = PosixConvert.FromFilePermissions (mode);
1546                         return sys_fchmod (filedes, _mode);
1547                 }
1548
1549                 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
1550                 private static extern int sys_umask (uint mask);
1551
1552                 public static int umask (FilePermissions mask)
1553                 {
1554                         uint _mask = PosixConvert.FromFilePermissions (mask);
1555                         return sys_umask (_mask);
1556                 }
1557
1558                 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
1559                 public static extern int sys_mkdir (string oldpath, uint mode);
1560
1561                 public static int mkdir (string oldpath, FilePermissions mode)
1562                 {
1563                         uint _mode = PosixConvert.FromFilePermissions (mode);
1564                         return sys_mkdir (oldpath, _mode);
1565                 }
1566
1567                 // mknod(2)
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);
1572
1573                 //
1574                 // <sys/time.h>
1575                 //
1576
1577                 [DllImport (MPH, SetLastError=true, 
1578                                 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1579                 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
1580
1581                 [DllImport (MPH, SetLastError=true,
1582                                 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1583                 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
1584
1585                 public static int gettimeofday (out Timeval tv)
1586                 {
1587                         return gettimeofday (out tv, IntPtr.Zero);
1588                 }
1589
1590                 [DllImport (MPH, SetLastError=true,
1591                                 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1592                 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
1593
1594                 public static int gettimeofday (out Timezone tz)
1595                 {
1596                         return gettimeofday (IntPtr.Zero, out tz);
1597                 }
1598
1599                 [DllImport (MPH, SetLastError=true,
1600                                 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1601                 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
1602
1603                 [DllImport (MPH, SetLastError=true,
1604                                 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1605                 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
1606
1607                 public static int settimeofday (ref Timeval tv)
1608                 {
1609                         return settimeofday (ref tv, IntPtr.Zero);
1610                 }
1611
1612                 //
1613                 // <sys/timeb.h>
1614                 //
1615
1616                 // TODO: ftime(3)
1617
1618                 //
1619                 // <sys/times.h>
1620                 //
1621
1622                 // TODO: times(2)
1623
1624                 //
1625                 // <sys/wait.h>
1626                 //
1627
1628                 // wait(2)
1629                 //    pid_t wait(int *status);
1630                 [DllImport (LIBC, SetLastError=true)]
1631                 public static extern int wait (out int status);
1632
1633                 // waitpid(2)
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);
1637
1638                 public static int waitpid (int pid, out int status, WaitOptions options)
1639                 {
1640                         int _options = PosixConvert.FromWaitOptions (options);
1641                         return waitpid (pid, out status, _options);
1642                 }
1643
1644                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
1645                 private static extern int _WIFEXITED (int status);
1646
1647                 public static bool WIFEXITED (int status)
1648                 {
1649                         return _WIFEXITED (status) != 0;
1650                 }
1651
1652                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
1653                 public static extern int WEXITSTATUS (int status);
1654
1655                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
1656                 private static extern int _WIFSIGNALED (int status);
1657
1658                 public static bool WIFSIGNALED (int status)
1659                 {
1660                         return _WIFSIGNALED (status) != 0;
1661                 }
1662
1663                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
1664                 private static extern int _WTERMSIG (int status);
1665
1666                 public static Signum WTERMSIG (int status)
1667                 {
1668                         int r = _WTERMSIG (status);
1669                         return PosixConvert.ToSignum (r);
1670                 }
1671
1672                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
1673                 private static extern int _WIFSTOPPED (int status);
1674
1675                 public static bool WIFSTOPPED (int status)
1676                 {
1677                         return _WIFSTOPPED (status) != 0;
1678                 }
1679
1680                 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
1681                 private static extern int _WSTOPSIG (int status);
1682
1683                 public static Signum WSTOPSIG (int status)
1684                 {
1685                         int r = _WSTOPSIG (status);
1686                         return PosixConvert.ToSignum (r);
1687                 }
1688
1689                 //
1690                 // <termios.h>
1691                 //
1692
1693                 //
1694                 // <time.h>
1695                 //
1696
1697                 // stime(2)
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);
1702
1703                 // time(2)
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);
1708
1709                 //
1710                 // <ulimit.h>
1711                 //
1712
1713                 // TODO: ulimit(3)
1714
1715                 //
1716                 // <unistd.h>
1717                 //
1718                 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
1719                 private static extern int sys_access (string pathname, int mode);
1720
1721                 public static int access (string pathname, AccessMode mode)
1722                 {
1723                         int _mode = PosixConvert.FromAccessMode (mode);
1724                         return sys_access (pathname, _mode);
1725                 }
1726
1727                 // lseek(2)
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);
1732
1733     [DllImport (LIBC, SetLastError=true)]
1734                 public static extern int close (int fd);
1735
1736                 // read(2)
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);
1741
1742                 public static unsafe long read (int fd, void *buf, ulong count)
1743                 {
1744                         return read (fd, (IntPtr) buf, count);
1745                 }
1746
1747                 // write(2)
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);
1752
1753                 public static unsafe long write (int fd, void *buf, ulong count)
1754                 {
1755                         return write (fd, (IntPtr) buf, count);
1756                 }
1757
1758                 // pread(2)
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);
1763
1764                 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
1765                 {
1766                         return pread (fd, (IntPtr) buf, count, offset);
1767                 }
1768
1769                 // pwrite(2)
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);
1774
1775                 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
1776                 {
1777                         return pwrite (fd, (IntPtr) buf, count, offset);
1778                 }
1779
1780                 [DllImport (MPH, SetLastError=true, 
1781                                 EntryPoint="Mono_Posix_Syscall_pipe")]
1782                 public static extern int pipe (out int reading, out int writing);
1783
1784                 public static int pipe (int[] filedes)
1785                 {
1786                         if (filedes == null || filedes.Length != 2) {
1787                                 // TODO: set errno
1788                                 return -1;
1789                         }
1790                         int reading, writing;
1791                         int r = pipe (out reading, out writing);
1792                         filedes[0] = reading;
1793                         filedes[1] = writing;
1794                         return r;
1795                 }
1796
1797                 [DllImport (LIBC, SetLastError=true)]
1798                 public static extern uint alarm (uint seconds);
1799
1800                 [DllImport (LIBC, SetLastError=true)]
1801                 public static extern int sleep (uint seconds);
1802
1803                 [DllImport (LIBC, SetLastError=true)]
1804                 public static extern uint ualarm (uint usecs, uint interval);
1805
1806                 [DllImport (LIBC, SetLastError=true)]
1807                 public static extern int pause ();
1808
1809                 // chown(2)
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);
1813
1814                 // fchown(2)
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);
1818
1819                 // lchown(2)
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);
1823
1824                 [DllImport (LIBC, SetLastError=true)]
1825                 public static extern int chdir (string path);
1826
1827                 [DllImport (LIBC, SetLastError=true)]
1828                 public static extern int fchdir (int fd);
1829
1830                 // getcwd(3)
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);
1835
1836                 public static StringBuilder getcwd (StringBuilder buf)
1837                 {
1838                         getcwd (buf, (ulong) buf.Capacity);
1839                         return buf;
1840                 }
1841
1842                 // getwd(2) is deprecated; don't expose it.
1843
1844                 [DllImport (LIBC, SetLastError=true)]
1845                 public static extern int dup (int fd);
1846
1847                 [DllImport (LIBC, SetLastError=true)]
1848                 public static extern int dup2 (int fd, int fd2);
1849
1850                 // TODO: does Mono marshal arrays properly?
1851                 [DllImport (LIBC, SetLastError=true)]
1852                 public static extern int execve (string path, string[] argv, string[] envp);
1853
1854                 [DllImport (LIBC, SetLastError=true)]
1855                 public static extern int execv (string path, string[] argv);
1856
1857                 // TODO: execle, execl
1858                 [DllImport (LIBC, SetLastError=true)]
1859                 public static extern int execvp (string path, string[] argv);
1860
1861                 [DllImport (LIBC, SetLastError=true)]
1862                 public static extern int nice (int inc);
1863
1864                 [DllImport (LIBC, SetLastError=true)]
1865                 public static extern int _exit (int status);
1866
1867                 [DllImport (MPH, SetLastError=true,
1868                                 EntryPoint="Mono_Posix_Syscall_fpathconf")]
1869                 public static extern long fpathconf (int filedes, PathConf name);
1870
1871                 [DllImport (MPH, SetLastError=true,
1872                                 EntryPoint="Mono_Posix_Syscall_pathconf")]
1873                 public static extern long pathconf (string path, PathConf name);
1874
1875                 [DllImport (MPH, SetLastError=true,
1876                                 EntryPoint="Mono_Posix_Syscall_sysconf")]
1877                 public static extern long sysconf (SysConf name);
1878
1879                 // confstr(3)
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);
1884
1885                 // getpid(2)
1886                 //    pid_t getpid(void);
1887                 [DllImport (LIBC, SetLastError=true)]
1888                 public static extern int getpid ();
1889
1890                 // setpgid(2)
1891                 //    int setpgid(pid_t pid, pid_t pgid);
1892                 [DllImport (LIBC, SetLastError=true)]
1893                 public static extern int setpgid (int pid, int pgid);
1894
1895                 // getpgid(2)
1896                 //    pid_t getpgid(pid_t pid);
1897                 [DllImport (LIBC, SetLastError=true)]
1898                 public static extern int getpgid (int pid);
1899
1900                 [DllImport (LIBC, SetLastError=true)]
1901                 public static extern int setpgrp ();
1902
1903                 // getpgrp(2)
1904                 //    pid_t getpgrp(void);
1905                 [DllImport (LIBC, SetLastError=true)]
1906                 public static extern int getpgrp ();
1907
1908                 // setsid(2)
1909                 //    pid_t setsid(void);
1910                 [DllImport (LIBC, SetLastError=true)]
1911                 public static extern int setsid ();
1912
1913                 // getsid(2)
1914                 //    pid_t getsid(pid_t pid);
1915                 [DllImport (LIBC, SetLastError=true)]
1916                 public static extern int getsid (int pid);
1917
1918                 // getuid(2)
1919                 //    uid_t getuid(void);
1920                 [DllImport (LIBC, SetLastError=true)]
1921                 public static extern uint getuid ();
1922
1923                 // geteuid(2)
1924                 //    uid_t geteuid(void);
1925                 [DllImport (LIBC, SetLastError=true)]
1926                 public static extern uint geteuid ();
1927
1928                 // getgid(2)
1929                 //    gid_t getgid(void);
1930                 [DllImport (LIBC, SetLastError=true)]
1931                 public static extern uint getgid ();
1932
1933                 // getegid(2)
1934                 //    gid_t getgid(void);
1935                 [DllImport (LIBC, SetLastError=true)]
1936                 public static extern uint getegid ();
1937
1938                 // getgroups(2)
1939                 //    int getgroups(int size, gid_t list[]);
1940                 [DllImport (LIBC, SetLastError=true)]
1941                 public static extern int getgroups (int size, uint[] list);
1942
1943                 public static int getgroups (uint[] list)
1944                 {
1945                         return getgroups (list.Length, list);
1946                 }
1947
1948                 // setuid(2)
1949                 //    int setuid(uid_t uid);
1950                 [DllImport (LIBC, SetLastError=true)]
1951                 public static extern int setuid (uint uid);
1952
1953                 // setreuid(2)
1954                 //    int setreuid(uid_t ruid, uid_t euid);
1955                 [DllImport (LIBC, SetLastError=true)]
1956                 public static extern int setreuid (uint ruid, uint euid);
1957
1958                 // setregid(2)
1959                 //    int setregid(gid_t ruid, gid_t euid);
1960                 [DllImport (LIBC, SetLastError=true)]
1961                 public static extern int setregid (uint rgid, uint egid);
1962
1963                 // seteuid(2)
1964                 //    int seteuid(uid_t euid);
1965                 [DllImport (LIBC, SetLastError=true)]
1966                 public static extern int seteuid (uint euid);
1967
1968                 // setegid(2)
1969                 //    int setegid(gid_t euid);
1970                 [DllImport (LIBC, SetLastError=true)]
1971                 public static extern int setegid (uint uid);
1972
1973                 // setgid(2)
1974                 //    int setgid(gid_t gid);
1975                 [DllImport (LIBC, SetLastError=true)]
1976                 public static extern int setgid (uint gid);
1977
1978                 // getresuid(2)
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);
1982
1983                 // getresgid(2)
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);
1987
1988                 // setresuid(2)
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);
1992
1993                 // setresgid(2)
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);
1997
1998                 // fork(2)
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 ();
2004
2005                 // vfork(2)
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 ();
2011
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);
2015
2016                 [Obsolete ("Not re-entrant.  Use ttyname_r instead.")]
2017                 public static string ttyname (int fd)
2018                 {
2019                         IntPtr r = sys_ttyname (fd);
2020                         return PosixMarshal.PtrToString (r);
2021                 }
2022
2023                 // ttyname_r(3)
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);
2028
2029                 public static int ttyname_r (int fd, StringBuilder buf)
2030                 {
2031                         return ttyname_r (fd, buf, (ulong) buf.Capacity);
2032                 }
2033
2034                 [DllImport (LIBC, EntryPoint="isatty")]
2035                 private static extern int sys_isatty (int fd);
2036
2037                 public static bool isatty (int fd)
2038                 {
2039                         return sys_isatty (fd) == 1;
2040                 }
2041
2042                 [DllImport (LIBC, SetLastError=true)]
2043                 public static extern int link (string oldpath, string newpath);
2044
2045                 [DllImport (LIBC, SetLastError=true)]
2046                 public static extern int symlink (string oldpath, string newpath);
2047
2048                 // readlink(2)
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);
2053
2054                 public static int readlink (string path, [Out] StringBuilder buf)
2055                 {
2056                         return readlink (path, buf, (ulong) buf.Capacity);
2057                 }
2058
2059                 [DllImport (LIBC, SetLastError=true)]
2060                 public static extern int unlink (string pathname);
2061
2062                 [DllImport (LIBC, SetLastError=true)]
2063                 public static extern int rmdir (string pathname);
2064
2065                 // tcgetpgrp(3)
2066                 //    pid_t tcgetpgrp(int fd);
2067                 [DllImport (LIBC, SetLastError=true)]
2068                 public static extern int tcgetpgrp (int fd);
2069
2070                 // tcsetpgrp(3)
2071                 //    int tcsetpgrp(int fd, pid_t pgrp);
2072                 [DllImport (LIBC, SetLastError=true)]
2073                 public static extern int tcsetpgrp (int fd, int pgrp);
2074
2075                 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
2076                 [Obsolete ("Not re-entrant.  Use getlogin_r instead.")]
2077                 public static extern IntPtr sys_getlogin ();
2078
2079                 [Obsolete ("Not re-entrant.  Use getlogin_r instead.")]
2080                 public static string getlogin ()
2081                 {
2082                         IntPtr r = sys_getlogin ();
2083                         return PosixMarshal.PtrToString (r);
2084                 }
2085
2086                 // getlogin_r(3)
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);
2091
2092                 public static int getlogin_r (StringBuilder name)
2093                 {
2094                         return getlogin_r (name, (ulong) name.Capacity);
2095                 }
2096
2097                 // gethostname(2)
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);
2102
2103                 public static int gethostname (StringBuilder name)
2104                 {
2105                         return gethostname (name, (ulong) name.Capacity);
2106                 }
2107
2108                 // sethostname(2)
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);
2113
2114                 public static int sethostname (string name)
2115                 {
2116                         return sethostname (name, (ulong) name.Length);
2117                 }
2118
2119                 [DllImport (MPH, SetLastError=true,
2120                                 EntryPoint="Mono_Posix_Syscall_gethostid")]
2121                 public static extern long gethostid ();
2122
2123                 [DllImport (MPH, SetLastError=true,
2124                                 EntryPoint="Mono_Posix_Syscall_sethostid")]
2125                 public static extern int sethostid (long hostid);
2126
2127                 // getdomainname(2)
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);
2132
2133                 public static int getdomainname (StringBuilder name)
2134                 {
2135                         return getdomainname (name, (ulong) name.Capacity);
2136                 }
2137
2138                 // setdomainname(2)
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);
2143
2144                 public static int setdomainname (string name)
2145                 {
2146                         return setdomainname (name, (ulong) name.Length);
2147                 }
2148
2149                 [DllImport (LIBC, SetLastError=true)]
2150                 public static extern int vhangup ();
2151
2152                 // Revoke doesn't appear to be POSIX.  Include it?
2153                 [DllImport (LIBC, SetLastError=true)]
2154                 public static extern int revoke (string file);
2155
2156                 // TODO: profil?  It's not POSIX.
2157
2158                 [DllImport (LIBC, SetLastError=true)]
2159                 public static extern int acct (string filename);
2160
2161                 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
2162                 public static extern IntPtr sys_getusershell ();
2163
2164                 public static string getusershell ()
2165                 {
2166                         IntPtr r = sys_getusershell ();
2167                         return PosixMarshal.PtrToString (r);
2168                 }
2169
2170                 [DllImport (LIBC, SetLastError=true)]
2171                 public static extern void setusershell ();
2172
2173                 [DllImport (LIBC, SetLastError=true)]
2174                 public static extern void endusershell ();
2175
2176                 [DllImport (LIBC, SetLastError=true)]
2177                 private static extern int daemon (int nochdir, int noclose);
2178
2179                 public static int daemon (bool nochdir, bool noclose)
2180                 {
2181                         return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
2182                 }
2183
2184                 [DllImport (LIBC, SetLastError=true)]
2185                 public static extern int chroot (string path);
2186
2187                 // skipping getpass(3) as the man page states:
2188                 //   This function is obsolete.  Do not use it.
2189
2190                 [DllImport (LIBC, SetLastError=true)]
2191                 public static extern int fsync (int fd);
2192
2193                 [DllImport (LIBC, SetLastError=true)]
2194                 public static extern int fdatasync (int fd);
2195
2196                 [DllImport (LIBC, SetLastError=true)]
2197                 public static extern void sync ();
2198
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 ();
2203
2204                 // truncate(2)
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);
2209
2210                 // ftruncate(2)
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);
2215
2216                 [DllImport (LIBC, SetLastError=true)]
2217                 public static extern int getdtablesize ();
2218
2219                 [DllImport (LIBC, SetLastError=true)]
2220                 public static extern int brk (IntPtr end_data_segment);
2221
2222                 [DllImport (LIBC, SetLastError=true)]
2223                 public static extern IntPtr sbrk (IntPtr increment);
2224
2225                 // TODO: syscall(2)?
2226                 // Probably safer to skip entirely.
2227
2228                 // lockf(3)
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);
2233
2234                 [DllImport (CRYPT, SetLastError=true, EntryPoint=CRYPT)]
2235                 public static extern IntPtr sys_crypt (string key, string salt);
2236
2237                 public static string crypt (string key, string salt)
2238                 {
2239                         IntPtr r = sys_crypt (key, salt);
2240                         return PosixMarshal.PtrToString (r);
2241                 }
2242
2243                 [DllImport (CRYPT, SetLastError=true, EntryPoint="encrypt")]
2244                 private static extern void sys_encrypt ([In, Out] byte[] block, int edflag);
2245
2246                 public static void encrypt (byte[] block, bool decode)
2247                 {
2248                         if (block.Length < 64)
2249                                 throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
2250                         sys_encrypt (block, decode ? 1 : 0);
2251                 }
2252
2253                 // swab(3)
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);
2258
2259                 public static unsafe void swab (void* from, void* to, long n)
2260                 {
2261                         swab ((IntPtr) from, (IntPtr) to, n);
2262                 }
2263
2264                 //
2265                 // <utime.h>
2266                 //
2267
2268                 [DllImport (MPH, SetLastError=true, 
2269                                 EntryPoint="Mono_Posix_Syscall_utime")]
2270                 public static extern int utime (string filename, ref Utimbuf buf);
2271
2272                 [DllImport (MPH, SetLastError=true, 
2273                                 EntryPoint="Mono_Posix_Syscall_utime")]
2274                 private static extern int utime (string filename, IntPtr buf);
2275
2276                 public static int utime (string filename)
2277                 {
2278                         return utime (filename, IntPtr.Zero);
2279                 }
2280
2281                 [DllImport (MPH, SetLastError=true, 
2282                                 EntryPoint="Mono_Posix_Syscall_utimes")]
2283                 public static extern int utimes (string filename, ref Timeval tvp);
2284
2285                 // Obsolete this after 1.2 is out:
2286                 //[Obsolete ("Use Mono.Posix.Stdlib.strerror")]
2287                 public static string strerror (int errnum)
2288                 {
2289                         IntPtr r = Stdlib.sys_strerror (errnum);
2290                         return PosixMarshal.PtrToString (r);
2291                 }
2292
2293
2294         }
2295 }
2296
2297 // vim: noexpandtab