2 // Mono.Unix/Syscall.cs
5 // Miguel de Icaza (miguel@novell.com)
6 // Jonathan Pryor (jonpryor@vt.edu)
8 // (C) 2003 Novell, Inc.
9 // (C) 2004 Jonathan Pryor
11 // This file implements the low-level syscall interface to the POSIX
14 // This file tries to stay close to the low-level API as much as possible
15 // using enumerations, structures and in a few cases, using existing .NET
18 // Implementation notes:
20 // Since the values for the various constants on the API changes
21 // from system to system (even Linux on different architectures will
22 // have different values), we define our own set of values, and we
23 // use a set of C helper routines to map from the constants we define
24 // to the values of the native OS.
26 // Bitfields are flagged with the [Map] attribute, and a helper program
27 // generates a set of routines that we can call to convert from our value
28 // definitions to the value definitions expected by the OS; see
29 // UnixConvert for the conversion routines.
31 // Methods that require tuning are bound as `private sys_NAME' methods
32 // and then a `NAME' method is exposed.
36 // Permission is hereby granted, free of charge, to any person obtaining
37 // a copy of this software and associated documentation files (the
38 // "Software"), to deal in the Software without restriction, including
39 // without limitation the rights to use, copy, modify, merge, publish,
40 // distribute, sublicense, and/or sell copies of the Software, and to
41 // permit persons to whom the Software is furnished to do so, subject to
42 // the following conditions:
44 // The above copyright notice and this permission notice shall be
45 // included in all copies or substantial portions of the Software.
47 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57 using System.Collections;
58 using System.Runtime.InteropServices;
62 [assembly:Mono.Unix.IncludeAttribute (
63 new string [] {"sys/types.h", "sys/stat.h", "sys/poll.h", "sys/wait.h",
64 "unistd.h", "fcntl.h", "signal.h", "poll.h", "grp.h", "errno.h"},
65 new string [] {"_GNU_SOURCE", "_XOPEN_SOURCE"})]
70 public enum Error : int {
71 // errors & their values liberally copied from
72 // FC2 /usr/include/asm/errno.h
74 EPERM = 1, // Operation not permitted
75 ENOENT = 2, // No such file or directory
76 ESRCH = 3, // No such process
77 EINTR = 4, // Interrupted system call
79 ENXIO = 6, // No such device or address
80 E2BIG = 7, // Arg list too long
81 ENOEXEC = 8, // Exec format error
82 EBADF = 9, // Bad file number
83 ECHILD = 10, // No child processes
84 EAGAIN = 11, // Try again
85 ENOMEM = 12, // Out of memory
86 EACCES = 13, // Permission denied
87 EFAULT = 14, // Bad address
88 ENOTBLK = 15, // Block device required
89 EBUSY = 16, // Device or resource busy
90 EEXIST = 17, // File exists
91 EXDEV = 18, // Cross-device link
92 ENODEV = 19, // No such device
93 ENOTDIR = 20, // Not a directory
94 EISDIR = 21, // Is a directory
95 EINVAL = 22, // Invalid argument
96 ENFILE = 23, // File table overflow
97 EMFILE = 24, // Too many open files
98 ENOTTY = 25, // Not a typewriter
99 ETXTBSY = 26, // Text file busy
100 EFBIG = 27, // File too large
101 ENOSPC = 28, // No space left on device
102 ESPIPE = 29, // Illegal seek
103 EROFS = 30, // Read-only file system
104 EMLINK = 31, // Too many links
105 EPIPE = 32, // Broken pipe
106 EDOM = 33, // Math argument out of domain of func
107 ERANGE = 34, // Math result not representable
108 EDEADLK = 35, // Resource deadlock would occur
109 ENAMETOOLONG = 36, // File name too long
110 ENOLCK = 37, // No record locks available
111 ENOSYS = 38, // Function not implemented
112 ENOTEMPTY = 39, // Directory not empty
113 ELOOP = 40, // Too many symbolic links encountered
114 EWOULDBLOCK = EAGAIN, // Operation would block
115 ENOMSG = 42, // No message of desired type
116 EIDRM = 43, // Identifier removed
117 ECHRNG = 44, // Channel number out of range
118 EL2NSYNC = 45, // Level 2 not synchronized
119 EL3HLT = 46, // Level 3 halted
120 EL3RST = 47, // Level 3 reset
121 ELNRNG = 48, // Link number out of range
122 EUNATCH = 49, // Protocol driver not attached
123 ENOCSI = 50, // No CSI structure available
124 EL2HLT = 51, // Level 2 halted
125 EBADE = 52, // Invalid exchange
126 EBADR = 53, // Invalid request descriptor
127 EXFULL = 54, // Exchange full
128 ENOANO = 55, // No anode
129 EBADRQC = 56, // Invalid request code
130 EBADSLT = 57, // Invalid slot
134 EBFONT = 59, // Bad font file format
135 ENOSTR = 60, // Device not a stream
136 ENODATA = 61, // No data available
137 ETIME = 62, // Timer expired
138 ENOSR = 63, // Out of streams resources
139 ENONET = 64, // Machine is not on the network
140 ENOPKG = 65, // Package not installed
141 EREMOTE = 66, // Object is remote
142 ENOLINK = 67, // Link has been severed
143 EADV = 68, // Advertise error
144 ESRMNT = 69, // Srmount error
145 ECOMM = 70, // Communication error on send
146 EPROTO = 71, // Protocol error
147 EMULTIHOP = 72, // Multihop attempted
148 EDOTDOT = 73, // RFS specific error
149 EBADMSG = 74, // Not a data message
150 EOVERFLOW = 75, // Value too large for defined data type
151 ENOTUNIQ = 76, // Name not unique on network
152 EBADFD = 77, // File descriptor in bad state
153 EREMCHG = 78, // Remote address changed
154 ELIBACC = 79, // Can not access a needed shared library
155 ELIBBAD = 80, // Accessing a corrupted shared library
156 ELIBSCN = 81, // .lib section in a.out corrupted
157 ELIBMAX = 82, // Attempting to link in too many shared libraries
158 ELIBEXEC = 83, // Cannot exec a shared library directly
159 EILSEQ = 84, // Illegal byte sequence
160 ERESTART = 85, // Interrupted system call should be restarted
161 ESTRPIPE = 86, // Streams pipe error
162 EUSERS = 87, // Too many users
163 ENOTSOCK = 88, // Socket operation on non-socket
164 EDESTADDRREQ = 89, // Destination address required
165 EMSGSIZE = 90, // Message too long
166 EPROTOTYPE = 91, // Protocol wrong type for socket
167 ENOPROTOOPT = 92, // Protocol not available
168 EPROTONOSUPPORT = 93, // Protocol not supported
169 ESOCKTNOSUPPORT = 94, // Socket type not supported
170 EOPNOTSUPP = 95, // Operation not supported on transport endpoint
171 EPFNOSUPPORT = 96, // Protocol family not supported
172 EAFNOSUPPORT = 97, // Address family not supported by protocol
173 EADDRINUSE = 98, // Address already in use
174 EADDRNOTAVAIL = 99, // Cannot assign requested address
175 ENETDOWN = 100, // Network is down
176 ENETUNREACH = 101, // Network is unreachable
177 ENETRESET = 102, // Network dropped connection because of reset
178 ECONNABORTED = 103, // Software caused connection abort
179 ECONNRESET = 104, // Connection reset by peer
180 ENOBUFS = 105, // No buffer space available
181 EISCONN = 106, // Transport endpoint is already connected
182 ENOTCONN = 107, // Transport endpoint is not connected
183 ESHUTDOWN = 108, // Cannot send after transport endpoint shutdown
184 ETOOMANYREFS = 109, // Too many references: cannot splice
185 ETIMEDOUT = 110, // Connection timed out
186 ECONNREFUSED = 111, // Connection refused
187 EHOSTDOWN = 112, // Host is down
188 EHOSTUNREACH = 113, // No route to host
189 EALREADY = 114, // Operation already in progress
190 EINPROGRESS = 115, // Operation now in progress
191 ESTALE = 116, // Stale NFS file handle
192 EUCLEAN = 117, // Structure needs cleaning
193 ENOTNAM = 118, // Not a XENIX named type file
194 ENAVAIL = 119, // No XENIX semaphores available
195 EISNAM = 120, // Is a named type file
196 EREMOTEIO = 121, // Remote I/O error
197 EDQUOT = 122, // Quota exceeded
199 ENOMEDIUM = 123, // No medium found
200 EMEDIUMTYPE = 124, // Wrong medium type
204 public enum OpenFlags : int {
213 // Or-ed with zero or more of these
224 // These are non-Posix. Using them will result in errors/exceptions on
225 // non-supported platforms.
227 // (For example, "C-wrapped" system calls -- calls with implementation in
228 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
229 // calls will generate an exception in UnixConvert, as the value can't be
230 // converted on the target platform.)
242 public enum FilePermissions : uint {
243 S_ISUID = 0x0800, // Set user ID on execution
244 S_ISGID = 0x0400, // Set gorup ID on execution
245 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
246 S_IRUSR = 0x0100, // Read by owner
247 S_IWUSR = 0x0080, // Write by owner
248 S_IXUSR = 0x0040, // Execute by owner
249 S_IRGRP = 0x0020, // Read by group
250 S_IWGRP = 0x0010, // Write by group
251 S_IXGRP = 0x0008, // Execute by group
252 S_IROTH = 0x0004, // Read by other
253 S_IWOTH = 0x0002, // Write by other
254 S_IXOTH = 0x0001, // Execute by other
256 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
257 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
258 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
259 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
260 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
261 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
264 // Why these are held in "mode_t" is beyond me...
265 S_IFMT = 0xF000, // Bits which determine file type
266 S_IFDIR = 0x4000, // Directory
267 S_IFCHR = 0x2000, // Character device
268 S_IFBLK = 0x6000, // Block device
269 S_IFREG = 0x8000, // Regular file
270 S_IFIFO = 0x1000, // FIFO
271 S_IFLNK = 0xA000, // Symbolic link
272 S_IFSOCK = 0xC000, // Socket
275 public struct Flock {
276 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
277 public SeekFlags l_whence; // How to interpret l_start
278 public /* off_t */ long l_start; // Starting offset for lock
279 public /* off_t */ long l_len; // Number of bytes to lock
280 public /* pid_t */ int l_pid; // PID of process blocking our lock (F_GETLK only)
284 public enum FcntlCommand : int {
285 // Form /usr/include/bits/fcntl.h
286 F_DUPFD = 0, // Duplicate file descriptor.
287 F_GETFD = 1, // Get file descriptor flags.
288 F_SETFD = 2, // Set file descriptor flags.
289 F_GETFL = 3, // Get file status flags.
290 F_SETFL = 4, // Set file status flags.
291 F_GETLK = 12, // Get record locking info. [64]
292 F_SETLK = 13, // Set record locking info (non-blocking). [64]
293 F_SETLKW = 14, // Set record locking info (blocking). [64]
294 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
295 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
296 F_SETSIG = 10, // Set number of signal to be sent.
297 F_GETSIG = 11, // Get number of signal to be sent.
298 F_SETLEASE = 1024, // Set a lease.
299 F_GETLEASE = 1025, // Enquire what lease is active.
300 F_NOTIFY = 1026, // Required notifications on a directory
304 public enum LockType : short {
305 F_RDLCK = 0, // Read lock.
306 F_WRLCK = 1, // Write lock.
307 F_UNLCK = 2, // Remove lock.
311 public enum SeekFlags : short {
312 // values liberally copied from /usr/include/unistd.h
313 SEEK_SET = 0, // Seek from beginning of file.
314 SEEK_CUR = 1, // Seek from current position.
315 SEEK_END = 2, // Seek from end of file.
317 L_SET = SEEK_SET, // BSD alias for SEEK_SET
318 L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
319 L_XTND = SEEK_END, // BSD alias for SEEK_END
323 public enum DirectoryNotifyFlags : int {
324 // from /usr/include/bits/fcntl.h
325 DN_ACCESS = 0x00000001, // File accessed.
326 DN_MODIFY = 0x00000002, // File modified.
327 DN_CREATE = 0x00000004, // File created.
328 DN_DELETE = 0x00000008, // File removed.
329 DN_RENAME = 0x00000010, // File renamed.
330 DN_ATTRIB = 0x00000020, // File changed attributes.
331 DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
335 public enum PosixFadviseAdvice : int {
336 POSIX_FADV_NORMAL = 0, // No further special treatment.
337 POSIX_FADV_RANDOM = 1, // Expect random page references.
338 POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
339 POSIX_FADV_WILLNEED = 3, // Will need these pages.
340 POSIX_FADV_DONTNEED = 4, // Don't need these pages.
341 POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
345 public enum PosixMadviseAdvice : int {
346 POSIX_MADV_NORMAL = 0, // No further special treatment.
347 POSIX_MADV_RANDOM = 1, // Expect random page references.
348 POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
349 POSIX_MADV_WILLNEED = 3, // Will need these pages.
350 POSIX_MADV_DONTNEED = 4, // Don't need these pages.
354 public enum Signum : int {
355 SIGHUP = 1, // Hangup (POSIX).
356 SIGINT = 2, // Interrupt (ANSI).
357 SIGQUIT = 3, // Quit (POSIX).
358 SIGILL = 4, // Illegal instruction (ANSI).
359 SIGTRAP = 5, // Trace trap (POSIX).
360 SIGABRT = 6, // Abort (ANSI).
361 SIGIOT = 6, // IOT trap (4.2 BSD).
362 SIGBUS = 7, // BUS error (4.2 BSD).
363 SIGFPE = 8, // Floating-point exception (ANSI).
364 SIGKILL = 9, // Kill, unblockable (POSIX).
365 SIGUSR1 = 10, // User-defined signal 1 (POSIX).
366 SIGSEGV = 11, // Segmentation violation (ANSI).
367 SIGUSR2 = 12, // User-defined signal 2 (POSIX).
368 SIGPIPE = 13, // Broken pipe (POSIX).
369 SIGALRM = 14, // Alarm clock (POSIX).
370 SIGTERM = 15, // Termination (ANSI).
371 SIGSTKFLT = 16, // Stack fault.
372 SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
373 SIGCHLD = 17, // Child status has changed (POSIX).
374 SIGCONT = 18, // Continue (POSIX).
375 SIGSTOP = 19, // Stop, unblockable (POSIX).
376 SIGTSTP = 20, // Keyboard stop (POSIX).
377 SIGTTIN = 21, // Background read from tty (POSIX).
378 SIGTTOU = 22, // Background write to tty (POSIX).
379 SIGURG = 23, // Urgent condition on socket (4.2 BSD).
380 SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
381 SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
382 SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
383 SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
384 SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
385 SIGPOLL = SIGIO, // Pollable event occurred (System V).
386 SIGIO = 29, // I/O now possible (4.2 BSD).
387 SIGPWR = 30, // Power failure restart (System V).
388 SIGSYS = 31, // Bad system call.
393 public enum WaitOptions : int {
394 WNOHANG = 1, // Don't block waiting
395 WUNTRACED = 2, // Report status of stopped children
399 public enum AccessMode : int {
407 public enum PathConf : int {
414 _PC_CHOWN_RESTRICTED,
422 _PC_REC_INCR_XFER_SIZE,
423 _PC_REC_MAX_XFER_SIZE,
424 _PC_REC_MIN_XFER_SIZE,
432 public enum SysConf : int {
442 _SC_REALTIME_SIGNALS,
443 _SC_PRIORITY_SCHEDULING,
452 _SC_MEMORY_PROTECTION,
455 _SC_SHARED_MEMORY_OBJECTS,
458 _SC_AIO_PRIO_DELTA_MAX,
469 /* Values for the argument to `sysconf'
470 corresponding to _POSIX2_* symbols. */
475 _SC_COLL_WEIGHTS_MAX,
480 _SC_CHARCLASS_NAME_MAX,
496 _SC_IOV_MAX = _SC_UIO_MAXIOV,
497 _SC_PII_INTERNET_STREAM,
498 _SC_PII_INTERNET_DGRAM,
503 /* Values according to POSIX 1003.1c (POSIX threads). */
505 _SC_THREAD_SAFE_FUNCTIONS,
506 _SC_GETGR_R_SIZE_MAX,
507 _SC_GETPW_R_SIZE_MAX,
510 _SC_THREAD_DESTRUCTOR_ITERATIONS,
512 _SC_THREAD_STACK_MIN,
513 _SC_THREAD_THREADS_MAX,
514 _SC_THREAD_ATTR_STACKADDR,
515 _SC_THREAD_ATTR_STACKSIZE,
516 _SC_THREAD_PRIORITY_SCHEDULING,
517 _SC_THREAD_PRIO_INHERIT,
518 _SC_THREAD_PRIO_PROTECT,
519 _SC_THREAD_PROCESS_SHARED,
520 _SC_NPROCESSORS_CONF,
521 _SC_NPROCESSORS_ONLN,
527 _SC_XOPEN_XCU_VERSION,
562 _SC_XBS5_ILP32_OFF32,
563 _SC_XBS5_ILP32_OFFBIG,
565 _SC_XBS5_LPBIG_OFFBIG,
568 _SC_XOPEN_REALTIME_THREADS,
573 _SC_C_LANG_SUPPORT_R,
579 _SC_DEVICE_SPECIFIC_R,
590 _SC_READER_WRITER_LOCKS,
598 _SC_THREAD_SPORADIC_SERVER,
600 _SC_SYSTEM_DATABASE_R,
602 _SC_TYPED_MEMORY_OBJECTS,
606 _SC_2_PBS_ACCOUNTING,
612 _SC_2_PBS_CHECKPOINT,
619 _SC_TRACE_EVENT_FILTER,
622 _SC_LEVEL1_ICACHE_SIZE,
623 _SC_LEVEL1_ICACHE_ASSOC,
624 _SC_LEVEL1_ICACHE_LINESIZE,
625 _SC_LEVEL1_DCACHE_SIZE,
626 _SC_LEVEL1_DCACHE_ASSOC,
627 _SC_LEVEL1_DCACHE_LINESIZE,
628 _SC_LEVEL2_CACHE_SIZE,
629 _SC_LEVEL2_CACHE_ASSOC,
630 _SC_LEVEL2_CACHE_LINESIZE,
631 _SC_LEVEL3_CACHE_SIZE,
632 _SC_LEVEL3_CACHE_ASSOC,
633 _SC_LEVEL3_CACHE_LINESIZE,
634 _SC_LEVEL4_CACHE_SIZE,
635 _SC_LEVEL4_CACHE_ASSOC,
636 _SC_LEVEL4_CACHE_LINESIZE
640 public enum ConfStr : int {
641 _CS_PATH, /* The default search path. */
642 _CS_V6_WIDTH_RESTRICTED_ENVS,
643 _CS_GNU_LIBC_VERSION,
644 _CS_GNU_LIBPTHREAD_VERSION,
645 _CS_LFS_CFLAGS = 1000,
653 _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
654 _CS_XBS5_ILP32_OFF32_LDFLAGS,
655 _CS_XBS5_ILP32_OFF32_LIBS,
656 _CS_XBS5_ILP32_OFF32_LINTFLAGS,
657 _CS_XBS5_ILP32_OFFBIG_CFLAGS,
658 _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
659 _CS_XBS5_ILP32_OFFBIG_LIBS,
660 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
661 _CS_XBS5_LP64_OFF64_CFLAGS,
662 _CS_XBS5_LP64_OFF64_LDFLAGS,
663 _CS_XBS5_LP64_OFF64_LIBS,
664 _CS_XBS5_LP64_OFF64_LINTFLAGS,
665 _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
666 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
667 _CS_XBS5_LPBIG_OFFBIG_LIBS,
668 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
669 _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
670 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
671 _CS_POSIX_V6_ILP32_OFF32_LIBS,
672 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
673 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
674 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
675 _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
676 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
677 _CS_POSIX_V6_LP64_OFF64_CFLAGS,
678 _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
679 _CS_POSIX_V6_LP64_OFF64_LIBS,
680 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
681 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
682 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
683 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
684 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
688 public enum LockFlags : int {
689 F_ULOCK = 0, // Unlock a previously locked region.
690 F_LOCK = 1, // Lock a region for exclusive use.
691 F_TLOCK = 2, // Test and lock a region for exclusive use.
692 F_TEST = 3, // Test a region for other process locks.
696 public enum PollEvents : short {
697 POLLIN = 0x0001, // There is data to read
698 POLLPRI = 0x0002, // There is urgent data to read
699 POLLOUT = 0x0004, // Writing now will not block
700 POLLERR = 0x0008, // Error condition
701 POLLHUP = 0x0010, // Hung up
702 POLLNVAL = 0x0020, // Invalid request; fd not open
703 // XPG4.2 definitions (via _XOPEN_SOURCE)
704 POLLRDNORM = 0x0040, // Normal data bay be read
705 POLLRDBAND = 0x0080, // Priority data may be read
706 POLLWRNORM = 0x0100, // Writing now will not block
707 POLLWRBAND = 0x0200, // Priority data may be written
710 [StructLayout(LayoutKind.Sequential)]
711 public struct Pollfd {
713 public PollEvents events;
714 public PollEvents revents;
717 public sealed class Dirent
719 public /* ino_t */ ulong d_ino;
720 public /* off_t */ long d_off;
721 public ushort d_reclen;
723 public string d_name;
725 public override int GetHashCode ()
727 return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
728 d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
729 d_name.GetHashCode ();
732 public override bool Equals (object obj)
734 if (obj == null || GetType() != obj.GetType())
736 Dirent d = (Dirent) obj;
737 return d.d_ino == d_ino && d.d_off == d_off &&
738 d.d_reclen == d_reclen && d.d_type == d_type &&
739 d.d_name == d.d_name;
742 public override string ToString ()
747 public static bool operator== (Dirent lhs, Dirent rhs)
749 return Object.Equals (lhs, rhs);
752 public static bool operator!= (Dirent lhs, Dirent rhs)
754 return Object.Equals (lhs, rhs);
758 public sealed class Group
760 public string gr_name;
761 public string gr_passwd;
762 public /* gid_t */ uint gr_gid;
763 public string[] gr_mem;
765 public override int GetHashCode ()
768 for (int i = 0; i < gr_mem.Length; ++i)
769 memhc ^= gr_mem[i].GetHashCode ();
771 return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
772 gr_gid.GetHashCode () ^ memhc;
775 public override bool Equals (object obj)
777 if (obj == null || GetType() != obj.GetType())
779 Group g = (Group) obj;
780 if (g.gr_gid != gr_gid)
782 if (g.gr_gid == gr_gid && g.gr_name == g.gr_name &&
783 g.gr_passwd == g.gr_passwd && g.gr_mem.Length == gr_mem.Length) {
784 for (int i = 0; i < gr_mem.Length; ++i)
785 if (gr_mem[i] != g.gr_mem[i])
792 // Generate string in /etc/group format
793 public override string ToString ()
795 StringBuilder sb = new StringBuilder ();
796 sb.AppendFormat ("{0}:{1}:{2}:", gr_name, gr_passwd, gr_gid);
797 GetMembers (sb, gr_mem);
798 return sb.ToString ();
801 private static void GetMembers (StringBuilder sb, string[] members)
803 if (members.Length > 0)
804 sb.Append (members[0]);
805 for (int i = 1; i < members.Length; ++i) {
807 sb.Append (members[i]);
811 public static bool operator== (Group lhs, Group rhs)
813 return Object.Equals (lhs, rhs);
816 public static bool operator!= (Group lhs, Group rhs)
818 return Object.Equals (lhs, rhs);
822 public sealed class Passwd
824 public string pw_name;
825 public string pw_passwd;
826 public /* uid_t */ uint pw_uid;
827 public /* gid_t */ uint pw_gid;
828 public string pw_gecos;
829 public string pw_dir;
830 public string pw_shell;
832 public override int GetHashCode ()
834 return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
835 pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
836 pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
837 pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
840 public override bool Equals (object obj)
842 if (obj == null || GetType() != obj.GetType())
844 Passwd p = (Passwd) obj;
845 return p.pw_uid == pw_uid && p.pw_gid == pw_gid && p.pw_name == pw_name &&
846 p.pw_passwd == pw_passwd && p.pw_gecos == p.pw_gecos &&
847 p.pw_dir == p.pw_dir && p.pw_shell == p.pw_shell;
850 // Generate string in /etc/passwd format
851 public override string ToString ()
853 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
854 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
857 public static bool operator== (Passwd lhs, Passwd rhs)
859 return Object.Equals (lhs, rhs);
862 public static bool operator!= (Passwd lhs, Passwd rhs)
864 return Object.Equals (lhs, rhs);
869 public /* dev_t */ ulong st_dev; // device
870 public /* ino_t */ ulong st_ino; // inode
871 public FilePermissions st_mode; // protection
872 private uint _padding_; // padding for structure alignment
873 public /* nlink_t */ ulong st_nlink; // number of hard links
874 public /* uid_t */ uint st_uid; // user ID of owner
875 public /* gid_t */ uint st_gid; // group ID of owner
876 public /* dev_t */ ulong st_rdev; // device type (if inode device)
877 public /* off_t */ long st_size; // total size, in bytes
878 public /* blksize_t */ long st_blksize; // blocksize for filesystem I/O
879 public /* blkcnt_t */ long st_blocks; // number of blocks allocated
880 public /* time_t */ long st_atime; // time of last access
881 public /* time_t */ long st_mtime; // time of last modification
882 public /* time_t */ long st_ctime; // time of last status change
885 public struct Timeval {
886 public /* time_t */ long tv_sec; // seconds
887 public /* suseconds_t */ long tv_usec; // microseconds
890 public struct Timezone {
891 public int tz_minuteswest; // minutes W of Greenwich
892 private int tz_dsttime; // type of dst correction (OBSOLETE)
895 public struct Utimbuf {
896 public /* time_t */ long actime; // access time
897 public /* time_t */ long modtime; // modification time
901 // Convention: Functions *not* part of the standard C library AND part of
902 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
904 // For example, the man page should be similar to:
906 // CONFORMING TO (or CONFORMS TO)
907 // XPG2, SUSv2, POSIX, etc.
909 // BSD- and GNU-specific exports can also be placed here.
911 // The only methods in here should be:
912 // (1) low-level functions
913 // (2) "Trivial" function overloads. For example, if the parameters to a
914 // function are related (e.g. getgroups(2))
915 // (3) The return type SHOULD NOT be changed. If you want to provide a
916 // convenience function with a nicer return type, place it into one of
917 // the Unix* wrapper classes, and give it a .NET-styled name.
918 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
919 // - If you're wrapping *broken* methods which make assumptions about
920 // input data, such as that an argument refers to N bytes of data.
921 // This is currently limited to cuserid(3) and encrypt(3).
922 // - If you call functions which themselves generate exceptions.
923 // This is the case for using UnixConvert, which will throw an
924 // exception if an invalid/unsupported value is used.
926 public sealed class Syscall : Stdlib
928 private const string LIBC = "libc";
929 private const string MPH = "MonoPosixHelper";
930 private const string CRYPT = "crypt";
932 private Syscall () {}
938 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
939 // aio_return(3), aio_suspend(3), aio_write(3)
941 // Then update UnixStream.BeginRead to use the aio* functions.
943 #region <dirent.h> Declarations
947 // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
949 [DllImport (LIBC, SetLastError=true)]
950 public static extern IntPtr opendir (string name);
952 [DllImport (LIBC, SetLastError=true)]
953 public static extern int closedir (IntPtr dir);
956 // void seekdir (DIR *dir, off_t offset);
957 // Slight modification. Returns -1 on error, 0 on success.
958 [DllImport (MPH, SetLastError=true,
959 EntryPoint="Mono_Posix_Syscall_seekdir")]
960 public static extern int seekdir (IntPtr dir, long offset);
963 // off_t telldir(DIR *dir);
964 [DllImport (MPH, SetLastError=true,
965 EntryPoint="Mono_Posix_Syscall_telldir")]
966 public static extern long telldir (IntPtr dir);
968 [DllImport (LIBC, SetLastError=true)]
969 public static extern void rewinddir (IntPtr dir);
971 private struct _Dirent {
972 public /* ino_t */ ulong d_ino;
973 public /* off_t */ long d_off;
974 public ushort d_reclen;
976 public IntPtr d_name;
979 private static void CopyDirent (Dirent to, ref _Dirent from)
982 to.d_ino = from.d_ino;
983 to.d_off = from.d_off;
984 to.d_reclen = from.d_reclen;
985 to.d_type = from.d_type;
986 if (from.d_name != IntPtr.Zero)
987 to.d_name = UnixMarshal.PtrToString (from.d_name);
992 Stdlib.free (from.d_name);
993 from.d_name = IntPtr.Zero;
997 [DllImport (MPH, SetLastError=true,
998 EntryPoint="Mono_Posix_Syscall_readdir")]
999 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
1001 public static Dirent readdir (IntPtr dir)
1004 int r = sys_readdir (dir, out dentry);
1007 Dirent d = new Dirent ();
1008 CopyDirent (d, ref dentry);
1012 [DllImport (MPH, SetLastError=true,
1013 EntryPoint="Mono_Posix_Syscall_readdir_r")]
1014 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
1016 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
1022 entry.d_name = null;
1025 int r = sys_readdir_r (dirp, out _d, out result);
1027 if (r == 0 && result != IntPtr.Zero) {
1028 CopyDirent (entry, ref _d);
1034 [DllImport (LIBC, SetLastError=true)]
1035 public static extern int dirfd (IntPtr dir);
1038 #region <errno.h> Declarations
1040 // <errno.h> -- COMPLETE
1043 public static Error GetLastError ()
1045 int errno = Marshal.GetLastWin32Error ();
1046 return UnixConvert.ToError (errno);
1049 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_SetLastError")]
1050 private static extern void SetLastError (int error);
1052 public static void SetLastError (Error error)
1054 int _error = UnixConvert.FromError (error);
1055 SetLastError (_error);
1059 #region <fcntl.h> Declarations
1061 // <fcntl.h> -- COMPLETE
1064 [DllImport (MPH, SetLastError=true,
1065 EntryPoint="Mono_Posix_Syscall_fcntl")]
1066 public static extern int fcntl (int fd, FcntlCommand cmd);
1068 [DllImport (MPH, SetLastError=true,
1069 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
1070 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
1072 [DllImport (MPH, SetLastError=true,
1073 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
1074 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
1076 [DllImport (MPH, SetLastError=true,
1077 EntryPoint="Mono_Posix_Syscall_open")]
1078 public static extern int open (string pathname, OpenFlags flags);
1081 // int open(const char *pathname, int flags, mode_t mode);
1082 [DllImport (MPH, SetLastError=true,
1083 EntryPoint="Mono_Posix_Syscall_open_mode")]
1084 public static extern int open (string pathname, OpenFlags flags, FilePermissions mode);
1087 // int creat(const char *pathname, mode_t mode);
1088 [DllImport (MPH, SetLastError=true,
1089 EntryPoint="Mono_Posix_Syscall_creat")]
1090 public static extern int creat (string pathname, FilePermissions mode);
1093 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
1094 [DllImport (MPH, SetLastError=true,
1095 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
1096 public static extern int posix_fadvise (int fd, long offset,
1097 long len, PosixFadviseAdvice advice);
1099 // posix_fallocate(P)
1100 // int posix_fallocate(int fd, off_t offset, size_t len);
1101 [DllImport (MPH, SetLastError=true,
1102 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
1103 public static extern int posix_fallocate (int fd, long offset, long len);
1106 #region <grp.h> Declarations
1110 // TODO: putgrent(3), fgetgrent_r(), getgrouplist(2), initgroups(3)
1113 // int setgroups (size_t size, const gid_t *list);
1114 [DllImport (MPH, SetLastError=true,
1115 EntryPoint="Mono_Posix_Syscall_setgroups")]
1116 public static extern int setgroups (ulong size, uint[] list);
1118 public static int setgroups (uint [] list)
1120 return setgroups ((ulong) list.Length, list);
1123 private struct _Group
1125 public IntPtr gr_name;
1126 public IntPtr gr_passwd;
1127 public /* gid_t */ uint gr_gid;
1128 public int _gr_nmem_;
1129 public IntPtr gr_mem;
1130 public IntPtr _gr_buf_;
1133 private static void CopyGroup (Group to, ref _Group from)
1136 to.gr_gid = from.gr_gid;
1137 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
1138 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
1139 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
1142 Stdlib.free (from.gr_mem);
1143 Stdlib.free (from._gr_buf_);
1144 from.gr_mem = IntPtr.Zero;
1145 from._gr_buf_ = IntPtr.Zero;
1149 [DllImport (MPH, SetLastError=true,
1150 EntryPoint="Mono_Posix_Syscall_getgrnam")]
1151 private static extern int sys_getgrnam (string name, out _Group group);
1153 public static Group getgrnam (string name)
1156 int r = sys_getgrnam (name, out group);
1159 Group gr = new Group ();
1160 CopyGroup (gr, ref group);
1165 // struct group *getgrgid(gid_t gid);
1166 [DllImport (MPH, SetLastError=true,
1167 EntryPoint="Mono_Posix_Syscall_getgrgid")]
1168 private static extern int sys_getgrgid (uint uid, out _Group group);
1170 public static Group getgrgid (uint uid)
1173 int r = sys_getgrgid (uid, out group);
1176 Group gr = new Group ();
1177 CopyGroup (gr, ref group);
1181 [DllImport (MPH, SetLastError=true,
1182 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
1183 private static extern int sys_getgrnam_r (string name, out _Group grbuf, out IntPtr grbufp);
1185 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
1190 int r = sys_getgrnam_r (name, out group, out _grbufp);
1191 if (r == 0 && _grbufp != IntPtr.Zero) {
1192 CopyGroup (grbuf, ref group);
1199 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
1200 // size_t buflen, struct group **gbufp);
1201 [DllImport (MPH, SetLastError=true,
1202 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
1203 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
1205 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
1210 int r = sys_getgrgid_r (uid, out group, out _grbufp);
1211 if (r == 0 && _grbufp != IntPtr.Zero) {
1212 CopyGroup (grbuf, ref group);
1218 [DllImport (MPH, SetLastError=true,
1219 EntryPoint="Mono_Posix_Syscall_getgrent")]
1220 private static extern int sys_getgrent (out _Group grbuf);
1222 public static Group getgrent ()
1225 int r = sys_getgrent (out group);
1228 Group gr = new Group();
1229 CopyGroup (gr, ref group);
1233 [DllImport (LIBC, SetLastError=true)]
1234 public static extern void setgrent ();
1236 [DllImport (LIBC, SetLastError=true)]
1237 public static extern void endgrent ();
1239 [DllImport (MPH, SetLastError=true,
1240 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
1241 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
1243 public static Group fgetgrent (IntPtr stream)
1246 int r = sys_fgetgrent (stream, out group);
1249 Group gr = new Group ();
1250 CopyGroup (gr, ref group);
1255 #region <pwd.h> Declarations
1259 // TODO: putpwent(3), fgetpwent_r()
1261 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
1263 private struct _Passwd
1265 public IntPtr pw_name;
1266 public IntPtr pw_passwd;
1267 public /* uid_t */ uint pw_uid;
1268 public /* gid_t */ uint pw_gid;
1269 public IntPtr pw_gecos;
1270 public IntPtr pw_dir;
1271 public IntPtr pw_shell;
1272 public IntPtr _pw_buf_;
1275 private static void CopyPasswd (Passwd to, ref _Passwd from)
1278 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
1279 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
1280 to.pw_uid = from.pw_uid;
1281 to.pw_gid = from.pw_gid;
1282 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
1283 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
1284 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
1287 Stdlib.free (from._pw_buf_);
1288 from._pw_buf_ = IntPtr.Zero;
1292 [DllImport (MPH, SetLastError=true,
1293 EntryPoint="Mono_Posix_Syscall_getpwnam")]
1294 private static extern int sys_getpwnam (string name, out _Passwd passwd);
1296 public static Passwd getpwnam (string name)
1299 int r = sys_getpwnam (name, out passwd);
1302 Passwd pw = new Passwd ();
1303 CopyPasswd (pw, ref passwd);
1308 // struct passwd *getpwnuid(uid_t uid);
1309 [DllImport (MPH, SetLastError=true,
1310 EntryPoint="Mono_Posix_Syscall_getpwuid")]
1311 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
1313 public static Passwd getpwuid (uint uid)
1316 int r = sys_getpwuid (uid, out passwd);
1319 Passwd pw = new Passwd ();
1320 CopyPasswd (pw, ref passwd);
1324 [DllImport (MPH, SetLastError=true,
1325 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
1326 private static extern int sys_getpwnam_r (string name, out _Passwd pwbuf, out IntPtr pwbufp);
1328 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
1333 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
1334 if (r == 0 && _pwbufp != IntPtr.Zero) {
1335 CopyPasswd (pwbuf, ref passwd);
1342 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
1343 // buflen, struct passwd **pwbufp);
1344 [DllImport (MPH, SetLastError=true,
1345 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
1346 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
1348 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
1353 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
1354 if (r == 0 && _pwbufp != IntPtr.Zero) {
1355 CopyPasswd (pwbuf, ref passwd);
1361 [DllImport (MPH, SetLastError=true,
1362 EntryPoint="Mono_Posix_Syscall_getpwent")]
1363 private static extern int sys_getpwent (out _Passwd pwbuf);
1365 public static Passwd getpwent ()
1368 int r = sys_getpwent (out passwd);
1371 Passwd pw = new Passwd ();
1372 CopyPasswd (pw, ref passwd);
1376 [DllImport (LIBC, SetLastError=true)]
1377 public static extern void setpwent ();
1379 [DllImport (LIBC, SetLastError=true)]
1380 public static extern void endpwent ();
1382 [DllImport (MPH, SetLastError=true,
1383 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
1384 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
1386 public static Passwd fgetpwent (IntPtr stream)
1389 int r = sys_fgetpwent (stream, out passwd);
1392 Passwd pw = new Passwd ();
1393 CopyPasswd (pw, ref passwd);
1398 #region <signal.h> Declarations
1402 [DllImport (LIBC, SetLastError=true)]
1403 private static extern void psignal (int sig, string s);
1405 public static void psignal (Signum sig, string s)
1407 int signum = UnixConvert.FromSignum (sig);
1408 psignal (signum, s);
1412 // int kill(pid_t pid, int sig);
1413 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
1414 private static extern int sys_kill (int pid, int sig);
1416 public static int kill (int pid, Signum sig)
1418 int _sig = UnixConvert.FromSignum (sig);
1419 return sys_kill (pid, _sig);
1422 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
1423 private static extern IntPtr sys_strsignal (int sig);
1425 public static IntPtr sys_strsignal (Signum sig)
1427 int s = UnixConvert.FromSignum (sig);
1428 return sys_strsignal (s);
1431 public static string strsignal (Signum sig)
1433 IntPtr r = sys_strsignal (sig);
1434 return UnixMarshal.PtrToString (r);
1437 // TODO: sigaction(2)
1438 // TODO: sigsuspend(2)
1439 // TODO: sigpending(2)
1443 #region <stdio.h> Declarations
1447 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
1448 private static extern int _L_ctermid ();
1450 public static readonly int L_ctermid = _L_ctermid ();
1452 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
1453 private static extern int _L_cuserid ();
1455 public static readonly int L_cuserid = _L_cuserid ();
1457 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
1458 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
1460 [Obsolete ("\"Nobody knows precisely what cuserid() does... DO NOT USE cuserid()." +
1461 "`string' must hold L_cuserid characters. Use Unistd.getlogin_r instead.")]
1462 public static string cuserid (StringBuilder @string)
1464 if (@string.Capacity < L_cuserid) {
1465 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
1467 IntPtr r = sys_cuserid (@string);
1468 return UnixMarshal.PtrToString (r);
1473 #region <stdlib.h> Declarations
1477 [DllImport (LIBC, SetLastError=true)]
1478 public static extern int ttyslot ();
1480 [DllImport (CRYPT, SetLastError=true)]
1481 public static extern void setkey (string key);
1485 #region <string.h> Declarations
1491 // int strerror_r(int errnum, char *buf, size_t n);
1492 [DllImport (LIBC, SetLastError=true,
1493 EntryPoint="Mono_Posix_Syscall_strerror_r")]
1494 private static extern int sys_strerror_r (int errnum,
1495 [Out] StringBuilder buf, ulong n);
1497 public static int strerror_r (Error errnum, StringBuilder buf, ulong n)
1499 int e = UnixConvert.FromError (errnum);
1500 return sys_strerror_r (e, buf, n);
1503 public static int strerror_r (Error errnum, StringBuilder buf)
1505 return strerror_r (errnum, buf, (ulong) buf.Capacity);
1510 #region <sys/mman.h> Declarations
1516 // int posix_madvise(void *addr, size_t len, int advice);
1517 [DllImport (MPH, SetLastError=true,
1518 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
1519 public static extern int posix_madvise (IntPtr addr, ulong len,
1520 PosixMadviseAdvice advice);
1524 #region <sys/poll.h> Declarations
1526 // <sys/poll.h> -- COMPLETE
1529 private struct _pollfd {
1531 public short events;
1532 public short revents;
1535 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
1536 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
1538 public static int poll (Pollfd [] fds, uint nfds, int timeout)
1540 if (fds.Length < nfds)
1541 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
1543 _pollfd[] send = new _pollfd[nfds];
1545 for (int i = 0; i < send.Length; i++) {
1546 send [i].fd = fds [i].fd;
1547 send [i].events = UnixConvert.FromPollEvents (fds [i].events);
1550 int r = sys_poll (send, nfds, timeout);
1552 for (int i = 0; i < send.Length; i++) {
1553 fds [i].revents = UnixConvert.ToPollEvents (send [i].revents);
1559 public static int poll (Pollfd [] fds, int timeout)
1561 return poll (fds, (uint) fds.Length, timeout);
1574 // TODO: setrlimit(2)
1575 // TODO: getrlimit(2)
1576 // TODO: getrusage(2)
1580 #region <sys/sendfile.h> Declarations
1582 // <sys/sendfile.h> -- COMPLETE
1585 [DllImport (MPH, SetLastError=true,
1586 EntryPoint="Mono_Posix_Syscall_sendfile")]
1587 public static extern long sendfile (int out_fd, int in_fd,
1588 ref long offset, ulong count);
1592 #region <sys/stat.h> Declarations
1594 // <sys/stat.h> -- COMPLETE
1596 [DllImport (MPH, SetLastError=true,
1597 EntryPoint="Mono_Posix_Syscall_stat")]
1598 public static extern int stat (string file_name, out Stat buf);
1600 [DllImport (MPH, SetLastError=true,
1601 EntryPoint="Mono_Posix_Syscall_fstat")]
1602 public static extern int fstat (int filedes, out Stat buf);
1604 [DllImport (MPH, SetLastError=true,
1605 EntryPoint="Mono_Posix_Syscall_lstat")]
1606 public static extern int lstat (string file_name, out Stat buf);
1609 // int chmod(const char *path, mode_t mode);
1610 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
1611 private static extern int sys_chmod (string path, uint mode);
1613 public static int chmod (string path, FilePermissions mode)
1615 uint _mode = UnixConvert.FromFilePermissions (mode);
1616 return sys_chmod (path, _mode);
1620 // int chmod(int filedes, mode_t mode);
1621 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
1622 private static extern int sys_fchmod (int filedes, uint mode);
1624 public static int fchmod (int filedes, FilePermissions mode)
1626 uint _mode = UnixConvert.FromFilePermissions (mode);
1627 return sys_fchmod (filedes, _mode);
1631 // mode_t umask(mode_t mask);
1632 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
1633 private static extern uint sys_umask (uint mask);
1635 public static FilePermissions umask (FilePermissions mask)
1637 uint _mask = UnixConvert.FromFilePermissions (mask);
1638 uint r = sys_umask (_mask);
1639 return UnixConvert.ToFilePermissions (r);
1643 // int mkdir(const char *pathname, mode_t mode);
1644 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
1645 public static extern int sys_mkdir (string oldpath, uint mode);
1647 public static int mkdir (string oldpath, FilePermissions mode)
1649 uint _mode = UnixConvert.FromFilePermissions (mode);
1650 return sys_mkdir (oldpath, _mode);
1654 // int mknod (const char *pathname, mode_t mode, dev_t dev);
1655 [DllImport (MPH, SetLastError=true,
1656 EntryPoint="Mono_Posix_Syscall_mknod")]
1657 public static extern int mknod (string pathname, FilePermissions mode, ulong dev);
1660 // int mkfifo(const char *pathname, mode_t mode);
1661 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
1662 private static extern int sys_mkfifo (string pathname, uint mode);
1664 public static int mkfifo (string pathname, FilePermissions mode)
1666 uint _mode = UnixConvert.FromFilePermissions (mode);
1667 return sys_mkfifo (pathname, _mode);
1672 #region <sys/time.h> Declarations
1676 // TODO: adjtime(), getitimer(2), setitimer(2), lutimes(), futimes()
1678 [DllImport (MPH, SetLastError=true,
1679 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1680 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
1682 [DllImport (MPH, SetLastError=true,
1683 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1684 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
1686 public static int gettimeofday (out Timeval tv)
1688 return gettimeofday (out tv, IntPtr.Zero);
1691 [DllImport (MPH, SetLastError=true,
1692 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1693 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
1695 public static int gettimeofday (out Timezone tz)
1697 return gettimeofday (IntPtr.Zero, out tz);
1700 [DllImport (MPH, SetLastError=true,
1701 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1702 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
1704 [DllImport (MPH, SetLastError=true,
1705 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1706 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
1708 public static int settimeofday (ref Timeval tv)
1710 return settimeofday (ref tv, IntPtr.Zero);
1713 [DllImport (MPH, SetLastError=true,
1714 EntryPoint="Mono_Posix_Syscall_utimes")]
1715 public static extern int utimes (string filename, ref Timeval tvp);
1731 #region <sys/wait.h> Declarations
1737 // pid_t wait(int *status);
1738 [DllImport (LIBC, SetLastError=true)]
1739 public static extern int wait (out int status);
1742 // pid_t waitpid(pid_t pid, int *status, int options);
1743 [DllImport (LIBC, SetLastError=true)]
1744 private static extern int waitpid (int pid, out int status, int options);
1746 public static int waitpid (int pid, out int status, WaitOptions options)
1748 int _options = UnixConvert.FromWaitOptions (options);
1749 return waitpid (pid, out status, _options);
1752 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
1753 private static extern int _WIFEXITED (int status);
1755 public static bool WIFEXITED (int status)
1757 return _WIFEXITED (status) != 0;
1760 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
1761 public static extern int WEXITSTATUS (int status);
1763 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
1764 private static extern int _WIFSIGNALED (int status);
1766 public static bool WIFSIGNALED (int status)
1768 return _WIFSIGNALED (status) != 0;
1771 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
1772 private static extern int _WTERMSIG (int status);
1774 public static Signum WTERMSIG (int status)
1776 int r = _WTERMSIG (status);
1777 return UnixConvert.ToSignum (r);
1780 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
1781 private static extern int _WIFSTOPPED (int status);
1783 public static bool WIFSTOPPED (int status)
1785 return _WIFSTOPPED (status) != 0;
1788 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
1789 private static extern int _WSTOPSIG (int status);
1791 public static Signum WSTOPSIG (int status)
1793 int r = _WSTOPSIG (status);
1794 return UnixConvert.ToSignum (r);
1803 #region <time.h> Declarations
1809 // int stime(time_t *t);
1810 [DllImport (MPH, SetLastError=true,
1811 EntryPoint="Mono_Posix_Syscall_stime")]
1812 public static extern int stime (ref long t);
1815 // time_t time(time_t *t);
1816 [DllImport (MPH, SetLastError=true,
1817 EntryPoint="Mono_Posix_Syscall_time")]
1818 public static extern long time (out long t);
1828 #region <unistd.h> Declarations
1832 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
1833 // other TODOs listed below.
1835 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
1836 private static extern int sys_access (string pathname, int mode);
1838 public static int access (string pathname, AccessMode mode)
1840 int _mode = UnixConvert.FromAccessMode (mode);
1841 return sys_access (pathname, _mode);
1845 // off_t lseek(int filedes, off_t offset, int whence);
1846 [DllImport (MPH, SetLastError=true,
1847 EntryPoint="Mono_Posix_Syscall_lseek")]
1848 public static extern long lseek (int fd, long offset, SeekFlags whence);
1850 [DllImport (LIBC, SetLastError=true)]
1851 public static extern int close (int fd);
1854 // ssize_t read(int fd, void *buf, size_t count);
1855 [DllImport (MPH, SetLastError=true,
1856 EntryPoint="Mono_Posix_Syscall_read")]
1857 public static extern long read (int fd, IntPtr buf, ulong count);
1859 public static unsafe long read (int fd, void *buf, ulong count)
1861 return read (fd, (IntPtr) buf, count);
1865 // ssize_t write(int fd, const void *buf, size_t count);
1866 [DllImport (MPH, SetLastError=true,
1867 EntryPoint="Mono_Posix_Syscall_write")]
1868 public static extern long write (int fd, IntPtr buf, ulong count);
1870 public static unsafe long write (int fd, void *buf, ulong count)
1872 return write (fd, (IntPtr) buf, count);
1876 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
1877 [DllImport (MPH, SetLastError=true,
1878 EntryPoint="Mono_Posix_Syscall_pread")]
1879 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
1881 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
1883 return pread (fd, (IntPtr) buf, count, offset);
1887 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
1888 [DllImport (MPH, SetLastError=true,
1889 EntryPoint="Mono_Posix_Syscall_pwrite")]
1890 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
1892 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
1894 return pwrite (fd, (IntPtr) buf, count, offset);
1897 [DllImport (MPH, SetLastError=true,
1898 EntryPoint="Mono_Posix_Syscall_pipe")]
1899 public static extern int pipe (out int reading, out int writing);
1901 public static int pipe (int[] filedes)
1903 if (filedes == null || filedes.Length != 2) {
1907 int reading, writing;
1908 int r = pipe (out reading, out writing);
1909 filedes[0] = reading;
1910 filedes[1] = writing;
1914 [DllImport (LIBC, SetLastError=true)]
1915 public static extern uint alarm (uint seconds);
1917 [DllImport (LIBC, SetLastError=true)]
1918 public static extern uint sleep (uint seconds);
1920 [DllImport (LIBC, SetLastError=true)]
1921 public static extern uint ualarm (uint usecs, uint interval);
1923 [DllImport (LIBC, SetLastError=true)]
1924 public static extern int pause ();
1927 // int chown(const char *path, uid_t owner, gid_t group);
1928 [DllImport (LIBC, SetLastError=true)]
1929 public static extern int chown (string path, uint owner, uint group);
1932 // int fchown(int fd, uid_t owner, gid_t group);
1933 [DllImport (LIBC, SetLastError=true)]
1934 public static extern int fchown (int fd, uint owner, uint group);
1937 // int lchown(const char *path, uid_t owner, gid_t group);
1938 [DllImport (LIBC, SetLastError=true)]
1939 public static extern int lchown (string path, uint owner, uint group);
1941 [DllImport (LIBC, SetLastError=true)]
1942 public static extern int chdir (string path);
1944 [DllImport (LIBC, SetLastError=true)]
1945 public static extern int fchdir (int fd);
1948 // char *getcwd(char *buf, size_t size);
1949 [DllImport (MPH, SetLastError=true,
1950 EntryPoint="Mono_Posix_Syscall_getcwd")]
1951 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
1953 public static StringBuilder getcwd (StringBuilder buf)
1955 getcwd (buf, (ulong) buf.Capacity);
1959 // getwd(2) is deprecated; don't expose it.
1961 [DllImport (LIBC, SetLastError=true)]
1962 public static extern int dup (int fd);
1964 [DllImport (LIBC, SetLastError=true)]
1965 public static extern int dup2 (int fd, int fd2);
1967 // TODO: does Mono marshal arrays properly?
1968 [DllImport (LIBC, SetLastError=true)]
1969 public static extern int execve (string path, string[] argv, string[] envp);
1971 [DllImport (LIBC, SetLastError=true)]
1972 public static extern int fexecve (int fd, string[] argv, string[] envp);
1974 [DllImport (LIBC, SetLastError=true)]
1975 public static extern int execv (string path, string[] argv);
1977 // TODO: execle, execl, execlp
1978 [DllImport (LIBC, SetLastError=true)]
1979 public static extern int execvp (string path, string[] argv);
1981 [DllImport (LIBC, SetLastError=true)]
1982 public static extern int nice (int inc);
1984 [DllImport (LIBC, SetLastError=true)]
1985 public static extern int _exit (int status);
1987 [DllImport (MPH, SetLastError=true,
1988 EntryPoint="Mono_Posix_Syscall_fpathconf")]
1989 public static extern long fpathconf (int filedes, PathConf name);
1991 [DllImport (MPH, SetLastError=true,
1992 EntryPoint="Mono_Posix_Syscall_pathconf")]
1993 public static extern long pathconf (string path, PathConf name);
1995 [DllImport (MPH, SetLastError=true,
1996 EntryPoint="Mono_Posix_Syscall_sysconf")]
1997 public static extern long sysconf (SysConf name);
2000 // size_t confstr(int name, char *buf, size_t len);
2001 [DllImport (MPH, SetLastError=true,
2002 EntryPoint="Mono_Posix_Syscall_confstr")]
2003 public static extern ulong confstr (ConfStr name, [Out] StringBuilder buf, ulong len);
2006 // pid_t getpid(void);
2007 [DllImport (LIBC, SetLastError=true)]
2008 public static extern int getpid ();
2011 // pid_t getppid(void);
2012 [DllImport (LIBC, SetLastError=true)]
2013 public static extern int getppid ();
2016 // int setpgid(pid_t pid, pid_t pgid);
2017 [DllImport (LIBC, SetLastError=true)]
2018 public static extern int setpgid (int pid, int pgid);
2021 // pid_t getpgid(pid_t pid);
2022 [DllImport (LIBC, SetLastError=true)]
2023 public static extern int getpgid (int pid);
2025 [DllImport (LIBC, SetLastError=true)]
2026 public static extern int setpgrp ();
2029 // pid_t getpgrp(void);
2030 [DllImport (LIBC, SetLastError=true)]
2031 public static extern int getpgrp ();
2034 // pid_t setsid(void);
2035 [DllImport (LIBC, SetLastError=true)]
2036 public static extern int setsid ();
2039 // pid_t getsid(pid_t pid);
2040 [DllImport (LIBC, SetLastError=true)]
2041 public static extern int getsid (int pid);
2044 // uid_t getuid(void);
2045 [DllImport (LIBC, SetLastError=true)]
2046 public static extern uint getuid ();
2049 // uid_t geteuid(void);
2050 [DllImport (LIBC, SetLastError=true)]
2051 public static extern uint geteuid ();
2054 // gid_t getgid(void);
2055 [DllImport (LIBC, SetLastError=true)]
2056 public static extern uint getgid ();
2059 // gid_t getgid(void);
2060 [DllImport (LIBC, SetLastError=true)]
2061 public static extern uint getegid ();
2064 // int getgroups(int size, gid_t list[]);
2065 [DllImport (LIBC, SetLastError=true)]
2066 public static extern int getgroups (int size, uint[] list);
2068 public static int getgroups (uint[] list)
2070 return getgroups (list.Length, list);
2074 // int setuid(uid_t uid);
2075 [DllImport (LIBC, SetLastError=true)]
2076 public static extern int setuid (uint uid);
2079 // int setreuid(uid_t ruid, uid_t euid);
2080 [DllImport (LIBC, SetLastError=true)]
2081 public static extern int setreuid (uint ruid, uint euid);
2084 // int setregid(gid_t ruid, gid_t euid);
2085 [DllImport (LIBC, SetLastError=true)]
2086 public static extern int setregid (uint rgid, uint egid);
2089 // int seteuid(uid_t euid);
2090 [DllImport (LIBC, SetLastError=true)]
2091 public static extern int seteuid (uint euid);
2094 // int setegid(gid_t euid);
2095 [DllImport (LIBC, SetLastError=true)]
2096 public static extern int setegid (uint uid);
2099 // int setgid(gid_t gid);
2100 [DllImport (LIBC, SetLastError=true)]
2101 public static extern int setgid (uint gid);
2104 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
2105 [DllImport (LIBC, SetLastError=true)]
2106 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
2109 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
2110 [DllImport (LIBC, SetLastError=true)]
2111 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
2114 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
2115 [DllImport (LIBC, SetLastError=true)]
2116 public static extern int setresuid (uint ruid, uint euid, uint suid);
2119 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
2120 [DllImport (LIBC, SetLastError=true)]
2121 public static extern int setresgid (uint rgid, uint egid, uint sgid);
2124 // pid_t fork(void);
2125 [DllImport (LIBC, SetLastError=true)]
2126 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
2127 "shutdown code.\nUse System.Diagnostics.Process instead")]
2128 public static extern int fork ();
2131 // pid_t vfork(void);
2132 [DllImport (LIBC, SetLastError=true)]
2133 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
2134 "shutdown code.\nUse System.Diagnostics.Process instead")]
2135 public static extern int vfork ();
2137 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
2138 [Obsolete ("Not re-entrant. Use ttyname_r instead.")]
2139 public static extern IntPtr sys_ttyname (int fd);
2141 [Obsolete ("Not re-entrant. Use ttyname_r instead.")]
2142 public static string ttyname (int fd)
2144 IntPtr r = sys_ttyname (fd);
2145 return UnixMarshal.PtrToString (r);
2149 // int ttyname_r(int fd, char *buf, size_t buflen);
2150 [DllImport (MPH, SetLastError=true,
2151 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
2152 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
2154 public static int ttyname_r (int fd, StringBuilder buf)
2156 return ttyname_r (fd, buf, (ulong) buf.Capacity);
2159 [DllImport (LIBC, EntryPoint="isatty")]
2160 private static extern int sys_isatty (int fd);
2162 public static bool isatty (int fd)
2164 return sys_isatty (fd) == 1;
2167 [DllImport (LIBC, SetLastError=true)]
2168 public static extern int link (string oldpath, string newpath);
2170 [DllImport (LIBC, SetLastError=true)]
2171 public static extern int symlink (string oldpath, string newpath);
2174 // int readlink(const char *path, char *buf, size_t bufsize);
2175 [DllImport (MPH, SetLastError=true,
2176 EntryPoint="Mono_Posix_Syscall_readlink")]
2177 public static extern int readlink (string path, [Out] StringBuilder buf, ulong bufsiz);
2179 public static int readlink (string path, [Out] StringBuilder buf)
2181 return readlink (path, buf, (ulong) buf.Capacity);
2184 [DllImport (LIBC, SetLastError=true)]
2185 public static extern int unlink (string pathname);
2187 [DllImport (LIBC, SetLastError=true)]
2188 public static extern int rmdir (string pathname);
2191 // pid_t tcgetpgrp(int fd);
2192 [DllImport (LIBC, SetLastError=true)]
2193 public static extern int tcgetpgrp (int fd);
2196 // int tcsetpgrp(int fd, pid_t pgrp);
2197 [DllImport (LIBC, SetLastError=true)]
2198 public static extern int tcsetpgrp (int fd, int pgrp);
2200 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
2201 [Obsolete ("Not re-entrant. Use getlogin_r instead.")]
2202 public static extern IntPtr sys_getlogin ();
2204 [Obsolete ("Not re-entrant. Use getlogin_r instead.")]
2205 public static string getlogin ()
2207 IntPtr r = sys_getlogin ();
2208 return UnixMarshal.PtrToString (r);
2212 // int getlogin_r(char *buf, size_t bufsize);
2213 [DllImport (MPH, SetLastError=true,
2214 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
2215 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
2217 public static int getlogin_r (StringBuilder name)
2219 return getlogin_r (name, (ulong) name.Capacity);
2222 [DllImport (LIBC, SetLastError=true)]
2223 public static extern int setlogin (string name);
2226 // int gethostname(char *name, size_t len);
2227 [DllImport (MPH, SetLastError=true,
2228 EntryPoint="Mono_Posix_Syscall_gethostname")]
2229 public static extern int gethostname ([Out] StringBuilder name, ulong len);
2231 public static int gethostname (StringBuilder name)
2233 return gethostname (name, (ulong) name.Capacity);
2237 // int gethostname(const char *name, size_t len);
2238 [DllImport (MPH, SetLastError=true,
2239 EntryPoint="Mono_Posix_Syscall_gethostname")]
2240 public static extern int sethostname (string name, ulong len);
2242 public static int sethostname (string name)
2244 return sethostname (name, (ulong) name.Length);
2247 [DllImport (MPH, SetLastError=true,
2248 EntryPoint="Mono_Posix_Syscall_gethostid")]
2249 public static extern long gethostid ();
2251 [DllImport (MPH, SetLastError=true,
2252 EntryPoint="Mono_Posix_Syscall_sethostid")]
2253 public static extern int sethostid (long hostid);
2256 // int getdomainname(char *name, size_t len);
2257 [DllImport (MPH, SetLastError=true,
2258 EntryPoint="Mono_Posix_Syscall_getdomainname")]
2259 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
2261 public static int getdomainname (StringBuilder name)
2263 return getdomainname (name, (ulong) name.Capacity);
2267 // int setdomainname(const char *name, size_t len);
2268 [DllImport (MPH, SetLastError=true,
2269 EntryPoint="Mono_Posix_Syscall_setdomainname")]
2270 public static extern int setdomainname (string name, ulong len);
2272 public static int setdomainname (string name)
2274 return setdomainname (name, (ulong) name.Length);
2277 [DllImport (LIBC, SetLastError=true)]
2278 public static extern int vhangup ();
2280 // Revoke doesn't appear to be POSIX. Include it?
2281 [DllImport (LIBC, SetLastError=true)]
2282 public static extern int revoke (string file);
2284 // TODO: profil? It's not POSIX.
2286 [DllImport (LIBC, SetLastError=true)]
2287 public static extern int acct (string filename);
2289 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
2290 public static extern IntPtr sys_getusershell ();
2292 public static string getusershell ()
2294 IntPtr r = sys_getusershell ();
2295 return UnixMarshal.PtrToString (r);
2298 [DllImport (LIBC, SetLastError=true)]
2299 public static extern void setusershell ();
2301 [DllImport (LIBC, SetLastError=true)]
2302 public static extern void endusershell ();
2304 [DllImport (LIBC, SetLastError=true)]
2305 private static extern int daemon (int nochdir, int noclose);
2307 public static int daemon (bool nochdir, bool noclose)
2309 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
2312 [DllImport (LIBC, SetLastError=true)]
2313 public static extern int chroot (string path);
2315 // skipping getpass(3) as the man page states:
2316 // This function is obsolete. Do not use it.
2318 [DllImport (LIBC, SetLastError=true)]
2319 public static extern int fsync (int fd);
2321 [DllImport (LIBC, SetLastError=true)]
2322 public static extern int fdatasync (int fd);
2324 [DllImport (LIBC, SetLastError=true)]
2325 public static extern void sync ();
2327 [DllImport (LIBC, SetLastError=true)]
2328 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
2329 "Use Unistd.sysconf (SysConf._SC_PAGESIZE).")]
2330 public static extern int getpagesize ();
2333 // int truncate(const char *path, off_t length);
2334 [DllImport (MPH, SetLastError=true,
2335 EntryPoint="Mono_Posix_Syscall_truncate")]
2336 public static extern int truncate (string path, long length);
2339 // int ftruncate(int fd, off_t length);
2340 [DllImport (MPH, SetLastError=true,
2341 EntryPoint="Mono_Posix_Syscall_ftruncate")]
2342 public static extern int ftruncate (int fd, long length);
2344 [DllImport (LIBC, SetLastError=true)]
2345 public static extern int getdtablesize ();
2347 [DllImport (LIBC, SetLastError=true)]
2348 public static extern int brk (IntPtr end_data_segment);
2350 [DllImport (LIBC, SetLastError=true)]
2351 public static extern IntPtr sbrk (IntPtr increment);
2353 // TODO: syscall(2)?
2354 // Probably safer to skip entirely.
2357 // int lockf(int fd, int cmd, off_t len);
2358 [DllImport (MPH, SetLastError=true,
2359 EntryPoint="Mono_Posix_Syscall_lockf")]
2360 public static extern int lockf (int fd, LockFlags cmd, long len);
2362 [DllImport (CRYPT, SetLastError=true, EntryPoint="crypt")]
2363 public static extern IntPtr sys_crypt (string key, string salt);
2365 public static string crypt (string key, string salt)
2367 IntPtr r = sys_crypt (key, salt);
2368 return UnixMarshal.PtrToString (r);
2371 [DllImport (CRYPT, SetLastError=true, EntryPoint="encrypt")]
2372 private static extern void sys_encrypt ([In, Out] byte[] block, int edflag);
2374 public static void encrypt (byte[] block, bool decode)
2376 if (block.Length < 64)
2377 throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
2378 sys_encrypt (block, decode ? 1 : 0);
2382 // void swab(const void *from, void *to, ssize_t n);
2383 [DllImport (MPH, SetLastError=true,
2384 EntryPoint="Mono_Posix_Syscall_swab")]
2385 public static extern void swab (IntPtr from, IntPtr to, long n);
2387 public static unsafe void swab (void* from, void* to, long n)
2389 swab ((IntPtr) from, (IntPtr) to, n);
2394 #region <utime.h> Declarations
2396 // <utime.h> -- COMPLETE
2399 [DllImport (MPH, SetLastError=true,
2400 EntryPoint="Mono_Posix_Syscall_utime")]
2401 public static extern int utime (string filename, ref Utimbuf buf);
2403 [DllImport (MPH, SetLastError=true,
2404 EntryPoint="Mono_Posix_Syscall_utime")]
2405 private static extern int utime (string filename, IntPtr buf);
2407 public static int utime (string filename)
2409 return utime (filename, IntPtr.Zero);