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-2005 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"})]
72 public enum SyslogOptions {
73 LOG_PID = 0x01, // log the pid with each message
74 LOG_CONS = 0x02, // log on the console if errors in sending
75 LOG_ODELAY = 0x04, // delay open until first syslog (default)
76 LOG_NDELAY = 0x08, // don't delay open
77 LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
78 LOG_PERROR = 0x20 // log to stderr as well
82 public enum SyslogFacility {
93 LOG_AUTHPRIV = 10 << 3,
100 LOG_LOCAL5 = 21 << 3,
101 LOG_LOCAL6 = 22 << 3,
102 LOG_LOCAL7 = 23 << 3,
106 public enum SyslogLevel {
107 LOG_EMERG = 0, // system is unusable
108 LOG_ALERT = 1, // action must be taken immediately
109 LOG_CRIT = 2, // critical conditions
110 LOG_ERR = 3, // warning conditions
111 LOG_WARNING = 4, // warning conditions
112 LOG_NOTICE = 5, // normal but significant condition
113 LOG_INFO = 6, // informational
114 LOG_DEBUG = 7 // debug-level messages
118 public enum OpenFlags : int {
122 O_RDONLY = 0x00000000,
123 O_WRONLY = 0x00000001,
127 // Or-ed with zero or more of these
129 O_CREAT = 0x00000040,
131 O_NOCTTY = 0x00000100,
132 O_TRUNC = 0x00000200,
133 O_APPEND = 0x00000400,
134 O_NONBLOCK = 0x00000800,
138 // These are non-Posix. Using them will result in errors/exceptions on
139 // non-supported platforms.
141 // (For example, "C-wrapped" system calls -- calls with implementation in
142 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
143 // calls will generate an exception in UnixConvert, as the value can't be
144 // converted on the target platform.)
147 O_NOFOLLOW = 0x00020000,
148 O_DIRECTORY = 0x00010000,
149 O_DIRECT = 0x00004000,
150 O_ASYNC = 0x00002000,
151 O_LARGEFILE = 0x00008000
156 public enum FilePermissions : uint {
157 S_ISUID = 0x0800, // Set user ID on execution
158 S_ISGID = 0x0400, // Set gorup ID on execution
159 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
160 S_IRUSR = 0x0100, // Read by owner
161 S_IWUSR = 0x0080, // Write by owner
162 S_IXUSR = 0x0040, // Execute by owner
163 S_IRGRP = 0x0020, // Read by group
164 S_IWGRP = 0x0010, // Write by group
165 S_IXGRP = 0x0008, // Execute by group
166 S_IROTH = 0x0004, // Read by other
167 S_IWOTH = 0x0002, // Write by other
168 S_IXOTH = 0x0001, // Execute by other
170 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
171 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
172 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
173 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
174 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
175 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
178 // Why these are held in "mode_t" is beyond me...
179 S_IFMT = 0xF000, // Bits which determine file type
180 S_IFDIR = 0x4000, // Directory
181 S_IFCHR = 0x2000, // Character device
182 S_IFBLK = 0x6000, // Block device
183 S_IFREG = 0x8000, // Regular file
184 S_IFIFO = 0x1000, // FIFO
185 S_IFLNK = 0xA000, // Symbolic link
186 S_IFSOCK = 0xC000, // Socket
190 public enum FcntlCommand : int {
191 // Form /usr/include/bits/fcntl.h
192 F_DUPFD = 0, // Duplicate file descriptor.
193 F_GETFD = 1, // Get file descriptor flags.
194 F_SETFD = 2, // Set file descriptor flags.
195 F_GETFL = 3, // Get file status flags.
196 F_SETFL = 4, // Set file status flags.
197 F_GETLK = 12, // Get record locking info. [64]
198 F_SETLK = 13, // Set record locking info (non-blocking). [64]
199 F_SETLKW = 14, // Set record locking info (blocking). [64]
200 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
201 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
202 F_SETSIG = 10, // Set number of signal to be sent.
203 F_GETSIG = 11, // Get number of signal to be sent.
204 F_SETLEASE = 1024, // Set a lease.
205 F_GETLEASE = 1025, // Enquire what lease is active.
206 F_NOTIFY = 1026, // Required notifications on a directory
210 public enum LockType : short {
211 F_RDLCK = 0, // Read lock.
212 F_WRLCK = 1, // Write lock.
213 F_UNLCK = 2, // Remove lock.
217 public enum SeekFlags : short {
218 // values liberally copied from /usr/include/unistd.h
219 SEEK_SET = 0, // Seek from beginning of file.
220 SEEK_CUR = 1, // Seek from current position.
221 SEEK_END = 2, // Seek from end of file.
223 L_SET = SEEK_SET, // BSD alias for SEEK_SET
224 L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
225 L_XTND = SEEK_END, // BSD alias for SEEK_END
229 public enum DirectoryNotifyFlags : int {
230 // from /usr/include/bits/fcntl.h
231 DN_ACCESS = 0x00000001, // File accessed.
232 DN_MODIFY = 0x00000002, // File modified.
233 DN_CREATE = 0x00000004, // File created.
234 DN_DELETE = 0x00000008, // File removed.
235 DN_RENAME = 0x00000010, // File renamed.
236 DN_ATTRIB = 0x00000020, // File changed attributes.
237 DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
241 public enum PosixFadviseAdvice : int {
242 POSIX_FADV_NORMAL = 0, // No further special treatment.
243 POSIX_FADV_RANDOM = 1, // Expect random page references.
244 POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
245 POSIX_FADV_WILLNEED = 3, // Will need these pages.
246 POSIX_FADV_DONTNEED = 4, // Don't need these pages.
247 POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
251 public enum PosixMadviseAdvice : int {
252 POSIX_MADV_NORMAL = 0, // No further special treatment.
253 POSIX_MADV_RANDOM = 1, // Expect random page references.
254 POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
255 POSIX_MADV_WILLNEED = 3, // Will need these pages.
256 POSIX_MADV_DONTNEED = 4, // Don't need these pages.
260 public enum Signum : int {
261 SIGHUP = 1, // Hangup (POSIX).
262 SIGINT = 2, // Interrupt (ANSI).
263 SIGQUIT = 3, // Quit (POSIX).
264 SIGILL = 4, // Illegal instruction (ANSI).
265 SIGTRAP = 5, // Trace trap (POSIX).
266 SIGABRT = 6, // Abort (ANSI).
267 SIGIOT = 6, // IOT trap (4.2 BSD).
268 SIGBUS = 7, // BUS error (4.2 BSD).
269 SIGFPE = 8, // Floating-point exception (ANSI).
270 SIGKILL = 9, // Kill, unblockable (POSIX).
271 SIGUSR1 = 10, // User-defined signal 1 (POSIX).
272 SIGSEGV = 11, // Segmentation violation (ANSI).
273 SIGUSR2 = 12, // User-defined signal 2 (POSIX).
274 SIGPIPE = 13, // Broken pipe (POSIX).
275 SIGALRM = 14, // Alarm clock (POSIX).
276 SIGTERM = 15, // Termination (ANSI).
277 SIGSTKFLT = 16, // Stack fault.
278 SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
279 SIGCHLD = 17, // Child status has changed (POSIX).
280 SIGCONT = 18, // Continue (POSIX).
281 SIGSTOP = 19, // Stop, unblockable (POSIX).
282 SIGTSTP = 20, // Keyboard stop (POSIX).
283 SIGTTIN = 21, // Background read from tty (POSIX).
284 SIGTTOU = 22, // Background write to tty (POSIX).
285 SIGURG = 23, // Urgent condition on socket (4.2 BSD).
286 SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
287 SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
288 SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
289 SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
290 SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
291 SIGPOLL = SIGIO, // Pollable event occurred (System V).
292 SIGIO = 29, // I/O now possible (4.2 BSD).
293 SIGPWR = 30, // Power failure restart (System V).
294 SIGSYS = 31, // Bad system call.
299 public enum WaitOptions : int {
300 WNOHANG = 1, // Don't block waiting
301 WUNTRACED = 2, // Report status of stopped children
305 public enum AccessMode : int {
313 public enum PathConf : int {
320 _PC_CHOWN_RESTRICTED,
328 _PC_REC_INCR_XFER_SIZE,
329 _PC_REC_MAX_XFER_SIZE,
330 _PC_REC_MIN_XFER_SIZE,
338 public enum SysConf : int {
348 _SC_REALTIME_SIGNALS,
349 _SC_PRIORITY_SCHEDULING,
358 _SC_MEMORY_PROTECTION,
361 _SC_SHARED_MEMORY_OBJECTS,
364 _SC_AIO_PRIO_DELTA_MAX,
375 /* Values for the argument to `sysconf'
376 corresponding to _POSIX2_* symbols. */
381 _SC_COLL_WEIGHTS_MAX,
386 _SC_CHARCLASS_NAME_MAX,
402 _SC_IOV_MAX = _SC_UIO_MAXIOV,
403 _SC_PII_INTERNET_STREAM,
404 _SC_PII_INTERNET_DGRAM,
409 /* Values according to POSIX 1003.1c (POSIX threads). */
411 _SC_THREAD_SAFE_FUNCTIONS,
412 _SC_GETGR_R_SIZE_MAX,
413 _SC_GETPW_R_SIZE_MAX,
416 _SC_THREAD_DESTRUCTOR_ITERATIONS,
418 _SC_THREAD_STACK_MIN,
419 _SC_THREAD_THREADS_MAX,
420 _SC_THREAD_ATTR_STACKADDR,
421 _SC_THREAD_ATTR_STACKSIZE,
422 _SC_THREAD_PRIORITY_SCHEDULING,
423 _SC_THREAD_PRIO_INHERIT,
424 _SC_THREAD_PRIO_PROTECT,
425 _SC_THREAD_PROCESS_SHARED,
426 _SC_NPROCESSORS_CONF,
427 _SC_NPROCESSORS_ONLN,
433 _SC_XOPEN_XCU_VERSION,
468 _SC_XBS5_ILP32_OFF32,
469 _SC_XBS5_ILP32_OFFBIG,
471 _SC_XBS5_LPBIG_OFFBIG,
474 _SC_XOPEN_REALTIME_THREADS,
479 _SC_C_LANG_SUPPORT_R,
485 _SC_DEVICE_SPECIFIC_R,
496 _SC_READER_WRITER_LOCKS,
504 _SC_THREAD_SPORADIC_SERVER,
506 _SC_SYSTEM_DATABASE_R,
508 _SC_TYPED_MEMORY_OBJECTS,
512 _SC_2_PBS_ACCOUNTING,
518 _SC_2_PBS_CHECKPOINT,
525 _SC_TRACE_EVENT_FILTER,
528 _SC_LEVEL1_ICACHE_SIZE,
529 _SC_LEVEL1_ICACHE_ASSOC,
530 _SC_LEVEL1_ICACHE_LINESIZE,
531 _SC_LEVEL1_DCACHE_SIZE,
532 _SC_LEVEL1_DCACHE_ASSOC,
533 _SC_LEVEL1_DCACHE_LINESIZE,
534 _SC_LEVEL2_CACHE_SIZE,
535 _SC_LEVEL2_CACHE_ASSOC,
536 _SC_LEVEL2_CACHE_LINESIZE,
537 _SC_LEVEL3_CACHE_SIZE,
538 _SC_LEVEL3_CACHE_ASSOC,
539 _SC_LEVEL3_CACHE_LINESIZE,
540 _SC_LEVEL4_CACHE_SIZE,
541 _SC_LEVEL4_CACHE_ASSOC,
542 _SC_LEVEL4_CACHE_LINESIZE
546 public enum ConfStr : int {
547 _CS_PATH, /* The default search path. */
548 _CS_V6_WIDTH_RESTRICTED_ENVS,
549 _CS_GNU_LIBC_VERSION,
550 _CS_GNU_LIBPTHREAD_VERSION,
551 _CS_LFS_CFLAGS = 1000,
559 _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
560 _CS_XBS5_ILP32_OFF32_LDFLAGS,
561 _CS_XBS5_ILP32_OFF32_LIBS,
562 _CS_XBS5_ILP32_OFF32_LINTFLAGS,
563 _CS_XBS5_ILP32_OFFBIG_CFLAGS,
564 _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
565 _CS_XBS5_ILP32_OFFBIG_LIBS,
566 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
567 _CS_XBS5_LP64_OFF64_CFLAGS,
568 _CS_XBS5_LP64_OFF64_LDFLAGS,
569 _CS_XBS5_LP64_OFF64_LIBS,
570 _CS_XBS5_LP64_OFF64_LINTFLAGS,
571 _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
572 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
573 _CS_XBS5_LPBIG_OFFBIG_LIBS,
574 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
575 _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
576 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
577 _CS_POSIX_V6_ILP32_OFF32_LIBS,
578 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
579 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
580 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
581 _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
582 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
583 _CS_POSIX_V6_LP64_OFF64_CFLAGS,
584 _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
585 _CS_POSIX_V6_LP64_OFF64_LIBS,
586 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
587 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
588 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
589 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
590 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
594 public enum LockFlags : int {
595 F_ULOCK = 0, // Unlock a previously locked region.
596 F_LOCK = 1, // Lock a region for exclusive use.
597 F_TLOCK = 2, // Test and lock a region for exclusive use.
598 F_TEST = 3, // Test a region for other process locks.
602 public enum PollEvents : short {
603 POLLIN = 0x0001, // There is data to read
604 POLLPRI = 0x0002, // There is urgent data to read
605 POLLOUT = 0x0004, // Writing now will not block
606 POLLERR = 0x0008, // Error condition
607 POLLHUP = 0x0010, // Hung up
608 POLLNVAL = 0x0020, // Invalid request; fd not open
609 // XPG4.2 definitions (via _XOPEN_SOURCE)
610 POLLRDNORM = 0x0040, // Normal data bay be read
611 POLLRDBAND = 0x0080, // Priority data may be read
612 POLLWRNORM = 0x0100, // Writing now will not block
613 POLLWRBAND = 0x0200, // Priority data may be written
620 public struct Flock {
621 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
622 public SeekFlags l_whence; // How to interpret l_start
623 public /* off_t */ long l_start; // Starting offset for lock
624 public /* off_t */ long l_len; // Number of bytes to lock
625 public /* pid_t */ int l_pid; // PID of process blocking our lock (F_GETLK only)
628 [StructLayout(LayoutKind.Sequential)]
629 public struct Pollfd {
631 public PollEvents events;
632 public PollEvents revents;
636 public /* dev_t */ ulong st_dev; // device
637 public /* ino_t */ ulong st_ino; // inode
638 public FilePermissions st_mode; // protection
639 private uint _padding_; // padding for structure alignment
640 public /* nlink_t */ ulong st_nlink; // number of hard links
641 public /* uid_t */ uint st_uid; // user ID of owner
642 public /* gid_t */ uint st_gid; // group ID of owner
643 public /* dev_t */ ulong st_rdev; // device type (if inode device)
644 public /* off_t */ long st_size; // total size, in bytes
645 public /* blksize_t */ long st_blksize; // blocksize for filesystem I/O
646 public /* blkcnt_t */ long st_blocks; // number of blocks allocated
647 public /* time_t */ long st_atime; // time of last access
648 public /* time_t */ long st_mtime; // time of last modification
649 public /* time_t */ long st_ctime; // time of last status change
652 public struct Statvfs {
653 public ulong f_bsize; // file system block size
654 public ulong f_frsize; // fragment size
655 public /* fsblkcnt_t */ ulong f_blocks; // size of fs in f_frsize units
656 public /* fsblkcnt_t */ ulong f_bfree; // # free blocks
657 public /* fsblkcnt_t */ ulong f_bavail; // # free blocks for non-root
658 public /* fsfilcnt_t */ ulong f_files; // # inodes
659 public /* fsfilcnt_t */ ulong f_ffree; // # free inodes
660 public /* fsfilcnt_t */ ulong f_favail; // # free inodes for non-root
661 public ulong f_fsid; // file system id
662 public ulong f_flag; // mount flags
663 public ulong f_namemax; // maximum filename length
666 public struct Timeval {
667 public /* time_t */ long tv_sec; // seconds
668 public /* suseconds_t */ long tv_usec; // microseconds
671 public struct Timezone {
672 public int tz_minuteswest; // minutes W of Greenwich
673 private int tz_dsttime; // type of dst correction (OBSOLETE)
676 public struct Utimbuf {
677 public /* time_t */ long actime; // access time
678 public /* time_t */ long modtime; // modification time
685 public sealed class Dirent
687 public /* ino_t */ ulong d_ino;
688 public /* off_t */ long d_off;
689 public ushort d_reclen;
691 public string d_name;
693 public override int GetHashCode ()
695 return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
696 d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
697 d_name.GetHashCode ();
700 public override bool Equals (object obj)
702 if (obj == null || GetType() != obj.GetType())
704 Dirent d = (Dirent) obj;
705 return d.d_ino == d_ino && d.d_off == d_off &&
706 d.d_reclen == d_reclen && d.d_type == d_type &&
710 public override string ToString ()
715 public static bool operator== (Dirent lhs, Dirent rhs)
717 return Object.Equals (lhs, rhs);
720 public static bool operator!= (Dirent lhs, Dirent rhs)
722 return !Object.Equals (lhs, rhs);
726 public sealed class Fstab
728 public string fs_spec;
729 public string fs_file;
730 public string fs_vfstype;
731 public string fs_mntops;
732 public string fs_type;
734 public int fs_passno;
736 public override int GetHashCode ()
738 return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
739 fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
740 fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
743 public override bool Equals (object obj)
745 if (obj == null || GetType() != obj.GetType())
747 Fstab f = (Fstab) obj;
748 return f.fs_spec == fs_spec && f.fs_file == fs_file &&
749 f.fs_vfstype == fs_vfstype && f.fs_mntops == fs_mntops &&
750 f.fs_type == fs_type && f.fs_freq == fs_freq &&
751 f.fs_passno == fs_passno;
754 public override string ToString ()
759 public static bool operator== (Fstab lhs, Fstab rhs)
761 return Object.Equals (lhs, rhs);
764 public static bool operator!= (Fstab lhs, Fstab rhs)
766 return !Object.Equals (lhs, rhs);
770 public sealed class Group
772 public string gr_name;
773 public string gr_passwd;
774 public /* gid_t */ uint gr_gid;
775 public string[] gr_mem;
777 public override int GetHashCode ()
780 for (int i = 0; i < gr_mem.Length; ++i)
781 memhc ^= gr_mem[i].GetHashCode ();
783 return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
784 gr_gid.GetHashCode () ^ memhc;
787 public override bool Equals (object obj)
789 if (obj == null || GetType() != obj.GetType())
791 Group g = (Group) obj;
792 if (g.gr_gid != gr_gid)
794 if (g.gr_gid == gr_gid && g.gr_name == gr_name &&
795 g.gr_passwd == gr_passwd) {
796 if (g.gr_mem == gr_mem)
798 if (g.gr_mem == null || gr_mem == null)
800 if (g.gr_mem.Length != gr_mem.Length)
802 for (int i = 0; i < gr_mem.Length; ++i)
803 if (gr_mem[i] != g.gr_mem[i])
810 // Generate string in /etc/group format
811 public override string ToString ()
813 StringBuilder sb = new StringBuilder ();
814 sb.AppendFormat ("{0}:{1}:{2}:", gr_name, gr_passwd, gr_gid);
815 GetMembers (sb, gr_mem);
816 return sb.ToString ();
819 private static void GetMembers (StringBuilder sb, string[] members)
821 if (members.Length > 0)
822 sb.Append (members[0]);
823 for (int i = 1; i < members.Length; ++i) {
825 sb.Append (members[i]);
829 public static bool operator== (Group lhs, Group rhs)
831 return Object.Equals (lhs, rhs);
834 public static bool operator!= (Group lhs, Group rhs)
836 return !Object.Equals (lhs, rhs);
840 public sealed class Passwd
842 public string pw_name;
843 public string pw_passwd;
844 public /* uid_t */ uint pw_uid;
845 public /* gid_t */ uint pw_gid;
846 public string pw_gecos;
847 public string pw_dir;
848 public string pw_shell;
850 public override int GetHashCode ()
852 return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
853 pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
854 pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
855 pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
858 public override bool Equals (object obj)
860 if (obj == null || GetType() != obj.GetType())
862 Passwd p = (Passwd) obj;
863 return p.pw_uid == pw_uid && p.pw_gid == pw_gid && p.pw_name == pw_name &&
864 p.pw_passwd == pw_passwd && p.pw_gecos == pw_gecos &&
865 p.pw_dir == pw_dir && p.pw_shell == pw_shell;
868 // Generate string in /etc/passwd format
869 public override string ToString ()
871 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
872 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
875 public static bool operator== (Passwd lhs, Passwd rhs)
877 return Object.Equals (lhs, rhs);
880 public static bool operator!= (Passwd lhs, Passwd rhs)
882 return !Object.Equals (lhs, rhs);
887 // Convention: Functions *not* part of the standard C library AND part of
888 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
890 // For example, the man page should be similar to:
892 // CONFORMING TO (or CONFORMS TO)
893 // XPG2, SUSv2, POSIX, etc.
895 // BSD- and GNU-specific exports can also be placed here.
897 // The only methods in here should be:
898 // (1) low-level functions
899 // (2) "Trivial" function overloads. For example, if the parameters to a
900 // function are related (e.g. getgroups(2))
901 // (3) The return type SHOULD NOT be changed. If you want to provide a
902 // convenience function with a nicer return type, place it into one of
903 // the Unix* wrapper classes, and give it a .NET-styled name.
904 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
905 // - If you're wrapping *broken* methods which make assumptions about
906 // input data, such as that an argument refers to N bytes of data.
907 // This is currently limited to cuserid(3) and encrypt(3).
908 // - If you call functions which themselves generate exceptions.
909 // This is the case for using UnixConvert, which will throw an
910 // exception if an invalid/unsupported value is used.
912 public sealed class Syscall : Stdlib
914 new internal const string LIBC = "libc";
915 private const string CRYPT = "crypt";
917 private Syscall () {}
923 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
924 // aio_return(3), aio_suspend(3), aio_write(3)
926 // Then update UnixStream.BeginRead to use the aio* functions.
928 #region <dirent.h> Declarations
932 // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
934 [DllImport (LIBC, SetLastError=true)]
935 public static extern IntPtr opendir (string name);
937 [DllImport (LIBC, SetLastError=true)]
938 public static extern int closedir (IntPtr dir);
941 // void seekdir (DIR *dir, off_t offset);
942 // Slight modification. Returns -1 on error, 0 on success.
943 [DllImport (MPH, SetLastError=true,
944 EntryPoint="Mono_Posix_Syscall_seekdir")]
945 public static extern int seekdir (IntPtr dir, long offset);
948 // off_t telldir(DIR *dir);
949 [DllImport (MPH, SetLastError=true,
950 EntryPoint="Mono_Posix_Syscall_telldir")]
951 public static extern long telldir (IntPtr dir);
953 [DllImport (LIBC, SetLastError=true)]
954 public static extern void rewinddir (IntPtr dir);
956 private struct _Dirent {
957 public /* ino_t */ ulong d_ino;
958 public /* off_t */ long d_off;
959 public ushort d_reclen;
961 public IntPtr d_name;
964 private static void CopyDirent (Dirent to, ref _Dirent from)
967 to.d_ino = from.d_ino;
968 to.d_off = from.d_off;
969 to.d_reclen = from.d_reclen;
970 to.d_type = from.d_type;
971 to.d_name = UnixMarshal.PtrToString (from.d_name);
974 Stdlib.free (from.d_name);
975 from.d_name = IntPtr.Zero;
979 [DllImport (MPH, SetLastError=true,
980 EntryPoint="Mono_Posix_Syscall_readdir")]
981 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
983 public static Dirent readdir (IntPtr dir)
986 int r = sys_readdir (dir, out dentry);
989 Dirent d = new Dirent ();
990 CopyDirent (d, ref dentry);
994 [DllImport (MPH, SetLastError=true,
995 EntryPoint="Mono_Posix_Syscall_readdir_r")]
996 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
998 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
1004 entry.d_name = null;
1007 int r = sys_readdir_r (dirp, out _d, out result);
1009 if (r == 0 && result != IntPtr.Zero) {
1010 CopyDirent (entry, ref _d);
1016 [DllImport (LIBC, SetLastError=true)]
1017 public static extern int dirfd (IntPtr dir);
1020 #region <fcntl.h> Declarations
1022 // <fcntl.h> -- COMPLETE
1025 [DllImport (MPH, SetLastError=true,
1026 EntryPoint="Mono_Posix_Syscall_fcntl")]
1027 public static extern int fcntl (int fd, FcntlCommand cmd);
1029 [DllImport (MPH, SetLastError=true,
1030 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
1031 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
1033 [DllImport (MPH, SetLastError=true,
1034 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
1035 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
1037 [DllImport (MPH, SetLastError=true,
1038 EntryPoint="Mono_Posix_Syscall_open")]
1039 public static extern int open (string pathname, OpenFlags flags);
1042 // int open(const char *pathname, int flags, mode_t mode);
1043 [DllImport (MPH, SetLastError=true,
1044 EntryPoint="Mono_Posix_Syscall_open_mode")]
1045 public static extern int open (string pathname, OpenFlags flags, FilePermissions mode);
1048 // int creat(const char *pathname, mode_t mode);
1049 [DllImport (MPH, SetLastError=true,
1050 EntryPoint="Mono_Posix_Syscall_creat")]
1051 public static extern int creat (string pathname, FilePermissions mode);
1054 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
1055 [DllImport (MPH, SetLastError=true,
1056 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
1057 public static extern int posix_fadvise (int fd, long offset,
1058 long len, PosixFadviseAdvice advice);
1060 // posix_fallocate(P)
1061 // int posix_fallocate(int fd, off_t offset, size_t len);
1062 [DllImport (MPH, SetLastError=true,
1063 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
1064 public static extern int posix_fallocate (int fd, long offset, long len);
1067 #region <fstab.h> Declarations
1069 // <fstab.h> -- COMPLETE
1071 private struct _Fstab {
1072 public IntPtr fs_spec;
1073 public IntPtr fs_file;
1074 public IntPtr fs_vfstype;
1075 public IntPtr fs_mntops;
1076 public IntPtr fs_type;
1078 public int fs_passno;
1079 public IntPtr _fs_buf_;
1082 private static void CopyFstab (Fstab to, ref _Fstab from)
1085 to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
1086 to.fs_file = UnixMarshal.PtrToString (from.fs_file);
1087 to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
1088 to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
1089 to.fs_type = UnixMarshal.PtrToString (from.fs_type);
1090 to.fs_freq = from.fs_freq;
1091 to.fs_passno = from.fs_passno;
1094 Stdlib.free (from._fs_buf_);
1095 from._fs_buf_ = IntPtr.Zero;
1099 [DllImport (MPH, SetLastError=true,
1100 EntryPoint="Mono_Posix_Syscall_endfsent")]
1101 public static extern void endfsent ();
1103 [DllImport (MPH, SetLastError=true,
1104 EntryPoint="Mono_Posix_Syscall_getfsent")]
1105 private static extern int sys_getfsent (out _Fstab fs);
1107 public static Fstab getfsent ()
1110 int r = sys_getfsent (out fsbuf);
1113 Fstab fs = new Fstab ();
1114 CopyFstab (fs, ref fsbuf);
1118 [DllImport (MPH, SetLastError=true,
1119 EntryPoint="Mono_Posix_Syscall_getfsfile")]
1120 private static extern int sys_getfsfile (string mount_point, out _Fstab fs);
1122 public static Fstab getfsfile (string mount_point)
1125 int r = sys_getfsfile (mount_point, out fsbuf);
1128 Fstab fs = new Fstab ();
1129 CopyFstab (fs, ref fsbuf);
1133 [DllImport (MPH, SetLastError=true,
1134 EntryPoint="Mono_Posix_Syscall_getfsspec")]
1135 private static extern int sys_getfsspec (string special_file, out _Fstab fs);
1137 public static Fstab getfsspec (string special_file)
1140 int r = sys_getfsspec (special_file, out fsbuf);
1143 Fstab fs = new Fstab ();
1144 CopyFstab (fs, ref fsbuf);
1148 [DllImport (MPH, SetLastError=true,
1149 EntryPoint="Mono_Posix_Syscall_setfsent")]
1150 public static extern int setfsent ();
1154 #region <grp.h> Declarations
1158 // TODO: putgrent(3), fgetgrent_r(), getgrouplist(2), initgroups(3)
1161 // int setgroups (size_t size, const gid_t *list);
1162 [DllImport (MPH, SetLastError=true,
1163 EntryPoint="Mono_Posix_Syscall_setgroups")]
1164 public static extern int setgroups (ulong size, uint[] list);
1166 public static int setgroups (uint [] list)
1168 return setgroups ((ulong) list.Length, list);
1171 private struct _Group
1173 public IntPtr gr_name;
1174 public IntPtr gr_passwd;
1175 public /* gid_t */ uint gr_gid;
1176 public int _gr_nmem_;
1177 public IntPtr gr_mem;
1178 public IntPtr _gr_buf_;
1181 private static void CopyGroup (Group to, ref _Group from)
1184 to.gr_gid = from.gr_gid;
1185 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
1186 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
1187 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
1190 Stdlib.free (from.gr_mem);
1191 Stdlib.free (from._gr_buf_);
1192 from.gr_mem = IntPtr.Zero;
1193 from._gr_buf_ = IntPtr.Zero;
1197 [DllImport (MPH, SetLastError=true,
1198 EntryPoint="Mono_Posix_Syscall_getgrnam")]
1199 private static extern int sys_getgrnam (string name, out _Group group);
1201 public static Group getgrnam (string name)
1204 int r = sys_getgrnam (name, out group);
1207 Group gr = new Group ();
1208 CopyGroup (gr, ref group);
1213 // struct group *getgrgid(gid_t gid);
1214 [DllImport (MPH, SetLastError=true,
1215 EntryPoint="Mono_Posix_Syscall_getgrgid")]
1216 private static extern int sys_getgrgid (uint uid, out _Group group);
1218 public static Group getgrgid (uint uid)
1221 int r = sys_getgrgid (uid, out group);
1224 Group gr = new Group ();
1225 CopyGroup (gr, ref group);
1229 [DllImport (MPH, SetLastError=true,
1230 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
1231 private static extern int sys_getgrnam_r (string name, out _Group grbuf, out IntPtr grbufp);
1233 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
1238 int r = sys_getgrnam_r (name, out group, out _grbufp);
1239 if (r == 0 && _grbufp != IntPtr.Zero) {
1240 CopyGroup (grbuf, ref group);
1247 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
1248 // size_t buflen, struct group **gbufp);
1249 [DllImport (MPH, SetLastError=true,
1250 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
1251 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
1253 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
1258 int r = sys_getgrgid_r (uid, out group, out _grbufp);
1259 if (r == 0 && _grbufp != IntPtr.Zero) {
1260 CopyGroup (grbuf, ref group);
1266 [DllImport (MPH, SetLastError=true,
1267 EntryPoint="Mono_Posix_Syscall_getgrent")]
1268 private static extern int sys_getgrent (out _Group grbuf);
1270 public static Group getgrent ()
1273 int r = sys_getgrent (out group);
1276 Group gr = new Group();
1277 CopyGroup (gr, ref group);
1281 [DllImport (LIBC, SetLastError=true)]
1282 public static extern void setgrent ();
1284 [DllImport (LIBC, SetLastError=true)]
1285 public static extern void endgrent ();
1287 [DllImport (MPH, SetLastError=true,
1288 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
1289 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
1291 public static Group fgetgrent (IntPtr stream)
1294 int r = sys_fgetgrent (stream, out group);
1297 Group gr = new Group ();
1298 CopyGroup (gr, ref group);
1303 #region <pwd.h> Declarations
1307 // TODO: putpwent(3), fgetpwent_r()
1309 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
1311 private struct _Passwd
1313 public IntPtr pw_name;
1314 public IntPtr pw_passwd;
1315 public /* uid_t */ uint pw_uid;
1316 public /* gid_t */ uint pw_gid;
1317 public IntPtr pw_gecos;
1318 public IntPtr pw_dir;
1319 public IntPtr pw_shell;
1320 public IntPtr _pw_buf_;
1323 private static void CopyPasswd (Passwd to, ref _Passwd from)
1326 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
1327 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
1328 to.pw_uid = from.pw_uid;
1329 to.pw_gid = from.pw_gid;
1330 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
1331 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
1332 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
1335 Stdlib.free (from._pw_buf_);
1336 from._pw_buf_ = IntPtr.Zero;
1340 [DllImport (MPH, SetLastError=true,
1341 EntryPoint="Mono_Posix_Syscall_getpwnam")]
1342 private static extern int sys_getpwnam (string name, out _Passwd passwd);
1344 public static Passwd getpwnam (string name)
1347 int r = sys_getpwnam (name, out passwd);
1350 Passwd pw = new Passwd ();
1351 CopyPasswd (pw, ref passwd);
1356 // struct passwd *getpwnuid(uid_t uid);
1357 [DllImport (MPH, SetLastError=true,
1358 EntryPoint="Mono_Posix_Syscall_getpwuid")]
1359 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
1361 public static Passwd getpwuid (uint uid)
1364 int r = sys_getpwuid (uid, out passwd);
1367 Passwd pw = new Passwd ();
1368 CopyPasswd (pw, ref passwd);
1372 [DllImport (MPH, SetLastError=true,
1373 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
1374 private static extern int sys_getpwnam_r (string name, out _Passwd pwbuf, out IntPtr pwbufp);
1376 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
1381 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
1382 if (r == 0 && _pwbufp != IntPtr.Zero) {
1383 CopyPasswd (pwbuf, ref passwd);
1390 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
1391 // buflen, struct passwd **pwbufp);
1392 [DllImport (MPH, SetLastError=true,
1393 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
1394 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
1396 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
1401 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
1402 if (r == 0 && _pwbufp != IntPtr.Zero) {
1403 CopyPasswd (pwbuf, ref passwd);
1409 [DllImport (MPH, SetLastError=true,
1410 EntryPoint="Mono_Posix_Syscall_getpwent")]
1411 private static extern int sys_getpwent (out _Passwd pwbuf);
1413 public static Passwd getpwent ()
1416 int r = sys_getpwent (out passwd);
1419 Passwd pw = new Passwd ();
1420 CopyPasswd (pw, ref passwd);
1424 [DllImport (LIBC, SetLastError=true)]
1425 public static extern void setpwent ();
1427 [DllImport (LIBC, SetLastError=true)]
1428 public static extern void endpwent ();
1430 [DllImport (MPH, SetLastError=true,
1431 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
1432 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
1434 public static Passwd fgetpwent (IntPtr stream)
1437 int r = sys_fgetpwent (stream, out passwd);
1440 Passwd pw = new Passwd ();
1441 CopyPasswd (pw, ref passwd);
1446 #region <signal.h> Declarations
1450 [DllImport (LIBC, SetLastError=true)]
1451 private static extern void psignal (int sig, string s);
1453 public static void psignal (Signum sig, string s)
1455 int signum = UnixConvert.FromSignum (sig);
1456 psignal (signum, s);
1460 // int kill(pid_t pid, int sig);
1461 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
1462 private static extern int sys_kill (int pid, int sig);
1464 public static int kill (int pid, Signum sig)
1466 int _sig = UnixConvert.FromSignum (sig);
1467 return sys_kill (pid, _sig);
1470 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
1471 private static extern IntPtr sys_strsignal (int sig);
1473 public static string strsignal (Signum sig)
1475 int s = UnixConvert.FromSignum (sig);
1476 IntPtr r = sys_strsignal (s);
1477 return UnixMarshal.PtrToString (r);
1480 // TODO: sigaction(2)
1481 // TODO: sigsuspend(2)
1482 // TODO: sigpending(2)
1486 #region <stdio.h> Declarations
1490 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
1491 private static extern int _L_ctermid ();
1493 public static readonly int L_ctermid = _L_ctermid ();
1495 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
1496 private static extern int _L_cuserid ();
1498 public static readonly int L_cuserid = _L_cuserid ();
1500 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
1501 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
1503 [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
1504 "DO NOT USE cuserid().\n" +
1505 "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
1506 public static string cuserid (StringBuilder @string)
1508 if (@string.Capacity < L_cuserid) {
1509 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
1511 IntPtr r = sys_cuserid (@string);
1512 return UnixMarshal.PtrToString (r);
1517 #region <stdlib.h> Declarations
1521 [DllImport (LIBC, SetLastError=true)]
1522 public static extern int ttyslot ();
1524 [DllImport (CRYPT, SetLastError=true)]
1525 public static extern void setkey (string key);
1529 #region <string.h> Declarations
1535 // int strerror_r(int errnum, char *buf, size_t n);
1536 [DllImport (MPH, SetLastError=true,
1537 EntryPoint="Mono_Posix_Syscall_strerror_r")]
1538 private static extern int sys_strerror_r (int errnum,
1539 [Out] StringBuilder buf, ulong n);
1541 public static int strerror_r (Error errnum, StringBuilder buf, ulong n)
1543 int e = UnixConvert.FromError (errnum);
1544 return sys_strerror_r (e, buf, n);
1547 public static int strerror_r (Error errnum, StringBuilder buf)
1549 return strerror_r (errnum, buf, (ulong) buf.Capacity);
1554 #region <sys/mman.h> Declarations
1560 // int posix_madvise(void *addr, size_t len, int advice);
1561 [DllImport (MPH, SetLastError=true,
1562 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
1563 public static extern int posix_madvise (IntPtr addr, ulong len,
1564 PosixMadviseAdvice advice);
1568 #region <sys/poll.h> Declarations
1570 // <sys/poll.h> -- COMPLETE
1573 private struct _pollfd {
1575 public short events;
1576 public short revents;
1579 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
1580 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
1582 public static int poll (Pollfd [] fds, uint nfds, int timeout)
1584 if (fds.Length < nfds)
1585 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
1587 _pollfd[] send = new _pollfd[nfds];
1589 for (int i = 0; i < send.Length; i++) {
1590 send [i].fd = fds [i].fd;
1591 send [i].events = UnixConvert.FromPollEvents (fds [i].events);
1594 int r = sys_poll (send, nfds, timeout);
1596 for (int i = 0; i < send.Length; i++) {
1597 fds [i].revents = UnixConvert.ToPollEvents (send [i].revents);
1603 public static int poll (Pollfd [] fds, int timeout)
1605 return poll (fds, (uint) fds.Length, timeout);
1618 // TODO: setrlimit(2)
1619 // TODO: getrlimit(2)
1620 // TODO: getrusage(2)
1624 #region <sys/sendfile.h> Declarations
1626 // <sys/sendfile.h> -- COMPLETE
1629 [DllImport (MPH, SetLastError=true,
1630 EntryPoint="Mono_Posix_Syscall_sendfile")]
1631 public static extern long sendfile (int out_fd, int in_fd,
1632 ref long offset, ulong count);
1636 #region <sys/stat.h> Declarations
1638 // <sys/stat.h> -- COMPLETE
1640 [DllImport (MPH, SetLastError=true,
1641 EntryPoint="Mono_Posix_Syscall_stat")]
1642 public static extern int stat (string file_name, out Stat buf);
1644 [DllImport (MPH, SetLastError=true,
1645 EntryPoint="Mono_Posix_Syscall_fstat")]
1646 public static extern int fstat (int filedes, out Stat buf);
1648 [DllImport (MPH, SetLastError=true,
1649 EntryPoint="Mono_Posix_Syscall_lstat")]
1650 public static extern int lstat (string file_name, out Stat buf);
1653 // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
1654 // All take FilePermissions
1657 // int chmod(const char *path, mode_t mode);
1658 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
1659 private static extern int sys_chmod (string path, uint mode);
1661 public static int chmod (string path, FilePermissions mode)
1663 uint _mode = UnixConvert.FromFilePermissions (mode);
1664 return sys_chmod (path, _mode);
1668 // int chmod(int filedes, mode_t mode);
1669 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
1670 private static extern int sys_fchmod (int filedes, uint mode);
1672 public static int fchmod (int filedes, FilePermissions mode)
1674 uint _mode = UnixConvert.FromFilePermissions (mode);
1675 return sys_fchmod (filedes, _mode);
1679 // mode_t umask(mode_t mask);
1680 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
1681 private static extern uint sys_umask (uint mask);
1683 public static FilePermissions umask (FilePermissions mask)
1685 uint _mask = UnixConvert.FromFilePermissions (mask);
1686 uint r = sys_umask (_mask);
1687 return UnixConvert.ToFilePermissions (r);
1691 // int mkdir(const char *pathname, mode_t mode);
1692 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
1693 private static extern int sys_mkdir (string oldpath, uint mode);
1695 public static int mkdir (string oldpath, FilePermissions mode)
1697 uint _mode = UnixConvert.FromFilePermissions (mode);
1698 return sys_mkdir (oldpath, _mode);
1702 // int mknod (const char *pathname, mode_t mode, dev_t dev);
1703 [DllImport (MPH, SetLastError=true,
1704 EntryPoint="Mono_Posix_Syscall_mknod")]
1705 public static extern int mknod (string pathname, FilePermissions mode, ulong dev);
1708 // int mkfifo(const char *pathname, mode_t mode);
1709 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
1710 private static extern int sys_mkfifo (string pathname, uint mode);
1712 public static int mkfifo (string pathname, FilePermissions mode)
1714 uint _mode = UnixConvert.FromFilePermissions (mode);
1715 return sys_mkfifo (pathname, _mode);
1720 #region <sys/stat.h> Declarations
1725 [DllImport (MPH, SetLastError=true,
1726 EntryPoint="Mono_Posix_Syscall_statvfs")]
1727 public static extern int statvfs (string path, out Statvfs buf);
1729 [DllImport (MPH, SetLastError=true,
1730 EntryPoint="Mono_Posix_Syscall_fstatvfs")]
1731 public static extern int fstatvfs (int fd, out Statvfs buf);
1735 #region <sys/time.h> Declarations
1739 // TODO: adjtime(), getitimer(2), setitimer(2), lutimes(), futimes()
1741 [DllImport (MPH, SetLastError=true,
1742 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1743 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
1745 [DllImport (MPH, SetLastError=true,
1746 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1747 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
1749 public static int gettimeofday (out Timeval tv)
1751 return gettimeofday (out tv, IntPtr.Zero);
1754 [DllImport (MPH, SetLastError=true,
1755 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1756 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
1758 public static int gettimeofday (out Timezone tz)
1760 return gettimeofday (IntPtr.Zero, out tz);
1763 [DllImport (MPH, SetLastError=true,
1764 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1765 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
1767 [DllImport (MPH, SetLastError=true,
1768 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
1769 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
1771 public static int settimeofday (ref Timeval tv)
1773 return settimeofday (ref tv, IntPtr.Zero);
1776 [DllImport (MPH, SetLastError=true,
1777 EntryPoint="Mono_Posix_Syscall_utimes")]
1778 public static extern int utimes (string filename, ref Timeval tvp);
1794 #region <sys/wait.h> Declarations
1800 // pid_t wait(int *status);
1801 [DllImport (LIBC, SetLastError=true)]
1802 public static extern int wait (out int status);
1805 // pid_t waitpid(pid_t pid, int *status, int options);
1806 [DllImport (LIBC, SetLastError=true)]
1807 private static extern int waitpid (int pid, out int status, int options);
1809 public static int waitpid (int pid, out int status, WaitOptions options)
1811 int _options = UnixConvert.FromWaitOptions (options);
1812 return waitpid (pid, out status, _options);
1815 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
1816 private static extern int _WIFEXITED (int status);
1818 public static bool WIFEXITED (int status)
1820 return _WIFEXITED (status) != 0;
1823 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
1824 public static extern int WEXITSTATUS (int status);
1826 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
1827 private static extern int _WIFSIGNALED (int status);
1829 public static bool WIFSIGNALED (int status)
1831 return _WIFSIGNALED (status) != 0;
1834 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
1835 private static extern int _WTERMSIG (int status);
1837 public static Signum WTERMSIG (int status)
1839 int r = _WTERMSIG (status);
1840 return UnixConvert.ToSignum (r);
1843 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
1844 private static extern int _WIFSTOPPED (int status);
1846 public static bool WIFSTOPPED (int status)
1848 return _WIFSTOPPED (status) != 0;
1851 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
1852 private static extern int _WSTOPSIG (int status);
1854 public static Signum WSTOPSIG (int status)
1856 int r = _WSTOPSIG (status);
1857 return UnixConvert.ToSignum (r);
1866 #region <syslog.h> Declarations
1871 [DllImport (LIBC, EntryPoint="openlog")]
1872 private static extern void sys_openlog (IntPtr ident, int option, int facility);
1874 public static void openlog (IntPtr ident, SyslogOptions option,
1875 SyslogFacility defaultFacility)
1877 int _option = UnixConvert.FromSyslogOptions (option);
1878 int _facility = UnixConvert.FromSyslogFacility (defaultFacility);
1880 sys_openlog (ident, _option, _facility);
1884 private static extern void sys_syslog (int priority, string message);
1886 public static void syslog (SyslogFacility facility, SyslogLevel level, string message)
1888 int _facility = UnixConvert.FromSyslogFacility (facility);
1889 int _level = UnixConvert.FromSyslogLevel (level);
1890 sys_syslog (_facility | _level, GetSyslogMessage (message));
1893 public static void syslog (SyslogLevel level, string message)
1895 int _level = UnixConvert.FromSyslogLevel (level);
1896 sys_syslog (_level, GetSyslogMessage (message));
1899 private static string GetSyslogMessage (string message)
1901 return UnixMarshal.EscapeFormatString (message, new char[]{'m'});
1904 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
1905 "Use syslog(SyslogFacility, SyslogLevel, string) instead.")]
1906 public static void syslog (SyslogFacility facility, SyslogLevel level,
1907 string format, params object[] parameters)
1909 int _facility = UnixConvert.FromSyslogFacility (facility);
1910 int _level = UnixConvert.FromSyslogLevel (level);
1912 object[] _parameters = new object[checked(parameters.Length+2)];
1913 _parameters [0] = _facility | _level;
1914 _parameters [1] = format;
1915 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
1916 XPrintfFunctions.syslog (_parameters);
1919 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
1920 "Use syslog(SyslogLevel, string) instead.")]
1921 public static void syslog (SyslogLevel level, string format,
1922 params object[] parameters)
1924 int _level = UnixConvert.FromSyslogLevel (level);
1926 object[] _parameters = new object[checked(parameters.Length+2)];
1927 _parameters [0] = _level;
1928 _parameters [1] = format;
1929 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
1930 XPrintfFunctions.syslog (_parameters);
1934 public static extern void closelog ();
1936 [DllImport (LIBC, EntryPoint="setlogmask")]
1937 private static extern int sys_setlogmask (int mask);
1939 public static int setlogmask (SyslogLevel mask)
1941 int _mask = UnixConvert.FromSyslogLevel (mask);
1942 return sys_setlogmask (_mask);
1947 #region <time.h> Declarations
1954 // int stime(time_t *t);
1955 [DllImport (MPH, SetLastError=true,
1956 EntryPoint="Mono_Posix_Syscall_stime")]
1957 public static extern int stime (ref long t);
1960 // time_t time(time_t *t);
1961 [DllImport (MPH, SetLastError=true,
1962 EntryPoint="Mono_Posix_Syscall_time")]
1963 public static extern long time (out long t);
1973 #region <unistd.h> Declarations
1977 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
1978 // other TODOs listed below.
1980 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
1981 private static extern int sys_access (string pathname, int mode);
1983 public static int access (string pathname, AccessMode mode)
1985 int _mode = UnixConvert.FromAccessMode (mode);
1986 return sys_access (pathname, _mode);
1990 // off_t lseek(int filedes, off_t offset, int whence);
1991 [DllImport (MPH, SetLastError=true,
1992 EntryPoint="Mono_Posix_Syscall_lseek")]
1993 public static extern long lseek (int fd, long offset, SeekFlags whence);
1995 [DllImport (LIBC, SetLastError=true)]
1996 public static extern int close (int fd);
1999 // ssize_t read(int fd, void *buf, size_t count);
2000 [DllImport (MPH, SetLastError=true,
2001 EntryPoint="Mono_Posix_Syscall_read")]
2002 public static extern long read (int fd, IntPtr buf, ulong count);
2004 public static unsafe long read (int fd, void *buf, ulong count)
2006 return read (fd, (IntPtr) buf, count);
2010 // ssize_t write(int fd, const void *buf, size_t count);
2011 [DllImport (MPH, SetLastError=true,
2012 EntryPoint="Mono_Posix_Syscall_write")]
2013 public static extern long write (int fd, IntPtr buf, ulong count);
2015 public static unsafe long write (int fd, void *buf, ulong count)
2017 return write (fd, (IntPtr) buf, count);
2021 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
2022 [DllImport (MPH, SetLastError=true,
2023 EntryPoint="Mono_Posix_Syscall_pread")]
2024 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
2026 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
2028 return pread (fd, (IntPtr) buf, count, offset);
2032 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
2033 [DllImport (MPH, SetLastError=true,
2034 EntryPoint="Mono_Posix_Syscall_pwrite")]
2035 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
2037 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
2039 return pwrite (fd, (IntPtr) buf, count, offset);
2042 [DllImport (MPH, SetLastError=true,
2043 EntryPoint="Mono_Posix_Syscall_pipe")]
2044 public static extern int pipe (out int reading, out int writing);
2046 public static int pipe (int[] filedes)
2048 if (filedes == null || filedes.Length != 2) {
2052 int reading, writing;
2053 int r = pipe (out reading, out writing);
2054 filedes[0] = reading;
2055 filedes[1] = writing;
2059 [DllImport (LIBC, SetLastError=true)]
2060 public static extern uint alarm (uint seconds);
2062 [DllImport (LIBC, SetLastError=true)]
2063 public static extern uint sleep (uint seconds);
2065 [DllImport (LIBC, SetLastError=true)]
2066 public static extern uint ualarm (uint usecs, uint interval);
2068 [DllImport (LIBC, SetLastError=true)]
2069 public static extern int pause ();
2072 // int chown(const char *path, uid_t owner, gid_t group);
2073 [DllImport (LIBC, SetLastError=true)]
2074 public static extern int chown (string path, uint owner, uint group);
2077 // int fchown(int fd, uid_t owner, gid_t group);
2078 [DllImport (LIBC, SetLastError=true)]
2079 public static extern int fchown (int fd, uint owner, uint group);
2082 // int lchown(const char *path, uid_t owner, gid_t group);
2083 [DllImport (LIBC, SetLastError=true)]
2084 public static extern int lchown (string path, uint owner, uint group);
2086 [DllImport (LIBC, SetLastError=true)]
2087 public static extern int chdir (string path);
2089 [DllImport (LIBC, SetLastError=true)]
2090 public static extern int fchdir (int fd);
2093 // char *getcwd(char *buf, size_t size);
2094 [DllImport (MPH, SetLastError=true,
2095 EntryPoint="Mono_Posix_Syscall_getcwd")]
2096 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
2098 public static StringBuilder getcwd (StringBuilder buf)
2100 getcwd (buf, (ulong) buf.Capacity);
2104 // getwd(2) is deprecated; don't expose it.
2106 [DllImport (LIBC, SetLastError=true)]
2107 public static extern int dup (int fd);
2109 [DllImport (LIBC, SetLastError=true)]
2110 public static extern int dup2 (int fd, int fd2);
2112 // TODO: does Mono marshal arrays properly?
2113 [DllImport (LIBC, SetLastError=true)]
2114 public static extern int execve (string path, string[] argv, string[] envp);
2116 [DllImport (LIBC, SetLastError=true)]
2117 public static extern int fexecve (int fd, string[] argv, string[] envp);
2119 [DllImport (LIBC, SetLastError=true)]
2120 public static extern int execv (string path, string[] argv);
2122 // TODO: execle, execl, execlp
2123 [DllImport (LIBC, SetLastError=true)]
2124 public static extern int execvp (string path, string[] argv);
2126 [DllImport (LIBC, SetLastError=true)]
2127 public static extern int nice (int inc);
2129 [DllImport (LIBC, SetLastError=true)]
2130 public static extern int _exit (int status);
2132 [DllImport (MPH, SetLastError=true,
2133 EntryPoint="Mono_Posix_Syscall_fpathconf")]
2134 public static extern long fpathconf (int filedes, PathConf name);
2136 [DllImport (MPH, SetLastError=true,
2137 EntryPoint="Mono_Posix_Syscall_pathconf")]
2138 public static extern long pathconf (string path, PathConf name);
2140 [DllImport (MPH, SetLastError=true,
2141 EntryPoint="Mono_Posix_Syscall_sysconf")]
2142 public static extern long sysconf (SysConf name);
2145 // size_t confstr(int name, char *buf, size_t len);
2146 [DllImport (MPH, SetLastError=true,
2147 EntryPoint="Mono_Posix_Syscall_confstr")]
2148 public static extern ulong confstr (ConfStr name, [Out] StringBuilder buf, ulong len);
2151 // pid_t getpid(void);
2152 [DllImport (LIBC, SetLastError=true)]
2153 public static extern int getpid ();
2156 // pid_t getppid(void);
2157 [DllImport (LIBC, SetLastError=true)]
2158 public static extern int getppid ();
2161 // int setpgid(pid_t pid, pid_t pgid);
2162 [DllImport (LIBC, SetLastError=true)]
2163 public static extern int setpgid (int pid, int pgid);
2166 // pid_t getpgid(pid_t pid);
2167 [DllImport (LIBC, SetLastError=true)]
2168 public static extern int getpgid (int pid);
2170 [DllImport (LIBC, SetLastError=true)]
2171 public static extern int setpgrp ();
2174 // pid_t getpgrp(void);
2175 [DllImport (LIBC, SetLastError=true)]
2176 public static extern int getpgrp ();
2179 // pid_t setsid(void);
2180 [DllImport (LIBC, SetLastError=true)]
2181 public static extern int setsid ();
2184 // pid_t getsid(pid_t pid);
2185 [DllImport (LIBC, SetLastError=true)]
2186 public static extern int getsid (int pid);
2189 // uid_t getuid(void);
2190 [DllImport (LIBC, SetLastError=true)]
2191 public static extern uint getuid ();
2194 // uid_t geteuid(void);
2195 [DllImport (LIBC, SetLastError=true)]
2196 public static extern uint geteuid ();
2199 // gid_t getgid(void);
2200 [DllImport (LIBC, SetLastError=true)]
2201 public static extern uint getgid ();
2204 // gid_t getgid(void);
2205 [DllImport (LIBC, SetLastError=true)]
2206 public static extern uint getegid ();
2209 // int getgroups(int size, gid_t list[]);
2210 [DllImport (LIBC, SetLastError=true)]
2211 public static extern int getgroups (int size, uint[] list);
2213 public static int getgroups (uint[] list)
2215 return getgroups (list.Length, list);
2219 // int setuid(uid_t uid);
2220 [DllImport (LIBC, SetLastError=true)]
2221 public static extern int setuid (uint uid);
2224 // int setreuid(uid_t ruid, uid_t euid);
2225 [DllImport (LIBC, SetLastError=true)]
2226 public static extern int setreuid (uint ruid, uint euid);
2229 // int setregid(gid_t ruid, gid_t euid);
2230 [DllImport (LIBC, SetLastError=true)]
2231 public static extern int setregid (uint rgid, uint egid);
2234 // int seteuid(uid_t euid);
2235 [DllImport (LIBC, SetLastError=true)]
2236 public static extern int seteuid (uint euid);
2239 // int setegid(gid_t euid);
2240 [DllImport (LIBC, SetLastError=true)]
2241 public static extern int setegid (uint uid);
2244 // int setgid(gid_t gid);
2245 [DllImport (LIBC, SetLastError=true)]
2246 public static extern int setgid (uint gid);
2249 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
2250 [DllImport (LIBC, SetLastError=true)]
2251 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
2254 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
2255 [DllImport (LIBC, SetLastError=true)]
2256 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
2259 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
2260 [DllImport (LIBC, SetLastError=true)]
2261 public static extern int setresuid (uint ruid, uint euid, uint suid);
2264 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
2265 [DllImport (LIBC, SetLastError=true)]
2266 public static extern int setresgid (uint rgid, uint egid, uint sgid);
2269 // pid_t fork(void);
2270 [DllImport (LIBC, SetLastError=true)]
2271 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
2272 "shutdown code.\nUse System.Diagnostics.Process instead")]
2273 public static extern int fork ();
2276 // pid_t vfork(void);
2277 [DllImport (LIBC, SetLastError=true)]
2278 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
2279 "shutdown code.\nUse System.Diagnostics.Process instead")]
2280 public static extern int vfork ();
2282 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
2283 private static extern IntPtr sys_ttyname (int fd);
2285 [Obsolete ("Not re-entrant. Use ttyname_r instead.")]
2286 public static string ttyname (int fd)
2288 IntPtr r = sys_ttyname (fd);
2289 return UnixMarshal.PtrToString (r);
2293 // int ttyname_r(int fd, char *buf, size_t buflen);
2294 [DllImport (MPH, SetLastError=true,
2295 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
2296 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
2298 public static int ttyname_r (int fd, StringBuilder buf)
2300 return ttyname_r (fd, buf, (ulong) buf.Capacity);
2303 [DllImport (LIBC, EntryPoint="isatty")]
2304 private static extern int sys_isatty (int fd);
2306 public static bool isatty (int fd)
2308 return sys_isatty (fd) == 1;
2311 [DllImport (LIBC, SetLastError=true)]
2312 public static extern int link (string oldpath, string newpath);
2314 [DllImport (LIBC, SetLastError=true)]
2315 public static extern int symlink (string oldpath, string newpath);
2318 // int readlink(const char *path, char *buf, size_t bufsize);
2319 [DllImport (MPH, SetLastError=true,
2320 EntryPoint="Mono_Posix_Syscall_readlink")]
2321 public static extern int readlink (string path, [Out] StringBuilder buf, ulong bufsiz);
2323 public static int readlink (string path, [Out] StringBuilder buf)
2325 return readlink (path, buf, (ulong) buf.Capacity);
2328 [DllImport (LIBC, SetLastError=true)]
2329 public static extern int unlink (string pathname);
2331 [DllImport (LIBC, SetLastError=true)]
2332 public static extern int rmdir (string pathname);
2335 // pid_t tcgetpgrp(int fd);
2336 [DllImport (LIBC, SetLastError=true)]
2337 public static extern int tcgetpgrp (int fd);
2340 // int tcsetpgrp(int fd, pid_t pgrp);
2341 [DllImport (LIBC, SetLastError=true)]
2342 public static extern int tcsetpgrp (int fd, int pgrp);
2344 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
2345 private static extern IntPtr sys_getlogin ();
2347 [Obsolete ("Not re-entrant. Use getlogin_r instead.")]
2348 public static string getlogin ()
2350 IntPtr r = sys_getlogin ();
2351 return UnixMarshal.PtrToString (r);
2355 // int getlogin_r(char *buf, size_t bufsize);
2356 [DllImport (MPH, SetLastError=true,
2357 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
2358 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
2360 public static int getlogin_r (StringBuilder name)
2362 return getlogin_r (name, (ulong) name.Capacity);
2365 [DllImport (LIBC, SetLastError=true)]
2366 public static extern int setlogin (string name);
2369 // int gethostname(char *name, size_t len);
2370 [DllImport (MPH, SetLastError=true,
2371 EntryPoint="Mono_Posix_Syscall_gethostname")]
2372 public static extern int gethostname ([Out] StringBuilder name, ulong len);
2374 public static int gethostname (StringBuilder name)
2376 return gethostname (name, (ulong) name.Capacity);
2380 // int gethostname(const char *name, size_t len);
2381 [DllImport (MPH, SetLastError=true,
2382 EntryPoint="Mono_Posix_Syscall_gethostname")]
2383 public static extern int sethostname (string name, ulong len);
2385 public static int sethostname (string name)
2387 return sethostname (name, (ulong) name.Length);
2390 [DllImport (MPH, SetLastError=true,
2391 EntryPoint="Mono_Posix_Syscall_gethostid")]
2392 public static extern long gethostid ();
2394 [DllImport (MPH, SetLastError=true,
2395 EntryPoint="Mono_Posix_Syscall_sethostid")]
2396 public static extern int sethostid (long hostid);
2399 // int getdomainname(char *name, size_t len);
2400 [DllImport (MPH, SetLastError=true,
2401 EntryPoint="Mono_Posix_Syscall_getdomainname")]
2402 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
2404 public static int getdomainname (StringBuilder name)
2406 return getdomainname (name, (ulong) name.Capacity);
2410 // int setdomainname(const char *name, size_t len);
2411 [DllImport (MPH, SetLastError=true,
2412 EntryPoint="Mono_Posix_Syscall_setdomainname")]
2413 public static extern int setdomainname (string name, ulong len);
2415 public static int setdomainname (string name)
2417 return setdomainname (name, (ulong) name.Length);
2420 [DllImport (LIBC, SetLastError=true)]
2421 public static extern int vhangup ();
2423 // Revoke doesn't appear to be POSIX. Include it?
2424 [DllImport (LIBC, SetLastError=true)]
2425 public static extern int revoke (string file);
2427 // TODO: profil? It's not POSIX.
2429 [DllImport (LIBC, SetLastError=true)]
2430 public static extern int acct (string filename);
2432 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
2433 private static extern IntPtr sys_getusershell ();
2435 public static string getusershell ()
2437 IntPtr r = sys_getusershell ();
2438 return UnixMarshal.PtrToString (r);
2441 [DllImport (LIBC, SetLastError=true)]
2442 public static extern void setusershell ();
2444 [DllImport (LIBC, SetLastError=true)]
2445 public static extern void endusershell ();
2447 [DllImport (LIBC, SetLastError=true)]
2448 private static extern int daemon (int nochdir, int noclose);
2450 public static int daemon (bool nochdir, bool noclose)
2452 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
2455 [DllImport (LIBC, SetLastError=true)]
2456 public static extern int chroot (string path);
2458 // skipping getpass(3) as the man page states:
2459 // This function is obsolete. Do not use it.
2461 [DllImport (LIBC, SetLastError=true)]
2462 public static extern int fsync (int fd);
2464 [DllImport (LIBC, SetLastError=true)]
2465 public static extern int fdatasync (int fd);
2467 [DllImport (LIBC, SetLastError=true)]
2468 public static extern void sync ();
2470 [DllImport (LIBC, SetLastError=true)]
2471 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
2472 "Use Unistd.sysconf (SysConf._SC_PAGESIZE).")]
2473 public static extern int getpagesize ();
2476 // int truncate(const char *path, off_t length);
2477 [DllImport (MPH, SetLastError=true,
2478 EntryPoint="Mono_Posix_Syscall_truncate")]
2479 public static extern int truncate (string path, long length);
2482 // int ftruncate(int fd, off_t length);
2483 [DllImport (MPH, SetLastError=true,
2484 EntryPoint="Mono_Posix_Syscall_ftruncate")]
2485 public static extern int ftruncate (int fd, long length);
2487 [DllImport (LIBC, SetLastError=true)]
2488 public static extern int getdtablesize ();
2490 [DllImport (LIBC, SetLastError=true)]
2491 public static extern int brk (IntPtr end_data_segment);
2493 [DllImport (LIBC, SetLastError=true)]
2494 public static extern IntPtr sbrk (IntPtr increment);
2496 // TODO: syscall(2)?
2497 // Probably safer to skip entirely.
2500 // int lockf(int fd, int cmd, off_t len);
2501 [DllImport (MPH, SetLastError=true,
2502 EntryPoint="Mono_Posix_Syscall_lockf")]
2503 public static extern int lockf (int fd, LockFlags cmd, long len);
2505 [DllImport (CRYPT, SetLastError=true, EntryPoint="crypt")]
2506 private static extern IntPtr sys_crypt (string key, string salt);
2508 public static string crypt (string key, string salt)
2510 IntPtr r = sys_crypt (key, salt);
2511 return UnixMarshal.PtrToString (r);
2514 [DllImport (CRYPT, SetLastError=true, EntryPoint="encrypt")]
2515 private static extern void sys_encrypt ([In, Out] byte[] block, int edflag);
2517 public static void encrypt (byte[] block, bool decode)
2519 if (block.Length < 64)
2520 throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
2521 sys_encrypt (block, decode ? 1 : 0);
2525 // void swab(const void *from, void *to, ssize_t n);
2526 [DllImport (MPH, SetLastError=true,
2527 EntryPoint="Mono_Posix_Syscall_swab")]
2528 public static extern void swab (IntPtr from, IntPtr to, long n);
2530 public static unsafe void swab (void* from, void* to, long n)
2532 swab ((IntPtr) from, (IntPtr) to, n);
2537 #region <utime.h> Declarations
2539 // <utime.h> -- COMPLETE
2542 [DllImport (MPH, SetLastError=true,
2543 EntryPoint="Mono_Posix_Syscall_utime")]
2544 public static extern int utime (string filename, ref Utimbuf buf);
2546 [DllImport (MPH, SetLastError=true,
2547 EntryPoint="Mono_Posix_Syscall_utime")]
2548 private static extern int utime (string filename, IntPtr buf);
2550 public static int utime (string filename)
2552 return utime (filename, IntPtr.Zero);