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-2006 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 // NativeConvert 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.Collections.Generic;
59 using System.Runtime.InteropServices;
60 using System.Security;
62 using Mono.Unix.Native;
64 namespace Mono.Unix.Native {
69 [CLSCompliant (false)]
70 public enum SyslogOptions {
71 LOG_PID = 0x01, // log the pid with each message
72 LOG_CONS = 0x02, // log on the console if errors in sending
73 LOG_ODELAY = 0x04, // delay open until first syslog (default)
74 LOG_NDELAY = 0x08, // don't delay open
75 LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
76 LOG_PERROR = 0x20 // log to stderr as well
80 [CLSCompliant (false)]
81 public enum SyslogFacility {
92 LOG_AUTHPRIV = 10 << 3,
100 LOG_LOCAL6 = 22 << 3,
101 LOG_LOCAL7 = 23 << 3,
105 [CLSCompliant (false)]
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 [CLSCompliant (false)]
119 public enum OpenFlags : int {
123 O_RDONLY = 0x00000000,
124 O_WRONLY = 0x00000001,
128 // Or-ed with zero or more of these
130 O_CREAT = 0x00000040,
132 O_NOCTTY = 0x00000100,
133 O_TRUNC = 0x00000200,
134 O_APPEND = 0x00000400,
135 O_NONBLOCK = 0x00000800,
139 // These are non-Posix. Using them will result in errors/exceptions on
140 // non-supported platforms.
142 // (For example, "C-wrapped" system calls -- calls with implementation in
143 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
144 // calls will generate an exception in NativeConvert, as the value can't be
145 // converted on the target platform.)
148 O_NOFOLLOW = 0x00020000,
149 O_DIRECTORY = 0x00010000,
150 O_DIRECT = 0x00004000,
151 O_ASYNC = 0x00002000,
152 O_LARGEFILE = 0x00008000
157 [CLSCompliant (false)]
158 public enum FilePermissions : uint {
159 S_ISUID = 0x0800, // Set user ID on execution
160 S_ISGID = 0x0400, // Set group ID on execution
161 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
162 S_IRUSR = 0x0100, // Read by owner
163 S_IWUSR = 0x0080, // Write by owner
164 S_IXUSR = 0x0040, // Execute by owner
165 S_IRGRP = 0x0020, // Read by group
166 S_IWGRP = 0x0010, // Write by group
167 S_IXGRP = 0x0008, // Execute by group
168 S_IROTH = 0x0004, // Read by other
169 S_IWOTH = 0x0002, // Write by other
170 S_IXOTH = 0x0001, // Execute by other
172 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
173 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
174 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
175 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
176 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
177 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
180 // Why these are held in "mode_t" is beyond me...
181 S_IFMT = 0xF000, // Bits which determine file type
182 [Map(SuppressFlags="S_IFMT")]
183 S_IFDIR = 0x4000, // Directory
184 [Map(SuppressFlags="S_IFMT")]
185 S_IFCHR = 0x2000, // Character device
186 [Map(SuppressFlags="S_IFMT")]
187 S_IFBLK = 0x6000, // Block device
188 [Map(SuppressFlags="S_IFMT")]
189 S_IFREG = 0x8000, // Regular file
190 [Map(SuppressFlags="S_IFMT")]
191 S_IFIFO = 0x1000, // FIFO
192 [Map(SuppressFlags="S_IFMT")]
193 S_IFLNK = 0xA000, // Symbolic link
194 [Map(SuppressFlags="S_IFMT")]
195 S_IFSOCK = 0xC000, // Socket
199 [CLSCompliant (false)]
200 public enum FcntlCommand : int {
201 // Form /usr/include/bits/fcntl.h
202 F_DUPFD = 0, // Duplicate file descriptor.
203 F_GETFD = 1, // Get file descriptor flags.
204 F_SETFD = 2, // Set file descriptor flags.
205 F_GETFL = 3, // Get file status flags.
206 F_SETFL = 4, // Set file status flags.
207 F_GETLK = 12, // Get record locking info. [64]
208 F_SETLK = 13, // Set record locking info (non-blocking). [64]
209 F_SETLKW = 14, // Set record locking info (blocking). [64]
210 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
211 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
212 F_SETSIG = 10, // Set number of signal to be sent.
213 F_GETSIG = 11, // Get number of signal to be sent.
214 F_SETLEASE = 1024, // Set a lease.
215 F_GETLEASE = 1025, // Enquire what lease is active.
216 F_NOTIFY = 1026, // Required notifications on a directory
220 [CLSCompliant (false)]
221 public enum LockType : short {
222 F_RDLCK = 0, // Read lock.
223 F_WRLCK = 1, // Write lock.
224 F_UNLCK = 2, // Remove lock.
228 [CLSCompliant (false)]
229 public enum SeekFlags : short {
230 // values liberally copied from /usr/include/unistd.h
231 SEEK_SET = 0, // Seek from beginning of file.
232 SEEK_CUR = 1, // Seek from current position.
233 SEEK_END = 2, // Seek from end of file.
235 L_SET = SEEK_SET, // BSD alias for SEEK_SET
236 L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
237 L_XTND = SEEK_END, // BSD alias for SEEK_END
241 [CLSCompliant (false)]
242 public enum DirectoryNotifyFlags : int {
243 // from /usr/include/bits/fcntl.h
244 DN_ACCESS = 0x00000001, // File accessed.
245 DN_MODIFY = 0x00000002, // File modified.
246 DN_CREATE = 0x00000004, // File created.
247 DN_DELETE = 0x00000008, // File removed.
248 DN_RENAME = 0x00000010, // File renamed.
249 DN_ATTRIB = 0x00000020, // File changed attributes.
250 DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
254 [CLSCompliant (false)]
255 public enum PosixFadviseAdvice : int {
256 POSIX_FADV_NORMAL = 0, // No further special treatment.
257 POSIX_FADV_RANDOM = 1, // Expect random page references.
258 POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
259 POSIX_FADV_WILLNEED = 3, // Will need these pages.
260 POSIX_FADV_DONTNEED = 4, // Don't need these pages.
261 POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
265 [CLSCompliant (false)]
266 public enum PosixMadviseAdvice : int {
267 POSIX_MADV_NORMAL = 0, // No further special treatment.
268 POSIX_MADV_RANDOM = 1, // Expect random page references.
269 POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
270 POSIX_MADV_WILLNEED = 3, // Will need these pages.
271 POSIX_MADV_DONTNEED = 4, // Don't need these pages.
275 public enum Signum : int {
276 SIGHUP = 1, // Hangup (POSIX).
277 SIGINT = 2, // Interrupt (ANSI).
278 SIGQUIT = 3, // Quit (POSIX).
279 SIGILL = 4, // Illegal instruction (ANSI).
280 SIGTRAP = 5, // Trace trap (POSIX).
281 SIGABRT = 6, // Abort (ANSI).
282 SIGIOT = 6, // IOT trap (4.2 BSD).
283 SIGBUS = 7, // BUS error (4.2 BSD).
284 SIGFPE = 8, // Floating-point exception (ANSI).
285 SIGKILL = 9, // Kill, unblockable (POSIX).
286 SIGUSR1 = 10, // User-defined signal 1 (POSIX).
287 SIGSEGV = 11, // Segmentation violation (ANSI).
288 SIGUSR2 = 12, // User-defined signal 2 (POSIX).
289 SIGPIPE = 13, // Broken pipe (POSIX).
290 SIGALRM = 14, // Alarm clock (POSIX).
291 SIGTERM = 15, // Termination (ANSI).
292 SIGSTKFLT = 16, // Stack fault.
293 SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
294 SIGCHLD = 17, // Child status has changed (POSIX).
295 SIGCONT = 18, // Continue (POSIX).
296 SIGSTOP = 19, // Stop, unblockable (POSIX).
297 SIGTSTP = 20, // Keyboard stop (POSIX).
298 SIGTTIN = 21, // Background read from tty (POSIX).
299 SIGTTOU = 22, // Background write to tty (POSIX).
300 SIGURG = 23, // Urgent condition on socket (4.2 BSD).
301 SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
302 SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
303 SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
304 SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
305 SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
306 SIGPOLL = SIGIO, // Pollable event occurred (System V).
307 SIGIO = 29, // I/O now possible (4.2 BSD).
308 SIGPWR = 30, // Power failure restart (System V).
309 SIGSYS = 31, // Bad system call.
314 public enum WaitOptions : int {
315 WNOHANG = 1, // Don't block waiting
316 WUNTRACED = 2, // Report status of stopped children
320 [CLSCompliant (false)]
321 public enum AccessModes : int {
329 [CLSCompliant (false)]
330 public enum PathconfName : int {
337 _PC_CHOWN_RESTRICTED,
345 _PC_REC_INCR_XFER_SIZE,
346 _PC_REC_MAX_XFER_SIZE,
347 _PC_REC_MIN_XFER_SIZE,
355 [CLSCompliant (false)]
356 public enum SysconfName : int {
366 _SC_REALTIME_SIGNALS,
367 _SC_PRIORITY_SCHEDULING,
376 _SC_MEMORY_PROTECTION,
379 _SC_SHARED_MEMORY_OBJECTS,
382 _SC_AIO_PRIO_DELTA_MAX,
393 /* Values for the argument to `sysconf'
394 corresponding to _POSIX2_* symbols. */
399 _SC_COLL_WEIGHTS_MAX,
404 _SC_CHARCLASS_NAME_MAX,
420 _SC_IOV_MAX = _SC_UIO_MAXIOV,
421 _SC_PII_INTERNET_STREAM,
422 _SC_PII_INTERNET_DGRAM,
427 /* Values according to POSIX 1003.1c (POSIX threads). */
429 _SC_THREAD_SAFE_FUNCTIONS,
430 _SC_GETGR_R_SIZE_MAX,
431 _SC_GETPW_R_SIZE_MAX,
434 _SC_THREAD_DESTRUCTOR_ITERATIONS,
436 _SC_THREAD_STACK_MIN,
437 _SC_THREAD_THREADS_MAX,
438 _SC_THREAD_ATTR_STACKADDR,
439 _SC_THREAD_ATTR_STACKSIZE,
440 _SC_THREAD_PRIORITY_SCHEDULING,
441 _SC_THREAD_PRIO_INHERIT,
442 _SC_THREAD_PRIO_PROTECT,
443 _SC_THREAD_PROCESS_SHARED,
444 _SC_NPROCESSORS_CONF,
445 _SC_NPROCESSORS_ONLN,
451 _SC_XOPEN_XCU_VERSION,
486 _SC_XBS5_ILP32_OFF32,
487 _SC_XBS5_ILP32_OFFBIG,
489 _SC_XBS5_LPBIG_OFFBIG,
492 _SC_XOPEN_REALTIME_THREADS,
497 _SC_C_LANG_SUPPORT_R,
503 _SC_DEVICE_SPECIFIC_R,
514 _SC_READER_WRITER_LOCKS,
522 _SC_THREAD_SPORADIC_SERVER,
524 _SC_SYSTEM_DATABASE_R,
526 _SC_TYPED_MEMORY_OBJECTS,
530 _SC_2_PBS_ACCOUNTING,
536 _SC_2_PBS_CHECKPOINT,
543 _SC_TRACE_EVENT_FILTER,
546 _SC_LEVEL1_ICACHE_SIZE,
547 _SC_LEVEL1_ICACHE_ASSOC,
548 _SC_LEVEL1_ICACHE_LINESIZE,
549 _SC_LEVEL1_DCACHE_SIZE,
550 _SC_LEVEL1_DCACHE_ASSOC,
551 _SC_LEVEL1_DCACHE_LINESIZE,
552 _SC_LEVEL2_CACHE_SIZE,
553 _SC_LEVEL2_CACHE_ASSOC,
554 _SC_LEVEL2_CACHE_LINESIZE,
555 _SC_LEVEL3_CACHE_SIZE,
556 _SC_LEVEL3_CACHE_ASSOC,
557 _SC_LEVEL3_CACHE_LINESIZE,
558 _SC_LEVEL4_CACHE_SIZE,
559 _SC_LEVEL4_CACHE_ASSOC,
560 _SC_LEVEL4_CACHE_LINESIZE
564 [CLSCompliant (false)]
565 public enum ConfstrName : int {
566 _CS_PATH, /* The default search path. */
567 _CS_V6_WIDTH_RESTRICTED_ENVS,
568 _CS_GNU_LIBC_VERSION,
569 _CS_GNU_LIBPTHREAD_VERSION,
570 _CS_LFS_CFLAGS = 1000,
578 _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
579 _CS_XBS5_ILP32_OFF32_LDFLAGS,
580 _CS_XBS5_ILP32_OFF32_LIBS,
581 _CS_XBS5_ILP32_OFF32_LINTFLAGS,
582 _CS_XBS5_ILP32_OFFBIG_CFLAGS,
583 _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
584 _CS_XBS5_ILP32_OFFBIG_LIBS,
585 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
586 _CS_XBS5_LP64_OFF64_CFLAGS,
587 _CS_XBS5_LP64_OFF64_LDFLAGS,
588 _CS_XBS5_LP64_OFF64_LIBS,
589 _CS_XBS5_LP64_OFF64_LINTFLAGS,
590 _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
591 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
592 _CS_XBS5_LPBIG_OFFBIG_LIBS,
593 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
594 _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
595 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
596 _CS_POSIX_V6_ILP32_OFF32_LIBS,
597 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
598 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
599 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
600 _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
601 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
602 _CS_POSIX_V6_LP64_OFF64_CFLAGS,
603 _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
604 _CS_POSIX_V6_LP64_OFF64_LIBS,
605 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
606 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
607 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
608 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
609 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
613 [CLSCompliant (false)]
614 public enum LockfCommand : int {
615 F_ULOCK = 0, // Unlock a previously locked region.
616 F_LOCK = 1, // Lock a region for exclusive use.
617 F_TLOCK = 2, // Test and lock a region for exclusive use.
618 F_TEST = 3, // Test a region for other process locks.
622 public enum PollEvents : short {
623 POLLIN = 0x0001, // There is data to read
624 POLLPRI = 0x0002, // There is urgent data to read
625 POLLOUT = 0x0004, // Writing now will not block
626 POLLERR = 0x0008, // Error condition
627 POLLHUP = 0x0010, // Hung up
628 POLLNVAL = 0x0020, // Invalid request; fd not open
629 // XPG4.2 definitions (via _XOPEN_SOURCE)
630 POLLRDNORM = 0x0040, // Normal data may be read
631 POLLRDBAND = 0x0080, // Priority data may be read
632 POLLWRNORM = 0x0100, // Writing now will not block
633 POLLWRBAND = 0x0200, // Priority data may be written
637 [CLSCompliant (false)]
638 public enum XattrFlags : int {
645 [CLSCompliant (false)]
646 public enum MountFlags : ulong {
647 ST_RDONLY = 1, // Mount read-only
648 ST_NOSUID = 2, // Ignore suid and sgid bits
649 ST_NODEV = 4, // Disallow access to device special files
650 ST_NOEXEC = 8, // Disallow program execution
651 ST_SYNCHRONOUS = 16, // Writes are synced at once
652 ST_REMOUNT = 32, // Alter flags of a mounted FS
653 ST_MANDLOCK = 64, // Allow mandatory locks on an FS
654 ST_WRITE = 128, // Write on file/directory/symlink
655 ST_APPEND = 256, // Append-only file
656 ST_IMMUTABLE = 512, // Immutable file
657 ST_NOATIME = 1024, // Do not update access times
658 ST_NODIRATIME = 2048, // Do not update directory access times
659 ST_BIND = 4096, // Bind directory at different place
663 [CLSCompliant (false)]
664 public enum MmapFlags : int {
665 MAP_SHARED = 0x01, // Share changes.
666 MAP_PRIVATE = 0x02, // Changes are private.
667 MAP_TYPE = 0x0f, // Mask for type of mapping.
668 MAP_FIXED = 0x10, // Interpret addr exactly.
670 MAP_ANONYMOUS = 0x20, // Don't use a file.
671 MAP_ANON = MAP_ANONYMOUS,
673 // These are Linux-specific.
674 MAP_GROWSDOWN = 0x00100, // Stack-like segment.
675 MAP_DENYWRITE = 0x00800, // ETXTBSY
676 MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
677 MAP_LOCKED = 0x02000, // Lock the mapping.
678 MAP_NORESERVE = 0x04000, // Don't check for reservations.
679 MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
680 MAP_NONBLOCK = 0x10000, // Do not block on IO.
684 [CLSCompliant (false)]
685 public enum MmapProts : int {
686 PROT_READ = 0x1, // Page can be read.
687 PROT_WRITE = 0x2, // Page can be written.
688 PROT_EXEC = 0x4, // Page can be executed.
689 PROT_NONE = 0x0, // Page can not be accessed.
690 PROT_GROWSDOWN = 0x01000000, // Extend change to start of
691 // growsdown vma (mprotect only).
692 PROT_GROWSUP = 0x02000000, // Extend change to start of
693 // growsup vma (mprotect only).
697 [CLSCompliant (false)]
698 public enum MsyncFlags : int {
699 MS_ASYNC = 0x1, // Sync memory asynchronously.
700 MS_SYNC = 0x4, // Synchronous memory sync.
701 MS_INVALIDATE = 0x2, // Invalidate the caches.
705 [CLSCompliant (false)]
706 public enum MlockallFlags : int {
707 MCL_CURRENT = 0x1, // Lock all currently mapped pages.
708 MCL_FUTURE = 0x2, // Lock all additions to address
712 [CLSCompliant (false)]
713 public enum MremapFlags : ulong {
714 MREMAP_MAYMOVE = 0x1,
721 [Map ("struct flock")]
727 [CLSCompliant (false)]
728 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
729 [CLSCompliant (false)]
730 public SeekFlags l_whence; // How to interpret l_start
731 [off_t] public long l_start; // Starting offset for lock
732 [off_t] public long l_len; // Number of bytes to lock
733 [pid_t] public int l_pid; // PID of process blocking our lock (F_GETLK only)
735 public override int GetHashCode ()
737 return l_type.GetHashCode () ^ l_whence.GetHashCode () ^
738 l_start.GetHashCode () ^ l_len.GetHashCode () ^
739 l_pid.GetHashCode ();
742 public override bool Equals (object obj)
744 if ((obj == null) || (obj.GetType () != GetType ()))
746 Flock value = (Flock) obj;
747 return l_type == value.l_type && l_whence == value.l_whence &&
748 l_start == value.l_start && l_len == value.l_len &&
749 l_pid == value.l_pid;
752 public bool Equals (Flock value)
754 return l_type == value.l_type && l_whence == value.l_whence &&
755 l_start == value.l_start && l_len == value.l_len &&
756 l_pid == value.l_pid;
759 public static bool operator== (Flock lhs, Flock rhs)
761 return lhs.Equals (rhs);
764 public static bool operator!= (Flock lhs, Flock rhs)
766 return !lhs.Equals (rhs);
770 [Map ("struct pollfd")]
773 : IEquatable <Pollfd>
777 [CLSCompliant (false)]
778 public PollEvents events;
779 [CLSCompliant (false)]
780 public PollEvents revents;
782 public override int GetHashCode ()
784 return events.GetHashCode () ^ revents.GetHashCode ();
787 public override bool Equals (object obj)
789 if (obj == null || obj.GetType () != GetType ())
791 Pollfd value = (Pollfd) obj;
792 return value.events == events && value.revents == revents;
795 public bool Equals (Pollfd value)
797 return value.events == events && value.revents == revents;
800 public static bool operator== (Pollfd lhs, Pollfd rhs)
802 return lhs.Equals (rhs);
805 public static bool operator!= (Pollfd lhs, Pollfd rhs)
807 return !lhs.Equals (rhs);
811 [Map ("struct stat")]
817 [CLSCompliant (false)]
818 [dev_t] public ulong st_dev; // device
819 [CLSCompliant (false)]
820 [ino_t] public ulong st_ino; // inode
821 [CLSCompliant (false)]
822 public FilePermissions st_mode; // protection
824 #pragma warning disable 169
825 private uint _padding_; // padding for structure alignment
826 #pragma warning restore 169
827 [CLSCompliant (false)]
828 [nlink_t] public ulong st_nlink; // number of hard links
829 [CLSCompliant (false)]
830 [uid_t] public uint st_uid; // user ID of owner
831 [CLSCompliant (false)]
832 [gid_t] public uint st_gid; // group ID of owner
833 [CLSCompliant (false)]
834 [dev_t] public ulong st_rdev; // device type (if inode device)
835 [off_t] public long st_size; // total size, in bytes
836 [blksize_t] public long st_blksize; // blocksize for filesystem I/O
837 [blkcnt_t] public long st_blocks; // number of blocks allocated
838 [time_t] public long st_atime; // time of last access
839 [time_t] public long st_mtime; // time of last modification
840 [time_t] public long st_ctime; // time of last status change
842 public override int GetHashCode ()
844 return st_dev.GetHashCode () ^
845 st_ino.GetHashCode () ^
846 st_mode.GetHashCode () ^
847 st_nlink.GetHashCode () ^
848 st_uid.GetHashCode () ^
849 st_gid.GetHashCode () ^
850 st_rdev.GetHashCode () ^
851 st_size.GetHashCode () ^
852 st_blksize.GetHashCode () ^
853 st_blocks.GetHashCode () ^
854 st_atime.GetHashCode () ^
855 st_mtime.GetHashCode () ^
856 st_ctime.GetHashCode ();
859 public override bool Equals (object obj)
861 if (obj == null || obj.GetType() != GetType ())
863 Stat value = (Stat) obj;
864 return value.st_dev == st_dev &&
865 value.st_ino == st_ino &&
866 value.st_mode == st_mode &&
867 value.st_nlink == st_nlink &&
868 value.st_uid == st_uid &&
869 value.st_gid == st_gid &&
870 value.st_rdev == st_rdev &&
871 value.st_size == st_size &&
872 value.st_blksize == st_blksize &&
873 value.st_blocks == st_blocks &&
874 value.st_atime == st_atime &&
875 value.st_mtime == st_mtime &&
876 value.st_ctime == st_ctime;
879 public bool Equals (Stat value)
881 return value.st_dev == st_dev &&
882 value.st_ino == st_ino &&
883 value.st_mode == st_mode &&
884 value.st_nlink == st_nlink &&
885 value.st_uid == st_uid &&
886 value.st_gid == st_gid &&
887 value.st_rdev == st_rdev &&
888 value.st_size == st_size &&
889 value.st_blksize == st_blksize &&
890 value.st_blocks == st_blocks &&
891 value.st_atime == st_atime &&
892 value.st_mtime == st_mtime &&
893 value.st_ctime == st_ctime;
896 public static bool operator== (Stat lhs, Stat rhs)
898 return lhs.Equals (rhs);
901 public static bool operator!= (Stat lhs, Stat rhs)
903 return !lhs.Equals (rhs);
907 // `struct statvfs' isn't portable, so don't generate To/From methods.
909 [CLSCompliant (false)]
910 public struct Statvfs
912 : IEquatable <Statvfs>
915 public ulong f_bsize; // file system block size
916 public ulong f_frsize; // fragment size
917 [fsblkcnt_t] public ulong f_blocks; // size of fs in f_frsize units
918 [fsblkcnt_t] public ulong f_bfree; // # free blocks
919 [fsblkcnt_t] public ulong f_bavail; // # free blocks for non-root
920 [fsfilcnt_t] public ulong f_files; // # inodes
921 [fsfilcnt_t] public ulong f_ffree; // # free inodes
922 [fsfilcnt_t] public ulong f_favail; // # free inodes for non-root
923 public ulong f_fsid; // file system id
924 public MountFlags f_flag; // mount flags
925 public ulong f_namemax; // maximum filename length
927 public override int GetHashCode ()
929 return f_bsize.GetHashCode () ^
930 f_frsize.GetHashCode () ^
931 f_blocks.GetHashCode () ^
932 f_bfree.GetHashCode () ^
933 f_bavail.GetHashCode () ^
934 f_files.GetHashCode () ^
935 f_ffree.GetHashCode () ^
936 f_favail.GetHashCode () ^
937 f_fsid.GetHashCode () ^
938 f_flag.GetHashCode () ^
939 f_namemax.GetHashCode ();
942 public override bool Equals (object obj)
944 if (obj == null || obj.GetType() != GetType ())
946 Statvfs value = (Statvfs) obj;
947 return value.f_bsize == f_bsize &&
948 value.f_frsize == f_frsize &&
949 value.f_blocks == f_blocks &&
950 value.f_bfree == f_bfree &&
951 value.f_bavail == f_bavail &&
952 value.f_files == f_files &&
953 value.f_ffree == f_ffree &&
954 value.f_favail == f_favail &&
955 value.f_fsid == f_fsid &&
956 value.f_flag == f_flag &&
957 value.f_namemax == f_namemax;
960 public bool Equals (Statvfs value)
962 return value.f_bsize == f_bsize &&
963 value.f_frsize == f_frsize &&
964 value.f_blocks == f_blocks &&
965 value.f_bfree == f_bfree &&
966 value.f_bavail == f_bavail &&
967 value.f_files == f_files &&
968 value.f_ffree == f_ffree &&
969 value.f_favail == f_favail &&
970 value.f_fsid == f_fsid &&
971 value.f_flag == f_flag &&
972 value.f_namemax == f_namemax;
975 public static bool operator== (Statvfs lhs, Statvfs rhs)
977 return lhs.Equals (rhs);
980 public static bool operator!= (Statvfs lhs, Statvfs rhs)
982 return !lhs.Equals (rhs);
986 [Map ("struct timeval")]
987 public struct Timeval
989 : IEquatable <Timeval>
992 [time_t] public long tv_sec; // seconds
993 [suseconds_t] public long tv_usec; // microseconds
995 public override int GetHashCode ()
997 return tv_sec.GetHashCode () ^ tv_usec.GetHashCode ();
1000 public override bool Equals (object obj)
1002 if (obj == null || obj.GetType () != GetType ())
1004 Timeval value = (Timeval) obj;
1005 return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
1008 public bool Equals (Timeval value)
1010 return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
1013 public static bool operator== (Timeval lhs, Timeval rhs)
1015 return lhs.Equals (rhs);
1018 public static bool operator!= (Timeval lhs, Timeval rhs)
1020 return !lhs.Equals (rhs);
1024 [Map ("struct timezone")]
1025 public struct Timezone
1027 : IEquatable <Timezone>
1030 public int tz_minuteswest; // minutes W of Greenwich
1031 #pragma warning disable 169
1032 private int tz_dsttime; // type of dst correction (OBSOLETE)
1033 #pragma warning restore 169
1035 public override int GetHashCode ()
1037 return tz_minuteswest.GetHashCode ();
1040 public override bool Equals (object obj)
1042 if (obj == null || obj.GetType () != GetType ())
1044 Timezone value = (Timezone) obj;
1045 return value.tz_minuteswest == tz_minuteswest;
1048 public bool Equals (Timezone value)
1050 return value.tz_minuteswest == tz_minuteswest;
1053 public static bool operator== (Timezone lhs, Timezone rhs)
1055 return lhs.Equals (rhs);
1058 public static bool operator!= (Timezone lhs, Timezone rhs)
1060 return !lhs.Equals (rhs);
1064 [Map ("struct utimbuf")]
1065 public struct Utimbuf
1067 : IEquatable <Utimbuf>
1070 [time_t] public long actime; // access time
1071 [time_t] public long modtime; // modification time
1073 public override int GetHashCode ()
1075 return actime.GetHashCode () ^ modtime.GetHashCode ();
1078 public override bool Equals (object obj)
1080 if (obj == null || obj.GetType () != GetType ())
1082 Utimbuf value = (Utimbuf) obj;
1083 return value.actime == actime && value.modtime == modtime;
1086 public bool Equals (Utimbuf value)
1088 return value.actime == actime && value.modtime == modtime;
1091 public static bool operator== (Utimbuf lhs, Utimbuf rhs)
1093 return lhs.Equals (rhs);
1096 public static bool operator!= (Utimbuf lhs, Utimbuf rhs)
1098 return !lhs.Equals (rhs);
1102 [Map ("struct timespec")]
1103 public struct Timespec
1105 : IEquatable <Timespec>
1108 [time_t] public long tv_sec; // Seconds.
1109 public long tv_nsec; // Nanoseconds.
1111 public override int GetHashCode ()
1113 return tv_sec.GetHashCode () ^ tv_nsec.GetHashCode ();
1116 public override bool Equals (object obj)
1118 if (obj == null || obj.GetType () != GetType ())
1120 Timespec value = (Timespec) obj;
1121 return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
1124 public bool Equals (Timespec value)
1126 return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
1129 public static bool operator== (Timespec lhs, Timespec rhs)
1131 return lhs.Equals (rhs);
1134 public static bool operator!= (Timespec lhs, Timespec rhs)
1136 return !lhs.Equals (rhs);
1141 public enum EpollFlags {
1142 EPOLL_CLOEXEC = 02000000,
1143 EPOLL_NONBLOCK = 04000,
1147 [CLSCompliant (false)]
1148 public enum EpollEvents : uint {
1152 EPOLLRDNORM = 0x040,
1153 EPOLLRDBAND = 0x080,
1154 EPOLLWRNORM = 0x100,
1155 EPOLLWRBAND = 0x200,
1159 EPOLLRDHUP = 0x2000,
1160 EPOLLONESHOT = 1 << 30,
1161 EPOLLET = unchecked ((uint) (1 << 31))
1164 public enum EpollOp {
1170 [StructLayout (LayoutKind.Explicit, Size=12, Pack=1)]
1171 [CLSCompliant (false)]
1172 public struct EpollEvent {
1174 public EpollEvents events;
1188 public sealed class Dirent
1190 : IEquatable <Dirent>
1193 [CLSCompliant (false)]
1194 public /* ino_t */ ulong d_ino;
1195 public /* off_t */ long d_off;
1196 [CLSCompliant (false)]
1197 public ushort d_reclen;
1199 public string d_name;
1201 public override int GetHashCode ()
1203 return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
1204 d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
1205 d_name.GetHashCode ();
1208 public override bool Equals (object obj)
1210 if (obj == null || GetType() != obj.GetType())
1212 Dirent d = (Dirent) obj;
1216 public bool Equals (Dirent value)
1220 return value.d_ino == d_ino && value.d_off == d_off &&
1221 value.d_reclen == d_reclen && value.d_type == d_type &&
1222 value.d_name == d_name;
1225 public override string ToString ()
1230 public static bool operator== (Dirent lhs, Dirent rhs)
1232 return Object.Equals (lhs, rhs);
1235 public static bool operator!= (Dirent lhs, Dirent rhs)
1237 return !Object.Equals (lhs, rhs);
1241 public sealed class Fstab
1243 : IEquatable <Fstab>
1246 public string fs_spec;
1247 public string fs_file;
1248 public string fs_vfstype;
1249 public string fs_mntops;
1250 public string fs_type;
1252 public int fs_passno;
1254 public override int GetHashCode ()
1256 return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
1257 fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
1258 fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
1261 public override bool Equals (object obj)
1263 if (obj == null || GetType() != obj.GetType())
1265 Fstab f = (Fstab) obj;
1269 public bool Equals (Fstab value)
1273 return value.fs_spec == fs_spec && value.fs_file == fs_file &&
1274 value.fs_vfstype == fs_vfstype && value.fs_mntops == fs_mntops &&
1275 value.fs_type == fs_type && value.fs_freq == fs_freq &&
1276 value.fs_passno == fs_passno;
1279 public override string ToString ()
1284 public static bool operator== (Fstab lhs, Fstab rhs)
1286 return Object.Equals (lhs, rhs);
1289 public static bool operator!= (Fstab lhs, Fstab rhs)
1291 return !Object.Equals (lhs, rhs);
1295 public sealed class Group
1297 : IEquatable <Group>
1300 public string gr_name;
1301 public string gr_passwd;
1302 [CLSCompliant (false)]
1303 public /* gid_t */ uint gr_gid;
1304 public string[] gr_mem;
1306 public override int GetHashCode ()
1309 for (int i = 0; i < gr_mem.Length; ++i)
1310 memhc ^= gr_mem[i].GetHashCode ();
1312 return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
1313 gr_gid.GetHashCode () ^ memhc;
1316 public override bool Equals (object obj)
1318 if (obj == null || GetType() != obj.GetType())
1320 Group g = (Group) obj;
1324 public bool Equals (Group value)
1328 if (value.gr_gid != gr_gid)
1330 if (value.gr_gid == gr_gid && value.gr_name == gr_name &&
1331 value.gr_passwd == gr_passwd) {
1332 if (value.gr_mem == gr_mem)
1334 if (value.gr_mem == null || gr_mem == null)
1336 if (value.gr_mem.Length != gr_mem.Length)
1338 for (int i = 0; i < gr_mem.Length; ++i)
1339 if (gr_mem[i] != value.gr_mem[i])
1346 // Generate string in /etc/group format
1347 public override string ToString ()
1349 StringBuilder sb = new StringBuilder ();
1350 sb.Append (gr_name).Append (":").Append (gr_passwd).Append (":");
1351 sb.Append (gr_gid).Append (":");
1352 GetMembers (sb, gr_mem);
1353 return sb.ToString ();
1356 private static void GetMembers (StringBuilder sb, string[] members)
1358 if (members.Length > 0)
1359 sb.Append (members[0]);
1360 for (int i = 1; i < members.Length; ++i) {
1362 sb.Append (members[i]);
1366 public static bool operator== (Group lhs, Group rhs)
1368 return Object.Equals (lhs, rhs);
1371 public static bool operator!= (Group lhs, Group rhs)
1373 return !Object.Equals (lhs, rhs);
1377 public sealed class Passwd
1379 : IEquatable <Passwd>
1382 public string pw_name;
1383 public string pw_passwd;
1384 [CLSCompliant (false)]
1385 public /* uid_t */ uint pw_uid;
1386 [CLSCompliant (false)]
1387 public /* gid_t */ uint pw_gid;
1388 public string pw_gecos;
1389 public string pw_dir;
1390 public string pw_shell;
1392 public override int GetHashCode ()
1394 return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
1395 pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
1396 pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
1397 pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
1400 public override bool Equals (object obj)
1402 if (obj == null || GetType() != obj.GetType())
1404 Passwd p = (Passwd) obj;
1408 public bool Equals (Passwd value)
1412 return value.pw_uid == pw_uid && value.pw_gid == pw_gid &&
1413 value.pw_name == pw_name && value.pw_passwd == pw_passwd &&
1414 value.pw_gecos == pw_gecos && value.pw_dir == pw_dir &&
1415 value.pw_shell == pw_shell;
1418 // Generate string in /etc/passwd format
1419 public override string ToString ()
1421 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
1422 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
1425 public static bool operator== (Passwd lhs, Passwd rhs)
1427 return Object.Equals (lhs, rhs);
1430 public static bool operator!= (Passwd lhs, Passwd rhs)
1432 return !Object.Equals (lhs, rhs);
1436 public sealed class Utsname
1438 : IEquatable <Utsname>
1441 public string sysname;
1442 public string nodename;
1443 public string release;
1444 public string version;
1445 public string machine;
1446 public string domainname;
1448 public override int GetHashCode ()
1450 return sysname.GetHashCode () ^ nodename.GetHashCode () ^
1451 release.GetHashCode () ^ version.GetHashCode () ^
1452 machine.GetHashCode () ^ domainname.GetHashCode ();
1455 public override bool Equals (object obj)
1457 if (obj == null || GetType() != obj.GetType())
1459 Utsname u = (Utsname) obj;
1463 public bool Equals (Utsname value)
1465 return value.sysname == sysname && value.nodename == nodename &&
1466 value.release == release && value.version == version &&
1467 value.machine == machine && value.domainname == domainname;
1470 // Generate string in /etc/passwd format
1471 public override string ToString ()
1473 return string.Format ("{0} {1} {2} {3} {4}",
1474 sysname, nodename, release, version, machine);
1477 public static bool operator== (Utsname lhs, Utsname rhs)
1479 return Object.Equals (lhs, rhs);
1482 public static bool operator!= (Utsname lhs, Utsname rhs)
1484 return !Object.Equals (lhs, rhs);
1489 // Convention: Functions *not* part of the standard C library AND part of
1490 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
1492 // For example, the man page should be similar to:
1494 // CONFORMING TO (or CONFORMS TO)
1495 // XPG2, SUSv2, POSIX, etc.
1497 // BSD- and GNU-specific exports can also be placed here.
1499 // Non-POSIX/XPG/etc. functions can also be placed here if:
1500 // (a) They'd be likely to be covered in a Steven's-like book
1501 // (b) The functions would be present in libc.so (or equivalent).
1503 // If a function has its own library, that's a STRONG indicator that the
1504 // function should get a different binding, probably in its own assembly,
1505 // so that package management can work sanely. (That is, we'd like to avoid
1506 // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
1507 // run, and libFooLib.so doesn't exist. That would be confusing.)
1509 // The only methods in here should be:
1510 // (1) low-level functions
1511 // (2) "Trivial" function overloads. For example, if the parameters to a
1512 // function are related (e.g. getgroups(2))
1513 // (3) The return type SHOULD NOT be changed. If you want to provide a
1514 // convenience function with a nicer return type, place it into one of
1515 // the Mono.Unix.Unix* wrapper classes, and give it a .NET-styled name.
1516 // - EXCEPTION: No public functions should have a `void' return type.
1517 // `void' return types should be replaced with `int'.
1518 // Rationality: `void'-return functions typically require a
1519 // complicated call sequence, such as clear errno, then call, then
1520 // check errno to see if any errors occurred. This sequence can't
1521 // be done safely in managed code, as errno may change as part of
1522 // the P/Invoke mechanism.
1523 // Instead, add a MonoPosixHelper export which does:
1526 // return errno == 0 ? 0 : -1;
1527 // This lets managed code check the return value in the usual manner.
1528 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
1529 // - If you're wrapping *broken* methods which make assumptions about
1530 // input data, such as that an argument refers to N bytes of data.
1531 // This is currently limited to cuserid(3) and encrypt(3).
1532 // - If you call functions which themselves generate exceptions.
1533 // This is the case for using NativeConvert, which will throw an
1534 // exception if an invalid/unsupported value is used.
1536 // Naming Conventions:
1537 // - Syscall method names should have the same name as the function being
1538 // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
1539 // consult the appropriate man page if necessary.
1540 // - Methods need not have the same arguments IF this simplifies or
1541 // permits correct usage. The current example is syslog, in which
1542 // syslog(3)'s single `priority' argument is split into SyslogFacility
1543 // and SyslogLevel arguments.
1544 // - Type names (structures, classes, enumerations) are always PascalCased.
1545 // - Enumerations are named as <MethodName><ArgumentName>, and are located
1546 // in the Mono.Unix.Native namespace. For readability, if ArgumentName
1547 // is "cmd", use Command instead. For example, fcntl(2) takes a
1548 // FcntlCommand argument. This naming convention is to provide an
1549 // assocation between an enumeration and where it should be used, and
1550 // allows a single method to accept multiple different enumerations
1551 // (see mmap(2), which takes MmapProts and MmapFlags).
1552 // - EXCEPTION: if an enumeration is shared between multiple different
1553 // methods, AND/OR the "obvious" enumeration name conflicts with an
1554 // existing .NET type, a more appropriate name should be used.
1555 // Example: FilePermissions
1556 // - EXCEPTION: [Flags] enumerations should get plural names to follow
1557 // .NET name guidelines. Usually this doesn't result in a change
1558 // (OpenFlags is the `flags' parameter for open(2)), but it can
1559 // (mmap(2) prot ==> MmapProts, access(2) mode ==> AccessModes).
1560 // - Enumerations should have the [Map] and (optional) [Flags] attributes.
1561 // [Map] is required for make-map to find the type and generate the
1562 // appropriate NativeConvert conversion functions.
1563 // - Enumeration contents should match the original Unix names. This helps
1564 // with documentation (the existing man pages are still useful), and is
1565 // required for use with the make-map generation program.
1566 // - Structure names should be the PascalCased version of the actual
1567 // structure name (struct flock ==> Flock). Structure members should
1568 // have the same names, or a (reasonably) portable subset (Dirent being
1569 // the poster child for questionable members).
1570 // - Whether the managed type should be a reference type (class) or a
1571 // value type (struct) should be determined on a case-by-case basis:
1572 // if you ever need to be able to use NULL for it (such as with Dirent,
1573 // Group, Passwd, as these are method return types and `null' is used
1574 // to signify the end), it should be a reference type; otherwise, use
1575 // your discretion, and keep any expected usage patterns in mind.
1576 // - Syscall should be a Single Point Of Truth (SPOT). There should be
1577 // only ONE way to do anything. By convention, the Linux function names
1578 // are used, but that need not always be the case (use your discretion).
1579 // It SHOULD NOT be required that developers know what platform they're
1580 // on, and choose among a set of similar functions. In short, anything
1581 // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
1582 // we can afford to clean things up whenever possible.
1584 // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
1585 // statvfs(2). MonoPosixHelper will "thunk" between the two,
1586 // exporting a statvfs that works across platforms.
1587 // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
1588 // instead provides getvfsent(3). MonoPosixHelper provides wrappers
1589 // to convert getvfsent(3) into Fstab data.
1590 // - Exception: If it isn't possible to cleanly wrap platforms, then the
1591 // method shouldn't be exported. The user will be expected to do their
1592 // own platform check and their own DllImports.
1593 // Examples: mount(2), umount(2), etc.
1594 // - Note: if a platform doesn't support a function AT ALL, the
1595 // MonoPosixHelper wrapper won't be compiled, resulting in a
1596 // EntryPointNotFoundException. This is also consistent with a missing
1597 // P/Invoke into libc.so.
1599 [CLSCompliant (false)]
1600 public sealed class Syscall : Stdlib
1602 new internal const string LIBC = "libc";
1604 private Syscall () {}
1610 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
1611 // aio_return(3), aio_suspend(3), aio_write(3)
1613 // Then update UnixStream.BeginRead to use the aio* functions.
1616 #region <attr/xattr.h> Declarations
1618 // <attr/xattr.h> -- COMPLETE
1622 // int setxattr (const char *path, const char *name,
1623 // const void *value, size_t size, int flags);
1624 [DllImport (MPH, SetLastError=true,
1625 EntryPoint="Mono_Posix_Syscall_setxattr")]
1626 public static extern int setxattr (
1627 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1629 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1630 string name, byte[] value, ulong size, XattrFlags flags);
1632 public static int setxattr (string path, string name, byte [] value, ulong size)
1634 return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1637 public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
1639 return setxattr (path, name, value, (ulong) value.Length, flags);
1642 public static int setxattr (string path, string name, byte [] value)
1644 return setxattr (path, name, value, (ulong) value.Length);
1648 // int lsetxattr (const char *path, const char *name,
1649 // const void *value, size_t size, int flags);
1650 [DllImport (MPH, SetLastError=true,
1651 EntryPoint="Mono_Posix_Syscall_lsetxattr")]
1652 public static extern int lsetxattr (
1653 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1655 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1656 string name, byte[] value, ulong size, XattrFlags flags);
1658 public static int lsetxattr (string path, string name, byte [] value, ulong size)
1660 return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1663 public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
1665 return lsetxattr (path, name, value, (ulong) value.Length, flags);
1668 public static int lsetxattr (string path, string name, byte [] value)
1670 return lsetxattr (path, name, value, (ulong) value.Length);
1674 // int fsetxattr (int fd, const char *name,
1675 // const void *value, size_t size, int flags);
1676 [DllImport (MPH, SetLastError=true,
1677 EntryPoint="Mono_Posix_Syscall_fsetxattr")]
1678 public static extern int fsetxattr (int fd,
1679 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1680 string name, byte[] value, ulong size, XattrFlags flags);
1682 public static int fsetxattr (int fd, string name, byte [] value, ulong size)
1684 return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
1687 public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
1689 return fsetxattr (fd, name, value, (ulong) value.Length, flags);
1692 public static int fsetxattr (int fd, string name, byte [] value)
1694 return fsetxattr (fd, name, value, (ulong) value.Length);
1698 // ssize_t getxattr (const char *path, const char *name,
1699 // void *value, size_t size);
1700 [DllImport (MPH, SetLastError=true,
1701 EntryPoint="Mono_Posix_Syscall_getxattr")]
1702 public static extern long getxattr (
1703 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1705 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1706 string name, byte[] value, ulong size);
1708 public static long getxattr (string path, string name, byte [] value)
1710 return getxattr (path, name, value, (ulong) value.Length);
1713 public static long getxattr (string path, string name, out byte [] value)
1716 long size = getxattr (path, name, value, 0);
1720 value = new byte [size];
1721 return getxattr (path, name, value, (ulong) size);
1725 // ssize_t lgetxattr (const char *path, const char *name,
1726 // void *value, size_t size);
1727 [DllImport (MPH, SetLastError=true,
1728 EntryPoint="Mono_Posix_Syscall_lgetxattr")]
1729 public static extern long lgetxattr (
1730 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1732 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1733 string name, byte[] value, ulong size);
1735 public static long lgetxattr (string path, string name, byte [] value)
1737 return lgetxattr (path, name, value, (ulong) value.Length);
1740 public static long lgetxattr (string path, string name, out byte [] value)
1743 long size = lgetxattr (path, name, value, 0);
1747 value = new byte [size];
1748 return lgetxattr (path, name, value, (ulong) size);
1752 // ssize_t fgetxattr (int fd, const char *name, void *value, size_t size);
1753 [DllImport (MPH, SetLastError=true,
1754 EntryPoint="Mono_Posix_Syscall_fgetxattr")]
1755 public static extern long fgetxattr (int fd,
1756 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1757 string name, byte[] value, ulong size);
1759 public static long fgetxattr (int fd, string name, byte [] value)
1761 return fgetxattr (fd, name, value, (ulong) value.Length);
1764 public static long fgetxattr (int fd, string name, out byte [] value)
1767 long size = fgetxattr (fd, name, value, 0);
1771 value = new byte [size];
1772 return fgetxattr (fd, name, value, (ulong) size);
1776 // ssize_t listxattr (const char *path, char *list, size_t size);
1777 [DllImport (MPH, SetLastError=true,
1778 EntryPoint="Mono_Posix_Syscall_listxattr")]
1779 public static extern long listxattr (
1780 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1781 string path, byte[] list, ulong size);
1783 // Slight modification: returns 0 on success, negative on error
1784 public static long listxattr (string path, Encoding encoding, out string [] values)
1787 long size = listxattr (path, null, 0);
1789 values = new string [0];
1793 byte[] list = new byte [size];
1794 long ret = listxattr (path, list, (ulong) size);
1798 GetValues (list, encoding, out values);
1802 public static long listxattr (string path, out string[] values)
1804 return listxattr (path, UnixEncoding.Instance, out values);
1807 private static void GetValues (byte[] list, Encoding encoding, out string[] values)
1810 for (int i = 0; i < list.Length; ++i)
1814 values = new string [num_values];
1817 for (int i = 0; i < list.Length; ++i) {
1818 if (list [i] == 0) {
1819 values [num_values++] = encoding.GetString (list, str_start, i - str_start);
1826 // ssize_t llistxattr (const char *path, char *list, size_t size);
1827 [DllImport (MPH, SetLastError=true,
1828 EntryPoint="Mono_Posix_Syscall_llistxattr")]
1829 public static extern long llistxattr (
1830 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1831 string path, byte[] list, ulong size);
1833 // Slight modification: returns 0 on success, negative on error
1834 public static long llistxattr (string path, Encoding encoding, out string [] values)
1837 long size = llistxattr (path, null, 0);
1839 values = new string [0];
1843 byte[] list = new byte [size];
1844 long ret = llistxattr (path, list, (ulong) size);
1848 GetValues (list, encoding, out values);
1852 public static long llistxattr (string path, out string[] values)
1854 return llistxattr (path, UnixEncoding.Instance, out values);
1858 // ssize_t flistxattr (int fd, char *list, size_t size);
1859 [DllImport (MPH, SetLastError=true,
1860 EntryPoint="Mono_Posix_Syscall_flistxattr")]
1861 public static extern long flistxattr (int fd, byte[] list, ulong size);
1863 // Slight modification: returns 0 on success, negative on error
1864 public static long flistxattr (int fd, Encoding encoding, out string [] values)
1867 long size = flistxattr (fd, null, 0);
1869 values = new string [0];
1873 byte[] list = new byte [size];
1874 long ret = flistxattr (fd, list, (ulong) size);
1878 GetValues (list, encoding, out values);
1882 public static long flistxattr (int fd, out string[] values)
1884 return flistxattr (fd, UnixEncoding.Instance, out values);
1887 [DllImport (MPH, SetLastError=true,
1888 EntryPoint="Mono_Posix_Syscall_removexattr")]
1889 public static extern int removexattr (
1890 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1892 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1895 [DllImport (MPH, SetLastError=true,
1896 EntryPoint="Mono_Posix_Syscall_lremovexattr")]
1897 public static extern int lremovexattr (
1898 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1900 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1903 [DllImport (MPH, SetLastError=true,
1904 EntryPoint="Mono_Posix_Syscall_fremovexattr")]
1905 public static extern int fremovexattr (int fd,
1906 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1910 #region <dirent.h> Declarations
1914 // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
1916 [DllImport (LIBC, SetLastError=true)]
1917 public static extern IntPtr opendir (
1918 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1921 [DllImport (LIBC, SetLastError=true)]
1922 public static extern int closedir (IntPtr dir);
1925 // void seekdir (DIR *dir, off_t offset);
1926 // Slight modification. Returns -1 on error, 0 on success.
1927 [DllImport (MPH, SetLastError=true,
1928 EntryPoint="Mono_Posix_Syscall_seekdir")]
1929 public static extern int seekdir (IntPtr dir, long offset);
1932 // off_t telldir(DIR *dir);
1933 [DllImport (MPH, SetLastError=true,
1934 EntryPoint="Mono_Posix_Syscall_telldir")]
1935 public static extern long telldir (IntPtr dir);
1937 [DllImport (MPH, SetLastError=true,
1938 EntryPoint="Mono_Posix_Syscall_rewinddir")]
1939 public static extern int rewinddir (IntPtr dir);
1941 private struct _Dirent {
1942 [ino_t] public ulong d_ino;
1943 [off_t] public long d_off;
1944 public ushort d_reclen;
1946 public IntPtr d_name;
1949 private static void CopyDirent (Dirent to, ref _Dirent from)
1952 to.d_ino = from.d_ino;
1953 to.d_off = from.d_off;
1954 to.d_reclen = from.d_reclen;
1955 to.d_type = from.d_type;
1956 to.d_name = UnixMarshal.PtrToString (from.d_name);
1959 Stdlib.free (from.d_name);
1960 from.d_name = IntPtr.Zero;
1964 internal static object readdir_lock = new object ();
1966 [DllImport (MPH, SetLastError=true,
1967 EntryPoint="Mono_Posix_Syscall_readdir")]
1968 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
1970 public static Dirent readdir (IntPtr dir)
1974 lock (readdir_lock) {
1975 r = sys_readdir (dir, out dentry);
1979 Dirent d = new Dirent ();
1980 CopyDirent (d, ref dentry);
1984 [DllImport (MPH, SetLastError=true,
1985 EntryPoint="Mono_Posix_Syscall_readdir_r")]
1986 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
1988 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
1994 entry.d_name = null;
1997 int r = sys_readdir_r (dirp, out _d, out result);
1999 if (r == 0 && result != IntPtr.Zero) {
2000 CopyDirent (entry, ref _d);
2006 [DllImport (LIBC, SetLastError=true)]
2007 public static extern int dirfd (IntPtr dir);
2010 #region <fcntl.h> Declarations
2012 // <fcntl.h> -- COMPLETE
2015 [DllImport (MPH, SetLastError=true,
2016 EntryPoint="Mono_Posix_Syscall_fcntl")]
2017 public static extern int fcntl (int fd, FcntlCommand cmd);
2019 [DllImport (MPH, SetLastError=true,
2020 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
2021 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
2023 public static int fcntl (int fd, FcntlCommand cmd, DirectoryNotifyFlags arg)
2025 if (cmd != FcntlCommand.F_NOTIFY) {
2026 SetLastError (Errno.EINVAL);
2029 long _arg = NativeConvert.FromDirectoryNotifyFlags (arg);
2030 return fcntl (fd, FcntlCommand.F_NOTIFY, _arg);
2033 [DllImport (MPH, SetLastError=true,
2034 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
2035 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
2037 [DllImport (MPH, SetLastError=true,
2038 EntryPoint="Mono_Posix_Syscall_open")]
2039 public static extern int open (
2040 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2041 string pathname, OpenFlags flags);
2044 // int open(const char *pathname, int flags, mode_t mode);
2045 [DllImport (MPH, SetLastError=true,
2046 EntryPoint="Mono_Posix_Syscall_open_mode")]
2047 public static extern int open (
2048 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2049 string pathname, OpenFlags flags, FilePermissions mode);
2052 // int creat(const char *pathname, mode_t mode);
2053 [DllImport (MPH, SetLastError=true,
2054 EntryPoint="Mono_Posix_Syscall_creat")]
2055 public static extern int creat (
2056 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2057 string pathname, FilePermissions mode);
2060 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
2061 [DllImport (MPH, SetLastError=true,
2062 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
2063 public static extern int posix_fadvise (int fd, long offset,
2064 long len, PosixFadviseAdvice advice);
2066 // posix_fallocate(P)
2067 // int posix_fallocate(int fd, off_t offset, size_t len);
2068 [DllImport (MPH, SetLastError=true,
2069 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
2070 public static extern int posix_fallocate (int fd, long offset, ulong len);
2073 #region <fstab.h> Declarations
2075 // <fstab.h> -- COMPLETE
2078 private struct _Fstab {
2079 public IntPtr fs_spec;
2080 public IntPtr fs_file;
2081 public IntPtr fs_vfstype;
2082 public IntPtr fs_mntops;
2083 public IntPtr fs_type;
2085 public int fs_passno;
2086 public IntPtr _fs_buf_;
2089 private static void CopyFstab (Fstab to, ref _Fstab from)
2092 to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
2093 to.fs_file = UnixMarshal.PtrToString (from.fs_file);
2094 to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
2095 to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
2096 to.fs_type = UnixMarshal.PtrToString (from.fs_type);
2097 to.fs_freq = from.fs_freq;
2098 to.fs_passno = from.fs_passno;
2101 Stdlib.free (from._fs_buf_);
2102 from._fs_buf_ = IntPtr.Zero;
2106 internal static object fstab_lock = new object ();
2108 [DllImport (MPH, SetLastError=true,
2109 EntryPoint="Mono_Posix_Syscall_endfsent")]
2110 private static extern int sys_endfsent ();
2112 public static int endfsent ()
2115 return sys_endfsent ();
2119 [DllImport (MPH, SetLastError=true,
2120 EntryPoint="Mono_Posix_Syscall_getfsent")]
2121 private static extern int sys_getfsent (out _Fstab fs);
2123 public static Fstab getfsent ()
2128 r = sys_getfsent (out fsbuf);
2132 Fstab fs = new Fstab ();
2133 CopyFstab (fs, ref fsbuf);
2137 [DllImport (MPH, SetLastError=true,
2138 EntryPoint="Mono_Posix_Syscall_getfsfile")]
2139 private static extern int sys_getfsfile (
2140 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2141 string mount_point, out _Fstab fs);
2143 public static Fstab getfsfile (string mount_point)
2148 r = sys_getfsfile (mount_point, out fsbuf);
2152 Fstab fs = new Fstab ();
2153 CopyFstab (fs, ref fsbuf);
2157 [DllImport (MPH, SetLastError=true,
2158 EntryPoint="Mono_Posix_Syscall_getfsspec")]
2159 private static extern int sys_getfsspec (
2160 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2161 string special_file, out _Fstab fs);
2163 public static Fstab getfsspec (string special_file)
2168 r = sys_getfsspec (special_file, out fsbuf);
2172 Fstab fs = new Fstab ();
2173 CopyFstab (fs, ref fsbuf);
2177 [DllImport (MPH, SetLastError=true,
2178 EntryPoint="Mono_Posix_Syscall_setfsent")]
2179 private static extern int sys_setfsent ();
2181 public static int setfsent ()
2184 return sys_setfsent ();
2190 #region <grp.h> Declarations
2194 // TODO: putgrent(3), fgetgrent_r(), initgroups(3)
2197 [DllImport (LIBC, SetLastError=true, EntryPoint="getgrouplist")]
2198 private static extern int sys_getgrouplist (string user, uint grp, uint [] groups,ref int ngroups);
2200 public static Group [] getgrouplist (string username)
2202 if (username == null)
2203 throw new ArgumentNullException ("username");
2204 if (username.Trim () == "")
2205 throw new ArgumentException ("Username cannot be empty", "username");
2206 // Syscall to getpwnam to retrieve user uid
2207 Passwd pw = Syscall.getpwnam (username);
2209 throw new ArgumentException (string.Format ("User {0} does not exists",username), "username");
2210 return getgrouplist (pw);
2213 public static Group [] getgrouplist (Passwd user)
2216 throw new ArgumentNullException ("user");
2217 // initializing ngroups by 16 to get the group count
2220 // allocating buffer to store group uid's
2221 uint [] groups=null;
2223 Array.Resize (ref groups, ngroups*=2);
2224 res = sys_getgrouplist (user.pw_name, user.pw_gid, groups, ref ngroups);
2227 List<Group> result = new List<Group> ();
2229 for (int i = 0; i < res; i++) {
2230 gr = Syscall.getgrgid (groups [i]);
2234 return result.ToArray ();
2238 // int setgroups (size_t size, const gid_t *list);
2239 [DllImport (MPH, SetLastError=true, EntryPoint="Mono_Posix_Syscall_setgroups")]
2240 public static extern int setgroups (ulong size, uint[] list);
2242 public static int setgroups (uint [] list)
2244 return setgroups ((ulong) list.Length, list);
2248 private struct _Group
2250 public IntPtr gr_name;
2251 public IntPtr gr_passwd;
2252 [gid_t] public uint gr_gid;
2253 public int _gr_nmem_;
2254 public IntPtr gr_mem;
2255 public IntPtr _gr_buf_;
2258 private static void CopyGroup (Group to, ref _Group from)
2261 to.gr_gid = from.gr_gid;
2262 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
2263 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
2264 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
2267 Stdlib.free (from.gr_mem);
2268 Stdlib.free (from._gr_buf_);
2269 from.gr_mem = IntPtr.Zero;
2270 from._gr_buf_ = IntPtr.Zero;
2274 internal static object grp_lock = new object ();
2276 [DllImport (MPH, SetLastError=true,
2277 EntryPoint="Mono_Posix_Syscall_getgrnam")]
2278 private static extern int sys_getgrnam (string name, out _Group group);
2280 public static Group getgrnam (string name)
2285 r = sys_getgrnam (name, out group);
2289 Group gr = new Group ();
2290 CopyGroup (gr, ref group);
2295 // struct group *getgrgid(gid_t gid);
2296 [DllImport (MPH, SetLastError=true,
2297 EntryPoint="Mono_Posix_Syscall_getgrgid")]
2298 private static extern int sys_getgrgid (uint uid, out _Group group);
2300 public static Group getgrgid (uint uid)
2305 r = sys_getgrgid (uid, out group);
2309 Group gr = new Group ();
2310 CopyGroup (gr, ref group);
2314 [DllImport (MPH, SetLastError=true,
2315 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
2316 private static extern int sys_getgrnam_r (
2317 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2318 string name, out _Group grbuf, out IntPtr grbufp);
2320 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
2325 int r = sys_getgrnam_r (name, out group, out _grbufp);
2326 if (r == 0 && _grbufp != IntPtr.Zero) {
2327 CopyGroup (grbuf, ref group);
2334 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
2335 // size_t buflen, struct group **gbufp);
2336 [DllImport (MPH, SetLastError=true,
2337 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
2338 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
2340 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
2345 int r = sys_getgrgid_r (uid, out group, out _grbufp);
2346 if (r == 0 && _grbufp != IntPtr.Zero) {
2347 CopyGroup (grbuf, ref group);
2353 [DllImport (MPH, SetLastError=true,
2354 EntryPoint="Mono_Posix_Syscall_getgrent")]
2355 private static extern int sys_getgrent (out _Group grbuf);
2357 public static Group getgrent ()
2362 r = sys_getgrent (out group);
2366 Group gr = new Group();
2367 CopyGroup (gr, ref group);
2371 [DllImport (MPH, SetLastError=true,
2372 EntryPoint="Mono_Posix_Syscall_setgrent")]
2373 private static extern int sys_setgrent ();
2375 public static int setgrent ()
2378 return sys_setgrent ();
2382 [DllImport (MPH, SetLastError=true,
2383 EntryPoint="Mono_Posix_Syscall_endgrent")]
2384 private static extern int sys_endgrent ();
2386 public static int endgrent ()
2389 return sys_endgrent ();
2393 [DllImport (MPH, SetLastError=true,
2394 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
2395 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
2397 public static Group fgetgrent (IntPtr stream)
2402 r = sys_fgetgrent (stream, out group);
2406 Group gr = new Group ();
2407 CopyGroup (gr, ref group);
2412 #region <pwd.h> Declarations
2416 // TODO: putpwent(3), fgetpwent_r()
2418 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
2421 private struct _Passwd
2423 public IntPtr pw_name;
2424 public IntPtr pw_passwd;
2425 [uid_t] public uint pw_uid;
2426 [gid_t] public uint pw_gid;
2427 public IntPtr pw_gecos;
2428 public IntPtr pw_dir;
2429 public IntPtr pw_shell;
2430 public IntPtr _pw_buf_;
2433 private static void CopyPasswd (Passwd to, ref _Passwd from)
2436 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
2437 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
2438 to.pw_uid = from.pw_uid;
2439 to.pw_gid = from.pw_gid;
2440 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
2441 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
2442 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
2445 Stdlib.free (from._pw_buf_);
2446 from._pw_buf_ = IntPtr.Zero;
2450 internal static object pwd_lock = new object ();
2452 [DllImport (MPH, SetLastError=true,
2453 EntryPoint="Mono_Posix_Syscall_getpwnam")]
2454 private static extern int sys_getpwnam (string name, out _Passwd passwd);
2456 public static Passwd getpwnam (string name)
2461 r = sys_getpwnam (name, out passwd);
2465 Passwd pw = new Passwd ();
2466 CopyPasswd (pw, ref passwd);
2471 // struct passwd *getpwnuid(uid_t uid);
2472 [DllImport (MPH, SetLastError=true,
2473 EntryPoint="Mono_Posix_Syscall_getpwuid")]
2474 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
2476 public static Passwd getpwuid (uint uid)
2481 r = sys_getpwuid (uid, out passwd);
2485 Passwd pw = new Passwd ();
2486 CopyPasswd (pw, ref passwd);
2490 [DllImport (MPH, SetLastError=true,
2491 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
2492 private static extern int sys_getpwnam_r (
2493 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2494 string name, out _Passwd pwbuf, out IntPtr pwbufp);
2496 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
2501 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
2502 if (r == 0 && _pwbufp != IntPtr.Zero) {
2503 CopyPasswd (pwbuf, ref passwd);
2510 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
2511 // buflen, struct passwd **pwbufp);
2512 [DllImport (MPH, SetLastError=true,
2513 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
2514 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
2516 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
2521 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
2522 if (r == 0 && _pwbufp != IntPtr.Zero) {
2523 CopyPasswd (pwbuf, ref passwd);
2529 [DllImport (MPH, SetLastError=true,
2530 EntryPoint="Mono_Posix_Syscall_getpwent")]
2531 private static extern int sys_getpwent (out _Passwd pwbuf);
2533 public static Passwd getpwent ()
2538 r = sys_getpwent (out passwd);
2542 Passwd pw = new Passwd ();
2543 CopyPasswd (pw, ref passwd);
2547 [DllImport (MPH, SetLastError=true,
2548 EntryPoint="Mono_Posix_Syscall_setpwent")]
2549 private static extern int sys_setpwent ();
2551 public static int setpwent ()
2554 return sys_setpwent ();
2558 [DllImport (MPH, SetLastError=true,
2559 EntryPoint="Mono_Posix_Syscall_endpwent")]
2560 private static extern int sys_endpwent ();
2562 public static int endpwent ()
2565 return sys_endpwent ();
2569 [DllImport (MPH, SetLastError=true,
2570 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
2571 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
2573 public static Passwd fgetpwent (IntPtr stream)
2578 r = sys_fgetpwent (stream, out passwd);
2582 Passwd pw = new Passwd ();
2583 CopyPasswd (pw, ref passwd);
2588 #region <signal.h> Declarations
2592 [DllImport (MPH, SetLastError=true,
2593 EntryPoint="Mono_Posix_Syscall_psignal")]
2594 private static extern int psignal (int sig, string s);
2596 public static int psignal (Signum sig, string s)
2598 int signum = NativeConvert.FromSignum (sig);
2599 return psignal (signum, s);
2603 // int kill(pid_t pid, int sig);
2604 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
2605 private static extern int sys_kill (int pid, int sig);
2607 public static int kill (int pid, Signum sig)
2609 int _sig = NativeConvert.FromSignum (sig);
2610 return sys_kill (pid, _sig);
2613 private static object signal_lock = new object ();
2615 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
2616 private static extern IntPtr sys_strsignal (int sig);
2618 public static string strsignal (Signum sig)
2620 int s = NativeConvert.FromSignum (sig);
2621 lock (signal_lock) {
2622 IntPtr r = sys_strsignal (s);
2623 return UnixMarshal.PtrToString (r);
2627 // TODO: sigaction(2)
2628 // TODO: sigsuspend(2)
2629 // TODO: sigpending(2)
2633 #region <stdio.h> Declarations
2637 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
2638 private static extern int _L_ctermid ();
2640 public static readonly int L_ctermid = _L_ctermid ();
2642 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
2643 private static extern int _L_cuserid ();
2645 public static readonly int L_cuserid = _L_cuserid ();
2647 internal static object getlogin_lock = new object ();
2649 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
2650 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
2652 [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
2653 "DO NOT USE cuserid().\n" +
2654 "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
2655 public static string cuserid (StringBuilder @string)
2657 if (@string.Capacity < L_cuserid) {
2658 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
2660 lock (getlogin_lock) {
2661 IntPtr r = sys_cuserid (@string);
2662 return UnixMarshal.PtrToString (r);
2668 #region <stdlib.h> Declarations
2672 [DllImport (LIBC, SetLastError=true)]
2673 public static extern int mkstemp (StringBuilder template);
2675 [DllImport (LIBC, SetLastError=true)]
2676 public static extern int ttyslot ();
2678 [Obsolete ("This is insecure and should not be used", true)]
2679 public static int setkey (string key)
2681 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
2686 #region <string.h> Declarations
2692 // int strerror_r(int errnum, char *buf, size_t n);
2693 [DllImport (MPH, SetLastError=true,
2694 EntryPoint="Mono_Posix_Syscall_strerror_r")]
2695 private static extern int sys_strerror_r (int errnum,
2696 [Out] StringBuilder buf, ulong n);
2698 public static int strerror_r (Errno errnum, StringBuilder buf, ulong n)
2700 int e = NativeConvert.FromErrno (errnum);
2701 return sys_strerror_r (e, buf, n);
2704 public static int strerror_r (Errno errnum, StringBuilder buf)
2706 return strerror_r (errnum, buf, (ulong) buf.Capacity);
2711 #region <sys/epoll.h> Declarations
2713 public static int epoll_create (int size)
2715 return sys_epoll_create (size);
2718 public static int epoll_create (EpollFlags flags)
2720 return sys_epoll_create1 (flags);
2723 public static int epoll_ctl (int epfd, EpollOp op, int fd, EpollEvents events)
2725 EpollEvent ee = new EpollEvent ();
2729 return sys_epoll_ctl (epfd, op, fd, ref ee);
2732 public static int epoll_wait (int epfd, EpollEvent [] events, int max_events, int timeout)
2734 if (events.Length < max_events)
2735 throw new ArgumentOutOfRangeException ("events", "Must refer to at least 'max_events' elements.");
2737 return sys_epoll_wait (epfd, events, max_events, timeout);
2740 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_create")]
2741 private static extern int sys_epoll_create (int size);
2743 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_create1")]
2744 private static extern int sys_epoll_create1 (EpollFlags flags);
2746 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_ctl")]
2747 private static extern int sys_epoll_ctl (int epfd, EpollOp op, int fd, ref EpollEvent ee);
2749 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_wait")]
2750 private static extern int sys_epoll_wait (int epfd, EpollEvent [] ee, int maxevents, int timeout);
2753 #region <sys/mman.h> Declarations
2759 // int posix_madvise(void *addr, size_t len, int advice);
2760 [DllImport (MPH, SetLastError=true,
2761 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
2762 public static extern int posix_madvise (IntPtr addr, ulong len,
2763 PosixMadviseAdvice advice);
2765 public static readonly IntPtr MAP_FAILED = unchecked((IntPtr)(-1));
2767 [DllImport (MPH, SetLastError=true,
2768 EntryPoint="Mono_Posix_Syscall_mmap")]
2769 public static extern IntPtr mmap (IntPtr start, ulong length,
2770 MmapProts prot, MmapFlags flags, int fd, long offset);
2772 [DllImport (MPH, SetLastError=true,
2773 EntryPoint="Mono_Posix_Syscall_munmap")]
2774 public static extern int munmap (IntPtr start, ulong length);
2776 [DllImport (MPH, SetLastError=true,
2777 EntryPoint="Mono_Posix_Syscall_mprotect")]
2778 public static extern int mprotect (IntPtr start, ulong len, MmapProts prot);
2780 [DllImport (MPH, SetLastError=true,
2781 EntryPoint="Mono_Posix_Syscall_msync")]
2782 public static extern int msync (IntPtr start, ulong len, MsyncFlags flags);
2784 [DllImport (MPH, SetLastError=true,
2785 EntryPoint="Mono_Posix_Syscall_mlock")]
2786 public static extern int mlock (IntPtr start, ulong len);
2788 [DllImport (MPH, SetLastError=true,
2789 EntryPoint="Mono_Posix_Syscall_munlock")]
2790 public static extern int munlock (IntPtr start, ulong len);
2792 [DllImport (LIBC, SetLastError=true, EntryPoint="mlockall")]
2793 private static extern int sys_mlockall (int flags);
2795 public static int mlockall (MlockallFlags flags)
2797 int _flags = NativeConvert.FromMlockallFlags (flags);
2798 return sys_mlockall (_flags);
2801 [DllImport (LIBC, SetLastError=true)]
2802 public static extern int munlockall ();
2804 [DllImport (MPH, SetLastError=true,
2805 EntryPoint="Mono_Posix_Syscall_mremap")]
2806 public static extern IntPtr mremap (IntPtr old_address, ulong old_size,
2807 ulong new_size, MremapFlags flags);
2809 [DllImport (MPH, SetLastError=true,
2810 EntryPoint="Mono_Posix_Syscall_mincore")]
2811 public static extern int mincore (IntPtr start, ulong length, byte[] vec);
2813 [DllImport (MPH, SetLastError=true,
2814 EntryPoint="Mono_Posix_Syscall_remap_file_pages")]
2815 public static extern int remap_file_pages (IntPtr start, ulong size,
2816 MmapProts prot, long pgoff, MmapFlags flags);
2820 #region <sys/poll.h> Declarations
2822 // <sys/poll.h> -- COMPLETE
2825 private struct _pollfd {
2827 public short events;
2828 public short revents;
2831 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
2832 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
2834 public static int poll (Pollfd [] fds, uint nfds, int timeout)
2836 if (fds.Length < nfds)
2837 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
2839 _pollfd[] send = new _pollfd[nfds];
2841 for (int i = 0; i < send.Length; i++) {
2842 send [i].fd = fds [i].fd;
2843 send [i].events = NativeConvert.FromPollEvents (fds [i].events);
2846 int r = sys_poll (send, nfds, timeout);
2848 for (int i = 0; i < send.Length; i++) {
2849 fds [i].revents = NativeConvert.ToPollEvents (send [i].revents);
2855 public static int poll (Pollfd [] fds, int timeout)
2857 return poll (fds, (uint) fds.Length, timeout);
2870 // TODO: setrlimit(2)
2871 // TODO: getrlimit(2)
2872 // TODO: getrusage(2)
2876 #region <sys/sendfile.h> Declarations
2878 // <sys/sendfile.h> -- COMPLETE
2881 [DllImport (MPH, SetLastError=true,
2882 EntryPoint="Mono_Posix_Syscall_sendfile")]
2883 public static extern long sendfile (int out_fd, int in_fd,
2884 ref long offset, ulong count);
2888 #region <sys/stat.h> Declarations
2890 // <sys/stat.h> -- COMPLETE
2892 [DllImport (MPH, SetLastError=true,
2893 EntryPoint="Mono_Posix_Syscall_stat")]
2894 public static extern int stat (
2895 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2896 string file_name, out Stat buf);
2898 [DllImport (MPH, SetLastError=true,
2899 EntryPoint="Mono_Posix_Syscall_fstat")]
2900 public static extern int fstat (int filedes, out Stat buf);
2902 [DllImport (MPH, SetLastError=true,
2903 EntryPoint="Mono_Posix_Syscall_lstat")]
2904 public static extern int lstat (
2905 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2906 string file_name, out Stat buf);
2909 // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
2910 // All take FilePermissions
2913 // int chmod(const char *path, mode_t mode);
2914 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
2915 private static extern int sys_chmod (
2916 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2917 string path, uint mode);
2919 public static int chmod (string path, FilePermissions mode)
2921 uint _mode = NativeConvert.FromFilePermissions (mode);
2922 return sys_chmod (path, _mode);
2926 // int chmod(int filedes, mode_t mode);
2927 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
2928 private static extern int sys_fchmod (int filedes, uint mode);
2930 public static int fchmod (int filedes, FilePermissions mode)
2932 uint _mode = NativeConvert.FromFilePermissions (mode);
2933 return sys_fchmod (filedes, _mode);
2937 // mode_t umask(mode_t mask);
2938 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
2939 private static extern uint sys_umask (uint mask);
2941 public static FilePermissions umask (FilePermissions mask)
2943 uint _mask = NativeConvert.FromFilePermissions (mask);
2944 uint r = sys_umask (_mask);
2945 return NativeConvert.ToFilePermissions (r);
2949 // int mkdir(const char *pathname, mode_t mode);
2950 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
2951 private static extern int sys_mkdir (
2952 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2953 string oldpath, uint mode);
2955 public static int mkdir (string oldpath, FilePermissions mode)
2957 uint _mode = NativeConvert.FromFilePermissions (mode);
2958 return sys_mkdir (oldpath, _mode);
2962 // int mknod (const char *pathname, mode_t mode, dev_t dev);
2963 [DllImport (MPH, SetLastError=true,
2964 EntryPoint="Mono_Posix_Syscall_mknod")]
2965 public static extern int mknod (
2966 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2967 string pathname, FilePermissions mode, ulong dev);
2970 // int mkfifo(const char *pathname, mode_t mode);
2971 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
2972 private static extern int sys_mkfifo (
2973 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2974 string pathname, uint mode);
2976 public static int mkfifo (string pathname, FilePermissions mode)
2978 uint _mode = NativeConvert.FromFilePermissions (mode);
2979 return sys_mkfifo (pathname, _mode);
2984 #region <sys/stat.h> Declarations
2989 [DllImport (MPH, SetLastError=true,
2990 EntryPoint="Mono_Posix_Syscall_statvfs")]
2991 public static extern int statvfs (
2992 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2993 string path, out Statvfs buf);
2995 [DllImport (MPH, SetLastError=true,
2996 EntryPoint="Mono_Posix_Syscall_fstatvfs")]
2997 public static extern int fstatvfs (int fd, out Statvfs buf);
3001 #region <sys/time.h> Declarations
3005 // TODO: adjtime(), getitimer(2), setitimer(2)
3007 [DllImport (MPH, SetLastError=true,
3008 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
3009 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
3011 [DllImport (MPH, SetLastError=true,
3012 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
3013 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
3015 public static int gettimeofday (out Timeval tv)
3017 return gettimeofday (out tv, IntPtr.Zero);
3020 [DllImport (MPH, SetLastError=true,
3021 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
3022 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
3024 public static int gettimeofday (out Timezone tz)
3026 return gettimeofday (IntPtr.Zero, out tz);
3029 [DllImport (MPH, SetLastError=true,
3030 EntryPoint="Mono_Posix_Syscall_settimeofday")]
3031 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
3033 [DllImport (MPH, SetLastError=true,
3034 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
3035 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
3037 public static int settimeofday (ref Timeval tv)
3039 return settimeofday (ref tv, IntPtr.Zero);
3042 [DllImport (MPH, SetLastError=true,
3043 EntryPoint="Mono_Posix_Syscall_utimes")]
3044 private static extern int sys_utimes (
3045 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3046 string filename, Timeval[] tvp);
3048 public static int utimes (string filename, Timeval[] tvp)
3050 if (tvp != null && tvp.Length != 2) {
3051 SetLastError (Errno.EINVAL);
3054 return sys_utimes (filename, tvp);
3057 [DllImport (MPH, SetLastError=true,
3058 EntryPoint="Mono_Posix_Syscall_lutimes")]
3059 private static extern int sys_lutimes (
3060 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3061 string filename, Timeval[] tvp);
3063 public static int lutimes (string filename, Timeval[] tvp)
3065 if (tvp != null && tvp.Length != 2) {
3066 SetLastError (Errno.EINVAL);
3069 return sys_lutimes (filename, tvp);
3072 [DllImport (MPH, SetLastError=true,
3073 EntryPoint="Mono_Posix_Syscall_futimes")]
3074 private static extern int sys_futimes (int fd, Timeval[] tvp);
3076 public static int futimes (int fd, Timeval[] tvp)
3078 if (tvp != null && tvp.Length != 2) {
3079 SetLastError (Errno.EINVAL);
3082 return sys_futimes (fd, tvp);
3104 private struct _Utsname
3106 public IntPtr sysname;
3107 public IntPtr nodename;
3108 public IntPtr release;
3109 public IntPtr version;
3110 public IntPtr machine;
3111 public IntPtr domainname;
3112 public IntPtr _buf_;
3115 private static void CopyUtsname (ref Utsname to, ref _Utsname from)
3118 to = new Utsname ();
3119 to.sysname = UnixMarshal.PtrToString (from.sysname);
3120 to.nodename = UnixMarshal.PtrToString (from.nodename);
3121 to.release = UnixMarshal.PtrToString (from.release);
3122 to.version = UnixMarshal.PtrToString (from.version);
3123 to.machine = UnixMarshal.PtrToString (from.machine);
3124 to.domainname = UnixMarshal.PtrToString (from.domainname);
3127 Stdlib.free (from._buf_);
3128 from._buf_ = IntPtr.Zero;
3132 [DllImport (MPH, SetLastError=true,
3133 EntryPoint="Mono_Posix_Syscall_uname")]
3134 private static extern int sys_uname (out _Utsname buf);
3136 public static int uname (out Utsname buf)
3139 int r = sys_uname (out _buf);
3140 buf = new Utsname ();
3142 CopyUtsname (ref buf, ref _buf);
3147 #region <sys/wait.h> Declarations
3153 // pid_t wait(int *status);
3154 [DllImport (LIBC, SetLastError=true)]
3155 public static extern int wait (out int status);
3158 // pid_t waitpid(pid_t pid, int *status, int options);
3159 [DllImport (LIBC, SetLastError=true)]
3160 private static extern int waitpid (int pid, out int status, int options);
3162 public static int waitpid (int pid, out int status, WaitOptions options)
3164 int _options = NativeConvert.FromWaitOptions (options);
3165 return waitpid (pid, out status, _options);
3168 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
3169 private static extern int _WIFEXITED (int status);
3171 public static bool WIFEXITED (int status)
3173 return _WIFEXITED (status) != 0;
3176 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
3177 public static extern int WEXITSTATUS (int status);
3179 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
3180 private static extern int _WIFSIGNALED (int status);
3182 public static bool WIFSIGNALED (int status)
3184 return _WIFSIGNALED (status) != 0;
3187 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
3188 private static extern int _WTERMSIG (int status);
3190 public static Signum WTERMSIG (int status)
3192 int r = _WTERMSIG (status);
3193 return NativeConvert.ToSignum (r);
3196 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
3197 private static extern int _WIFSTOPPED (int status);
3199 public static bool WIFSTOPPED (int status)
3201 return _WIFSTOPPED (status) != 0;
3204 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
3205 private static extern int _WSTOPSIG (int status);
3207 public static Signum WSTOPSIG (int status)
3209 int r = _WSTOPSIG (status);
3210 return NativeConvert.ToSignum (r);
3219 #region <syslog.h> Declarations
3224 [DllImport (MPH, SetLastError=true,
3225 EntryPoint="Mono_Posix_Syscall_openlog")]
3226 private static extern int sys_openlog (IntPtr ident, int option, int facility);
3228 public static int openlog (IntPtr ident, SyslogOptions option,
3229 SyslogFacility defaultFacility)
3231 int _option = NativeConvert.FromSyslogOptions (option);
3232 int _facility = NativeConvert.FromSyslogFacility (defaultFacility);
3234 return sys_openlog (ident, _option, _facility);
3237 [DllImport (MPH, SetLastError=true,
3238 EntryPoint="Mono_Posix_Syscall_syslog")]
3239 private static extern int sys_syslog (int priority, string message);
3241 public static int syslog (SyslogFacility facility, SyslogLevel level, string message)
3243 int _facility = NativeConvert.FromSyslogFacility (facility);
3244 int _level = NativeConvert.FromSyslogLevel (level);
3245 return sys_syslog (_facility | _level, GetSyslogMessage (message));
3248 public static int syslog (SyslogLevel level, string message)
3250 int _level = NativeConvert.FromSyslogLevel (level);
3251 return sys_syslog (_level, GetSyslogMessage (message));
3254 private static string GetSyslogMessage (string message)
3256 return UnixMarshal.EscapeFormatString (message, new char[]{'m'});
3259 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
3260 "Use syslog(SyslogFacility, SyslogLevel, string) instead.")]
3261 public static int syslog (SyslogFacility facility, SyslogLevel level,
3262 string format, params object[] parameters)
3264 int _facility = NativeConvert.FromSyslogFacility (facility);
3265 int _level = NativeConvert.FromSyslogLevel (level);
3267 object[] _parameters = new object[checked(parameters.Length+2)];
3268 _parameters [0] = _facility | _level;
3269 _parameters [1] = format;
3270 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
3271 return (int) XPrintfFunctions.syslog (_parameters);
3274 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
3275 "Use syslog(SyslogLevel, string) instead.")]
3276 public static int syslog (SyslogLevel level, string format,
3277 params object[] parameters)
3279 int _level = NativeConvert.FromSyslogLevel (level);
3281 object[] _parameters = new object[checked(parameters.Length+2)];
3282 _parameters [0] = _level;
3283 _parameters [1] = format;
3284 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
3285 return (int) XPrintfFunctions.syslog (_parameters);
3288 [DllImport (MPH, SetLastError=true,
3289 EntryPoint="Mono_Posix_Syscall_closelog")]
3290 public static extern int closelog ();
3292 [DllImport (LIBC, SetLastError=true, EntryPoint="setlogmask")]
3293 private static extern int sys_setlogmask (int mask);
3295 public static int setlogmask (SyslogLevel mask)
3297 int _mask = NativeConvert.FromSyslogLevel (mask);
3298 return sys_setlogmask (_mask);
3303 #region <time.h> Declarations
3310 // int nanosleep(const struct timespec *req, struct timespec *rem);
3311 [DllImport (MPH, SetLastError=true,
3312 EntryPoint="Mono_Posix_Syscall_nanosleep")]
3313 public static extern int nanosleep (ref Timespec req, ref Timespec rem);
3316 // int stime(time_t *t);
3317 [DllImport (MPH, SetLastError=true,
3318 EntryPoint="Mono_Posix_Syscall_stime")]
3319 public static extern int stime (ref long t);
3322 // time_t time(time_t *t);
3323 [DllImport (MPH, SetLastError=true,
3324 EntryPoint="Mono_Posix_Syscall_time")]
3325 public static extern long time (out long t);
3335 #region <unistd.h> Declarations
3339 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
3340 // other TODOs listed below.
3342 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
3343 private static extern int sys_access (
3344 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3345 string pathname, int mode);
3347 public static int access (string pathname, AccessModes mode)
3349 int _mode = NativeConvert.FromAccessModes (mode);
3350 return sys_access (pathname, _mode);
3354 // off_t lseek(int filedes, off_t offset, int whence);
3355 [DllImport (MPH, SetLastError=true,
3356 EntryPoint="Mono_Posix_Syscall_lseek")]
3357 private static extern long sys_lseek (int fd, long offset, int whence);
3359 public static long lseek (int fd, long offset, SeekFlags whence)
3361 short _whence = NativeConvert.FromSeekFlags (whence);
3362 return sys_lseek (fd, offset, _whence);
3365 [DllImport (LIBC, SetLastError=true)]
3366 public static extern int close (int fd);
3369 // ssize_t read(int fd, void *buf, size_t count);
3370 [DllImport (MPH, SetLastError=true,
3371 EntryPoint="Mono_Posix_Syscall_read")]
3372 public static extern long read (int fd, IntPtr buf, ulong count);
3374 public static unsafe long read (int fd, void *buf, ulong count)
3376 return read (fd, (IntPtr) buf, count);
3380 // ssize_t write(int fd, const void *buf, size_t count);
3381 [DllImport (MPH, SetLastError=true,
3382 EntryPoint="Mono_Posix_Syscall_write")]
3383 public static extern long write (int fd, IntPtr buf, ulong count);
3385 public static unsafe long write (int fd, void *buf, ulong count)
3387 return write (fd, (IntPtr) buf, count);
3391 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
3392 [DllImport (MPH, SetLastError=true,
3393 EntryPoint="Mono_Posix_Syscall_pread")]
3394 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
3396 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
3398 return pread (fd, (IntPtr) buf, count, offset);
3402 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
3403 [DllImport (MPH, SetLastError=true,
3404 EntryPoint="Mono_Posix_Syscall_pwrite")]
3405 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
3407 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
3409 return pwrite (fd, (IntPtr) buf, count, offset);
3412 [DllImport (MPH, SetLastError=true,
3413 EntryPoint="Mono_Posix_Syscall_pipe")]
3414 public static extern int pipe (out int reading, out int writing);
3416 public static int pipe (int[] filedes)
3418 if (filedes == null || filedes.Length != 2) {
3422 int reading, writing;
3423 int r = pipe (out reading, out writing);
3424 filedes[0] = reading;
3425 filedes[1] = writing;
3429 [DllImport (LIBC, SetLastError=true)]
3430 public static extern uint alarm (uint seconds);
3432 [DllImport (LIBC, SetLastError=true)]
3433 public static extern uint sleep (uint seconds);
3435 [DllImport (LIBC, SetLastError=true)]
3436 public static extern uint ualarm (uint usecs, uint interval);
3438 [DllImport (LIBC, SetLastError=true)]
3439 public static extern int pause ();
3442 // int chown(const char *path, uid_t owner, gid_t group);
3443 [DllImport (LIBC, SetLastError=true)]
3444 public static extern int chown (
3445 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3446 string path, uint owner, uint group);
3449 // int fchown(int fd, uid_t owner, gid_t group);
3450 [DllImport (LIBC, SetLastError=true)]
3451 public static extern int fchown (int fd, uint owner, uint group);
3454 // int lchown(const char *path, uid_t owner, gid_t group);
3455 [DllImport (LIBC, SetLastError=true)]
3456 public static extern int lchown (
3457 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3458 string path, uint owner, uint group);
3460 [DllImport (LIBC, SetLastError=true)]
3461 public static extern int chdir (
3462 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3465 [DllImport (LIBC, SetLastError=true)]
3466 public static extern int fchdir (int fd);
3469 // char *getcwd(char *buf, size_t size);
3470 [DllImport (MPH, SetLastError=true,
3471 EntryPoint="Mono_Posix_Syscall_getcwd")]
3472 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
3474 public static StringBuilder getcwd (StringBuilder buf)
3476 getcwd (buf, (ulong) buf.Capacity);
3480 // getwd(2) is deprecated; don't expose it.
3482 [DllImport (LIBC, SetLastError=true)]
3483 public static extern int dup (int fd);
3485 [DllImport (LIBC, SetLastError=true)]
3486 public static extern int dup2 (int fd, int fd2);
3488 // TODO: does Mono marshal arrays properly?
3489 [DllImport (LIBC, SetLastError=true)]
3490 public static extern int execve (
3491 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3492 string path, string[] argv, string[] envp);
3494 [DllImport (LIBC, SetLastError=true)]
3495 public static extern int fexecve (int fd, string[] argv, string[] envp);
3497 [DllImport (LIBC, SetLastError=true)]
3498 public static extern int execv (
3499 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3500 string path, string[] argv);
3502 // TODO: execle, execl, execlp
3503 [DllImport (LIBC, SetLastError=true)]
3504 public static extern int execvp (
3505 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3506 string path, string[] argv);
3508 [DllImport (LIBC, SetLastError=true)]
3509 public static extern int nice (int inc);
3511 [DllImport (LIBC, SetLastError=true)]
3512 [CLSCompliant (false)]
3513 public static extern int _exit (int status);
3515 [DllImport (MPH, SetLastError=true,
3516 EntryPoint="Mono_Posix_Syscall_fpathconf")]
3517 public static extern long fpathconf (int filedes, PathconfName name, Errno defaultError);
3519 public static long fpathconf (int filedes, PathconfName name)
3521 return fpathconf (filedes, name, (Errno) 0);
3524 [DllImport (MPH, SetLastError=true,
3525 EntryPoint="Mono_Posix_Syscall_pathconf")]
3526 public static extern long pathconf (
3527 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3528 string path, PathconfName name, Errno defaultError);
3530 public static long pathconf (string path, PathconfName name)
3532 return pathconf (path, name, (Errno) 0);
3535 [DllImport (MPH, SetLastError=true,
3536 EntryPoint="Mono_Posix_Syscall_sysconf")]
3537 public static extern long sysconf (SysconfName name, Errno defaultError);
3539 public static long sysconf (SysconfName name)
3541 return sysconf (name, (Errno) 0);
3545 // size_t confstr(int name, char *buf, size_t len);
3546 [DllImport (MPH, SetLastError=true,
3547 EntryPoint="Mono_Posix_Syscall_confstr")]
3548 public static extern ulong confstr (ConfstrName name, [Out] StringBuilder buf, ulong len);
3551 // pid_t getpid(void);
3552 [DllImport (LIBC, SetLastError=true)]
3553 public static extern int getpid ();
3556 // pid_t getppid(void);
3557 [DllImport (LIBC, SetLastError=true)]
3558 public static extern int getppid ();
3561 // int setpgid(pid_t pid, pid_t pgid);
3562 [DllImport (LIBC, SetLastError=true)]
3563 public static extern int setpgid (int pid, int pgid);
3566 // pid_t getpgid(pid_t pid);
3567 [DllImport (LIBC, SetLastError=true)]
3568 public static extern int getpgid (int pid);
3570 [DllImport (LIBC, SetLastError=true)]
3571 public static extern int setpgrp ();
3574 // pid_t getpgrp(void);
3575 [DllImport (LIBC, SetLastError=true)]
3576 public static extern int getpgrp ();
3579 // pid_t setsid(void);
3580 [DllImport (LIBC, SetLastError=true)]
3581 public static extern int setsid ();
3584 // pid_t getsid(pid_t pid);
3585 [DllImport (LIBC, SetLastError=true)]
3586 public static extern int getsid (int pid);
3589 // uid_t getuid(void);
3590 [DllImport (LIBC, SetLastError=true)]
3591 public static extern uint getuid ();
3594 // uid_t geteuid(void);
3595 [DllImport (LIBC, SetLastError=true)]
3596 public static extern uint geteuid ();
3599 // gid_t getgid(void);
3600 [DllImport (LIBC, SetLastError=true)]
3601 public static extern uint getgid ();
3604 // gid_t getgid(void);
3605 [DllImport (LIBC, SetLastError=true)]
3606 public static extern uint getegid ();
3609 // int getgroups(int size, gid_t list[]);
3610 [DllImport (LIBC, SetLastError=true)]
3611 public static extern int getgroups (int size, uint[] list);
3613 public static int getgroups (uint[] list)
3615 return getgroups (list.Length, list);
3619 // int setuid(uid_t uid);
3620 [DllImport (LIBC, SetLastError=true)]
3621 public static extern int setuid (uint uid);
3624 // int setreuid(uid_t ruid, uid_t euid);
3625 [DllImport (LIBC, SetLastError=true)]
3626 public static extern int setreuid (uint ruid, uint euid);
3629 // int setregid(gid_t ruid, gid_t euid);
3630 [DllImport (LIBC, SetLastError=true)]
3631 public static extern int setregid (uint rgid, uint egid);
3634 // int seteuid(uid_t euid);
3635 [DllImport (LIBC, SetLastError=true)]
3636 public static extern int seteuid (uint euid);
3639 // int setegid(gid_t euid);
3640 [DllImport (LIBC, SetLastError=true)]
3641 public static extern int setegid (uint uid);
3644 // int setgid(gid_t gid);
3645 [DllImport (LIBC, SetLastError=true)]
3646 public static extern int setgid (uint gid);
3649 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
3650 [DllImport (LIBC, SetLastError=true)]
3651 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
3654 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
3655 [DllImport (LIBC, SetLastError=true)]
3656 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
3659 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
3660 [DllImport (LIBC, SetLastError=true)]
3661 public static extern int setresuid (uint ruid, uint euid, uint suid);
3664 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
3665 [DllImport (LIBC, SetLastError=true)]
3666 public static extern int setresgid (uint rgid, uint egid, uint sgid);
3670 // pid_t fork(void);
3671 [DllImport (LIBC, SetLastError=true)]
3672 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
3673 "shutdown code.\nUse System.Diagnostics.Process instead")]
3674 private static extern int fork ();
3677 // pid_t vfork(void);
3678 [DllImport (LIBC, SetLastError=true)]
3679 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
3680 "shutdown code.\nUse System.Diagnostics.Process instead")]
3681 private static extern int vfork ();
3684 private static object tty_lock = new object ();
3686 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
3687 private static extern IntPtr sys_ttyname (int fd);
3689 public static string ttyname (int fd)
3692 IntPtr r = sys_ttyname (fd);
3693 return UnixMarshal.PtrToString (r);
3698 // int ttyname_r(int fd, char *buf, size_t buflen);
3699 [DllImport (MPH, SetLastError=true,
3700 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
3701 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
3703 public static int ttyname_r (int fd, StringBuilder buf)
3705 return ttyname_r (fd, buf, (ulong) buf.Capacity);
3708 [DllImport (LIBC, EntryPoint="isatty")]
3709 private static extern int sys_isatty (int fd);
3711 public static bool isatty (int fd)
3713 return sys_isatty (fd) == 1;
3716 [DllImport (LIBC, SetLastError=true)]
3717 public static extern int link (
3718 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3720 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3723 [DllImport (LIBC, SetLastError=true)]
3724 public static extern int symlink (
3725 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3727 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3731 // int readlink(const char *path, char *buf, size_t bufsize);
3732 [DllImport (MPH, SetLastError=true,
3733 EntryPoint="Mono_Posix_Syscall_readlink")]
3734 public static extern int readlink (
3735 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3736 string path, [Out] StringBuilder buf, ulong bufsiz);
3738 public static int readlink (string path, [Out] StringBuilder buf)
3740 return readlink (path, buf, (ulong) buf.Capacity);
3743 [DllImport (LIBC, SetLastError=true)]
3744 public static extern int unlink (
3745 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3748 [DllImport (LIBC, SetLastError=true)]
3749 public static extern int rmdir (
3750 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3754 // pid_t tcgetpgrp(int fd);
3755 [DllImport (LIBC, SetLastError=true)]
3756 public static extern int tcgetpgrp (int fd);
3759 // int tcsetpgrp(int fd, pid_t pgrp);
3760 [DllImport (LIBC, SetLastError=true)]
3761 public static extern int tcsetpgrp (int fd, int pgrp);
3763 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
3764 private static extern IntPtr sys_getlogin ();
3766 public static string getlogin ()
3768 lock (getlogin_lock) {
3769 IntPtr r = sys_getlogin ();
3770 return UnixMarshal.PtrToString (r);
3775 // int getlogin_r(char *buf, size_t bufsize);
3776 [DllImport (MPH, SetLastError=true,
3777 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
3778 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
3780 public static int getlogin_r (StringBuilder name)
3782 return getlogin_r (name, (ulong) name.Capacity);
3785 [DllImport (LIBC, SetLastError=true)]
3786 public static extern int setlogin (string name);
3789 // int gethostname(char *name, size_t len);
3790 [DllImport (MPH, SetLastError=true,
3791 EntryPoint="Mono_Posix_Syscall_gethostname")]
3792 public static extern int gethostname ([Out] StringBuilder name, ulong len);
3794 public static int gethostname (StringBuilder name)
3796 return gethostname (name, (ulong) name.Capacity);
3800 // int gethostname(const char *name, size_t len);
3801 [DllImport (MPH, SetLastError=true,
3802 EntryPoint="Mono_Posix_Syscall_sethostname")]
3803 public static extern int sethostname (string name, ulong len);
3805 public static int sethostname (string name)
3807 return sethostname (name, (ulong) name.Length);
3810 [DllImport (MPH, SetLastError=true,
3811 EntryPoint="Mono_Posix_Syscall_gethostid")]
3812 public static extern long gethostid ();
3814 [DllImport (MPH, SetLastError=true,
3815 EntryPoint="Mono_Posix_Syscall_sethostid")]
3816 public static extern int sethostid (long hostid);
3819 // int getdomainname(char *name, size_t len);
3820 [DllImport (MPH, SetLastError=true,
3821 EntryPoint="Mono_Posix_Syscall_getdomainname")]
3822 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
3824 public static int getdomainname (StringBuilder name)
3826 return getdomainname (name, (ulong) name.Capacity);
3830 // int setdomainname(const char *name, size_t len);
3831 [DllImport (MPH, SetLastError=true,
3832 EntryPoint="Mono_Posix_Syscall_setdomainname")]
3833 public static extern int setdomainname (string name, ulong len);
3835 public static int setdomainname (string name)
3837 return setdomainname (name, (ulong) name.Length);
3840 [DllImport (LIBC, SetLastError=true)]
3841 public static extern int vhangup ();
3843 // Revoke doesn't appear to be POSIX. Include it?
3844 [DllImport (LIBC, SetLastError=true)]
3845 public static extern int revoke (
3846 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3849 // TODO: profil? It's not POSIX.
3851 [DllImport (LIBC, SetLastError=true)]
3852 public static extern int acct (
3853 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3856 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
3857 private static extern IntPtr sys_getusershell ();
3859 internal static object usershell_lock = new object ();
3861 public static string getusershell ()
3863 lock (usershell_lock) {
3864 IntPtr r = sys_getusershell ();
3865 return UnixMarshal.PtrToString (r);
3869 [DllImport (MPH, SetLastError=true,
3870 EntryPoint="Mono_Posix_Syscall_setusershell")]
3871 private static extern int sys_setusershell ();
3873 public static int setusershell ()
3875 lock (usershell_lock) {
3876 return sys_setusershell ();
3880 [DllImport (MPH, SetLastError=true,
3881 EntryPoint="Mono_Posix_Syscall_endusershell")]
3882 private static extern int sys_endusershell ();
3884 public static int endusershell ()
3886 lock (usershell_lock) {
3887 return sys_endusershell ();
3892 [DllImport (LIBC, SetLastError=true)]
3893 private static extern int daemon (int nochdir, int noclose);
3895 // this implicitly forks, and thus isn't safe.
3896 private static int daemon (bool nochdir, bool noclose)
3898 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
3902 [DllImport (LIBC, SetLastError=true)]
3903 public static extern int chroot (
3904 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3907 // skipping getpass(3) as the man page states:
3908 // This function is obsolete. Do not use it.
3910 [DllImport (LIBC, SetLastError=true)]
3911 public static extern int fsync (int fd);
3913 [DllImport (LIBC, SetLastError=true)]
3914 public static extern int fdatasync (int fd);
3916 [DllImport (MPH, SetLastError=true,
3917 EntryPoint="Mono_Posix_Syscall_sync")]
3918 public static extern int sync ();
3920 [DllImport (LIBC, SetLastError=true)]
3921 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
3922 "Use Syscall.sysconf (SysconfName._SC_PAGESIZE).")]
3923 public static extern int getpagesize ();
3926 // int truncate(const char *path, off_t length);
3927 [DllImport (MPH, SetLastError=true,
3928 EntryPoint="Mono_Posix_Syscall_truncate")]
3929 public static extern int truncate (
3930 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3931 string path, long length);
3934 // int ftruncate(int fd, off_t length);
3935 [DllImport (MPH, SetLastError=true,
3936 EntryPoint="Mono_Posix_Syscall_ftruncate")]
3937 public static extern int ftruncate (int fd, long length);
3939 [DllImport (LIBC, SetLastError=true)]
3940 public static extern int getdtablesize ();
3942 [DllImport (LIBC, SetLastError=true)]
3943 public static extern int brk (IntPtr end_data_segment);
3945 [DllImport (LIBC, SetLastError=true)]
3946 public static extern IntPtr sbrk (IntPtr increment);
3948 // TODO: syscall(2)?
3949 // Probably safer to skip entirely.
3952 // int lockf(int fd, int cmd, off_t len);
3953 [DllImport (MPH, SetLastError=true,
3954 EntryPoint="Mono_Posix_Syscall_lockf")]
3955 public static extern int lockf (int fd, LockfCommand cmd, long len);
3957 [Obsolete ("This is insecure and should not be used", true)]
3958 public static string crypt (string key, string salt)
3960 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
3963 [Obsolete ("This is insecure and should not be used", true)]
3964 public static int encrypt (byte[] block, bool decode)
3966 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
3970 // void swab(const void *from, void *to, ssize_t n);
3971 [DllImport (MPH, SetLastError=true,
3972 EntryPoint="Mono_Posix_Syscall_swab")]
3973 public static extern int swab (IntPtr from, IntPtr to, long n);
3975 public static unsafe void swab (void* from, void* to, long n)
3977 swab ((IntPtr) from, (IntPtr) to, n);
3982 #region <utime.h> Declarations
3984 // <utime.h> -- COMPLETE
3987 [DllImport (MPH, SetLastError=true,
3988 EntryPoint="Mono_Posix_Syscall_utime")]
3989 private static extern int sys_utime (
3990 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3991 string filename, ref Utimbuf buf, int use_buf);
3993 public static int utime (string filename, ref Utimbuf buf)
3995 return sys_utime (filename, ref buf, 1);
3998 public static int utime (string filename)
4000 Utimbuf buf = new Utimbuf ();
4001 return sys_utime (filename, ref buf, 0);