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.Runtime.InteropServices;
59 using System.Security;
61 using Mono.Unix.Native;
63 namespace Mono.Unix.Native {
68 [CLSCompliant (false)]
69 public enum SyslogOptions {
70 LOG_PID = 0x01, // log the pid with each message
71 LOG_CONS = 0x02, // log on the console if errors in sending
72 LOG_ODELAY = 0x04, // delay open until first syslog (default)
73 LOG_NDELAY = 0x08, // don't delay open
74 LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
75 LOG_PERROR = 0x20 // log to stderr as well
79 [CLSCompliant (false)]
80 public enum SyslogFacility {
91 LOG_AUTHPRIV = 10 << 3,
100 LOG_LOCAL7 = 23 << 3,
104 [CLSCompliant (false)]
105 public enum SyslogLevel {
106 LOG_EMERG = 0, // system is unusable
107 LOG_ALERT = 1, // action must be taken immediately
108 LOG_CRIT = 2, // critical conditions
109 LOG_ERR = 3, // warning conditions
110 LOG_WARNING = 4, // warning conditions
111 LOG_NOTICE = 5, // normal but significant condition
112 LOG_INFO = 6, // informational
113 LOG_DEBUG = 7 // debug-level messages
117 [CLSCompliant (false)]
118 public enum OpenFlags : int {
122 O_RDONLY = 0x00000000,
123 O_WRONLY = 0x00000001,
127 // Or-ed with zero or more of these
129 O_CREAT = 0x00000040,
131 O_NOCTTY = 0x00000100,
132 O_TRUNC = 0x00000200,
133 O_APPEND = 0x00000400,
134 O_NONBLOCK = 0x00000800,
138 // These are non-Posix. Using them will result in errors/exceptions on
139 // non-supported platforms.
141 // (For example, "C-wrapped" system calls -- calls with implementation in
142 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
143 // calls will generate an exception in NativeConvert, as the value can't be
144 // converted on the target platform.)
147 O_NOFOLLOW = 0x00020000,
148 O_DIRECTORY = 0x00010000,
149 O_DIRECT = 0x00004000,
150 O_ASYNC = 0x00002000,
151 O_LARGEFILE = 0x00008000
156 [CLSCompliant (false)]
157 public enum FilePermissions : uint {
158 S_ISUID = 0x0800, // Set user ID on execution
159 S_ISGID = 0x0400, // Set group ID on execution
160 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
161 S_IRUSR = 0x0100, // Read by owner
162 S_IWUSR = 0x0080, // Write by owner
163 S_IXUSR = 0x0040, // Execute by owner
164 S_IRGRP = 0x0020, // Read by group
165 S_IWGRP = 0x0010, // Write by group
166 S_IXGRP = 0x0008, // Execute by group
167 S_IROTH = 0x0004, // Read by other
168 S_IWOTH = 0x0002, // Write by other
169 S_IXOTH = 0x0001, // Execute by other
171 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
172 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
173 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
174 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
175 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
176 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
179 // Why these are held in "mode_t" is beyond me...
180 S_IFMT = 0xF000, // Bits which determine file type
181 [Map(SuppressFlags="S_IFMT")]
182 S_IFDIR = 0x4000, // Directory
183 [Map(SuppressFlags="S_IFMT")]
184 S_IFCHR = 0x2000, // Character device
185 [Map(SuppressFlags="S_IFMT")]
186 S_IFBLK = 0x6000, // Block device
187 [Map(SuppressFlags="S_IFMT")]
188 S_IFREG = 0x8000, // Regular file
189 [Map(SuppressFlags="S_IFMT")]
190 S_IFIFO = 0x1000, // FIFO
191 [Map(SuppressFlags="S_IFMT")]
192 S_IFLNK = 0xA000, // Symbolic link
193 [Map(SuppressFlags="S_IFMT")]
194 S_IFSOCK = 0xC000, // Socket
198 [CLSCompliant (false)]
199 public enum FcntlCommand : int {
200 // Form /usr/include/bits/fcntl.h
201 F_DUPFD = 0, // Duplicate file descriptor.
202 F_GETFD = 1, // Get file descriptor flags.
203 F_SETFD = 2, // Set file descriptor flags.
204 F_GETFL = 3, // Get file status flags.
205 F_SETFL = 4, // Set file status flags.
206 F_GETLK = 12, // Get record locking info. [64]
207 F_SETLK = 13, // Set record locking info (non-blocking). [64]
208 F_SETLKW = 14, // Set record locking info (blocking). [64]
209 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
210 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
211 F_SETSIG = 10, // Set number of signal to be sent.
212 F_GETSIG = 11, // Get number of signal to be sent.
213 F_SETLEASE = 1024, // Set a lease.
214 F_GETLEASE = 1025, // Enquire what lease is active.
215 F_NOTIFY = 1026, // Required notifications on a directory
219 [CLSCompliant (false)]
220 public enum LockType : short {
221 F_RDLCK = 0, // Read lock.
222 F_WRLCK = 1, // Write lock.
223 F_UNLCK = 2, // Remove lock.
227 [CLSCompliant (false)]
228 public enum SeekFlags : short {
229 // values liberally copied from /usr/include/unistd.h
230 SEEK_SET = 0, // Seek from beginning of file.
231 SEEK_CUR = 1, // Seek from current position.
232 SEEK_END = 2, // Seek from end of file.
234 L_SET = SEEK_SET, // BSD alias for SEEK_SET
235 L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
236 L_XTND = SEEK_END, // BSD alias for SEEK_END
240 [CLSCompliant (false)]
241 public enum DirectoryNotifyFlags : int {
242 // from /usr/include/bits/fcntl.h
243 DN_ACCESS = 0x00000001, // File accessed.
244 DN_MODIFY = 0x00000002, // File modified.
245 DN_CREATE = 0x00000004, // File created.
246 DN_DELETE = 0x00000008, // File removed.
247 DN_RENAME = 0x00000010, // File renamed.
248 DN_ATTRIB = 0x00000020, // File changed attributes.
249 DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
253 [CLSCompliant (false)]
254 public enum PosixFadviseAdvice : int {
255 POSIX_FADV_NORMAL = 0, // No further special treatment.
256 POSIX_FADV_RANDOM = 1, // Expect random page references.
257 POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
258 POSIX_FADV_WILLNEED = 3, // Will need these pages.
259 POSIX_FADV_DONTNEED = 4, // Don't need these pages.
260 POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
264 [CLSCompliant (false)]
265 public enum PosixMadviseAdvice : int {
266 POSIX_MADV_NORMAL = 0, // No further special treatment.
267 POSIX_MADV_RANDOM = 1, // Expect random page references.
268 POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
269 POSIX_MADV_WILLNEED = 3, // Will need these pages.
270 POSIX_MADV_DONTNEED = 4, // Don't need these pages.
274 public enum Signum : int {
275 SIGHUP = 1, // Hangup (POSIX).
276 SIGINT = 2, // Interrupt (ANSI).
277 SIGQUIT = 3, // Quit (POSIX).
278 SIGILL = 4, // Illegal instruction (ANSI).
279 SIGTRAP = 5, // Trace trap (POSIX).
280 SIGABRT = 6, // Abort (ANSI).
281 SIGIOT = 6, // IOT trap (4.2 BSD).
282 SIGBUS = 7, // BUS error (4.2 BSD).
283 SIGFPE = 8, // Floating-point exception (ANSI).
284 SIGKILL = 9, // Kill, unblockable (POSIX).
285 SIGUSR1 = 10, // User-defined signal 1 (POSIX).
286 SIGSEGV = 11, // Segmentation violation (ANSI).
287 SIGUSR2 = 12, // User-defined signal 2 (POSIX).
288 SIGPIPE = 13, // Broken pipe (POSIX).
289 SIGALRM = 14, // Alarm clock (POSIX).
290 SIGTERM = 15, // Termination (ANSI).
291 SIGSTKFLT = 16, // Stack fault.
292 SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
293 SIGCHLD = 17, // Child status has changed (POSIX).
294 SIGCONT = 18, // Continue (POSIX).
295 SIGSTOP = 19, // Stop, unblockable (POSIX).
296 SIGTSTP = 20, // Keyboard stop (POSIX).
297 SIGTTIN = 21, // Background read from tty (POSIX).
298 SIGTTOU = 22, // Background write to tty (POSIX).
299 SIGURG = 23, // Urgent condition on socket (4.2 BSD).
300 SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
301 SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
302 SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
303 SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
304 SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
305 SIGPOLL = SIGIO, // Pollable event occurred (System V).
306 SIGIO = 29, // I/O now possible (4.2 BSD).
307 SIGPWR = 30, // Power failure restart (System V).
308 SIGSYS = 31, // Bad system call.
313 public enum WaitOptions : int {
314 WNOHANG = 1, // Don't block waiting
315 WUNTRACED = 2, // Report status of stopped children
319 [CLSCompliant (false)]
320 public enum AccessModes : int {
328 [CLSCompliant (false)]
329 public enum PathconfName : int {
336 _PC_CHOWN_RESTRICTED,
344 _PC_REC_INCR_XFER_SIZE,
345 _PC_REC_MAX_XFER_SIZE,
346 _PC_REC_MIN_XFER_SIZE,
354 [CLSCompliant (false)]
355 public enum SysconfName : int {
365 _SC_REALTIME_SIGNALS,
366 _SC_PRIORITY_SCHEDULING,
375 _SC_MEMORY_PROTECTION,
378 _SC_SHARED_MEMORY_OBJECTS,
381 _SC_AIO_PRIO_DELTA_MAX,
392 /* Values for the argument to `sysconf'
393 corresponding to _POSIX2_* symbols. */
398 _SC_COLL_WEIGHTS_MAX,
403 _SC_CHARCLASS_NAME_MAX,
419 _SC_IOV_MAX = _SC_UIO_MAXIOV,
420 _SC_PII_INTERNET_STREAM,
421 _SC_PII_INTERNET_DGRAM,
426 /* Values according to POSIX 1003.1c (POSIX threads). */
428 _SC_THREAD_SAFE_FUNCTIONS,
429 _SC_GETGR_R_SIZE_MAX,
430 _SC_GETPW_R_SIZE_MAX,
433 _SC_THREAD_DESTRUCTOR_ITERATIONS,
435 _SC_THREAD_STACK_MIN,
436 _SC_THREAD_THREADS_MAX,
437 _SC_THREAD_ATTR_STACKADDR,
438 _SC_THREAD_ATTR_STACKSIZE,
439 _SC_THREAD_PRIORITY_SCHEDULING,
440 _SC_THREAD_PRIO_INHERIT,
441 _SC_THREAD_PRIO_PROTECT,
442 _SC_THREAD_PROCESS_SHARED,
443 _SC_NPROCESSORS_CONF,
444 _SC_NPROCESSORS_ONLN,
450 _SC_XOPEN_XCU_VERSION,
485 _SC_XBS5_ILP32_OFF32,
486 _SC_XBS5_ILP32_OFFBIG,
488 _SC_XBS5_LPBIG_OFFBIG,
491 _SC_XOPEN_REALTIME_THREADS,
496 _SC_C_LANG_SUPPORT_R,
502 _SC_DEVICE_SPECIFIC_R,
513 _SC_READER_WRITER_LOCKS,
521 _SC_THREAD_SPORADIC_SERVER,
523 _SC_SYSTEM_DATABASE_R,
525 _SC_TYPED_MEMORY_OBJECTS,
529 _SC_2_PBS_ACCOUNTING,
535 _SC_2_PBS_CHECKPOINT,
542 _SC_TRACE_EVENT_FILTER,
545 _SC_LEVEL1_ICACHE_SIZE,
546 _SC_LEVEL1_ICACHE_ASSOC,
547 _SC_LEVEL1_ICACHE_LINESIZE,
548 _SC_LEVEL1_DCACHE_SIZE,
549 _SC_LEVEL1_DCACHE_ASSOC,
550 _SC_LEVEL1_DCACHE_LINESIZE,
551 _SC_LEVEL2_CACHE_SIZE,
552 _SC_LEVEL2_CACHE_ASSOC,
553 _SC_LEVEL2_CACHE_LINESIZE,
554 _SC_LEVEL3_CACHE_SIZE,
555 _SC_LEVEL3_CACHE_ASSOC,
556 _SC_LEVEL3_CACHE_LINESIZE,
557 _SC_LEVEL4_CACHE_SIZE,
558 _SC_LEVEL4_CACHE_ASSOC,
559 _SC_LEVEL4_CACHE_LINESIZE
563 [CLSCompliant (false)]
564 public enum ConfstrName : int {
565 _CS_PATH, /* The default search path. */
566 _CS_V6_WIDTH_RESTRICTED_ENVS,
567 _CS_GNU_LIBC_VERSION,
568 _CS_GNU_LIBPTHREAD_VERSION,
569 _CS_LFS_CFLAGS = 1000,
577 _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
578 _CS_XBS5_ILP32_OFF32_LDFLAGS,
579 _CS_XBS5_ILP32_OFF32_LIBS,
580 _CS_XBS5_ILP32_OFF32_LINTFLAGS,
581 _CS_XBS5_ILP32_OFFBIG_CFLAGS,
582 _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
583 _CS_XBS5_ILP32_OFFBIG_LIBS,
584 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
585 _CS_XBS5_LP64_OFF64_CFLAGS,
586 _CS_XBS5_LP64_OFF64_LDFLAGS,
587 _CS_XBS5_LP64_OFF64_LIBS,
588 _CS_XBS5_LP64_OFF64_LINTFLAGS,
589 _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
590 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
591 _CS_XBS5_LPBIG_OFFBIG_LIBS,
592 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
593 _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
594 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
595 _CS_POSIX_V6_ILP32_OFF32_LIBS,
596 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
597 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
598 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
599 _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
600 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
601 _CS_POSIX_V6_LP64_OFF64_CFLAGS,
602 _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
603 _CS_POSIX_V6_LP64_OFF64_LIBS,
604 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
605 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
606 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
607 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
608 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
612 [CLSCompliant (false)]
613 public enum LockfCommand : int {
614 F_ULOCK = 0, // Unlock a previously locked region.
615 F_LOCK = 1, // Lock a region for exclusive use.
616 F_TLOCK = 2, // Test and lock a region for exclusive use.
617 F_TEST = 3, // Test a region for other process locks.
621 public enum PollEvents : short {
622 POLLIN = 0x0001, // There is data to read
623 POLLPRI = 0x0002, // There is urgent data to read
624 POLLOUT = 0x0004, // Writing now will not block
625 POLLERR = 0x0008, // Error condition
626 POLLHUP = 0x0010, // Hung up
627 POLLNVAL = 0x0020, // Invalid request; fd not open
628 // XPG4.2 definitions (via _XOPEN_SOURCE)
629 POLLRDNORM = 0x0040, // Normal data may be read
630 POLLRDBAND = 0x0080, // Priority data may be read
631 POLLWRNORM = 0x0100, // Writing now will not block
632 POLLWRBAND = 0x0200, // Priority data may be written
636 [CLSCompliant (false)]
637 public enum XattrFlags : int {
644 [CLSCompliant (false)]
645 public enum MountFlags : ulong {
646 ST_RDONLY = 1, // Mount read-only
647 ST_NOSUID = 2, // Ignore suid and sgid bits
648 ST_NODEV = 4, // Disallow access to device special files
649 ST_NOEXEC = 8, // Disallow program execution
650 ST_SYNCHRONOUS = 16, // Writes are synced at once
651 ST_REMOUNT = 32, // Alter flags of a mounted FS
652 ST_MANDLOCK = 64, // Allow mandatory locks on an FS
653 ST_WRITE = 128, // Write on file/directory/symlink
654 ST_APPEND = 256, // Append-only file
655 ST_IMMUTABLE = 512, // Immutable file
656 ST_NOATIME = 1024, // Do not update access times
657 ST_NODIRATIME = 2048, // Do not update directory access times
658 ST_BIND = 4096, // Bind directory at different place
662 [CLSCompliant (false)]
663 public enum MmapFlags : int {
664 MAP_SHARED = 0x01, // Share changes.
665 MAP_PRIVATE = 0x02, // Changes are private.
666 MAP_TYPE = 0x0f, // Mask for type of mapping.
667 MAP_FIXED = 0x10, // Interpret addr exactly.
669 MAP_ANONYMOUS = 0x20, // Don't use a file.
670 MAP_ANON = MAP_ANONYMOUS,
672 // These are Linux-specific.
673 MAP_GROWSDOWN = 0x00100, // Stack-like segment.
674 MAP_DENYWRITE = 0x00800, // ETXTBSY
675 MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
676 MAP_LOCKED = 0x02000, // Lock the mapping.
677 MAP_NORESERVE = 0x04000, // Don't check for reservations.
678 MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
679 MAP_NONBLOCK = 0x10000, // Do not block on IO.
683 [CLSCompliant (false)]
684 public enum MmapProts : int {
685 PROT_READ = 0x1, // Page can be read.
686 PROT_WRITE = 0x2, // Page can be written.
687 PROT_EXEC = 0x4, // Page can be executed.
688 PROT_NONE = 0x0, // Page can not be accessed.
689 PROT_GROWSDOWN = 0x01000000, // Extend change to start of
690 // growsdown vma (mprotect only).
691 PROT_GROWSUP = 0x02000000, // Extend change to start of
692 // growsup vma (mprotect only).
696 [CLSCompliant (false)]
697 public enum MsyncFlags : int {
698 MS_ASYNC = 0x1, // Sync memory asynchronously.
699 MS_SYNC = 0x4, // Synchronous memory sync.
700 MS_INVALIDATE = 0x2, // Invalidate the caches.
704 [CLSCompliant (false)]
705 public enum MlockallFlags : int {
706 MCL_CURRENT = 0x1, // Lock all currently mapped pages.
707 MCL_FUTURE = 0x2, // Lock all additions to address
711 [CLSCompliant (false)]
712 public enum MremapFlags : ulong {
713 MREMAP_MAYMOVE = 0x1,
720 [Map ("struct flock")]
726 [CLSCompliant (false)]
727 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
728 [CLSCompliant (false)]
729 public SeekFlags l_whence; // How to interpret l_start
730 [off_t] public long l_start; // Starting offset for lock
731 [off_t] public long l_len; // Number of bytes to lock
732 [pid_t] public int l_pid; // PID of process blocking our lock (F_GETLK only)
734 public override int GetHashCode ()
736 return l_type.GetHashCode () ^ l_whence.GetHashCode () ^
737 l_start.GetHashCode () ^ l_len.GetHashCode () ^
738 l_pid.GetHashCode ();
741 public override bool Equals (object obj)
743 if ((obj == null) || (obj.GetType () != GetType ()))
745 Flock value = (Flock) obj;
746 return l_type == value.l_type && l_whence == value.l_whence &&
747 l_start == value.l_start && l_len == value.l_len &&
748 l_pid == value.l_pid;
751 public bool Equals (Flock value)
753 return l_type == value.l_type && l_whence == value.l_whence &&
754 l_start == value.l_start && l_len == value.l_len &&
755 l_pid == value.l_pid;
758 public static bool operator== (Flock lhs, Flock rhs)
760 return lhs.Equals (rhs);
763 public static bool operator!= (Flock lhs, Flock rhs)
765 return !lhs.Equals (rhs);
769 [Map ("struct pollfd")]
772 : IEquatable <Pollfd>
776 [CLSCompliant (false)]
777 public PollEvents events;
778 [CLSCompliant (false)]
779 public PollEvents revents;
781 public override int GetHashCode ()
783 return events.GetHashCode () ^ revents.GetHashCode ();
786 public override bool Equals (object obj)
788 if (obj == null || obj.GetType () != GetType ())
790 Pollfd value = (Pollfd) obj;
791 return value.events == events && value.revents == revents;
794 public bool Equals (Pollfd value)
796 return value.events == events && value.revents == revents;
799 public static bool operator== (Pollfd lhs, Pollfd rhs)
801 return lhs.Equals (rhs);
804 public static bool operator!= (Pollfd lhs, Pollfd rhs)
806 return !lhs.Equals (rhs);
810 [Map ("struct stat")]
816 [CLSCompliant (false)]
817 [dev_t] public ulong st_dev; // device
818 [CLSCompliant (false)]
819 [ino_t] public ulong st_ino; // inode
820 [CLSCompliant (false)]
821 public FilePermissions st_mode; // protection
823 #pragma warning disable 169
824 private uint _padding_; // padding for structure alignment
825 #pragma warning restore 169
826 [CLSCompliant (false)]
827 [nlink_t] public ulong st_nlink; // number of hard links
828 [CLSCompliant (false)]
829 [uid_t] public uint st_uid; // user ID of owner
830 [CLSCompliant (false)]
831 [gid_t] public uint st_gid; // group ID of owner
832 [CLSCompliant (false)]
833 [dev_t] public ulong st_rdev; // device type (if inode device)
834 [off_t] public long st_size; // total size, in bytes
835 [blksize_t] public long st_blksize; // blocksize for filesystem I/O
836 [blkcnt_t] public long st_blocks; // number of blocks allocated
837 [time_t] public long st_atime; // time of last access
838 [time_t] public long st_mtime; // time of last modification
839 [time_t] public long st_ctime; // time of last status change
841 public override int GetHashCode ()
843 return st_dev.GetHashCode () ^
844 st_ino.GetHashCode () ^
845 st_mode.GetHashCode () ^
846 st_nlink.GetHashCode () ^
847 st_uid.GetHashCode () ^
848 st_gid.GetHashCode () ^
849 st_rdev.GetHashCode () ^
850 st_size.GetHashCode () ^
851 st_blksize.GetHashCode () ^
852 st_blocks.GetHashCode () ^
853 st_atime.GetHashCode () ^
854 st_mtime.GetHashCode () ^
855 st_ctime.GetHashCode ();
858 public override bool Equals (object obj)
860 if (obj == null || obj.GetType() != GetType ())
862 Stat value = (Stat) obj;
863 return value.st_dev == st_dev &&
864 value.st_ino == st_ino &&
865 value.st_mode == st_mode &&
866 value.st_nlink == st_nlink &&
867 value.st_uid == st_uid &&
868 value.st_gid == st_gid &&
869 value.st_rdev == st_rdev &&
870 value.st_size == st_size &&
871 value.st_blksize == st_blksize &&
872 value.st_blocks == st_blocks &&
873 value.st_atime == st_atime &&
874 value.st_mtime == st_mtime &&
875 value.st_ctime == st_ctime;
878 public bool Equals (Stat value)
880 return value.st_dev == st_dev &&
881 value.st_ino == st_ino &&
882 value.st_mode == st_mode &&
883 value.st_nlink == st_nlink &&
884 value.st_uid == st_uid &&
885 value.st_gid == st_gid &&
886 value.st_rdev == st_rdev &&
887 value.st_size == st_size &&
888 value.st_blksize == st_blksize &&
889 value.st_blocks == st_blocks &&
890 value.st_atime == st_atime &&
891 value.st_mtime == st_mtime &&
892 value.st_ctime == st_ctime;
895 public static bool operator== (Stat lhs, Stat rhs)
897 return lhs.Equals (rhs);
900 public static bool operator!= (Stat lhs, Stat rhs)
902 return !lhs.Equals (rhs);
906 // `struct statvfs' isn't portable, so don't generate To/From methods.
908 [CLSCompliant (false)]
909 public struct Statvfs
911 : IEquatable <Statvfs>
914 public ulong f_bsize; // file system block size
915 public ulong f_frsize; // fragment size
916 [fsblkcnt_t] public ulong f_blocks; // size of fs in f_frsize units
917 [fsblkcnt_t] public ulong f_bfree; // # free blocks
918 [fsblkcnt_t] public ulong f_bavail; // # free blocks for non-root
919 [fsfilcnt_t] public ulong f_files; // # inodes
920 [fsfilcnt_t] public ulong f_ffree; // # free inodes
921 [fsfilcnt_t] public ulong f_favail; // # free inodes for non-root
922 public ulong f_fsid; // file system id
923 public MountFlags f_flag; // mount flags
924 public ulong f_namemax; // maximum filename length
926 public override int GetHashCode ()
928 return f_bsize.GetHashCode () ^
929 f_frsize.GetHashCode () ^
930 f_blocks.GetHashCode () ^
931 f_bfree.GetHashCode () ^
932 f_bavail.GetHashCode () ^
933 f_files.GetHashCode () ^
934 f_ffree.GetHashCode () ^
935 f_favail.GetHashCode () ^
936 f_fsid.GetHashCode () ^
937 f_flag.GetHashCode () ^
938 f_namemax.GetHashCode ();
941 public override bool Equals (object obj)
943 if (obj == null || obj.GetType() != GetType ())
945 Statvfs value = (Statvfs) obj;
946 return value.f_bsize == f_bsize &&
947 value.f_frsize == f_frsize &&
948 value.f_blocks == f_blocks &&
949 value.f_bfree == f_bfree &&
950 value.f_bavail == f_bavail &&
951 value.f_files == f_files &&
952 value.f_ffree == f_ffree &&
953 value.f_favail == f_favail &&
954 value.f_fsid == f_fsid &&
955 value.f_flag == f_flag &&
956 value.f_namemax == f_namemax;
959 public bool Equals (Statvfs value)
961 return value.f_bsize == f_bsize &&
962 value.f_frsize == f_frsize &&
963 value.f_blocks == f_blocks &&
964 value.f_bfree == f_bfree &&
965 value.f_bavail == f_bavail &&
966 value.f_files == f_files &&
967 value.f_ffree == f_ffree &&
968 value.f_favail == f_favail &&
969 value.f_fsid == f_fsid &&
970 value.f_flag == f_flag &&
971 value.f_namemax == f_namemax;
974 public static bool operator== (Statvfs lhs, Statvfs rhs)
976 return lhs.Equals (rhs);
979 public static bool operator!= (Statvfs lhs, Statvfs rhs)
981 return !lhs.Equals (rhs);
985 [Map ("struct timeval")]
986 public struct Timeval
988 : IEquatable <Timeval>
991 [time_t] public long tv_sec; // seconds
992 [suseconds_t] public long tv_usec; // microseconds
994 public override int GetHashCode ()
996 return tv_sec.GetHashCode () ^ tv_usec.GetHashCode ();
999 public override bool Equals (object obj)
1001 if (obj == null || obj.GetType () != GetType ())
1003 Timeval value = (Timeval) obj;
1004 return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
1007 public bool Equals (Timeval value)
1009 return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
1012 public static bool operator== (Timeval lhs, Timeval rhs)
1014 return lhs.Equals (rhs);
1017 public static bool operator!= (Timeval lhs, Timeval rhs)
1019 return !lhs.Equals (rhs);
1023 [Map ("struct timezone")]
1024 public struct Timezone
1026 : IEquatable <Timezone>
1029 public int tz_minuteswest; // minutes W of Greenwich
1030 #pragma warning disable 169
1031 private int tz_dsttime; // type of dst correction (OBSOLETE)
1032 #pragma warning restore 169
1034 public override int GetHashCode ()
1036 return tz_minuteswest.GetHashCode ();
1039 public override bool Equals (object obj)
1041 if (obj == null || obj.GetType () != GetType ())
1043 Timezone value = (Timezone) obj;
1044 return value.tz_minuteswest == tz_minuteswest;
1047 public bool Equals (Timezone value)
1049 return value.tz_minuteswest == tz_minuteswest;
1052 public static bool operator== (Timezone lhs, Timezone rhs)
1054 return lhs.Equals (rhs);
1057 public static bool operator!= (Timezone lhs, Timezone rhs)
1059 return !lhs.Equals (rhs);
1063 [Map ("struct utimbuf")]
1064 public struct Utimbuf
1066 : IEquatable <Utimbuf>
1069 [time_t] public long actime; // access time
1070 [time_t] public long modtime; // modification time
1072 public override int GetHashCode ()
1074 return actime.GetHashCode () ^ modtime.GetHashCode ();
1077 public override bool Equals (object obj)
1079 if (obj == null || obj.GetType () != GetType ())
1081 Utimbuf value = (Utimbuf) obj;
1082 return value.actime == actime && value.modtime == modtime;
1085 public bool Equals (Utimbuf value)
1087 return value.actime == actime && value.modtime == modtime;
1090 public static bool operator== (Utimbuf lhs, Utimbuf rhs)
1092 return lhs.Equals (rhs);
1095 public static bool operator!= (Utimbuf lhs, Utimbuf rhs)
1097 return !lhs.Equals (rhs);
1101 [Map ("struct timespec")]
1102 public struct Timespec
1104 : IEquatable <Timespec>
1107 [time_t] public long tv_sec; // Seconds.
1108 public long tv_nsec; // Nanoseconds.
1110 public override int GetHashCode ()
1112 return tv_sec.GetHashCode () ^ tv_nsec.GetHashCode ();
1115 public override bool Equals (object obj)
1117 if (obj == null || obj.GetType () != GetType ())
1119 Timespec value = (Timespec) obj;
1120 return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
1123 public bool Equals (Timespec value)
1125 return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
1128 public static bool operator== (Timespec lhs, Timespec rhs)
1130 return lhs.Equals (rhs);
1133 public static bool operator!= (Timespec lhs, Timespec rhs)
1135 return !lhs.Equals (rhs);
1140 public enum EpollFlags {
1141 EPOLL_CLOEXEC = 02000000,
1142 EPOLL_NONBLOCK = 04000,
1146 [CLSCompliant (false)]
1147 public enum EpollEvents : uint {
1151 EPOLLRDNORM = 0x040,
1152 EPOLLRDBAND = 0x080,
1153 EPOLLWRNORM = 0x100,
1154 EPOLLWRBAND = 0x200,
1158 EPOLLRDHUP = 0x2000,
1159 EPOLLONESHOT = 1 << 30,
1160 EPOLLET = unchecked ((uint) (1 << 31))
1163 public enum EpollOp {
1169 [StructLayout (LayoutKind.Explicit, Size=12, Pack=1)]
1170 [CLSCompliant (false)]
1171 public struct EpollEvent {
1173 public EpollEvents events;
1187 public sealed class Dirent
1189 : IEquatable <Dirent>
1192 [CLSCompliant (false)]
1193 public /* ino_t */ ulong d_ino;
1194 public /* off_t */ long d_off;
1195 [CLSCompliant (false)]
1196 public ushort d_reclen;
1198 public string d_name;
1200 public override int GetHashCode ()
1202 return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
1203 d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
1204 d_name.GetHashCode ();
1207 public override bool Equals (object obj)
1209 if (obj == null || GetType() != obj.GetType())
1211 Dirent d = (Dirent) obj;
1215 public bool Equals (Dirent value)
1219 return value.d_ino == d_ino && value.d_off == d_off &&
1220 value.d_reclen == d_reclen && value.d_type == d_type &&
1221 value.d_name == d_name;
1224 public override string ToString ()
1229 public static bool operator== (Dirent lhs, Dirent rhs)
1231 return Object.Equals (lhs, rhs);
1234 public static bool operator!= (Dirent lhs, Dirent rhs)
1236 return !Object.Equals (lhs, rhs);
1240 public sealed class Fstab
1242 : IEquatable <Fstab>
1245 public string fs_spec;
1246 public string fs_file;
1247 public string fs_vfstype;
1248 public string fs_mntops;
1249 public string fs_type;
1251 public int fs_passno;
1253 public override int GetHashCode ()
1255 return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
1256 fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
1257 fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
1260 public override bool Equals (object obj)
1262 if (obj == null || GetType() != obj.GetType())
1264 Fstab f = (Fstab) obj;
1268 public bool Equals (Fstab value)
1272 return value.fs_spec == fs_spec && value.fs_file == fs_file &&
1273 value.fs_vfstype == fs_vfstype && value.fs_mntops == fs_mntops &&
1274 value.fs_type == fs_type && value.fs_freq == fs_freq &&
1275 value.fs_passno == fs_passno;
1278 public override string ToString ()
1283 public static bool operator== (Fstab lhs, Fstab rhs)
1285 return Object.Equals (lhs, rhs);
1288 public static bool operator!= (Fstab lhs, Fstab rhs)
1290 return !Object.Equals (lhs, rhs);
1294 public sealed class Group
1296 : IEquatable <Group>
1299 public string gr_name;
1300 public string gr_passwd;
1301 [CLSCompliant (false)]
1302 public /* gid_t */ uint gr_gid;
1303 public string[] gr_mem;
1305 public override int GetHashCode ()
1308 for (int i = 0; i < gr_mem.Length; ++i)
1309 memhc ^= gr_mem[i].GetHashCode ();
1311 return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
1312 gr_gid.GetHashCode () ^ memhc;
1315 public override bool Equals (object obj)
1317 if (obj == null || GetType() != obj.GetType())
1319 Group g = (Group) obj;
1323 public bool Equals (Group value)
1327 if (value.gr_gid != gr_gid)
1329 if (value.gr_gid == gr_gid && value.gr_name == gr_name &&
1330 value.gr_passwd == gr_passwd) {
1331 if (value.gr_mem == gr_mem)
1333 if (value.gr_mem == null || gr_mem == null)
1335 if (value.gr_mem.Length != gr_mem.Length)
1337 for (int i = 0; i < gr_mem.Length; ++i)
1338 if (gr_mem[i] != value.gr_mem[i])
1345 // Generate string in /etc/group format
1346 public override string ToString ()
1348 StringBuilder sb = new StringBuilder ();
1349 sb.Append (gr_name).Append (":").Append (gr_passwd).Append (":");
1350 sb.Append (gr_gid).Append (":");
1351 GetMembers (sb, gr_mem);
1352 return sb.ToString ();
1355 private static void GetMembers (StringBuilder sb, string[] members)
1357 if (members.Length > 0)
1358 sb.Append (members[0]);
1359 for (int i = 1; i < members.Length; ++i) {
1361 sb.Append (members[i]);
1365 public static bool operator== (Group lhs, Group rhs)
1367 return Object.Equals (lhs, rhs);
1370 public static bool operator!= (Group lhs, Group rhs)
1372 return !Object.Equals (lhs, rhs);
1376 public sealed class Passwd
1378 : IEquatable <Passwd>
1381 public string pw_name;
1382 public string pw_passwd;
1383 [CLSCompliant (false)]
1384 public /* uid_t */ uint pw_uid;
1385 [CLSCompliant (false)]
1386 public /* gid_t */ uint pw_gid;
1387 public string pw_gecos;
1388 public string pw_dir;
1389 public string pw_shell;
1391 public override int GetHashCode ()
1393 return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
1394 pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
1395 pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
1396 pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
1399 public override bool Equals (object obj)
1401 if (obj == null || GetType() != obj.GetType())
1403 Passwd p = (Passwd) obj;
1407 public bool Equals (Passwd value)
1411 return value.pw_uid == pw_uid && value.pw_gid == pw_gid &&
1412 value.pw_name == pw_name && value.pw_passwd == pw_passwd &&
1413 value.pw_gecos == pw_gecos && value.pw_dir == pw_dir &&
1414 value.pw_shell == pw_shell;
1417 // Generate string in /etc/passwd format
1418 public override string ToString ()
1420 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
1421 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
1424 public static bool operator== (Passwd lhs, Passwd rhs)
1426 return Object.Equals (lhs, rhs);
1429 public static bool operator!= (Passwd lhs, Passwd rhs)
1431 return !Object.Equals (lhs, rhs);
1435 public sealed class Utsname
1437 : IEquatable <Utsname>
1440 public string sysname;
1441 public string nodename;
1442 public string release;
1443 public string version;
1444 public string machine;
1445 public string domainname;
1447 public override int GetHashCode ()
1449 return sysname.GetHashCode () ^ nodename.GetHashCode () ^
1450 release.GetHashCode () ^ version.GetHashCode () ^
1451 machine.GetHashCode () ^ domainname.GetHashCode ();
1454 public override bool Equals (object obj)
1456 if (obj == null || GetType() != obj.GetType())
1458 Utsname u = (Utsname) obj;
1462 public bool Equals (Utsname value)
1464 return value.sysname == sysname && value.nodename == nodename &&
1465 value.release == release && value.version == version &&
1466 value.machine == machine && value.domainname == domainname;
1469 // Generate string in /etc/passwd format
1470 public override string ToString ()
1472 return string.Format ("{0} {1} {2} {3} {4}",
1473 sysname, nodename, release, version, machine);
1476 public static bool operator== (Utsname lhs, Utsname rhs)
1478 return Object.Equals (lhs, rhs);
1481 public static bool operator!= (Utsname lhs, Utsname rhs)
1483 return !Object.Equals (lhs, rhs);
1488 // Convention: Functions *not* part of the standard C library AND part of
1489 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
1491 // For example, the man page should be similar to:
1493 // CONFORMING TO (or CONFORMS TO)
1494 // XPG2, SUSv2, POSIX, etc.
1496 // BSD- and GNU-specific exports can also be placed here.
1498 // Non-POSIX/XPG/etc. functions can also be placed here if:
1499 // (a) They'd be likely to be covered in a Steven's-like book
1500 // (b) The functions would be present in libc.so (or equivalent).
1502 // If a function has its own library, that's a STRONG indicator that the
1503 // function should get a different binding, probably in its own assembly,
1504 // so that package management can work sanely. (That is, we'd like to avoid
1505 // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
1506 // run, and libFooLib.so doesn't exist. That would be confusing.)
1508 // The only methods in here should be:
1509 // (1) low-level functions
1510 // (2) "Trivial" function overloads. For example, if the parameters to a
1511 // function are related (e.g. getgroups(2))
1512 // (3) The return type SHOULD NOT be changed. If you want to provide a
1513 // convenience function with a nicer return type, place it into one of
1514 // the Mono.Unix.Unix* wrapper classes, and give it a .NET-styled name.
1515 // - EXCEPTION: No public functions should have a `void' return type.
1516 // `void' return types should be replaced with `int'.
1517 // Rationality: `void'-return functions typically require a
1518 // complicated call sequence, such as clear errno, then call, then
1519 // check errno to see if any errors occurred. This sequence can't
1520 // be done safely in managed code, as errno may change as part of
1521 // the P/Invoke mechanism.
1522 // Instead, add a MonoPosixHelper export which does:
1525 // return errno == 0 ? 0 : -1;
1526 // This lets managed code check the return value in the usual manner.
1527 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
1528 // - If you're wrapping *broken* methods which make assumptions about
1529 // input data, such as that an argument refers to N bytes of data.
1530 // This is currently limited to cuserid(3) and encrypt(3).
1531 // - If you call functions which themselves generate exceptions.
1532 // This is the case for using NativeConvert, which will throw an
1533 // exception if an invalid/unsupported value is used.
1535 // Naming Conventions:
1536 // - Syscall method names should have the same name as the function being
1537 // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
1538 // consult the appropriate man page if necessary.
1539 // - Methods need not have the same arguments IF this simplifies or
1540 // permits correct usage. The current example is syslog, in which
1541 // syslog(3)'s single `priority' argument is split into SyslogFacility
1542 // and SyslogLevel arguments.
1543 // - Type names (structures, classes, enumerations) are always PascalCased.
1544 // - Enumerations are named as <MethodName><ArgumentName>, and are located
1545 // in the Mono.Unix.Native namespace. For readability, if ArgumentName
1546 // is "cmd", use Command instead. For example, fcntl(2) takes a
1547 // FcntlCommand argument. This naming convention is to provide an
1548 // assocation between an enumeration and where it should be used, and
1549 // allows a single method to accept multiple different enumerations
1550 // (see mmap(2), which takes MmapProts and MmapFlags).
1551 // - EXCEPTION: if an enumeration is shared between multiple different
1552 // methods, AND/OR the "obvious" enumeration name conflicts with an
1553 // existing .NET type, a more appropriate name should be used.
1554 // Example: FilePermissions
1555 // - EXCEPTION: [Flags] enumerations should get plural names to follow
1556 // .NET name guidelines. Usually this doesn't result in a change
1557 // (OpenFlags is the `flags' parameter for open(2)), but it can
1558 // (mmap(2) prot ==> MmapProts, access(2) mode ==> AccessModes).
1559 // - Enumerations should have the [Map] and (optional) [Flags] attributes.
1560 // [Map] is required for make-map to find the type and generate the
1561 // appropriate NativeConvert conversion functions.
1562 // - Enumeration contents should match the original Unix names. This helps
1563 // with documentation (the existing man pages are still useful), and is
1564 // required for use with the make-map generation program.
1565 // - Structure names should be the PascalCased version of the actual
1566 // structure name (struct flock ==> Flock). Structure members should
1567 // have the same names, or a (reasonably) portable subset (Dirent being
1568 // the poster child for questionable members).
1569 // - Whether the managed type should be a reference type (class) or a
1570 // value type (struct) should be determined on a case-by-case basis:
1571 // if you ever need to be able to use NULL for it (such as with Dirent,
1572 // Group, Passwd, as these are method return types and `null' is used
1573 // to signify the end), it should be a reference type; otherwise, use
1574 // your discretion, and keep any expected usage patterns in mind.
1575 // - Syscall should be a Single Point Of Truth (SPOT). There should be
1576 // only ONE way to do anything. By convention, the Linux function names
1577 // are used, but that need not always be the case (use your discretion).
1578 // It SHOULD NOT be required that developers know what platform they're
1579 // on, and choose among a set of similar functions. In short, anything
1580 // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
1581 // we can afford to clean things up whenever possible.
1583 // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
1584 // statvfs(2). MonoPosixHelper will "thunk" between the two,
1585 // exporting a statvfs that works across platforms.
1586 // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
1587 // instead provides getvfsent(3). MonoPosixHelper provides wrappers
1588 // to convert getvfsent(3) into Fstab data.
1589 // - Exception: If it isn't possible to cleanly wrap platforms, then the
1590 // method shouldn't be exported. The user will be expected to do their
1591 // own platform check and their own DllImports.
1592 // Examples: mount(2), umount(2), etc.
1593 // - Note: if a platform doesn't support a function AT ALL, the
1594 // MonoPosixHelper wrapper won't be compiled, resulting in a
1595 // EntryPointNotFoundException. This is also consistent with a missing
1596 // P/Invoke into libc.so.
1598 [CLSCompliant (false)]
1599 public sealed class Syscall : Stdlib
1601 new internal const string LIBC = "libc";
1603 private Syscall () {}
1609 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
1610 // aio_return(3), aio_suspend(3), aio_write(3)
1612 // Then update UnixStream.BeginRead to use the aio* functions.
1615 #region <attr/xattr.h> Declarations
1617 // <attr/xattr.h> -- COMPLETE
1621 // int setxattr (const char *path, const char *name,
1622 // const void *value, size_t size, int flags);
1623 [DllImport (MPH, SetLastError=true,
1624 EntryPoint="Mono_Posix_Syscall_setxattr")]
1625 public static extern int setxattr (
1626 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1628 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1629 string name, byte[] value, ulong size, XattrFlags flags);
1631 public static int setxattr (string path, string name, byte [] value, ulong size)
1633 return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1636 public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
1638 return setxattr (path, name, value, (ulong) value.Length, flags);
1641 public static int setxattr (string path, string name, byte [] value)
1643 return setxattr (path, name, value, (ulong) value.Length);
1647 // int lsetxattr (const char *path, const char *name,
1648 // const void *value, size_t size, int flags);
1649 [DllImport (MPH, SetLastError=true,
1650 EntryPoint="Mono_Posix_Syscall_lsetxattr")]
1651 public static extern int lsetxattr (
1652 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1654 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1655 string name, byte[] value, ulong size, XattrFlags flags);
1657 public static int lsetxattr (string path, string name, byte [] value, ulong size)
1659 return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1662 public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
1664 return lsetxattr (path, name, value, (ulong) value.Length, flags);
1667 public static int lsetxattr (string path, string name, byte [] value)
1669 return lsetxattr (path, name, value, (ulong) value.Length);
1673 // int fsetxattr (int fd, const char *name,
1674 // const void *value, size_t size, int flags);
1675 [DllImport (MPH, SetLastError=true,
1676 EntryPoint="Mono_Posix_Syscall_fsetxattr")]
1677 public static extern int fsetxattr (int fd,
1678 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1679 string name, byte[] value, ulong size, XattrFlags flags);
1681 public static int fsetxattr (int fd, string name, byte [] value, ulong size)
1683 return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
1686 public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
1688 return fsetxattr (fd, name, value, (ulong) value.Length, flags);
1691 public static int fsetxattr (int fd, string name, byte [] value)
1693 return fsetxattr (fd, name, value, (ulong) value.Length);
1697 // ssize_t getxattr (const char *path, const char *name,
1698 // void *value, size_t size);
1699 [DllImport (MPH, SetLastError=true,
1700 EntryPoint="Mono_Posix_Syscall_getxattr")]
1701 public static extern long getxattr (
1702 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1704 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1705 string name, byte[] value, ulong size);
1707 public static long getxattr (string path, string name, byte [] value)
1709 return getxattr (path, name, value, (ulong) value.Length);
1712 public static long getxattr (string path, string name, out byte [] value)
1715 long size = getxattr (path, name, value, 0);
1719 value = new byte [size];
1720 return getxattr (path, name, value, (ulong) size);
1724 // ssize_t lgetxattr (const char *path, const char *name,
1725 // void *value, size_t size);
1726 [DllImport (MPH, SetLastError=true,
1727 EntryPoint="Mono_Posix_Syscall_lgetxattr")]
1728 public static extern long lgetxattr (
1729 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1731 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1732 string name, byte[] value, ulong size);
1734 public static long lgetxattr (string path, string name, byte [] value)
1736 return lgetxattr (path, name, value, (ulong) value.Length);
1739 public static long lgetxattr (string path, string name, out byte [] value)
1742 long size = lgetxattr (path, name, value, 0);
1746 value = new byte [size];
1747 return lgetxattr (path, name, value, (ulong) size);
1751 // ssize_t fgetxattr (int fd, const char *name, void *value, size_t size);
1752 [DllImport (MPH, SetLastError=true,
1753 EntryPoint="Mono_Posix_Syscall_fgetxattr")]
1754 public static extern long fgetxattr (int fd,
1755 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1756 string name, byte[] value, ulong size);
1758 public static long fgetxattr (int fd, string name, byte [] value)
1760 return fgetxattr (fd, name, value, (ulong) value.Length);
1763 public static long fgetxattr (int fd, string name, out byte [] value)
1766 long size = fgetxattr (fd, name, value, 0);
1770 value = new byte [size];
1771 return fgetxattr (fd, name, value, (ulong) size);
1775 // ssize_t listxattr (const char *path, char *list, size_t size);
1776 [DllImport (MPH, SetLastError=true,
1777 EntryPoint="Mono_Posix_Syscall_listxattr")]
1778 public static extern long listxattr (
1779 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1780 string path, byte[] list, ulong size);
1782 // Slight modification: returns 0 on success, negative on error
1783 public static long listxattr (string path, Encoding encoding, out string [] values)
1786 long size = listxattr (path, null, 0);
1788 values = new string [0];
1792 byte[] list = new byte [size];
1793 long ret = listxattr (path, list, (ulong) size);
1797 GetValues (list, encoding, out values);
1801 public static long listxattr (string path, out string[] values)
1803 return listxattr (path, UnixEncoding.Instance, out values);
1806 private static void GetValues (byte[] list, Encoding encoding, out string[] values)
1809 for (int i = 0; i < list.Length; ++i)
1813 values = new string [num_values];
1816 for (int i = 0; i < list.Length; ++i) {
1817 if (list [i] == 0) {
1818 values [num_values++] = encoding.GetString (list, str_start, i - str_start);
1825 // ssize_t llistxattr (const char *path, char *list, size_t size);
1826 [DllImport (MPH, SetLastError=true,
1827 EntryPoint="Mono_Posix_Syscall_llistxattr")]
1828 public static extern long llistxattr (
1829 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1830 string path, byte[] list, ulong size);
1832 // Slight modification: returns 0 on success, negative on error
1833 public static long llistxattr (string path, Encoding encoding, out string [] values)
1836 long size = llistxattr (path, null, 0);
1838 values = new string [0];
1842 byte[] list = new byte [size];
1843 long ret = llistxattr (path, list, (ulong) size);
1847 GetValues (list, encoding, out values);
1851 public static long llistxattr (string path, out string[] values)
1853 return llistxattr (path, UnixEncoding.Instance, out values);
1857 // ssize_t flistxattr (int fd, char *list, size_t size);
1858 [DllImport (MPH, SetLastError=true,
1859 EntryPoint="Mono_Posix_Syscall_flistxattr")]
1860 public static extern long flistxattr (int fd, byte[] list, ulong size);
1862 // Slight modification: returns 0 on success, negative on error
1863 public static long flistxattr (int fd, Encoding encoding, out string [] values)
1866 long size = flistxattr (fd, null, 0);
1868 values = new string [0];
1872 byte[] list = new byte [size];
1873 long ret = flistxattr (fd, list, (ulong) size);
1877 GetValues (list, encoding, out values);
1881 public static long flistxattr (int fd, out string[] values)
1883 return flistxattr (fd, UnixEncoding.Instance, out values);
1886 [DllImport (MPH, SetLastError=true,
1887 EntryPoint="Mono_Posix_Syscall_removexattr")]
1888 public static extern int removexattr (
1889 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1891 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1894 [DllImport (MPH, SetLastError=true,
1895 EntryPoint="Mono_Posix_Syscall_lremovexattr")]
1896 public static extern int lremovexattr (
1897 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1899 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1902 [DllImport (MPH, SetLastError=true,
1903 EntryPoint="Mono_Posix_Syscall_fremovexattr")]
1904 public static extern int fremovexattr (int fd,
1905 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1909 #region <dirent.h> Declarations
1913 // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
1915 [DllImport (LIBC, SetLastError=true)]
1916 public static extern IntPtr opendir (
1917 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1920 [DllImport (LIBC, SetLastError=true)]
1921 public static extern int closedir (IntPtr dir);
1924 // void seekdir (DIR *dir, off_t offset);
1925 // Slight modification. Returns -1 on error, 0 on success.
1926 [DllImport (MPH, SetLastError=true,
1927 EntryPoint="Mono_Posix_Syscall_seekdir")]
1928 public static extern int seekdir (IntPtr dir, long offset);
1931 // off_t telldir(DIR *dir);
1932 [DllImport (MPH, SetLastError=true,
1933 EntryPoint="Mono_Posix_Syscall_telldir")]
1934 public static extern long telldir (IntPtr dir);
1936 [DllImport (MPH, SetLastError=true,
1937 EntryPoint="Mono_Posix_Syscall_rewinddir")]
1938 public static extern int rewinddir (IntPtr dir);
1940 private struct _Dirent {
1941 [ino_t] public ulong d_ino;
1942 [off_t] public long d_off;
1943 public ushort d_reclen;
1945 public IntPtr d_name;
1948 private static void CopyDirent (Dirent to, ref _Dirent from)
1951 to.d_ino = from.d_ino;
1952 to.d_off = from.d_off;
1953 to.d_reclen = from.d_reclen;
1954 to.d_type = from.d_type;
1955 to.d_name = UnixMarshal.PtrToString (from.d_name);
1958 Stdlib.free (from.d_name);
1959 from.d_name = IntPtr.Zero;
1963 internal static object readdir_lock = new object ();
1965 [DllImport (MPH, SetLastError=true,
1966 EntryPoint="Mono_Posix_Syscall_readdir")]
1967 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
1969 public static Dirent readdir (IntPtr dir)
1973 lock (readdir_lock) {
1974 r = sys_readdir (dir, out dentry);
1978 Dirent d = new Dirent ();
1979 CopyDirent (d, ref dentry);
1983 [DllImport (MPH, SetLastError=true,
1984 EntryPoint="Mono_Posix_Syscall_readdir_r")]
1985 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
1987 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
1993 entry.d_name = null;
1996 int r = sys_readdir_r (dirp, out _d, out result);
1998 if (r == 0 && result != IntPtr.Zero) {
1999 CopyDirent (entry, ref _d);
2005 [DllImport (LIBC, SetLastError=true)]
2006 public static extern int dirfd (IntPtr dir);
2009 #region <fcntl.h> Declarations
2011 // <fcntl.h> -- COMPLETE
2014 [DllImport (MPH, SetLastError=true,
2015 EntryPoint="Mono_Posix_Syscall_fcntl")]
2016 public static extern int fcntl (int fd, FcntlCommand cmd);
2018 [DllImport (MPH, SetLastError=true,
2019 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
2020 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
2022 public static int fcntl (int fd, FcntlCommand cmd, DirectoryNotifyFlags arg)
2024 if (cmd != FcntlCommand.F_NOTIFY) {
2025 SetLastError (Errno.EINVAL);
2028 long _arg = NativeConvert.FromDirectoryNotifyFlags (arg);
2029 return fcntl (fd, FcntlCommand.F_NOTIFY, _arg);
2032 [DllImport (MPH, SetLastError=true,
2033 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
2034 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
2036 [DllImport (MPH, SetLastError=true,
2037 EntryPoint="Mono_Posix_Syscall_open")]
2038 public static extern int open (
2039 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2040 string pathname, OpenFlags flags);
2043 // int open(const char *pathname, int flags, mode_t mode);
2044 [DllImport (MPH, SetLastError=true,
2045 EntryPoint="Mono_Posix_Syscall_open_mode")]
2046 public static extern int open (
2047 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2048 string pathname, OpenFlags flags, FilePermissions mode);
2051 // int creat(const char *pathname, mode_t mode);
2052 [DllImport (MPH, SetLastError=true,
2053 EntryPoint="Mono_Posix_Syscall_creat")]
2054 public static extern int creat (
2055 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2056 string pathname, FilePermissions mode);
2059 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
2060 [DllImport (MPH, SetLastError=true,
2061 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
2062 public static extern int posix_fadvise (int fd, long offset,
2063 long len, PosixFadviseAdvice advice);
2065 // posix_fallocate(P)
2066 // int posix_fallocate(int fd, off_t offset, size_t len);
2067 [DllImport (MPH, SetLastError=true,
2068 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
2069 public static extern int posix_fallocate (int fd, long offset, ulong len);
2072 #region <fstab.h> Declarations
2074 // <fstab.h> -- COMPLETE
2077 private struct _Fstab {
2078 public IntPtr fs_spec;
2079 public IntPtr fs_file;
2080 public IntPtr fs_vfstype;
2081 public IntPtr fs_mntops;
2082 public IntPtr fs_type;
2084 public int fs_passno;
2085 public IntPtr _fs_buf_;
2088 private static void CopyFstab (Fstab to, ref _Fstab from)
2091 to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
2092 to.fs_file = UnixMarshal.PtrToString (from.fs_file);
2093 to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
2094 to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
2095 to.fs_type = UnixMarshal.PtrToString (from.fs_type);
2096 to.fs_freq = from.fs_freq;
2097 to.fs_passno = from.fs_passno;
2100 Stdlib.free (from._fs_buf_);
2101 from._fs_buf_ = IntPtr.Zero;
2105 internal static object fstab_lock = new object ();
2107 [DllImport (MPH, SetLastError=true,
2108 EntryPoint="Mono_Posix_Syscall_endfsent")]
2109 private static extern int sys_endfsent ();
2111 public static int endfsent ()
2114 return sys_endfsent ();
2118 [DllImport (MPH, SetLastError=true,
2119 EntryPoint="Mono_Posix_Syscall_getfsent")]
2120 private static extern int sys_getfsent (out _Fstab fs);
2122 public static Fstab getfsent ()
2127 r = sys_getfsent (out fsbuf);
2131 Fstab fs = new Fstab ();
2132 CopyFstab (fs, ref fsbuf);
2136 [DllImport (MPH, SetLastError=true,
2137 EntryPoint="Mono_Posix_Syscall_getfsfile")]
2138 private static extern int sys_getfsfile (
2139 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2140 string mount_point, out _Fstab fs);
2142 public static Fstab getfsfile (string mount_point)
2147 r = sys_getfsfile (mount_point, out fsbuf);
2151 Fstab fs = new Fstab ();
2152 CopyFstab (fs, ref fsbuf);
2156 [DllImport (MPH, SetLastError=true,
2157 EntryPoint="Mono_Posix_Syscall_getfsspec")]
2158 private static extern int sys_getfsspec (
2159 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2160 string special_file, out _Fstab fs);
2162 public static Fstab getfsspec (string special_file)
2167 r = sys_getfsspec (special_file, out fsbuf);
2171 Fstab fs = new Fstab ();
2172 CopyFstab (fs, ref fsbuf);
2176 [DllImport (MPH, SetLastError=true,
2177 EntryPoint="Mono_Posix_Syscall_setfsent")]
2178 private static extern int sys_setfsent ();
2180 public static int setfsent ()
2183 return sys_setfsent ();
2189 #region <grp.h> Declarations
2193 // TODO: putgrent(3), fgetgrent_r(), getgrouplist(2), initgroups(3)
2196 // int setgroups (size_t size, const gid_t *list);
2197 [DllImport (MPH, SetLastError=true,
2198 EntryPoint="Mono_Posix_Syscall_setgroups")]
2199 public static extern int setgroups (ulong size, uint[] list);
2201 public static int setgroups (uint [] list)
2203 return setgroups ((ulong) list.Length, list);
2207 private struct _Group
2209 public IntPtr gr_name;
2210 public IntPtr gr_passwd;
2211 [gid_t] public uint gr_gid;
2212 public int _gr_nmem_;
2213 public IntPtr gr_mem;
2214 public IntPtr _gr_buf_;
2217 private static void CopyGroup (Group to, ref _Group from)
2220 to.gr_gid = from.gr_gid;
2221 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
2222 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
2223 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
2226 Stdlib.free (from.gr_mem);
2227 Stdlib.free (from._gr_buf_);
2228 from.gr_mem = IntPtr.Zero;
2229 from._gr_buf_ = IntPtr.Zero;
2233 internal static object grp_lock = new object ();
2235 [DllImport (MPH, SetLastError=true,
2236 EntryPoint="Mono_Posix_Syscall_getgrnam")]
2237 private static extern int sys_getgrnam (string name, out _Group group);
2239 public static Group getgrnam (string name)
2244 r = sys_getgrnam (name, out group);
2248 Group gr = new Group ();
2249 CopyGroup (gr, ref group);
2254 // struct group *getgrgid(gid_t gid);
2255 [DllImport (MPH, SetLastError=true,
2256 EntryPoint="Mono_Posix_Syscall_getgrgid")]
2257 private static extern int sys_getgrgid (uint uid, out _Group group);
2259 public static Group getgrgid (uint uid)
2264 r = sys_getgrgid (uid, out group);
2268 Group gr = new Group ();
2269 CopyGroup (gr, ref group);
2273 [DllImport (MPH, SetLastError=true,
2274 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
2275 private static extern int sys_getgrnam_r (
2276 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2277 string name, out _Group grbuf, out IntPtr grbufp);
2279 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
2284 int r = sys_getgrnam_r (name, out group, out _grbufp);
2285 if (r == 0 && _grbufp != IntPtr.Zero) {
2286 CopyGroup (grbuf, ref group);
2293 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
2294 // size_t buflen, struct group **gbufp);
2295 [DllImport (MPH, SetLastError=true,
2296 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
2297 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
2299 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
2304 int r = sys_getgrgid_r (uid, out group, out _grbufp);
2305 if (r == 0 && _grbufp != IntPtr.Zero) {
2306 CopyGroup (grbuf, ref group);
2312 [DllImport (MPH, SetLastError=true,
2313 EntryPoint="Mono_Posix_Syscall_getgrent")]
2314 private static extern int sys_getgrent (out _Group grbuf);
2316 public static Group getgrent ()
2321 r = sys_getgrent (out group);
2325 Group gr = new Group();
2326 CopyGroup (gr, ref group);
2330 [DllImport (MPH, SetLastError=true,
2331 EntryPoint="Mono_Posix_Syscall_setgrent")]
2332 private static extern int sys_setgrent ();
2334 public static int setgrent ()
2337 return sys_setgrent ();
2341 [DllImport (MPH, SetLastError=true,
2342 EntryPoint="Mono_Posix_Syscall_endgrent")]
2343 private static extern int sys_endgrent ();
2345 public static int endgrent ()
2348 return sys_endgrent ();
2352 [DllImport (MPH, SetLastError=true,
2353 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
2354 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
2356 public static Group fgetgrent (IntPtr stream)
2361 r = sys_fgetgrent (stream, out group);
2365 Group gr = new Group ();
2366 CopyGroup (gr, ref group);
2371 #region <pwd.h> Declarations
2375 // TODO: putpwent(3), fgetpwent_r()
2377 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
2380 private struct _Passwd
2382 public IntPtr pw_name;
2383 public IntPtr pw_passwd;
2384 [uid_t] public uint pw_uid;
2385 [gid_t] public uint pw_gid;
2386 public IntPtr pw_gecos;
2387 public IntPtr pw_dir;
2388 public IntPtr pw_shell;
2389 public IntPtr _pw_buf_;
2392 private static void CopyPasswd (Passwd to, ref _Passwd from)
2395 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
2396 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
2397 to.pw_uid = from.pw_uid;
2398 to.pw_gid = from.pw_gid;
2399 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
2400 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
2401 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
2404 Stdlib.free (from._pw_buf_);
2405 from._pw_buf_ = IntPtr.Zero;
2409 internal static object pwd_lock = new object ();
2411 [DllImport (MPH, SetLastError=true,
2412 EntryPoint="Mono_Posix_Syscall_getpwnam")]
2413 private static extern int sys_getpwnam (string name, out _Passwd passwd);
2415 public static Passwd getpwnam (string name)
2420 r = sys_getpwnam (name, out passwd);
2424 Passwd pw = new Passwd ();
2425 CopyPasswd (pw, ref passwd);
2430 // struct passwd *getpwnuid(uid_t uid);
2431 [DllImport (MPH, SetLastError=true,
2432 EntryPoint="Mono_Posix_Syscall_getpwuid")]
2433 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
2435 public static Passwd getpwuid (uint uid)
2440 r = sys_getpwuid (uid, out passwd);
2444 Passwd pw = new Passwd ();
2445 CopyPasswd (pw, ref passwd);
2449 [DllImport (MPH, SetLastError=true,
2450 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
2451 private static extern int sys_getpwnam_r (
2452 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2453 string name, out _Passwd pwbuf, out IntPtr pwbufp);
2455 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
2460 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
2461 if (r == 0 && _pwbufp != IntPtr.Zero) {
2462 CopyPasswd (pwbuf, ref passwd);
2469 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
2470 // buflen, struct passwd **pwbufp);
2471 [DllImport (MPH, SetLastError=true,
2472 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
2473 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
2475 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
2480 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
2481 if (r == 0 && _pwbufp != IntPtr.Zero) {
2482 CopyPasswd (pwbuf, ref passwd);
2488 [DllImport (MPH, SetLastError=true,
2489 EntryPoint="Mono_Posix_Syscall_getpwent")]
2490 private static extern int sys_getpwent (out _Passwd pwbuf);
2492 public static Passwd getpwent ()
2497 r = sys_getpwent (out passwd);
2501 Passwd pw = new Passwd ();
2502 CopyPasswd (pw, ref passwd);
2506 [DllImport (MPH, SetLastError=true,
2507 EntryPoint="Mono_Posix_Syscall_setpwent")]
2508 private static extern int sys_setpwent ();
2510 public static int setpwent ()
2513 return sys_setpwent ();
2517 [DllImport (MPH, SetLastError=true,
2518 EntryPoint="Mono_Posix_Syscall_endpwent")]
2519 private static extern int sys_endpwent ();
2521 public static int endpwent ()
2524 return sys_endpwent ();
2528 [DllImport (MPH, SetLastError=true,
2529 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
2530 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
2532 public static Passwd fgetpwent (IntPtr stream)
2537 r = sys_fgetpwent (stream, out passwd);
2541 Passwd pw = new Passwd ();
2542 CopyPasswd (pw, ref passwd);
2547 #region <signal.h> Declarations
2551 [DllImport (MPH, SetLastError=true,
2552 EntryPoint="Mono_Posix_Syscall_psignal")]
2553 private static extern int psignal (int sig, string s);
2555 public static int psignal (Signum sig, string s)
2557 int signum = NativeConvert.FromSignum (sig);
2558 return psignal (signum, s);
2562 // int kill(pid_t pid, int sig);
2563 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
2564 private static extern int sys_kill (int pid, int sig);
2566 public static int kill (int pid, Signum sig)
2568 int _sig = NativeConvert.FromSignum (sig);
2569 return sys_kill (pid, _sig);
2572 private static object signal_lock = new object ();
2574 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
2575 private static extern IntPtr sys_strsignal (int sig);
2577 public static string strsignal (Signum sig)
2579 int s = NativeConvert.FromSignum (sig);
2580 lock (signal_lock) {
2581 IntPtr r = sys_strsignal (s);
2582 return UnixMarshal.PtrToString (r);
2586 // TODO: sigaction(2)
2587 // TODO: sigsuspend(2)
2588 // TODO: sigpending(2)
2592 #region <stdio.h> Declarations
2596 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
2597 private static extern int _L_ctermid ();
2599 public static readonly int L_ctermid = _L_ctermid ();
2601 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
2602 private static extern int _L_cuserid ();
2604 public static readonly int L_cuserid = _L_cuserid ();
2606 internal static object getlogin_lock = new object ();
2608 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
2609 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
2611 [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
2612 "DO NOT USE cuserid().\n" +
2613 "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
2614 public static string cuserid (StringBuilder @string)
2616 if (@string.Capacity < L_cuserid) {
2617 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
2619 lock (getlogin_lock) {
2620 IntPtr r = sys_cuserid (@string);
2621 return UnixMarshal.PtrToString (r);
2627 #region <stdlib.h> Declarations
2631 [DllImport (LIBC, SetLastError=true)]
2632 public static extern int mkstemp (StringBuilder template);
2634 [DllImport (LIBC, SetLastError=true)]
2635 public static extern int ttyslot ();
2637 [Obsolete ("This is insecure and should not be used", true)]
2638 public static int setkey (string key)
2640 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
2645 #region <string.h> Declarations
2651 // int strerror_r(int errnum, char *buf, size_t n);
2652 [DllImport (MPH, SetLastError=true,
2653 EntryPoint="Mono_Posix_Syscall_strerror_r")]
2654 private static extern int sys_strerror_r (int errnum,
2655 [Out] StringBuilder buf, ulong n);
2657 public static int strerror_r (Errno errnum, StringBuilder buf, ulong n)
2659 int e = NativeConvert.FromErrno (errnum);
2660 return sys_strerror_r (e, buf, n);
2663 public static int strerror_r (Errno errnum, StringBuilder buf)
2665 return strerror_r (errnum, buf, (ulong) buf.Capacity);
2670 #region <sys/epoll.h> Declarations
2672 public static int epoll_create (int size)
2674 return sys_epoll_create (size);
2677 public static int epoll_create (EpollFlags flags)
2679 return sys_epoll_create1 (flags);
2682 public static int epoll_ctl (int epfd, EpollOp op, int fd, EpollEvents events)
2684 EpollEvent ee = new EpollEvent ();
2688 return sys_epoll_ctl (epfd, op, fd, ref ee);
2691 public static int epoll_wait (int epfd, EpollEvent [] events, int max_events, int timeout)
2693 if (events.Length < max_events)
2694 throw new ArgumentOutOfRangeException ("events", "Must refer to at least 'max_events' elements.");
2696 return sys_epoll_wait (epfd, events, max_events, timeout);
2699 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_create")]
2700 private static extern int sys_epoll_create (int size);
2702 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_create1")]
2703 private static extern int sys_epoll_create1 (EpollFlags flags);
2705 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_ctl")]
2706 private static extern int sys_epoll_ctl (int epfd, EpollOp op, int fd, ref EpollEvent ee);
2708 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_wait")]
2709 private static extern int sys_epoll_wait (int epfd, EpollEvent [] ee, int maxevents, int timeout);
2712 #region <sys/mman.h> Declarations
2718 // int posix_madvise(void *addr, size_t len, int advice);
2719 [DllImport (MPH, SetLastError=true,
2720 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
2721 public static extern int posix_madvise (IntPtr addr, ulong len,
2722 PosixMadviseAdvice advice);
2724 public static readonly IntPtr MAP_FAILED = unchecked((IntPtr)(-1));
2726 [DllImport (MPH, SetLastError=true,
2727 EntryPoint="Mono_Posix_Syscall_mmap")]
2728 public static extern IntPtr mmap (IntPtr start, ulong length,
2729 MmapProts prot, MmapFlags flags, int fd, long offset);
2731 [DllImport (MPH, SetLastError=true,
2732 EntryPoint="Mono_Posix_Syscall_munmap")]
2733 public static extern int munmap (IntPtr start, ulong length);
2735 [DllImport (MPH, SetLastError=true,
2736 EntryPoint="Mono_Posix_Syscall_mprotect")]
2737 public static extern int mprotect (IntPtr start, ulong len, MmapProts prot);
2739 [DllImport (MPH, SetLastError=true,
2740 EntryPoint="Mono_Posix_Syscall_msync")]
2741 public static extern int msync (IntPtr start, ulong len, MsyncFlags flags);
2743 [DllImport (MPH, SetLastError=true,
2744 EntryPoint="Mono_Posix_Syscall_mlock")]
2745 public static extern int mlock (IntPtr start, ulong len);
2747 [DllImport (MPH, SetLastError=true,
2748 EntryPoint="Mono_Posix_Syscall_munlock")]
2749 public static extern int munlock (IntPtr start, ulong len);
2751 [DllImport (LIBC, SetLastError=true, EntryPoint="mlockall")]
2752 private static extern int sys_mlockall (int flags);
2754 public static int mlockall (MlockallFlags flags)
2756 int _flags = NativeConvert.FromMlockallFlags (flags);
2757 return sys_mlockall (_flags);
2760 [DllImport (LIBC, SetLastError=true)]
2761 public static extern int munlockall ();
2763 [DllImport (MPH, SetLastError=true,
2764 EntryPoint="Mono_Posix_Syscall_mremap")]
2765 public static extern IntPtr mremap (IntPtr old_address, ulong old_size,
2766 ulong new_size, MremapFlags flags);
2768 [DllImport (MPH, SetLastError=true,
2769 EntryPoint="Mono_Posix_Syscall_mincore")]
2770 public static extern int mincore (IntPtr start, ulong length, byte[] vec);
2772 [DllImport (MPH, SetLastError=true,
2773 EntryPoint="Mono_Posix_Syscall_remap_file_pages")]
2774 public static extern int remap_file_pages (IntPtr start, ulong size,
2775 MmapProts prot, long pgoff, MmapFlags flags);
2779 #region <sys/poll.h> Declarations
2781 // <sys/poll.h> -- COMPLETE
2784 private struct _pollfd {
2786 public short events;
2787 public short revents;
2790 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
2791 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
2793 public static int poll (Pollfd [] fds, uint nfds, int timeout)
2795 if (fds.Length < nfds)
2796 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
2798 _pollfd[] send = new _pollfd[nfds];
2800 for (int i = 0; i < send.Length; i++) {
2801 send [i].fd = fds [i].fd;
2802 send [i].events = NativeConvert.FromPollEvents (fds [i].events);
2805 int r = sys_poll (send, nfds, timeout);
2807 for (int i = 0; i < send.Length; i++) {
2808 fds [i].revents = NativeConvert.ToPollEvents (send [i].revents);
2814 public static int poll (Pollfd [] fds, int timeout)
2816 return poll (fds, (uint) fds.Length, timeout);
2829 // TODO: setrlimit(2)
2830 // TODO: getrlimit(2)
2831 // TODO: getrusage(2)
2835 #region <sys/sendfile.h> Declarations
2837 // <sys/sendfile.h> -- COMPLETE
2840 [DllImport (MPH, SetLastError=true,
2841 EntryPoint="Mono_Posix_Syscall_sendfile")]
2842 public static extern long sendfile (int out_fd, int in_fd,
2843 ref long offset, ulong count);
2847 #region <sys/stat.h> Declarations
2849 // <sys/stat.h> -- COMPLETE
2851 [DllImport (MPH, SetLastError=true,
2852 EntryPoint="Mono_Posix_Syscall_stat")]
2853 public static extern int stat (
2854 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2855 string file_name, out Stat buf);
2857 [DllImport (MPH, SetLastError=true,
2858 EntryPoint="Mono_Posix_Syscall_fstat")]
2859 public static extern int fstat (int filedes, out Stat buf);
2861 [DllImport (MPH, SetLastError=true,
2862 EntryPoint="Mono_Posix_Syscall_lstat")]
2863 public static extern int lstat (
2864 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2865 string file_name, out Stat buf);
2868 // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
2869 // All take FilePermissions
2872 // int chmod(const char *path, mode_t mode);
2873 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
2874 private static extern int sys_chmod (
2875 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2876 string path, uint mode);
2878 public static int chmod (string path, FilePermissions mode)
2880 uint _mode = NativeConvert.FromFilePermissions (mode);
2881 return sys_chmod (path, _mode);
2885 // int chmod(int filedes, mode_t mode);
2886 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
2887 private static extern int sys_fchmod (int filedes, uint mode);
2889 public static int fchmod (int filedes, FilePermissions mode)
2891 uint _mode = NativeConvert.FromFilePermissions (mode);
2892 return sys_fchmod (filedes, _mode);
2896 // mode_t umask(mode_t mask);
2897 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
2898 private static extern uint sys_umask (uint mask);
2900 public static FilePermissions umask (FilePermissions mask)
2902 uint _mask = NativeConvert.FromFilePermissions (mask);
2903 uint r = sys_umask (_mask);
2904 return NativeConvert.ToFilePermissions (r);
2908 // int mkdir(const char *pathname, mode_t mode);
2909 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
2910 private static extern int sys_mkdir (
2911 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2912 string oldpath, uint mode);
2914 public static int mkdir (string oldpath, FilePermissions mode)
2916 uint _mode = NativeConvert.FromFilePermissions (mode);
2917 return sys_mkdir (oldpath, _mode);
2921 // int mknod (const char *pathname, mode_t mode, dev_t dev);
2922 [DllImport (MPH, SetLastError=true,
2923 EntryPoint="Mono_Posix_Syscall_mknod")]
2924 public static extern int mknod (
2925 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2926 string pathname, FilePermissions mode, ulong dev);
2929 // int mkfifo(const char *pathname, mode_t mode);
2930 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
2931 private static extern int sys_mkfifo (
2932 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2933 string pathname, uint mode);
2935 public static int mkfifo (string pathname, FilePermissions mode)
2937 uint _mode = NativeConvert.FromFilePermissions (mode);
2938 return sys_mkfifo (pathname, _mode);
2943 #region <sys/stat.h> Declarations
2948 [DllImport (MPH, SetLastError=true,
2949 EntryPoint="Mono_Posix_Syscall_statvfs")]
2950 public static extern int statvfs (
2951 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2952 string path, out Statvfs buf);
2954 [DllImport (MPH, SetLastError=true,
2955 EntryPoint="Mono_Posix_Syscall_fstatvfs")]
2956 public static extern int fstatvfs (int fd, out Statvfs buf);
2960 #region <sys/time.h> Declarations
2964 // TODO: adjtime(), getitimer(2), setitimer(2)
2966 [DllImport (MPH, SetLastError=true,
2967 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2968 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
2970 [DllImport (MPH, SetLastError=true,
2971 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2972 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
2974 public static int gettimeofday (out Timeval tv)
2976 return gettimeofday (out tv, IntPtr.Zero);
2979 [DllImport (MPH, SetLastError=true,
2980 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2981 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
2983 public static int gettimeofday (out Timezone tz)
2985 return gettimeofday (IntPtr.Zero, out tz);
2988 [DllImport (MPH, SetLastError=true,
2989 EntryPoint="Mono_Posix_Syscall_settimeofday")]
2990 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
2992 [DllImport (MPH, SetLastError=true,
2993 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2994 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
2996 public static int settimeofday (ref Timeval tv)
2998 return settimeofday (ref tv, IntPtr.Zero);
3001 [DllImport (MPH, SetLastError=true,
3002 EntryPoint="Mono_Posix_Syscall_utimes")]
3003 private static extern int sys_utimes (
3004 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3005 string filename, Timeval[] tvp);
3007 public static int utimes (string filename, Timeval[] tvp)
3009 if (tvp != null && tvp.Length != 2) {
3010 SetLastError (Errno.EINVAL);
3013 return sys_utimes (filename, tvp);
3016 [DllImport (MPH, SetLastError=true,
3017 EntryPoint="Mono_Posix_Syscall_lutimes")]
3018 private static extern int sys_lutimes (
3019 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3020 string filename, Timeval[] tvp);
3022 public static int lutimes (string filename, Timeval[] tvp)
3024 if (tvp != null && tvp.Length != 2) {
3025 SetLastError (Errno.EINVAL);
3028 return sys_lutimes (filename, tvp);
3031 [DllImport (MPH, SetLastError=true,
3032 EntryPoint="Mono_Posix_Syscall_futimes")]
3033 private static extern int sys_futimes (int fd, Timeval[] tvp);
3035 public static int futimes (int fd, Timeval[] tvp)
3037 if (tvp != null && tvp.Length != 2) {
3038 SetLastError (Errno.EINVAL);
3041 return sys_futimes (fd, tvp);
3063 private struct _Utsname
3065 public IntPtr sysname;
3066 public IntPtr nodename;
3067 public IntPtr release;
3068 public IntPtr version;
3069 public IntPtr machine;
3070 public IntPtr domainname;
3071 public IntPtr _buf_;
3074 private static void CopyUtsname (ref Utsname to, ref _Utsname from)
3077 to = new Utsname ();
3078 to.sysname = UnixMarshal.PtrToString (from.sysname);
3079 to.nodename = UnixMarshal.PtrToString (from.nodename);
3080 to.release = UnixMarshal.PtrToString (from.release);
3081 to.version = UnixMarshal.PtrToString (from.version);
3082 to.machine = UnixMarshal.PtrToString (from.machine);
3083 to.domainname = UnixMarshal.PtrToString (from.domainname);
3086 Stdlib.free (from._buf_);
3087 from._buf_ = IntPtr.Zero;
3091 [DllImport (MPH, SetLastError=true,
3092 EntryPoint="Mono_Posix_Syscall_uname")]
3093 private static extern int sys_uname (out _Utsname buf);
3095 public static int uname (out Utsname buf)
3098 int r = sys_uname (out _buf);
3099 buf = new Utsname ();
3101 CopyUtsname (ref buf, ref _buf);
3106 #region <sys/wait.h> Declarations
3112 // pid_t wait(int *status);
3113 [DllImport (LIBC, SetLastError=true)]
3114 public static extern int wait (out int status);
3117 // pid_t waitpid(pid_t pid, int *status, int options);
3118 [DllImport (LIBC, SetLastError=true)]
3119 private static extern int waitpid (int pid, out int status, int options);
3121 public static int waitpid (int pid, out int status, WaitOptions options)
3123 int _options = NativeConvert.FromWaitOptions (options);
3124 return waitpid (pid, out status, _options);
3127 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
3128 private static extern int _WIFEXITED (int status);
3130 public static bool WIFEXITED (int status)
3132 return _WIFEXITED (status) != 0;
3135 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
3136 public static extern int WEXITSTATUS (int status);
3138 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
3139 private static extern int _WIFSIGNALED (int status);
3141 public static bool WIFSIGNALED (int status)
3143 return _WIFSIGNALED (status) != 0;
3146 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
3147 private static extern int _WTERMSIG (int status);
3149 public static Signum WTERMSIG (int status)
3151 int r = _WTERMSIG (status);
3152 return NativeConvert.ToSignum (r);
3155 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
3156 private static extern int _WIFSTOPPED (int status);
3158 public static bool WIFSTOPPED (int status)
3160 return _WIFSTOPPED (status) != 0;
3163 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
3164 private static extern int _WSTOPSIG (int status);
3166 public static Signum WSTOPSIG (int status)
3168 int r = _WSTOPSIG (status);
3169 return NativeConvert.ToSignum (r);
3178 #region <syslog.h> Declarations
3183 [DllImport (MPH, SetLastError=true,
3184 EntryPoint="Mono_Posix_Syscall_openlog")]
3185 private static extern int sys_openlog (IntPtr ident, int option, int facility);
3187 public static int openlog (IntPtr ident, SyslogOptions option,
3188 SyslogFacility defaultFacility)
3190 int _option = NativeConvert.FromSyslogOptions (option);
3191 int _facility = NativeConvert.FromSyslogFacility (defaultFacility);
3193 return sys_openlog (ident, _option, _facility);
3196 [DllImport (MPH, SetLastError=true,
3197 EntryPoint="Mono_Posix_Syscall_syslog")]
3198 private static extern int sys_syslog (int priority, string message);
3200 public static int syslog (SyslogFacility facility, SyslogLevel level, string message)
3202 int _facility = NativeConvert.FromSyslogFacility (facility);
3203 int _level = NativeConvert.FromSyslogLevel (level);
3204 return sys_syslog (_facility | _level, GetSyslogMessage (message));
3207 public static int syslog (SyslogLevel level, string message)
3209 int _level = NativeConvert.FromSyslogLevel (level);
3210 return sys_syslog (_level, GetSyslogMessage (message));
3213 private static string GetSyslogMessage (string message)
3215 return UnixMarshal.EscapeFormatString (message, new char[]{'m'});
3218 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
3219 "Use syslog(SyslogFacility, SyslogLevel, string) instead.")]
3220 public static int syslog (SyslogFacility facility, SyslogLevel level,
3221 string format, params object[] parameters)
3223 int _facility = NativeConvert.FromSyslogFacility (facility);
3224 int _level = NativeConvert.FromSyslogLevel (level);
3226 object[] _parameters = new object[checked(parameters.Length+2)];
3227 _parameters [0] = _facility | _level;
3228 _parameters [1] = format;
3229 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
3230 return (int) XPrintfFunctions.syslog (_parameters);
3233 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
3234 "Use syslog(SyslogLevel, string) instead.")]
3235 public static int syslog (SyslogLevel level, string format,
3236 params object[] parameters)
3238 int _level = NativeConvert.FromSyslogLevel (level);
3240 object[] _parameters = new object[checked(parameters.Length+2)];
3241 _parameters [0] = _level;
3242 _parameters [1] = format;
3243 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
3244 return (int) XPrintfFunctions.syslog (_parameters);
3247 [DllImport (MPH, SetLastError=true,
3248 EntryPoint="Mono_Posix_Syscall_closelog")]
3249 public static extern int closelog ();
3251 [DllImport (LIBC, SetLastError=true, EntryPoint="setlogmask")]
3252 private static extern int sys_setlogmask (int mask);
3254 public static int setlogmask (SyslogLevel mask)
3256 int _mask = NativeConvert.FromSyslogLevel (mask);
3257 return sys_setlogmask (_mask);
3262 #region <time.h> Declarations
3269 // int nanosleep(const struct timespec *req, struct timespec *rem);
3270 [DllImport (MPH, SetLastError=true,
3271 EntryPoint="Mono_Posix_Syscall_nanosleep")]
3272 public static extern int nanosleep (ref Timespec req, ref Timespec rem);
3275 // int stime(time_t *t);
3276 [DllImport (MPH, SetLastError=true,
3277 EntryPoint="Mono_Posix_Syscall_stime")]
3278 public static extern int stime (ref long t);
3281 // time_t time(time_t *t);
3282 [DllImport (MPH, SetLastError=true,
3283 EntryPoint="Mono_Posix_Syscall_time")]
3284 public static extern long time (out long t);
3294 #region <unistd.h> Declarations
3298 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
3299 // other TODOs listed below.
3301 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
3302 private static extern int sys_access (
3303 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3304 string pathname, int mode);
3306 public static int access (string pathname, AccessModes mode)
3308 int _mode = NativeConvert.FromAccessModes (mode);
3309 return sys_access (pathname, _mode);
3313 // off_t lseek(int filedes, off_t offset, int whence);
3314 [DllImport (MPH, SetLastError=true,
3315 EntryPoint="Mono_Posix_Syscall_lseek")]
3316 private static extern long sys_lseek (int fd, long offset, int whence);
3318 public static long lseek (int fd, long offset, SeekFlags whence)
3320 short _whence = NativeConvert.FromSeekFlags (whence);
3321 return sys_lseek (fd, offset, _whence);
3324 [DllImport (LIBC, SetLastError=true)]
3325 public static extern int close (int fd);
3328 // ssize_t read(int fd, void *buf, size_t count);
3329 [DllImport (MPH, SetLastError=true,
3330 EntryPoint="Mono_Posix_Syscall_read")]
3331 public static extern long read (int fd, IntPtr buf, ulong count);
3333 public static unsafe long read (int fd, void *buf, ulong count)
3335 return read (fd, (IntPtr) buf, count);
3339 // ssize_t write(int fd, const void *buf, size_t count);
3340 [DllImport (MPH, SetLastError=true,
3341 EntryPoint="Mono_Posix_Syscall_write")]
3342 public static extern long write (int fd, IntPtr buf, ulong count);
3344 public static unsafe long write (int fd, void *buf, ulong count)
3346 return write (fd, (IntPtr) buf, count);
3350 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
3351 [DllImport (MPH, SetLastError=true,
3352 EntryPoint="Mono_Posix_Syscall_pread")]
3353 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
3355 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
3357 return pread (fd, (IntPtr) buf, count, offset);
3361 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
3362 [DllImport (MPH, SetLastError=true,
3363 EntryPoint="Mono_Posix_Syscall_pwrite")]
3364 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
3366 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
3368 return pwrite (fd, (IntPtr) buf, count, offset);
3371 [DllImport (MPH, SetLastError=true,
3372 EntryPoint="Mono_Posix_Syscall_pipe")]
3373 public static extern int pipe (out int reading, out int writing);
3375 public static int pipe (int[] filedes)
3377 if (filedes == null || filedes.Length != 2) {
3381 int reading, writing;
3382 int r = pipe (out reading, out writing);
3383 filedes[0] = reading;
3384 filedes[1] = writing;
3388 [DllImport (LIBC, SetLastError=true)]
3389 public static extern uint alarm (uint seconds);
3391 [DllImport (LIBC, SetLastError=true)]
3392 public static extern uint sleep (uint seconds);
3394 [DllImport (LIBC, SetLastError=true)]
3395 public static extern uint ualarm (uint usecs, uint interval);
3397 [DllImport (LIBC, SetLastError=true)]
3398 public static extern int pause ();
3401 // int chown(const char *path, uid_t owner, gid_t group);
3402 [DllImport (LIBC, SetLastError=true)]
3403 public static extern int chown (
3404 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3405 string path, uint owner, uint group);
3408 // int fchown(int fd, uid_t owner, gid_t group);
3409 [DllImport (LIBC, SetLastError=true)]
3410 public static extern int fchown (int fd, uint owner, uint group);
3413 // int lchown(const char *path, uid_t owner, gid_t group);
3414 [DllImport (LIBC, SetLastError=true)]
3415 public static extern int lchown (
3416 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3417 string path, uint owner, uint group);
3419 [DllImport (LIBC, SetLastError=true)]
3420 public static extern int chdir (
3421 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3424 [DllImport (LIBC, SetLastError=true)]
3425 public static extern int fchdir (int fd);
3428 // char *getcwd(char *buf, size_t size);
3429 [DllImport (MPH, SetLastError=true,
3430 EntryPoint="Mono_Posix_Syscall_getcwd")]
3431 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
3433 public static StringBuilder getcwd (StringBuilder buf)
3435 getcwd (buf, (ulong) buf.Capacity);
3439 // getwd(2) is deprecated; don't expose it.
3441 [DllImport (LIBC, SetLastError=true)]
3442 public static extern int dup (int fd);
3444 [DllImport (LIBC, SetLastError=true)]
3445 public static extern int dup2 (int fd, int fd2);
3447 // TODO: does Mono marshal arrays properly?
3448 [DllImport (LIBC, SetLastError=true)]
3449 public static extern int execve (
3450 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3451 string path, string[] argv, string[] envp);
3453 [DllImport (LIBC, SetLastError=true)]
3454 public static extern int fexecve (int fd, string[] argv, string[] envp);
3456 [DllImport (LIBC, SetLastError=true)]
3457 public static extern int execv (
3458 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3459 string path, string[] argv);
3461 // TODO: execle, execl, execlp
3462 [DllImport (LIBC, SetLastError=true)]
3463 public static extern int execvp (
3464 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3465 string path, string[] argv);
3467 [DllImport (LIBC, SetLastError=true)]
3468 public static extern int nice (int inc);
3470 [DllImport (LIBC, SetLastError=true)]
3471 [CLSCompliant (false)]
3472 public static extern int _exit (int status);
3474 [DllImport (MPH, SetLastError=true,
3475 EntryPoint="Mono_Posix_Syscall_fpathconf")]
3476 public static extern long fpathconf (int filedes, PathconfName name, Errno defaultError);
3478 public static long fpathconf (int filedes, PathconfName name)
3480 return fpathconf (filedes, name, (Errno) 0);
3483 [DllImport (MPH, SetLastError=true,
3484 EntryPoint="Mono_Posix_Syscall_pathconf")]
3485 public static extern long pathconf (
3486 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3487 string path, PathconfName name, Errno defaultError);
3489 public static long pathconf (string path, PathconfName name)
3491 return pathconf (path, name, (Errno) 0);
3494 [DllImport (MPH, SetLastError=true,
3495 EntryPoint="Mono_Posix_Syscall_sysconf")]
3496 public static extern long sysconf (SysconfName name, Errno defaultError);
3498 public static long sysconf (SysconfName name)
3500 return sysconf (name, (Errno) 0);
3504 // size_t confstr(int name, char *buf, size_t len);
3505 [DllImport (MPH, SetLastError=true,
3506 EntryPoint="Mono_Posix_Syscall_confstr")]
3507 public static extern ulong confstr (ConfstrName name, [Out] StringBuilder buf, ulong len);
3510 // pid_t getpid(void);
3511 [DllImport (LIBC, SetLastError=true)]
3512 public static extern int getpid ();
3515 // pid_t getppid(void);
3516 [DllImport (LIBC, SetLastError=true)]
3517 public static extern int getppid ();
3520 // int setpgid(pid_t pid, pid_t pgid);
3521 [DllImport (LIBC, SetLastError=true)]
3522 public static extern int setpgid (int pid, int pgid);
3525 // pid_t getpgid(pid_t pid);
3526 [DllImport (LIBC, SetLastError=true)]
3527 public static extern int getpgid (int pid);
3529 [DllImport (LIBC, SetLastError=true)]
3530 public static extern int setpgrp ();
3533 // pid_t getpgrp(void);
3534 [DllImport (LIBC, SetLastError=true)]
3535 public static extern int getpgrp ();
3538 // pid_t setsid(void);
3539 [DllImport (LIBC, SetLastError=true)]
3540 public static extern int setsid ();
3543 // pid_t getsid(pid_t pid);
3544 [DllImport (LIBC, SetLastError=true)]
3545 public static extern int getsid (int pid);
3548 // uid_t getuid(void);
3549 [DllImport (LIBC, SetLastError=true)]
3550 public static extern uint getuid ();
3553 // uid_t geteuid(void);
3554 [DllImport (LIBC, SetLastError=true)]
3555 public static extern uint geteuid ();
3558 // gid_t getgid(void);
3559 [DllImport (LIBC, SetLastError=true)]
3560 public static extern uint getgid ();
3563 // gid_t getgid(void);
3564 [DllImport (LIBC, SetLastError=true)]
3565 public static extern uint getegid ();
3568 // int getgroups(int size, gid_t list[]);
3569 [DllImport (LIBC, SetLastError=true)]
3570 public static extern int getgroups (int size, uint[] list);
3572 public static int getgroups (uint[] list)
3574 return getgroups (list.Length, list);
3578 // int setuid(uid_t uid);
3579 [DllImport (LIBC, SetLastError=true)]
3580 public static extern int setuid (uint uid);
3583 // int setreuid(uid_t ruid, uid_t euid);
3584 [DllImport (LIBC, SetLastError=true)]
3585 public static extern int setreuid (uint ruid, uint euid);
3588 // int setregid(gid_t ruid, gid_t euid);
3589 [DllImport (LIBC, SetLastError=true)]
3590 public static extern int setregid (uint rgid, uint egid);
3593 // int seteuid(uid_t euid);
3594 [DllImport (LIBC, SetLastError=true)]
3595 public static extern int seteuid (uint euid);
3598 // int setegid(gid_t euid);
3599 [DllImport (LIBC, SetLastError=true)]
3600 public static extern int setegid (uint uid);
3603 // int setgid(gid_t gid);
3604 [DllImport (LIBC, SetLastError=true)]
3605 public static extern int setgid (uint gid);
3608 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
3609 [DllImport (LIBC, SetLastError=true)]
3610 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
3613 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
3614 [DllImport (LIBC, SetLastError=true)]
3615 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
3618 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
3619 [DllImport (LIBC, SetLastError=true)]
3620 public static extern int setresuid (uint ruid, uint euid, uint suid);
3623 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
3624 [DllImport (LIBC, SetLastError=true)]
3625 public static extern int setresgid (uint rgid, uint egid, uint sgid);
3629 // pid_t fork(void);
3630 [DllImport (LIBC, SetLastError=true)]
3631 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
3632 "shutdown code.\nUse System.Diagnostics.Process instead")]
3633 private static extern int fork ();
3636 // pid_t vfork(void);
3637 [DllImport (LIBC, SetLastError=true)]
3638 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
3639 "shutdown code.\nUse System.Diagnostics.Process instead")]
3640 private static extern int vfork ();
3643 private static object tty_lock = new object ();
3645 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
3646 private static extern IntPtr sys_ttyname (int fd);
3648 public static string ttyname (int fd)
3651 IntPtr r = sys_ttyname (fd);
3652 return UnixMarshal.PtrToString (r);
3657 // int ttyname_r(int fd, char *buf, size_t buflen);
3658 [DllImport (MPH, SetLastError=true,
3659 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
3660 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
3662 public static int ttyname_r (int fd, StringBuilder buf)
3664 return ttyname_r (fd, buf, (ulong) buf.Capacity);
3667 [DllImport (LIBC, EntryPoint="isatty")]
3668 private static extern int sys_isatty (int fd);
3670 public static bool isatty (int fd)
3672 return sys_isatty (fd) == 1;
3675 [DllImport (LIBC, SetLastError=true)]
3676 public static extern int link (
3677 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3679 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3682 [DllImport (LIBC, SetLastError=true)]
3683 public static extern int symlink (
3684 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3686 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3690 // int readlink(const char *path, char *buf, size_t bufsize);
3691 [DllImport (MPH, SetLastError=true,
3692 EntryPoint="Mono_Posix_Syscall_readlink")]
3693 public static extern int readlink (
3694 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3695 string path, [Out] StringBuilder buf, ulong bufsiz);
3697 public static int readlink (string path, [Out] StringBuilder buf)
3699 return readlink (path, buf, (ulong) buf.Capacity);
3702 [DllImport (LIBC, SetLastError=true)]
3703 public static extern int unlink (
3704 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3707 [DllImport (LIBC, SetLastError=true)]
3708 public static extern int rmdir (
3709 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3713 // pid_t tcgetpgrp(int fd);
3714 [DllImport (LIBC, SetLastError=true)]
3715 public static extern int tcgetpgrp (int fd);
3718 // int tcsetpgrp(int fd, pid_t pgrp);
3719 [DllImport (LIBC, SetLastError=true)]
3720 public static extern int tcsetpgrp (int fd, int pgrp);
3722 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
3723 private static extern IntPtr sys_getlogin ();
3725 public static string getlogin ()
3727 lock (getlogin_lock) {
3728 IntPtr r = sys_getlogin ();
3729 return UnixMarshal.PtrToString (r);
3734 // int getlogin_r(char *buf, size_t bufsize);
3735 [DllImport (MPH, SetLastError=true,
3736 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
3737 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
3739 public static int getlogin_r (StringBuilder name)
3741 return getlogin_r (name, (ulong) name.Capacity);
3744 [DllImport (LIBC, SetLastError=true)]
3745 public static extern int setlogin (string name);
3748 // int gethostname(char *name, size_t len);
3749 [DllImport (MPH, SetLastError=true,
3750 EntryPoint="Mono_Posix_Syscall_gethostname")]
3751 public static extern int gethostname ([Out] StringBuilder name, ulong len);
3753 public static int gethostname (StringBuilder name)
3755 return gethostname (name, (ulong) name.Capacity);
3759 // int gethostname(const char *name, size_t len);
3760 [DllImport (MPH, SetLastError=true,
3761 EntryPoint="Mono_Posix_Syscall_sethostname")]
3762 public static extern int sethostname (string name, ulong len);
3764 public static int sethostname (string name)
3766 return sethostname (name, (ulong) name.Length);
3769 [DllImport (MPH, SetLastError=true,
3770 EntryPoint="Mono_Posix_Syscall_gethostid")]
3771 public static extern long gethostid ();
3773 [DllImport (MPH, SetLastError=true,
3774 EntryPoint="Mono_Posix_Syscall_sethostid")]
3775 public static extern int sethostid (long hostid);
3778 // int getdomainname(char *name, size_t len);
3779 [DllImport (MPH, SetLastError=true,
3780 EntryPoint="Mono_Posix_Syscall_getdomainname")]
3781 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
3783 public static int getdomainname (StringBuilder name)
3785 return getdomainname (name, (ulong) name.Capacity);
3789 // int setdomainname(const char *name, size_t len);
3790 [DllImport (MPH, SetLastError=true,
3791 EntryPoint="Mono_Posix_Syscall_setdomainname")]
3792 public static extern int setdomainname (string name, ulong len);
3794 public static int setdomainname (string name)
3796 return setdomainname (name, (ulong) name.Length);
3799 [DllImport (LIBC, SetLastError=true)]
3800 public static extern int vhangup ();
3802 // Revoke doesn't appear to be POSIX. Include it?
3803 [DllImport (LIBC, SetLastError=true)]
3804 public static extern int revoke (
3805 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3808 // TODO: profil? It's not POSIX.
3810 [DllImport (LIBC, SetLastError=true)]
3811 public static extern int acct (
3812 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3815 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
3816 private static extern IntPtr sys_getusershell ();
3818 internal static object usershell_lock = new object ();
3820 public static string getusershell ()
3822 lock (usershell_lock) {
3823 IntPtr r = sys_getusershell ();
3824 return UnixMarshal.PtrToString (r);
3828 [DllImport (MPH, SetLastError=true,
3829 EntryPoint="Mono_Posix_Syscall_setusershell")]
3830 private static extern int sys_setusershell ();
3832 public static int setusershell ()
3834 lock (usershell_lock) {
3835 return sys_setusershell ();
3839 [DllImport (MPH, SetLastError=true,
3840 EntryPoint="Mono_Posix_Syscall_endusershell")]
3841 private static extern int sys_endusershell ();
3843 public static int endusershell ()
3845 lock (usershell_lock) {
3846 return sys_endusershell ();
3851 [DllImport (LIBC, SetLastError=true)]
3852 private static extern int daemon (int nochdir, int noclose);
3854 // this implicitly forks, and thus isn't safe.
3855 private static int daemon (bool nochdir, bool noclose)
3857 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
3861 [DllImport (LIBC, SetLastError=true)]
3862 public static extern int chroot (
3863 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3866 // skipping getpass(3) as the man page states:
3867 // This function is obsolete. Do not use it.
3869 [DllImport (LIBC, SetLastError=true)]
3870 public static extern int fsync (int fd);
3872 [DllImport (LIBC, SetLastError=true)]
3873 public static extern int fdatasync (int fd);
3875 [DllImport (MPH, SetLastError=true,
3876 EntryPoint="Mono_Posix_Syscall_sync")]
3877 public static extern int sync ();
3879 [DllImport (LIBC, SetLastError=true)]
3880 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
3881 "Use Syscall.sysconf (SysconfName._SC_PAGESIZE).")]
3882 public static extern int getpagesize ();
3885 // int truncate(const char *path, off_t length);
3886 [DllImport (MPH, SetLastError=true,
3887 EntryPoint="Mono_Posix_Syscall_truncate")]
3888 public static extern int truncate (
3889 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3890 string path, long length);
3893 // int ftruncate(int fd, off_t length);
3894 [DllImport (MPH, SetLastError=true,
3895 EntryPoint="Mono_Posix_Syscall_ftruncate")]
3896 public static extern int ftruncate (int fd, long length);
3898 [DllImport (LIBC, SetLastError=true)]
3899 public static extern int getdtablesize ();
3901 [DllImport (LIBC, SetLastError=true)]
3902 public static extern int brk (IntPtr end_data_segment);
3904 [DllImport (LIBC, SetLastError=true)]
3905 public static extern IntPtr sbrk (IntPtr increment);
3907 // TODO: syscall(2)?
3908 // Probably safer to skip entirely.
3911 // int lockf(int fd, int cmd, off_t len);
3912 [DllImport (MPH, SetLastError=true,
3913 EntryPoint="Mono_Posix_Syscall_lockf")]
3914 public static extern int lockf (int fd, LockfCommand cmd, long len);
3916 [Obsolete ("This is insecure and should not be used", true)]
3917 public static string crypt (string key, string salt)
3919 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
3922 [Obsolete ("This is insecure and should not be used", true)]
3923 public static int encrypt (byte[] block, bool decode)
3925 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
3929 // void swab(const void *from, void *to, ssize_t n);
3930 [DllImport (MPH, SetLastError=true,
3931 EntryPoint="Mono_Posix_Syscall_swab")]
3932 public static extern int swab (IntPtr from, IntPtr to, long n);
3934 public static unsafe void swab (void* from, void* to, long n)
3936 swab ((IntPtr) from, (IntPtr) to, n);
3941 #region <utime.h> Declarations
3943 // <utime.h> -- COMPLETE
3946 [DllImport (MPH, SetLastError=true,
3947 EntryPoint="Mono_Posix_Syscall_utime")]
3948 private static extern int sys_utime (
3949 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3950 string filename, ref Utimbuf buf, int use_buf);
3952 public static int utime (string filename, ref Utimbuf buf)
3954 return sys_utime (filename, ref buf, 1);
3957 public static int utime (string filename)
3959 Utimbuf buf = new Utimbuf ();
3960 return sys_utime (filename, ref buf, 0);