2 // Mono.Unix/Syscall.cs
5 // Miguel de Icaza (miguel@novell.com)
6 // Jonathan Pryor (jonpryor@vt.edu)
8 // (C) 2003 Novell, Inc.
9 // (C) 2004-2005 Jonathan Pryor
11 // This file implements the low-level syscall interface to the POSIX
14 // This file tries to stay close to the low-level API as much as possible
15 // using enumerations, structures and in a few cases, using existing .NET
18 // Implementation notes:
20 // Since the values for the various constants on the API changes
21 // from system to system (even Linux on different architectures will
22 // have different values), we define our own set of values, and we
23 // use a set of C helper routines to map from the constants we define
24 // to the values of the native OS.
26 // Bitfields are flagged with the [Map] attribute, and a helper program
27 // generates a set of routines that we can call to convert from our value
28 // definitions to the value definitions expected by the OS; see
29 // 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;
60 using Mono.Unix.Native;
62 [assembly:Mono.Unix.Native.HeaderAttribute (
82 namespace Mono.Unix.Native {
87 [CLSCompliant (false)]
88 public enum SyslogOptions {
89 LOG_PID = 0x01, // log the pid with each message
90 LOG_CONS = 0x02, // log on the console if errors in sending
91 LOG_ODELAY = 0x04, // delay open until first syslog (default)
92 LOG_NDELAY = 0x08, // don't delay open
93 LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
94 LOG_PERROR = 0x20 // log to stderr as well
98 [CLSCompliant (false)]
99 public enum SyslogFacility {
102 [Obsolete ("use SyslogFacility.LOG_USER")]
112 LOG_AUTHPRIV = 10 << 3,
114 LOG_LOCAL0 = 16 << 3,
115 LOG_LOCAL1 = 17 << 3,
116 LOG_LOCAL2 = 18 << 3,
117 LOG_LOCAL3 = 19 << 3,
118 LOG_LOCAL4 = 20 << 3,
119 LOG_LOCAL5 = 21 << 3,
120 LOG_LOCAL6 = 22 << 3,
121 LOG_LOCAL7 = 23 << 3,
125 [CLSCompliant (false)]
126 public enum SyslogLevel {
127 LOG_EMERG = 0, // system is unusable
128 LOG_ALERT = 1, // action must be taken immediately
129 LOG_CRIT = 2, // critical conditions
130 LOG_ERR = 3, // warning conditions
131 LOG_WARNING = 4, // warning conditions
132 LOG_NOTICE = 5, // normal but significant condition
133 LOG_INFO = 6, // informational
134 LOG_DEBUG = 7 // debug-level messages
138 [CLSCompliant (false)]
139 public enum OpenFlags : int {
143 O_RDONLY = 0x00000000,
144 O_WRONLY = 0x00000001,
148 // Or-ed with zero or more of these
150 O_CREAT = 0x00000040,
152 O_NOCTTY = 0x00000100,
153 O_TRUNC = 0x00000200,
154 O_APPEND = 0x00000400,
155 O_NONBLOCK = 0x00000800,
159 // These are non-Posix. Using them will result in errors/exceptions on
160 // non-supported platforms.
162 // (For example, "C-wrapped" system calls -- calls with implementation in
163 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
164 // calls will generate an exception in NativeConvert, as the value can't be
165 // converted on the target platform.)
168 O_NOFOLLOW = 0x00020000,
169 O_DIRECTORY = 0x00010000,
170 O_DIRECT = 0x00004000,
171 O_ASYNC = 0x00002000,
172 O_LARGEFILE = 0x00008000
177 [CLSCompliant (false)]
178 public enum FilePermissions : uint {
179 S_ISUID = 0x0800, // Set user ID on execution
180 S_ISGID = 0x0400, // Set gorup ID on execution
181 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
182 S_IRUSR = 0x0100, // Read by owner
183 S_IWUSR = 0x0080, // Write by owner
184 S_IXUSR = 0x0040, // Execute by owner
185 S_IRGRP = 0x0020, // Read by group
186 S_IWGRP = 0x0010, // Write by group
187 S_IXGRP = 0x0008, // Execute by group
188 S_IROTH = 0x0004, // Read by other
189 S_IWOTH = 0x0002, // Write by other
190 S_IXOTH = 0x0001, // Execute by other
192 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
193 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
194 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
195 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
196 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
197 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
200 // Why these are held in "mode_t" is beyond me...
201 S_IFMT = 0xF000, // Bits which determine file type
202 S_IFDIR = 0x4000, // Directory
203 S_IFCHR = 0x2000, // Character device
204 S_IFBLK = 0x6000, // Block device
205 S_IFREG = 0x8000, // Regular file
206 S_IFIFO = 0x1000, // FIFO
207 S_IFLNK = 0xA000, // Symbolic link
208 S_IFSOCK = 0xC000, // Socket
212 [CLSCompliant (false)]
213 public enum FcntlCommand : int {
214 // Form /usr/include/bits/fcntl.h
215 F_DUPFD = 0, // Duplicate file descriptor.
216 F_GETFD = 1, // Get file descriptor flags.
217 F_SETFD = 2, // Set file descriptor flags.
218 F_GETFL = 3, // Get file status flags.
219 F_SETFL = 4, // Set file status flags.
220 F_GETLK = 12, // Get record locking info. [64]
221 F_SETLK = 13, // Set record locking info (non-blocking). [64]
222 F_SETLKW = 14, // Set record locking info (blocking). [64]
223 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
224 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
225 F_SETSIG = 10, // Set number of signal to be sent.
226 F_GETSIG = 11, // Get number of signal to be sent.
227 F_SETLEASE = 1024, // Set a lease.
228 F_GETLEASE = 1025, // Enquire what lease is active.
229 F_NOTIFY = 1026, // Required notifications on a directory
233 [CLSCompliant (false)]
234 public enum LockType : short {
235 F_RDLCK = 0, // Read lock.
236 F_WRLCK = 1, // Write lock.
237 F_UNLCK = 2, // Remove lock.
241 [CLSCompliant (false)]
242 public enum SeekFlags : short {
243 // values liberally copied from /usr/include/unistd.h
244 SEEK_SET = 0, // Seek from beginning of file.
245 SEEK_CUR = 1, // Seek from current position.
246 SEEK_END = 2, // Seek from end of file.
248 L_SET = SEEK_SET, // BSD alias for SEEK_SET
249 L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
250 L_XTND = SEEK_END, // BSD alias for SEEK_END
254 [CLSCompliant (false)]
255 public enum DirectoryNotifyFlags : int {
256 // from /usr/include/bits/fcntl.h
257 DN_ACCESS = 0x00000001, // File accessed.
258 DN_MODIFY = 0x00000002, // File modified.
259 DN_CREATE = 0x00000004, // File created.
260 DN_DELETE = 0x00000008, // File removed.
261 DN_RENAME = 0x00000010, // File renamed.
262 DN_ATTRIB = 0x00000020, // File changed attributes.
263 DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
267 [CLSCompliant (false)]
268 public enum PosixFadviseAdvice : int {
269 POSIX_FADV_NORMAL = 0, // No further special treatment.
270 POSIX_FADV_RANDOM = 1, // Expect random page references.
271 POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
272 POSIX_FADV_WILLNEED = 3, // Will need these pages.
273 POSIX_FADV_DONTNEED = 4, // Don't need these pages.
274 POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
278 [CLSCompliant (false)]
279 public enum PosixMadviseAdvice : int {
280 POSIX_MADV_NORMAL = 0, // No further special treatment.
281 POSIX_MADV_RANDOM = 1, // Expect random page references.
282 POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
283 POSIX_MADV_WILLNEED = 3, // Will need these pages.
284 POSIX_MADV_DONTNEED = 4, // Don't need these pages.
288 [CLSCompliant (false)]
289 public enum Signum : int {
290 SIGHUP = 1, // Hangup (POSIX).
291 SIGINT = 2, // Interrupt (ANSI).
292 SIGQUIT = 3, // Quit (POSIX).
293 SIGILL = 4, // Illegal instruction (ANSI).
294 SIGTRAP = 5, // Trace trap (POSIX).
295 SIGABRT = 6, // Abort (ANSI).
296 SIGIOT = 6, // IOT trap (4.2 BSD).
297 SIGBUS = 7, // BUS error (4.2 BSD).
298 SIGFPE = 8, // Floating-point exception (ANSI).
299 SIGKILL = 9, // Kill, unblockable (POSIX).
300 SIGUSR1 = 10, // User-defined signal 1 (POSIX).
301 SIGSEGV = 11, // Segmentation violation (ANSI).
302 SIGUSR2 = 12, // User-defined signal 2 (POSIX).
303 SIGPIPE = 13, // Broken pipe (POSIX).
304 SIGALRM = 14, // Alarm clock (POSIX).
305 SIGTERM = 15, // Termination (ANSI).
306 SIGSTKFLT = 16, // Stack fault.
307 SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
308 SIGCHLD = 17, // Child status has changed (POSIX).
309 SIGCONT = 18, // Continue (POSIX).
310 SIGSTOP = 19, // Stop, unblockable (POSIX).
311 SIGTSTP = 20, // Keyboard stop (POSIX).
312 SIGTTIN = 21, // Background read from tty (POSIX).
313 SIGTTOU = 22, // Background write to tty (POSIX).
314 SIGURG = 23, // Urgent condition on socket (4.2 BSD).
315 SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
316 SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
317 SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
318 SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
319 SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
320 SIGPOLL = SIGIO, // Pollable event occurred (System V).
321 SIGIO = 29, // I/O now possible (4.2 BSD).
322 SIGPWR = 30, // Power failure restart (System V).
323 SIGSYS = 31, // Bad system call.
328 [CLSCompliant (false)]
329 public enum WaitOptions : int {
330 WNOHANG = 1, // Don't block waiting
331 WUNTRACED = 2, // Report status of stopped children
335 [CLSCompliant (false)]
336 public enum AccessModes : int {
344 [CLSCompliant (false)]
345 public enum PathconfName : int {
352 _PC_CHOWN_RESTRICTED,
360 _PC_REC_INCR_XFER_SIZE,
361 _PC_REC_MAX_XFER_SIZE,
362 _PC_REC_MIN_XFER_SIZE,
370 [CLSCompliant (false)]
371 public enum SysconfName : int {
381 _SC_REALTIME_SIGNALS,
382 _SC_PRIORITY_SCHEDULING,
391 _SC_MEMORY_PROTECTION,
394 _SC_SHARED_MEMORY_OBJECTS,
397 _SC_AIO_PRIO_DELTA_MAX,
408 /* Values for the argument to `sysconf'
409 corresponding to _POSIX2_* symbols. */
414 _SC_COLL_WEIGHTS_MAX,
419 _SC_CHARCLASS_NAME_MAX,
435 _SC_IOV_MAX = _SC_UIO_MAXIOV,
436 _SC_PII_INTERNET_STREAM,
437 _SC_PII_INTERNET_DGRAM,
442 /* Values according to POSIX 1003.1c (POSIX threads). */
444 _SC_THREAD_SAFE_FUNCTIONS,
445 _SC_GETGR_R_SIZE_MAX,
446 _SC_GETPW_R_SIZE_MAX,
449 _SC_THREAD_DESTRUCTOR_ITERATIONS,
451 _SC_THREAD_STACK_MIN,
452 _SC_THREAD_THREADS_MAX,
453 _SC_THREAD_ATTR_STACKADDR,
454 _SC_THREAD_ATTR_STACKSIZE,
455 _SC_THREAD_PRIORITY_SCHEDULING,
456 _SC_THREAD_PRIO_INHERIT,
457 _SC_THREAD_PRIO_PROTECT,
458 _SC_THREAD_PROCESS_SHARED,
459 _SC_NPROCESSORS_CONF,
460 _SC_NPROCESSORS_ONLN,
466 _SC_XOPEN_XCU_VERSION,
501 _SC_XBS5_ILP32_OFF32,
502 _SC_XBS5_ILP32_OFFBIG,
504 _SC_XBS5_LPBIG_OFFBIG,
507 _SC_XOPEN_REALTIME_THREADS,
512 _SC_C_LANG_SUPPORT_R,
518 _SC_DEVICE_SPECIFIC_R,
529 _SC_READER_WRITER_LOCKS,
537 _SC_THREAD_SPORADIC_SERVER,
539 _SC_SYSTEM_DATABASE_R,
541 _SC_TYPED_MEMORY_OBJECTS,
545 _SC_2_PBS_ACCOUNTING,
551 _SC_2_PBS_CHECKPOINT,
558 _SC_TRACE_EVENT_FILTER,
561 _SC_LEVEL1_ICACHE_SIZE,
562 _SC_LEVEL1_ICACHE_ASSOC,
563 _SC_LEVEL1_ICACHE_LINESIZE,
564 _SC_LEVEL1_DCACHE_SIZE,
565 _SC_LEVEL1_DCACHE_ASSOC,
566 _SC_LEVEL1_DCACHE_LINESIZE,
567 _SC_LEVEL2_CACHE_SIZE,
568 _SC_LEVEL2_CACHE_ASSOC,
569 _SC_LEVEL2_CACHE_LINESIZE,
570 _SC_LEVEL3_CACHE_SIZE,
571 _SC_LEVEL3_CACHE_ASSOC,
572 _SC_LEVEL3_CACHE_LINESIZE,
573 _SC_LEVEL4_CACHE_SIZE,
574 _SC_LEVEL4_CACHE_ASSOC,
575 _SC_LEVEL4_CACHE_LINESIZE
579 [CLSCompliant (false)]
580 public enum ConfstrName : int {
581 _CS_PATH, /* The default search path. */
582 _CS_V6_WIDTH_RESTRICTED_ENVS,
583 _CS_GNU_LIBC_VERSION,
584 _CS_GNU_LIBPTHREAD_VERSION,
585 _CS_LFS_CFLAGS = 1000,
593 _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
594 _CS_XBS5_ILP32_OFF32_LDFLAGS,
595 _CS_XBS5_ILP32_OFF32_LIBS,
596 _CS_XBS5_ILP32_OFF32_LINTFLAGS,
597 _CS_XBS5_ILP32_OFFBIG_CFLAGS,
598 _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
599 _CS_XBS5_ILP32_OFFBIG_LIBS,
600 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
601 _CS_XBS5_LP64_OFF64_CFLAGS,
602 _CS_XBS5_LP64_OFF64_LDFLAGS,
603 _CS_XBS5_LP64_OFF64_LIBS,
604 _CS_XBS5_LP64_OFF64_LINTFLAGS,
605 _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
606 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
607 _CS_XBS5_LPBIG_OFFBIG_LIBS,
608 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
609 _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
610 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
611 _CS_POSIX_V6_ILP32_OFF32_LIBS,
612 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
613 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
614 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
615 _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
616 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
617 _CS_POSIX_V6_LP64_OFF64_CFLAGS,
618 _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
619 _CS_POSIX_V6_LP64_OFF64_LIBS,
620 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
621 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
622 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
623 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
624 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
628 [CLSCompliant (false)]
629 public enum LockfCommand : int {
630 F_ULOCK = 0, // Unlock a previously locked region.
631 F_LOCK = 1, // Lock a region for exclusive use.
632 F_TLOCK = 2, // Test and lock a region for exclusive use.
633 F_TEST = 3, // Test a region for other process locks.
637 [CLSCompliant (false)]
638 public enum PollEvents : short {
639 POLLIN = 0x0001, // There is data to read
640 POLLPRI = 0x0002, // There is urgent data to read
641 POLLOUT = 0x0004, // Writing now will not block
642 POLLERR = 0x0008, // Error condition
643 POLLHUP = 0x0010, // Hung up
644 POLLNVAL = 0x0020, // Invalid request; fd not open
645 // XPG4.2 definitions (via _XOPEN_SOURCE)
646 POLLRDNORM = 0x0040, // Normal data bay be read
647 POLLRDBAND = 0x0080, // Priority data may be read
648 POLLWRNORM = 0x0100, // Writing now will not block
649 POLLWRBAND = 0x0200, // Priority data may be written
653 [CLSCompliant (false)]
654 public enum XattrFlags : int {
661 [CLSCompliant (false)]
662 public enum MountFlags : ulong {
663 ST_RDONLY = 1, // Mount read-only
664 ST_NOSUID = 2, // Ignore suid and sgid bits
665 ST_NODEV = 4, // Disallow access to device special files
666 ST_SYNCHRONOUS = 16, // Writes are synced at once
667 ST_MANDLOCK = 64, // Allow mandatory locks on an FS
668 ST_WRITE = 128, // Write on file/directory/symlink
669 ST_APPEND = 256, // Append-only file
670 ST_IMMUTABLE = 512, // Immutable file
671 ST_NOATIME = 1024, // Do not update access times
672 ST_NODIRATIME = 2048, // Do not update directory access times
676 [CLSCompliant (false)]
677 public enum MmapFlags : int {
678 MAP_SHARED = 0x01, // Share changes.
679 MAP_PRIVATE = 0x02, // Changes are private.
680 MAP_TYPE = 0x0f, // Mask for type of mapping.
681 MAP_FIXED = 0x10, // Interpret addr exactly.
683 MAP_ANONYMOUS = 0x20, // Don't use a file.
684 MAP_ANON = MAP_ANONYMOUS,
686 // These are Linux-specific.
687 MAP_GROWSDOWN = 0x00100, // Stack-like segment.
688 MAP_DENYWRITE = 0x00800, // ETXTBSY
689 MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
690 MAP_LOCKED = 0x02000, // Lock the mapping.
691 MAP_NORESERVE = 0x04000, // Don't check for reservations.
692 MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
693 MAP_NONBLOCK = 0x10000, // Do not block on IO.
697 [CLSCompliant (false)]
698 public enum MmapProts : int {
699 PROT_READ = 0x1, // Page can be read.
700 PROT_WRITE = 0x2, // Page can be written.
701 PROT_EXEC = 0x4, // Page can be executed.
702 PROT_NONE = 0x0, // Page can not be accessed.
703 PROT_GROWSDOWN = 0x01000000, // Extend change to start of
704 // growsdown vma (mprotect only).
705 PROT_GROWSUP = 0x02000000, // Extend change to start of
706 // growsup vma (mprotect only).
710 [CLSCompliant (false)]
711 public enum MsyncFlags : int {
712 MS_ASYNC = 0x1, // Sync memory asynchronously.
713 MS_SYNC = 0x4, // Synchronous memory sync.
714 MS_INVALIDATE = 0x2, // Invalidate the caches.
718 [CLSCompliant (false)]
719 public enum MlockallFlags : int {
720 MCL_CURRENT = 0x1, // Lock all currently mapped pages.
721 MCL_FUTURE = 0x2, // Lock all additions to address
725 [CLSCompliant (false)]
726 public enum MremapFlags : ulong {
727 MREMAP_MAYMOVE = 0x1,
734 public struct Flock {
735 [CLSCompliant (false)]
736 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
737 [CLSCompliant (false)]
738 public SeekFlags l_whence; // How to interpret l_start
739 public /* off_t */ long l_start; // Starting offset for lock
740 public /* off_t */ long l_len; // Number of bytes to lock
741 public /* pid_t */ int l_pid; // PID of process blocking our lock (F_GETLK only)
744 [StructLayout(LayoutKind.Sequential)]
745 public struct Pollfd {
747 [CLSCompliant (false)]
748 public PollEvents events;
749 [CLSCompliant (false)]
750 public PollEvents revents;
754 [CLSCompliant (false)]
755 public /* dev_t */ ulong st_dev; // device
756 [CLSCompliant (false)]
757 public /* ino_t */ ulong st_ino; // inode
758 [CLSCompliant (false)]
759 public FilePermissions st_mode; // protection
760 [CLSCompliant (false)]
761 private uint _padding_; // padding for structure alignment
762 [CLSCompliant (false)]
763 public /* nlink_t */ ulong st_nlink; // number of hard links
764 [CLSCompliant (false)]
765 public /* uid_t */ uint st_uid; // user ID of owner
766 [CLSCompliant (false)]
767 public /* gid_t */ uint st_gid; // group ID of owner
768 [CLSCompliant (false)]
769 public /* dev_t */ ulong st_rdev; // device type (if inode device)
770 public /* off_t */ long st_size; // total size, in bytes
771 public /* blksize_t */ long st_blksize; // blocksize for filesystem I/O
772 public /* blkcnt_t */ long st_blocks; // number of blocks allocated
773 public /* time_t */ long st_atime; // time of last access
774 public /* time_t */ long st_mtime; // time of last modification
775 public /* time_t */ long st_ctime; // time of last status change
778 [CLSCompliant (false)]
779 public struct Statvfs {
780 public ulong f_bsize; // file system block size
781 public ulong f_frsize; // fragment size
782 public /* fsblkcnt_t */ ulong f_blocks; // size of fs in f_frsize units
783 public /* fsblkcnt_t */ ulong f_bfree; // # free blocks
784 public /* fsblkcnt_t */ ulong f_bavail; // # free blocks for non-root
785 public /* fsfilcnt_t */ ulong f_files; // # inodes
786 public /* fsfilcnt_t */ ulong f_ffree; // # free inodes
787 public /* fsfilcnt_t */ ulong f_favail; // # free inodes for non-root
788 public ulong f_fsid; // file system id
789 public MountFlags f_flag; // mount flags
790 public ulong f_namemax; // maximum filename length
793 public struct Timeval {
794 public /* time_t */ long tv_sec; // seconds
795 public /* suseconds_t */ long tv_usec; // microseconds
798 public struct Timezone {
799 public int tz_minuteswest; // minutes W of Greenwich
800 private int tz_dsttime; // type of dst correction (OBSOLETE)
803 public struct Utimbuf {
804 public /* time_t */ long actime; // access time
805 public /* time_t */ long modtime; // modification time
812 [CLSCompliant (false)]
813 public sealed class Dirent
815 [CLSCompliant (false)]
816 public /* ino_t */ ulong d_ino;
817 public /* off_t */ long d_off;
818 [CLSCompliant (false)]
819 public ushort d_reclen;
821 public string d_name;
823 public override int GetHashCode ()
825 return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
826 d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
827 d_name.GetHashCode ();
830 public override bool Equals (object obj)
832 if (obj == null || GetType() != obj.GetType())
834 Dirent d = (Dirent) obj;
835 return d.d_ino == d_ino && d.d_off == d_off &&
836 d.d_reclen == d_reclen && d.d_type == d_type &&
840 public override string ToString ()
845 public static bool operator== (Dirent lhs, Dirent rhs)
847 return Object.Equals (lhs, rhs);
850 public static bool operator!= (Dirent lhs, Dirent rhs)
852 return !Object.Equals (lhs, rhs);
856 public sealed class Fstab
858 public string fs_spec;
859 public string fs_file;
860 public string fs_vfstype;
861 public string fs_mntops;
862 public string fs_type;
864 public int fs_passno;
866 public override int GetHashCode ()
868 return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
869 fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
870 fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
873 public override bool Equals (object obj)
875 if (obj == null || GetType() != obj.GetType())
877 Fstab f = (Fstab) obj;
878 return f.fs_spec == fs_spec && f.fs_file == fs_file &&
879 f.fs_vfstype == fs_vfstype && f.fs_mntops == fs_mntops &&
880 f.fs_type == fs_type && f.fs_freq == fs_freq &&
881 f.fs_passno == fs_passno;
884 public override string ToString ()
889 public static bool operator== (Fstab lhs, Fstab rhs)
891 return Object.Equals (lhs, rhs);
894 public static bool operator!= (Fstab lhs, Fstab rhs)
896 return !Object.Equals (lhs, rhs);
900 public sealed class Group
902 public string gr_name;
903 public string gr_passwd;
904 [CLSCompliant (false)]
905 public /* gid_t */ uint gr_gid;
906 public string[] gr_mem;
908 public override int GetHashCode ()
911 for (int i = 0; i < gr_mem.Length; ++i)
912 memhc ^= gr_mem[i].GetHashCode ();
914 return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
915 gr_gid.GetHashCode () ^ memhc;
918 public override bool Equals (object obj)
920 if (obj == null || GetType() != obj.GetType())
922 Group g = (Group) obj;
923 if (g.gr_gid != gr_gid)
925 if (g.gr_gid == gr_gid && g.gr_name == gr_name &&
926 g.gr_passwd == gr_passwd) {
927 if (g.gr_mem == gr_mem)
929 if (g.gr_mem == null || gr_mem == null)
931 if (g.gr_mem.Length != gr_mem.Length)
933 for (int i = 0; i < gr_mem.Length; ++i)
934 if (gr_mem[i] != g.gr_mem[i])
941 // Generate string in /etc/group format
942 public override string ToString ()
944 StringBuilder sb = new StringBuilder ();
945 sb.AppendFormat ("{0}:{1}:{2}:", gr_name, gr_passwd, gr_gid);
946 GetMembers (sb, gr_mem);
947 return sb.ToString ();
950 private static void GetMembers (StringBuilder sb, string[] members)
952 if (members.Length > 0)
953 sb.Append (members[0]);
954 for (int i = 1; i < members.Length; ++i) {
956 sb.Append (members[i]);
960 public static bool operator== (Group lhs, Group rhs)
962 return Object.Equals (lhs, rhs);
965 public static bool operator!= (Group lhs, Group rhs)
967 return !Object.Equals (lhs, rhs);
971 public sealed class Passwd
973 public string pw_name;
974 public string pw_passwd;
975 [CLSCompliant (false)]
976 public /* uid_t */ uint pw_uid;
977 [CLSCompliant (false)]
978 public /* gid_t */ uint pw_gid;
979 public string pw_gecos;
980 public string pw_dir;
981 public string pw_shell;
983 public override int GetHashCode ()
985 return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
986 pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
987 pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
988 pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
991 public override bool Equals (object obj)
993 if (obj == null || GetType() != obj.GetType())
995 Passwd p = (Passwd) obj;
996 return p.pw_uid == pw_uid && p.pw_gid == pw_gid && p.pw_name == pw_name &&
997 p.pw_passwd == pw_passwd && p.pw_gecos == pw_gecos &&
998 p.pw_dir == pw_dir && p.pw_shell == pw_shell;
1001 // Generate string in /etc/passwd format
1002 public override string ToString ()
1004 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
1005 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
1008 public static bool operator== (Passwd lhs, Passwd rhs)
1010 return Object.Equals (lhs, rhs);
1013 public static bool operator!= (Passwd lhs, Passwd rhs)
1015 return !Object.Equals (lhs, rhs);
1020 // Convention: Functions *not* part of the standard C library AND part of
1021 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
1023 // For example, the man page should be similar to:
1025 // CONFORMING TO (or CONFORMS TO)
1026 // XPG2, SUSv2, POSIX, etc.
1028 // BSD- and GNU-specific exports can also be placed here.
1030 // Non-POSIX/XPG/etc. functions can also be placed here if:
1031 // (a) They'd be likely to be covered in a Steven's-like book
1032 // (b) The functions would be present in libc.so (or equivalent).
1034 // If a function has its own library, that's a STRONG indicator that the
1035 // function should get a different binding, probably in its own assembly,
1036 // so that package management can work sanely. (That is, we'd like to avoid
1037 // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
1038 // run, and libFooLib.so doesn't exist. That would be confusing.)
1040 // The only methods in here should be:
1041 // (1) low-level functions
1042 // (2) "Trivial" function overloads. For example, if the parameters to a
1043 // function are related (e.g. getgroups(2))
1044 // (3) The return type SHOULD NOT be changed. If you want to provide a
1045 // convenience function with a nicer return type, place it into one of
1046 // the Mono.Unix.Unix* wrapper classes, and give it a .NET-styled name.
1047 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
1048 // - If you're wrapping *broken* methods which make assumptions about
1049 // input data, such as that an argument refers to N bytes of data.
1050 // This is currently limited to cuserid(3) and encrypt(3).
1051 // - If you call functions which themselves generate exceptions.
1052 // This is the case for using NativeConvert, which will throw an
1053 // exception if an invalid/unsupported value is used.
1055 // Naming Conventions:
1056 // - Syscall method names should have the same name as the function being
1057 // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
1058 // consult the appropriate man page if necessary.
1059 // - Methods need not have the same arguments IF this simplifies or
1060 // permits correct usage. The current example is syslog, in which
1061 // syslog(3)'s single `priority' argument is split into SyslogFacility
1062 // and SyslogLevel arguments.
1063 // - Type names (structures, classes, enumerations) are always PascalCased.
1064 // - Enumerations are named as <MethodName><ArgumentName>, and are located
1065 // in the Mono.Unix namespace. For readability, if ArgumentName is
1066 // "cmd", use Command instead. For example, fcntl(2) takes a
1067 // FcntlCommand argument. This naming convention is to provide an
1068 // assocation between an enumeration and where it should be used, and
1069 // allows a single method to accept multiple different enumerations
1070 // (see mmap(2), which takes MmapProts and MmapFlags).
1071 // - EXCEPTION: if an enumeration is shared between multiple different
1072 // methods, AND/OR the "obvious" enumeration name conflicts with an
1073 // existing .NET type, a more appropriate name should be used.
1074 // Example: FilePermissions
1075 // - EXCEPTION: [Flags] enumerations should get plural names to follow
1076 // .NET name guidelines. Usually this doesn't result in a change
1077 // (OpenFlags is the `flags' parameter for open(2)), but it can
1078 // (mmap(2) prot ==> MmapProts, access(2) mode ==> AccessModes).
1079 // - Enumerations should have the [Map] and (optional) [Flags] attributes.
1080 // [Map] is required for make-map to find the type and generate the
1081 // appropriate NativeConvert conversion functions.
1082 // - Enumeration contents should match the original Unix names. This helps
1083 // with documentation (the existing man pages are still useful), and is
1084 // required for use with the make-map generation program.
1085 // - Structure names should be the PascalCased version of the actual
1086 // structure name (struct flock ==> Flock). Structure members should
1087 // have the same names, or a (reasonably) portable subset (Dirent being
1088 // the poster child for questionable members).
1089 // - Whether the managed type should be a reference type (class) or a
1090 // value type (struct) should be determined on a case-by-case basis:
1091 // if you ever need to be able to use NULL for it (such as with Dirent,
1092 // Group, Passwd, as these are method return types and `null' is used
1093 // to signify the end), it should be a reference type; otherwise, use
1094 // your discretion, and keep any expected usage patterns in mind.
1095 // - Syscall should be a Single Point Of Truth (SPOT). There should be
1096 // only ONE way to do anything. By convention, the Linux function names
1097 // are used, but that need not always be the case (use your discretion).
1098 // It SHOULD NOT be required that developers know what platform they're
1099 // on, and choose among a set of similar functions. In short, anything
1100 // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
1101 // we can afford to clean things up whenever possible.
1103 // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
1104 // statvfs(2). MonoPosixHelper will "thunk" between the two,
1105 // exporting a statvfs that works across platforms.
1106 // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
1107 // instead provides getvfsent(3). MonoPosixHelper provides wrappers
1108 // to convert getvfsent(3) into Fstab data.
1109 // - Exception: If it isn't possible to cleanly wrap platforms, then the
1110 // method shouldn't be exported. The user will be expected to do their
1111 // own platform check and their own DllImports.
1112 // Examples: mount(2), umount(2), etc.
1113 // - Note: if a platform doesn't support a function AT ALL, the
1114 // MonoPosixHelper wrapper won't be compiled, resulting in a
1115 // EntryPointNotFoundException. This is also consistent with a missing
1116 // P/Invoke into libc.so.
1118 [CLSCompliant (false)]
1119 public sealed class Syscall : Stdlib
1121 new internal const string LIBC = "libc";
1122 private const string CRYPT = "crypt";
1124 private Syscall () {}
1130 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
1131 // aio_return(3), aio_suspend(3), aio_write(3)
1133 // Then update UnixStream.BeginRead to use the aio* functions.
1136 #region <attr/xattr.h> Declarations
1138 // <attr/xattr.h> -- COMPLETE
1142 // int setxattr (const char *path, const char *name,
1143 // const void *value, size_t size, int flags);
1144 [DllImport (MPH, SetLastError=true,
1145 EntryPoint="Mono_Posix_Syscall_setxattr")]
1146 public static extern int setxattr (string path, string name, byte[] value, ulong size, XattrFlags flags);
1148 public static int setxattr (string path, string name, byte [] value, ulong size)
1150 return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1153 public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
1155 return setxattr (path, name, value, (ulong) value.Length, flags);
1158 public static int setxattr (string path, string name, byte [] value)
1160 return setxattr (path, name, value, (ulong) value.Length);
1164 // int lsetxattr (const char *path, const char *name,
1165 // const void *value, size_t size, int flags);
1166 [DllImport (MPH, SetLastError=true,
1167 EntryPoint="Mono_Posix_Syscall_lsetxattr")]
1168 public static extern int lsetxattr (string path, string name, byte[] value, ulong size, XattrFlags flags);
1170 public static int lsetxattr (string path, string name, byte [] value, ulong size)
1172 return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1175 public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
1177 return lsetxattr (path, name, value, (ulong) value.Length, flags);
1180 public static int lsetxattr (string path, string name, byte [] value)
1182 return lsetxattr (path, name, value, (ulong) value.Length);
1186 // int fsetxattr (int fd, const char *name,
1187 // const void *value, size_t size, int flags);
1188 [DllImport (MPH, SetLastError=true,
1189 EntryPoint="Mono_Posix_Syscall_fsetxattr")]
1190 public static extern int fsetxattr (int fd, string name, byte[] value, ulong size, XattrFlags flags);
1192 public static int fsetxattr (int fd, string name, byte [] value, ulong size)
1194 return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
1197 public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
1199 return fsetxattr (fd, name, value, (ulong) value.Length, flags);
1202 public static int fsetxattr (int fd, string name, byte [] value)
1204 return fsetxattr (fd, name, value, (ulong) value.Length);
1208 // ssize_t getxattr (const char *path, const char *name,
1209 // void *value, size_t size);
1210 [DllImport (MPH, SetLastError=true,
1211 EntryPoint="Mono_Posix_Syscall_getxattr")]
1212 public static extern long getxattr (string path, string name, byte[] value, ulong size);
1214 public static long getxattr (string path, string name, byte [] value)
1216 return getxattr (path, name, value, (ulong) value.Length);
1219 public static long getxattr (string path, string name, out byte [] value)
1222 long size = getxattr (path, name, value, 0);
1226 value = new byte [size];
1227 return getxattr (path, name, value, (ulong) size);
1231 // ssize_t lgetxattr (const char *path, const char *name,
1232 // void *value, size_t size);
1233 [DllImport (MPH, SetLastError=true,
1234 EntryPoint="Mono_Posix_Syscall_lgetxattr")]
1235 public static extern long lgetxattr (string path, string name, byte[] value, ulong size);
1237 public static long lgetxattr (string path, string name, byte [] value)
1239 return lgetxattr (path, name, value, (ulong) value.Length);
1242 public static long lgetxattr (string path, string name, out byte [] value)
1245 long size = lgetxattr (path, name, value, 0);
1249 value = new byte [size];
1250 return lgetxattr (path, name, value, (ulong) size);
1254 // ssize_t fgetxattr (int fd, const char *name, void *value, size_t size);
1255 [DllImport (MPH, SetLastError=true,
1256 EntryPoint="Mono_Posix_Syscall_fgetxattr")]
1257 public static extern long fgetxattr (int fd, string name, byte[] value, ulong size);
1259 public static long fgetxattr (int fd, string name, byte [] value)
1261 return fgetxattr (fd, name, value, (ulong) value.Length);
1264 public static long fgetxattr (int fd, string name, out byte [] value)
1267 long size = fgetxattr (fd, name, value, 0);
1271 value = new byte [size];
1272 return fgetxattr (fd, name, value, (ulong) size);
1276 // ssize_t listxattr (const char *path, char *list, size_t size);
1277 [DllImport (MPH, SetLastError=true,
1278 EntryPoint="Mono_Posix_Syscall_listxattr")]
1279 public static extern long listxattr (string path, byte[] list, ulong size);
1281 // Slight modification: returns 0 on success, negative on error
1282 public static long listxattr (string path, Encoding encoding, out string [] values)
1285 long size = listxattr (path, null, 0);
1287 values = new string [0];
1291 byte[] list = new byte [size];
1292 long ret = listxattr (path, list, (ulong) size);
1296 string [] output = encoding.GetString (list).Split((char) 0);
1297 values = new string [output.Length - 1];
1298 Array.Copy (output, 0, values, 0, output.Length - 1);
1303 // ssize_t llistxattr (const char *path, char *list, size_t size);
1304 [DllImport (MPH, SetLastError=true,
1305 EntryPoint="Mono_Posix_Syscall_llistxattr")]
1306 public static extern long llistxattr (string path, byte[] list, ulong size);
1308 // Slight modification: returns 0 on success, negative on error
1309 public static long llistxattr (string path, Encoding encoding, out string [] values)
1312 long size = llistxattr (path, null, 0);
1314 values = new string [0];
1318 byte[] list = new byte [size];
1319 long ret = llistxattr (path, list, (ulong) size);
1323 string [] output = encoding.GetString (list).Split((char) 0);
1324 values = new string [output.Length - 1];
1325 Array.Copy (output, 0, values, 0, output.Length - 1);
1330 // ssize_t flistxattr (int fd, char *list, size_t size);
1331 [DllImport (MPH, SetLastError=true,
1332 EntryPoint="Mono_Posix_Syscall_flistxattr")]
1333 public static extern long flistxattr (int fd, byte[] list, ulong size);
1335 // Slight modification: returns 0 on success, negative on error
1336 public static long flistxattr (int fd, Encoding encoding, out string [] values)
1339 long size = flistxattr (fd, null, 0);
1341 values = new string [0];
1345 byte[] list = new byte [size];
1346 long ret = flistxattr (fd, list, (ulong) size);
1350 string [] output = encoding.GetString (list).Split((char) 0);
1351 values = new string [output.Length - 1];
1352 Array.Copy (output, 0, values, 0, output.Length - 1);
1356 [DllImport (MPH, SetLastError=true,
1357 EntryPoint="Mono_Posix_Syscall_removexattr")]
1358 public static extern int removexattr (string path, string name);
1360 [DllImport (MPH, SetLastError=true,
1361 EntryPoint="Mono_Posix_Syscall_lremovexattr")]
1362 public static extern int lremovexattr (string path, string name);
1364 [DllImport (MPH, SetLastError=true,
1365 EntryPoint="Mono_Posix_Syscall_fremovexattr")]
1366 public static extern int fremovexattr (int fd, string name);
1369 #region <dirent.h> Declarations
1373 // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
1375 [DllImport (LIBC, SetLastError=true)]
1376 public static extern IntPtr opendir (string name);
1378 [DllImport (LIBC, SetLastError=true)]
1379 public static extern int closedir (IntPtr dir);
1382 // void seekdir (DIR *dir, off_t offset);
1383 // Slight modification. Returns -1 on error, 0 on success.
1384 [DllImport (MPH, SetLastError=true,
1385 EntryPoint="Mono_Posix_Syscall_seekdir")]
1386 public static extern int seekdir (IntPtr dir, long offset);
1389 // off_t telldir(DIR *dir);
1390 [DllImport (MPH, SetLastError=true,
1391 EntryPoint="Mono_Posix_Syscall_telldir")]
1392 public static extern long telldir (IntPtr dir);
1394 [DllImport (MPH, SetLastError=true,
1395 EntryPoint="Mono_Posix_Syscall_rewinddir")]
1396 public static extern int rewinddir (IntPtr dir);
1398 private struct _Dirent {
1399 public /* ino_t */ ulong d_ino;
1400 public /* off_t */ long d_off;
1401 public ushort d_reclen;
1403 public IntPtr d_name;
1406 private static void CopyDirent (Dirent to, ref _Dirent from)
1409 to.d_ino = from.d_ino;
1410 to.d_off = from.d_off;
1411 to.d_reclen = from.d_reclen;
1412 to.d_type = from.d_type;
1413 to.d_name = UnixMarshal.PtrToString (from.d_name);
1416 Stdlib.free (from.d_name);
1417 from.d_name = IntPtr.Zero;
1421 [DllImport (MPH, SetLastError=true,
1422 EntryPoint="Mono_Posix_Syscall_readdir")]
1423 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
1425 public static Dirent readdir (IntPtr dir)
1428 int r = sys_readdir (dir, out dentry);
1431 Dirent d = new Dirent ();
1432 CopyDirent (d, ref dentry);
1436 [DllImport (MPH, SetLastError=true,
1437 EntryPoint="Mono_Posix_Syscall_readdir_r")]
1438 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
1440 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
1446 entry.d_name = null;
1449 int r = sys_readdir_r (dirp, out _d, out result);
1451 if (r == 0 && result != IntPtr.Zero) {
1452 CopyDirent (entry, ref _d);
1458 [DllImport (LIBC, SetLastError=true)]
1459 public static extern int dirfd (IntPtr dir);
1462 #region <fcntl.h> Declarations
1464 // <fcntl.h> -- COMPLETE
1467 [DllImport (MPH, SetLastError=true,
1468 EntryPoint="Mono_Posix_Syscall_fcntl")]
1469 public static extern int fcntl (int fd, FcntlCommand cmd);
1471 [DllImport (MPH, SetLastError=true,
1472 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
1473 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
1475 public static int fcntl (int fd, FcntlCommand cmd, DirectoryNotifyFlags arg)
1477 if (cmd != FcntlCommand.F_NOTIFY) {
1478 SetLastError (Errno.EINVAL);
1481 long _arg = NativeConvert.FromDirectoryNotifyFlags (arg);
1482 return fcntl (fd, FcntlCommand.F_NOTIFY, _arg);
1485 [DllImport (MPH, SetLastError=true,
1486 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
1487 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
1489 [DllImport (MPH, SetLastError=true,
1490 EntryPoint="Mono_Posix_Syscall_open")]
1491 public static extern int open (string pathname, OpenFlags flags);
1494 // int open(const char *pathname, int flags, mode_t mode);
1495 [DllImport (MPH, SetLastError=true,
1496 EntryPoint="Mono_Posix_Syscall_open_mode")]
1497 public static extern int open (string pathname, OpenFlags flags, FilePermissions mode);
1500 // int creat(const char *pathname, mode_t mode);
1501 [DllImport (MPH, SetLastError=true,
1502 EntryPoint="Mono_Posix_Syscall_creat")]
1503 public static extern int creat (string pathname, FilePermissions mode);
1506 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
1507 [DllImport (MPH, SetLastError=true,
1508 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
1509 public static extern int posix_fadvise (int fd, long offset,
1510 long len, PosixFadviseAdvice advice);
1512 // posix_fallocate(P)
1513 // int posix_fallocate(int fd, off_t offset, size_t len);
1514 [DllImport (MPH, SetLastError=true,
1515 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
1516 public static extern int posix_fallocate (int fd, long offset, ulong len);
1519 #region <fstab.h> Declarations
1521 // <fstab.h> -- COMPLETE
1523 private struct _Fstab {
1524 public IntPtr fs_spec;
1525 public IntPtr fs_file;
1526 public IntPtr fs_vfstype;
1527 public IntPtr fs_mntops;
1528 public IntPtr fs_type;
1530 public int fs_passno;
1531 public IntPtr _fs_buf_;
1534 private static void CopyFstab (Fstab to, ref _Fstab from)
1537 to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
1538 to.fs_file = UnixMarshal.PtrToString (from.fs_file);
1539 to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
1540 to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
1541 to.fs_type = UnixMarshal.PtrToString (from.fs_type);
1542 to.fs_freq = from.fs_freq;
1543 to.fs_passno = from.fs_passno;
1546 Stdlib.free (from._fs_buf_);
1547 from._fs_buf_ = IntPtr.Zero;
1551 internal static object fstab_lock = new object ();
1553 [DllImport (MPH, SetLastError=true,
1554 EntryPoint="Mono_Posix_Syscall_endfsent")]
1555 private static extern int sys_endfsent ();
1557 public static int endfsent ()
1560 return sys_endfsent ();
1564 [DllImport (MPH, SetLastError=true,
1565 EntryPoint="Mono_Posix_Syscall_getfsent")]
1566 private static extern int sys_getfsent (out _Fstab fs);
1568 public static Fstab getfsent ()
1573 r = sys_getfsent (out fsbuf);
1577 Fstab fs = new Fstab ();
1578 CopyFstab (fs, ref fsbuf);
1582 [DllImport (MPH, SetLastError=true,
1583 EntryPoint="Mono_Posix_Syscall_getfsfile")]
1584 private static extern int sys_getfsfile (string mount_point, out _Fstab fs);
1586 public static Fstab getfsfile (string mount_point)
1591 r = sys_getfsfile (mount_point, out fsbuf);
1595 Fstab fs = new Fstab ();
1596 CopyFstab (fs, ref fsbuf);
1600 [DllImport (MPH, SetLastError=true,
1601 EntryPoint="Mono_Posix_Syscall_getfsspec")]
1602 private static extern int sys_getfsspec (string special_file, out _Fstab fs);
1604 public static Fstab getfsspec (string special_file)
1609 r = sys_getfsspec (special_file, out fsbuf);
1613 Fstab fs = new Fstab ();
1614 CopyFstab (fs, ref fsbuf);
1618 [DllImport (MPH, SetLastError=true,
1619 EntryPoint="Mono_Posix_Syscall_setfsent")]
1620 private static extern int sys_setfsent ();
1622 public static int setfsent ()
1625 return sys_setfsent ();
1631 #region <grp.h> Declarations
1635 // TODO: putgrent(3), fgetgrent_r(), getgrouplist(2), initgroups(3)
1638 // int setgroups (size_t size, const gid_t *list);
1639 [DllImport (MPH, SetLastError=true,
1640 EntryPoint="Mono_Posix_Syscall_setgroups")]
1641 public static extern int setgroups (ulong size, uint[] list);
1643 public static int setgroups (uint [] list)
1645 return setgroups ((ulong) list.Length, list);
1648 private struct _Group
1650 public IntPtr gr_name;
1651 public IntPtr gr_passwd;
1652 public /* gid_t */ uint gr_gid;
1653 public int _gr_nmem_;
1654 public IntPtr gr_mem;
1655 public IntPtr _gr_buf_;
1658 private static void CopyGroup (Group to, ref _Group from)
1661 to.gr_gid = from.gr_gid;
1662 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
1663 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
1664 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
1667 Stdlib.free (from.gr_mem);
1668 Stdlib.free (from._gr_buf_);
1669 from.gr_mem = IntPtr.Zero;
1670 from._gr_buf_ = IntPtr.Zero;
1674 internal static object grp_lock = new object ();
1676 [DllImport (MPH, SetLastError=true,
1677 EntryPoint="Mono_Posix_Syscall_getgrnam")]
1678 private static extern int sys_getgrnam (string name, out _Group group);
1680 public static Group getgrnam (string name)
1685 r = sys_getgrnam (name, out group);
1689 Group gr = new Group ();
1690 CopyGroup (gr, ref group);
1695 // struct group *getgrgid(gid_t gid);
1696 [DllImport (MPH, SetLastError=true,
1697 EntryPoint="Mono_Posix_Syscall_getgrgid")]
1698 private static extern int sys_getgrgid (uint uid, out _Group group);
1700 public static Group getgrgid (uint uid)
1705 r = sys_getgrgid (uid, out group);
1709 Group gr = new Group ();
1710 CopyGroup (gr, ref group);
1714 [DllImport (MPH, SetLastError=true,
1715 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
1716 private static extern int sys_getgrnam_r (string name, out _Group grbuf, out IntPtr grbufp);
1718 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
1723 int r = sys_getgrnam_r (name, out group, out _grbufp);
1724 if (r == 0 && _grbufp != IntPtr.Zero) {
1725 CopyGroup (grbuf, ref group);
1732 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
1733 // size_t buflen, struct group **gbufp);
1734 [DllImport (MPH, SetLastError=true,
1735 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
1736 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
1738 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
1743 int r = sys_getgrgid_r (uid, out group, out _grbufp);
1744 if (r == 0 && _grbufp != IntPtr.Zero) {
1745 CopyGroup (grbuf, ref group);
1751 [DllImport (MPH, SetLastError=true,
1752 EntryPoint="Mono_Posix_Syscall_getgrent")]
1753 private static extern int sys_getgrent (out _Group grbuf);
1755 public static Group getgrent ()
1760 r = sys_getgrent (out group);
1764 Group gr = new Group();
1765 CopyGroup (gr, ref group);
1769 [DllImport (MPH, SetLastError=true,
1770 EntryPoint="Mono_Posix_Syscall_setgrent")]
1771 private static extern int sys_setgrent ();
1773 public static int setgrent ()
1776 return sys_setgrent ();
1780 [DllImport (MPH, SetLastError=true,
1781 EntryPoint="Mono_Posix_Syscall_endgrent")]
1782 private static extern int sys_endgrent ();
1784 public static int endgrent ()
1787 return sys_endgrent ();
1791 [DllImport (MPH, SetLastError=true,
1792 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
1793 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
1795 public static Group fgetgrent (IntPtr stream)
1800 r = sys_fgetgrent (stream, out group);
1804 Group gr = new Group ();
1805 CopyGroup (gr, ref group);
1810 #region <pwd.h> Declarations
1814 // TODO: putpwent(3), fgetpwent_r()
1816 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
1818 private struct _Passwd
1820 public IntPtr pw_name;
1821 public IntPtr pw_passwd;
1822 public /* uid_t */ uint pw_uid;
1823 public /* gid_t */ uint pw_gid;
1824 public IntPtr pw_gecos;
1825 public IntPtr pw_dir;
1826 public IntPtr pw_shell;
1827 public IntPtr _pw_buf_;
1830 private static void CopyPasswd (Passwd to, ref _Passwd from)
1833 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
1834 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
1835 to.pw_uid = from.pw_uid;
1836 to.pw_gid = from.pw_gid;
1837 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
1838 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
1839 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
1842 Stdlib.free (from._pw_buf_);
1843 from._pw_buf_ = IntPtr.Zero;
1847 internal static object pwd_lock = new object ();
1849 [DllImport (MPH, SetLastError=true,
1850 EntryPoint="Mono_Posix_Syscall_getpwnam")]
1851 private static extern int sys_getpwnam (string name, out _Passwd passwd);
1853 public static Passwd getpwnam (string name)
1858 r = sys_getpwnam (name, out passwd);
1862 Passwd pw = new Passwd ();
1863 CopyPasswd (pw, ref passwd);
1868 // struct passwd *getpwnuid(uid_t uid);
1869 [DllImport (MPH, SetLastError=true,
1870 EntryPoint="Mono_Posix_Syscall_getpwuid")]
1871 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
1873 public static Passwd getpwuid (uint uid)
1878 r = sys_getpwuid (uid, out passwd);
1882 Passwd pw = new Passwd ();
1883 CopyPasswd (pw, ref passwd);
1887 [DllImport (MPH, SetLastError=true,
1888 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
1889 private static extern int sys_getpwnam_r (string name, out _Passwd pwbuf, out IntPtr pwbufp);
1891 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
1896 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
1897 if (r == 0 && _pwbufp != IntPtr.Zero) {
1898 CopyPasswd (pwbuf, ref passwd);
1905 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
1906 // buflen, struct passwd **pwbufp);
1907 [DllImport (MPH, SetLastError=true,
1908 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
1909 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
1911 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
1916 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
1917 if (r == 0 && _pwbufp != IntPtr.Zero) {
1918 CopyPasswd (pwbuf, ref passwd);
1924 [DllImport (MPH, SetLastError=true,
1925 EntryPoint="Mono_Posix_Syscall_getpwent")]
1926 private static extern int sys_getpwent (out _Passwd pwbuf);
1928 public static Passwd getpwent ()
1933 r = sys_getpwent (out passwd);
1937 Passwd pw = new Passwd ();
1938 CopyPasswd (pw, ref passwd);
1942 [DllImport (MPH, SetLastError=true,
1943 EntryPoint="Mono_Posix_Syscall_setpwent")]
1944 private static extern int sys_setpwent ();
1946 public static int setpwent ()
1949 return sys_setpwent ();
1953 [DllImport (MPH, SetLastError=true,
1954 EntryPoint="Mono_Posix_Syscall_endpwent")]
1955 private static extern int sys_endpwent ();
1957 public static int endpwent ()
1960 return sys_endpwent ();
1964 [DllImport (MPH, SetLastError=true,
1965 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
1966 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
1968 public static Passwd fgetpwent (IntPtr stream)
1973 r = sys_fgetpwent (stream, out passwd);
1977 Passwd pw = new Passwd ();
1978 CopyPasswd (pw, ref passwd);
1983 #region <signal.h> Declarations
1987 [DllImport (MPH, SetLastError=true,
1988 EntryPoint="Mono_Posix_Syscall_psignal")]
1989 private static extern int psignal (int sig, string s);
1991 public static int psignal (Signum sig, string s)
1993 int signum = NativeConvert.FromSignum (sig);
1994 return psignal (signum, s);
1998 // int kill(pid_t pid, int sig);
1999 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
2000 private static extern int sys_kill (int pid, int sig);
2002 public static int kill (int pid, Signum sig)
2004 int _sig = NativeConvert.FromSignum (sig);
2005 return sys_kill (pid, _sig);
2008 private static object signal_lock = new object ();
2010 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
2011 private static extern IntPtr sys_strsignal (int sig);
2013 public static string strsignal (Signum sig)
2015 int s = NativeConvert.FromSignum (sig);
2016 lock (signal_lock) {
2017 IntPtr r = sys_strsignal (s);
2018 return UnixMarshal.PtrToString (r);
2022 // TODO: sigaction(2)
2023 // TODO: sigsuspend(2)
2024 // TODO: sigpending(2)
2028 #region <stdio.h> Declarations
2032 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
2033 private static extern int _L_ctermid ();
2035 public static readonly int L_ctermid = _L_ctermid ();
2037 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
2038 private static extern int _L_cuserid ();
2040 public static readonly int L_cuserid = _L_cuserid ();
2042 internal static object getlogin_lock = new object ();
2044 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
2045 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
2047 [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
2048 "DO NOT USE cuserid().\n" +
2049 "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
2050 public static string cuserid (StringBuilder @string)
2052 if (@string.Capacity < L_cuserid) {
2053 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
2055 lock (getlogin_lock) {
2056 IntPtr r = sys_cuserid (@string);
2057 return UnixMarshal.PtrToString (r);
2063 #region <stdlib.h> Declarations
2067 [DllImport (LIBC, SetLastError=true)]
2068 public static extern int mkstemp (StringBuilder template);
2070 [DllImport (LIBC, SetLastError=true)]
2071 public static extern int ttyslot ();
2073 [DllImport (MPH, SetLastError=true,
2074 EntryPoint="Mono_Posix_Syscall_setkey")]
2075 public static extern int setkey (string key);
2079 #region <string.h> Declarations
2085 // int strerror_r(int errnum, char *buf, size_t n);
2086 [DllImport (MPH, SetLastError=true,
2087 EntryPoint="Mono_Posix_Syscall_strerror_r")]
2088 private static extern int sys_strerror_r (int errnum,
2089 [Out] StringBuilder buf, ulong n);
2091 public static int strerror_r (Errno errnum, StringBuilder buf, ulong n)
2093 int e = NativeConvert.FromErrno (errnum);
2094 return sys_strerror_r (e, buf, n);
2097 public static int strerror_r (Errno errnum, StringBuilder buf)
2099 return strerror_r (errnum, buf, (ulong) buf.Capacity);
2104 #region <sys/mman.h> Declarations
2110 // int posix_madvise(void *addr, size_t len, int advice);
2111 [DllImport (MPH, SetLastError=true,
2112 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
2113 public static extern int posix_madvise (IntPtr addr, ulong len,
2114 PosixMadviseAdvice advice);
2116 public static readonly IntPtr MAP_FAILED = unchecked((IntPtr)(-1));
2118 [DllImport (MPH, SetLastError=true,
2119 EntryPoint="Mono_Posix_Syscall_mmap")]
2120 public static extern IntPtr mmap (IntPtr start, ulong length,
2121 MmapProts prot, MmapFlags flags, int fd, long offset);
2123 [DllImport (MPH, SetLastError=true,
2124 EntryPoint="Mono_Posix_Syscall_munmap")]
2125 public static extern int munmap (IntPtr start, ulong length);
2127 [DllImport (MPH, SetLastError=true,
2128 EntryPoint="Mono_Posix_Syscall_mprotect")]
2129 public static extern int mprotect (IntPtr start, ulong len, MmapProts prot);
2131 [DllImport (MPH, SetLastError=true,
2132 EntryPoint="Mono_Posix_Syscall_msync")]
2133 public static extern int msync (IntPtr start, ulong len, MsyncFlags flags);
2135 [DllImport (MPH, SetLastError=true,
2136 EntryPoint="Mono_Posix_Syscall_mlock")]
2137 public static extern int mlock (IntPtr start, ulong len);
2139 [DllImport (MPH, SetLastError=true,
2140 EntryPoint="Mono_Posix_Syscall_munlock")]
2141 public static extern int munlock (IntPtr start, ulong len);
2143 [DllImport (LIBC, SetLastError=true, EntryPoint="mlockall")]
2144 private static extern int sys_mlockall (int flags);
2146 public static int mlockall (MlockallFlags flags)
2148 int _flags = NativeConvert.FromMlockallFlags (flags);
2149 return sys_mlockall (_flags);
2152 [DllImport (LIBC, SetLastError=true)]
2153 public static extern int munlockall ();
2155 [DllImport (MPH, SetLastError=true,
2156 EntryPoint="Mono_Posix_Syscall_mremap")]
2157 public static extern IntPtr mremap (IntPtr old_address, ulong old_size,
2158 ulong new_size, MremapFlags flags);
2160 [DllImport (MPH, SetLastError=true,
2161 EntryPoint="Mono_Posix_Syscall_mincore")]
2162 public static extern int mincore (IntPtr start, ulong length, byte[] vec);
2164 [DllImport (MPH, SetLastError=true,
2165 EntryPoint="Mono_Posix_Syscall_remap_file_pages")]
2166 public static extern int remap_file_pages (IntPtr start, ulong size,
2167 MmapProts prot, long pgoff, MmapFlags flags);
2171 #region <sys/poll.h> Declarations
2173 // <sys/poll.h> -- COMPLETE
2176 private struct _pollfd {
2178 public short events;
2179 public short revents;
2182 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
2183 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
2185 public static int poll (Pollfd [] fds, uint nfds, int timeout)
2187 if (fds.Length < nfds)
2188 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
2190 _pollfd[] send = new _pollfd[nfds];
2192 for (int i = 0; i < send.Length; i++) {
2193 send [i].fd = fds [i].fd;
2194 send [i].events = NativeConvert.FromPollEvents (fds [i].events);
2197 int r = sys_poll (send, nfds, timeout);
2199 for (int i = 0; i < send.Length; i++) {
2200 fds [i].revents = NativeConvert.ToPollEvents (send [i].revents);
2206 public static int poll (Pollfd [] fds, int timeout)
2208 return poll (fds, (uint) fds.Length, timeout);
2221 // TODO: setrlimit(2)
2222 // TODO: getrlimit(2)
2223 // TODO: getrusage(2)
2227 #region <sys/sendfile.h> Declarations
2229 // <sys/sendfile.h> -- COMPLETE
2232 [DllImport (MPH, SetLastError=true,
2233 EntryPoint="Mono_Posix_Syscall_sendfile")]
2234 public static extern long sendfile (int out_fd, int in_fd,
2235 ref long offset, ulong count);
2239 #region <sys/stat.h> Declarations
2241 // <sys/stat.h> -- COMPLETE
2243 [DllImport (MPH, SetLastError=true,
2244 EntryPoint="Mono_Posix_Syscall_stat")]
2245 public static extern int stat (string file_name, out Stat buf);
2247 [DllImport (MPH, SetLastError=true,
2248 EntryPoint="Mono_Posix_Syscall_fstat")]
2249 public static extern int fstat (int filedes, out Stat buf);
2251 [DllImport (MPH, SetLastError=true,
2252 EntryPoint="Mono_Posix_Syscall_lstat")]
2253 public static extern int lstat (string file_name, out Stat buf);
2256 // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
2257 // All take FilePermissions
2260 // int chmod(const char *path, mode_t mode);
2261 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
2262 private static extern int sys_chmod (string path, uint mode);
2264 public static int chmod (string path, FilePermissions mode)
2266 uint _mode = NativeConvert.FromFilePermissions (mode);
2267 return sys_chmod (path, _mode);
2271 // int chmod(int filedes, mode_t mode);
2272 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
2273 private static extern int sys_fchmod (int filedes, uint mode);
2275 public static int fchmod (int filedes, FilePermissions mode)
2277 uint _mode = NativeConvert.FromFilePermissions (mode);
2278 return sys_fchmod (filedes, _mode);
2282 // mode_t umask(mode_t mask);
2283 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
2284 private static extern uint sys_umask (uint mask);
2286 public static FilePermissions umask (FilePermissions mask)
2288 uint _mask = NativeConvert.FromFilePermissions (mask);
2289 uint r = sys_umask (_mask);
2290 return NativeConvert.ToFilePermissions (r);
2294 // int mkdir(const char *pathname, mode_t mode);
2295 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
2296 private static extern int sys_mkdir (string oldpath, uint mode);
2298 public static int mkdir (string oldpath, FilePermissions mode)
2300 uint _mode = NativeConvert.FromFilePermissions (mode);
2301 return sys_mkdir (oldpath, _mode);
2305 // int mknod (const char *pathname, mode_t mode, dev_t dev);
2306 [DllImport (MPH, SetLastError=true,
2307 EntryPoint="Mono_Posix_Syscall_mknod")]
2308 public static extern int mknod (string pathname, FilePermissions mode, ulong dev);
2311 // int mkfifo(const char *pathname, mode_t mode);
2312 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
2313 private static extern int sys_mkfifo (string pathname, uint mode);
2315 public static int mkfifo (string pathname, FilePermissions mode)
2317 uint _mode = NativeConvert.FromFilePermissions (mode);
2318 return sys_mkfifo (pathname, _mode);
2323 #region <sys/stat.h> Declarations
2328 [DllImport (MPH, SetLastError=true,
2329 EntryPoint="Mono_Posix_Syscall_statvfs")]
2330 public static extern int statvfs (string path, out Statvfs buf);
2332 [DllImport (MPH, SetLastError=true,
2333 EntryPoint="Mono_Posix_Syscall_fstatvfs")]
2334 public static extern int fstatvfs (int fd, out Statvfs buf);
2338 #region <sys/time.h> Declarations
2342 // TODO: adjtime(), getitimer(2), setitimer(2), lutimes(), futimes()
2344 [DllImport (MPH, SetLastError=true,
2345 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2346 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
2348 [DllImport (MPH, SetLastError=true,
2349 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2350 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
2352 public static int gettimeofday (out Timeval tv)
2354 return gettimeofday (out tv, IntPtr.Zero);
2357 [DllImport (MPH, SetLastError=true,
2358 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2359 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
2361 public static int gettimeofday (out Timezone tz)
2363 return gettimeofday (IntPtr.Zero, out tz);
2366 [DllImport (MPH, SetLastError=true,
2367 EntryPoint="Mono_Posix_Syscall_settimeofday")]
2368 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
2370 [DllImport (MPH, SetLastError=true,
2371 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2372 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
2374 public static int settimeofday (ref Timeval tv)
2376 return settimeofday (ref tv, IntPtr.Zero);
2379 [DllImport (MPH, SetLastError=true,
2380 EntryPoint="Mono_Posix_Syscall_utimes")]
2381 public static extern int utimes (string filename, ref Timeval tvp);
2403 #region <sys/wait.h> Declarations
2409 // pid_t wait(int *status);
2410 [DllImport (LIBC, SetLastError=true)]
2411 public static extern int wait (out int status);
2414 // pid_t waitpid(pid_t pid, int *status, int options);
2415 [DllImport (LIBC, SetLastError=true)]
2416 private static extern int waitpid (int pid, out int status, int options);
2418 public static int waitpid (int pid, out int status, WaitOptions options)
2420 int _options = NativeConvert.FromWaitOptions (options);
2421 return waitpid (pid, out status, _options);
2424 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
2425 private static extern int _WIFEXITED (int status);
2427 public static bool WIFEXITED (int status)
2429 return _WIFEXITED (status) != 0;
2432 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
2433 public static extern int WEXITSTATUS (int status);
2435 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
2436 private static extern int _WIFSIGNALED (int status);
2438 public static bool WIFSIGNALED (int status)
2440 return _WIFSIGNALED (status) != 0;
2443 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
2444 private static extern int _WTERMSIG (int status);
2446 public static Signum WTERMSIG (int status)
2448 int r = _WTERMSIG (status);
2449 return NativeConvert.ToSignum (r);
2452 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
2453 private static extern int _WIFSTOPPED (int status);
2455 public static bool WIFSTOPPED (int status)
2457 return _WIFSTOPPED (status) != 0;
2460 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
2461 private static extern int _WSTOPSIG (int status);
2463 public static Signum WSTOPSIG (int status)
2465 int r = _WSTOPSIG (status);
2466 return NativeConvert.ToSignum (r);
2475 #region <syslog.h> Declarations
2480 [DllImport (MPH, SetLastError=true,
2481 EntryPoint="Mono_Posix_Syscall_openlog")]
2482 private static extern int sys_openlog (IntPtr ident, int option, int facility);
2484 public static int openlog (IntPtr ident, SyslogOptions option,
2485 SyslogFacility defaultFacility)
2487 int _option = NativeConvert.FromSyslogOptions (option);
2488 int _facility = NativeConvert.FromSyslogFacility (defaultFacility);
2490 return sys_openlog (ident, _option, _facility);
2493 [DllImport (MPH, SetLastError=true,
2494 EntryPoint="Mono_Posix_Syscall_syslog")]
2495 private static extern int sys_syslog (int priority, string message);
2497 public static int syslog (SyslogFacility facility, SyslogLevel level, string message)
2499 int _facility = NativeConvert.FromSyslogFacility (facility);
2500 int _level = NativeConvert.FromSyslogLevel (level);
2501 return sys_syslog (_facility | _level, GetSyslogMessage (message));
2504 public static int syslog (SyslogLevel level, string message)
2506 int _level = NativeConvert.FromSyslogLevel (level);
2507 return sys_syslog (_level, GetSyslogMessage (message));
2510 private static string GetSyslogMessage (string message)
2512 return UnixMarshal.EscapeFormatString (message, new char[]{'m'});
2515 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
2516 "Use syslog(SyslogFacility, SyslogLevel, string) instead.")]
2517 public static int syslog (SyslogFacility facility, SyslogLevel level,
2518 string format, params object[] parameters)
2520 int _facility = NativeConvert.FromSyslogFacility (facility);
2521 int _level = NativeConvert.FromSyslogLevel (level);
2523 object[] _parameters = new object[checked(parameters.Length+2)];
2524 _parameters [0] = _facility | _level;
2525 _parameters [1] = format;
2526 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
2527 return (int) XPrintfFunctions.syslog (_parameters);
2530 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
2531 "Use syslog(SyslogLevel, string) instead.")]
2532 public static int syslog (SyslogLevel level, string format,
2533 params object[] parameters)
2535 int _level = NativeConvert.FromSyslogLevel (level);
2537 object[] _parameters = new object[checked(parameters.Length+2)];
2538 _parameters [0] = _level;
2539 _parameters [1] = format;
2540 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
2541 return (int) XPrintfFunctions.syslog (_parameters);
2544 [DllImport (MPH, SetLastError=true,
2545 EntryPoint="Mono_Posix_Syscall_closelog")]
2546 public static extern int closelog ();
2548 [DllImport (LIBC, SetLastError=true, EntryPoint="setlogmask")]
2549 private static extern int sys_setlogmask (int mask);
2551 public static int setlogmask (SyslogLevel mask)
2553 int _mask = NativeConvert.FromSyslogLevel (mask);
2554 return sys_setlogmask (_mask);
2559 #region <time.h> Declarations
2566 // int stime(time_t *t);
2567 [DllImport (MPH, SetLastError=true,
2568 EntryPoint="Mono_Posix_Syscall_stime")]
2569 public static extern int stime (ref long t);
2572 // time_t time(time_t *t);
2573 [DllImport (MPH, SetLastError=true,
2574 EntryPoint="Mono_Posix_Syscall_time")]
2575 public static extern long time (out long t);
2585 #region <unistd.h> Declarations
2589 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
2590 // other TODOs listed below.
2592 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
2593 private static extern int sys_access (string pathname, int mode);
2595 public static int access (string pathname, AccessModes mode)
2597 int _mode = NativeConvert.FromAccessModes (mode);
2598 return sys_access (pathname, _mode);
2602 // off_t lseek(int filedes, off_t offset, int whence);
2603 [DllImport (MPH, SetLastError=true,
2604 EntryPoint="Mono_Posix_Syscall_lseek")]
2605 private static extern long sys_lseek (int fd, long offset, int whence);
2607 public static long lseek (int fd, long offset, SeekFlags whence)
2609 short _whence = NativeConvert.FromSeekFlags (whence);
2610 return sys_lseek (fd, offset, _whence);
2613 [DllImport (LIBC, SetLastError=true)]
2614 public static extern int close (int fd);
2617 // ssize_t read(int fd, void *buf, size_t count);
2618 [DllImport (MPH, SetLastError=true,
2619 EntryPoint="Mono_Posix_Syscall_read")]
2620 public static extern long read (int fd, IntPtr buf, ulong count);
2622 public static unsafe long read (int fd, void *buf, ulong count)
2624 return read (fd, (IntPtr) buf, count);
2628 // ssize_t write(int fd, const void *buf, size_t count);
2629 [DllImport (MPH, SetLastError=true,
2630 EntryPoint="Mono_Posix_Syscall_write")]
2631 public static extern long write (int fd, IntPtr buf, ulong count);
2633 public static unsafe long write (int fd, void *buf, ulong count)
2635 return write (fd, (IntPtr) buf, count);
2639 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
2640 [DllImport (MPH, SetLastError=true,
2641 EntryPoint="Mono_Posix_Syscall_pread")]
2642 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
2644 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
2646 return pread (fd, (IntPtr) buf, count, offset);
2650 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
2651 [DllImport (MPH, SetLastError=true,
2652 EntryPoint="Mono_Posix_Syscall_pwrite")]
2653 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
2655 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
2657 return pwrite (fd, (IntPtr) buf, count, offset);
2660 [DllImport (MPH, SetLastError=true,
2661 EntryPoint="Mono_Posix_Syscall_pipe")]
2662 public static extern int pipe (out int reading, out int writing);
2664 public static int pipe (int[] filedes)
2666 if (filedes == null || filedes.Length != 2) {
2670 int reading, writing;
2671 int r = pipe (out reading, out writing);
2672 filedes[0] = reading;
2673 filedes[1] = writing;
2677 [DllImport (LIBC, SetLastError=true)]
2678 public static extern uint alarm (uint seconds);
2680 [DllImport (LIBC, SetLastError=true)]
2681 public static extern uint sleep (uint seconds);
2683 [DllImport (LIBC, SetLastError=true)]
2684 public static extern uint ualarm (uint usecs, uint interval);
2686 [DllImport (LIBC, SetLastError=true)]
2687 public static extern int pause ();
2690 // int chown(const char *path, uid_t owner, gid_t group);
2691 [DllImport (LIBC, SetLastError=true)]
2692 public static extern int chown (string path, uint owner, uint group);
2695 // int fchown(int fd, uid_t owner, gid_t group);
2696 [DllImport (LIBC, SetLastError=true)]
2697 public static extern int fchown (int fd, uint owner, uint group);
2700 // int lchown(const char *path, uid_t owner, gid_t group);
2701 [DllImport (LIBC, SetLastError=true)]
2702 public static extern int lchown (string path, uint owner, uint group);
2704 [DllImport (LIBC, SetLastError=true)]
2705 public static extern int chdir (string path);
2707 [DllImport (LIBC, SetLastError=true)]
2708 public static extern int fchdir (int fd);
2711 // char *getcwd(char *buf, size_t size);
2712 [DllImport (MPH, SetLastError=true,
2713 EntryPoint="Mono_Posix_Syscall_getcwd")]
2714 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
2716 public static StringBuilder getcwd (StringBuilder buf)
2718 getcwd (buf, (ulong) buf.Capacity);
2722 // getwd(2) is deprecated; don't expose it.
2724 [DllImport (LIBC, SetLastError=true)]
2725 public static extern int dup (int fd);
2727 [DllImport (LIBC, SetLastError=true)]
2728 public static extern int dup2 (int fd, int fd2);
2730 // TODO: does Mono marshal arrays properly?
2731 [DllImport (LIBC, SetLastError=true)]
2732 public static extern int execve (string path, string[] argv, string[] envp);
2734 [DllImport (LIBC, SetLastError=true)]
2735 public static extern int fexecve (int fd, string[] argv, string[] envp);
2737 [DllImport (LIBC, SetLastError=true)]
2738 public static extern int execv (string path, string[] argv);
2740 // TODO: execle, execl, execlp
2741 [DllImport (LIBC, SetLastError=true)]
2742 public static extern int execvp (string path, string[] argv);
2744 [DllImport (LIBC, SetLastError=true)]
2745 public static extern int nice (int inc);
2747 [DllImport (LIBC, SetLastError=true)]
2748 [CLSCompliant (false)]
2749 public static extern int _exit (int status);
2751 [DllImport (MPH, SetLastError=true,
2752 EntryPoint="Mono_Posix_Syscall_fpathconf")]
2753 public static extern long fpathconf (int filedes, PathconfName name, Errno defaultError);
2755 public static long fpathconf (int filedes, PathconfName name)
2757 return fpathconf (filedes, name, (Errno) 0);
2760 [DllImport (MPH, SetLastError=true,
2761 EntryPoint="Mono_Posix_Syscall_pathconf")]
2762 public static extern long pathconf (string path, PathconfName name, Errno defaultError);
2764 public static long pathconf (string path, PathconfName name)
2766 return pathconf (path, name, (Errno) 0);
2769 [DllImport (MPH, SetLastError=true,
2770 EntryPoint="Mono_Posix_Syscall_sysconf")]
2771 public static extern long sysconf (SysconfName name, Errno defaultError);
2773 public static long sysconf (SysconfName name)
2775 return sysconf (name, (Errno) 0);
2779 // size_t confstr(int name, char *buf, size_t len);
2780 [DllImport (MPH, SetLastError=true,
2781 EntryPoint="Mono_Posix_Syscall_confstr")]
2782 public static extern ulong confstr (ConfstrName name, [Out] StringBuilder buf, ulong len);
2785 // pid_t getpid(void);
2786 [DllImport (LIBC, SetLastError=true)]
2787 public static extern int getpid ();
2790 // pid_t getppid(void);
2791 [DllImport (LIBC, SetLastError=true)]
2792 public static extern int getppid ();
2795 // int setpgid(pid_t pid, pid_t pgid);
2796 [DllImport (LIBC, SetLastError=true)]
2797 public static extern int setpgid (int pid, int pgid);
2800 // pid_t getpgid(pid_t pid);
2801 [DllImport (LIBC, SetLastError=true)]
2802 public static extern int getpgid (int pid);
2804 [DllImport (LIBC, SetLastError=true)]
2805 public static extern int setpgrp ();
2808 // pid_t getpgrp(void);
2809 [DllImport (LIBC, SetLastError=true)]
2810 public static extern int getpgrp ();
2813 // pid_t setsid(void);
2814 [DllImport (LIBC, SetLastError=true)]
2815 public static extern int setsid ();
2818 // pid_t getsid(pid_t pid);
2819 [DllImport (LIBC, SetLastError=true)]
2820 public static extern int getsid (int pid);
2823 // uid_t getuid(void);
2824 [DllImport (LIBC, SetLastError=true)]
2825 public static extern uint getuid ();
2828 // uid_t geteuid(void);
2829 [DllImport (LIBC, SetLastError=true)]
2830 public static extern uint geteuid ();
2833 // gid_t getgid(void);
2834 [DllImport (LIBC, SetLastError=true)]
2835 public static extern uint getgid ();
2838 // gid_t getgid(void);
2839 [DllImport (LIBC, SetLastError=true)]
2840 public static extern uint getegid ();
2843 // int getgroups(int size, gid_t list[]);
2844 [DllImport (LIBC, SetLastError=true)]
2845 public static extern int getgroups (int size, uint[] list);
2847 public static int getgroups (uint[] list)
2849 return getgroups (list.Length, list);
2853 // int setuid(uid_t uid);
2854 [DllImport (LIBC, SetLastError=true)]
2855 public static extern int setuid (uint uid);
2858 // int setreuid(uid_t ruid, uid_t euid);
2859 [DllImport (LIBC, SetLastError=true)]
2860 public static extern int setreuid (uint ruid, uint euid);
2863 // int setregid(gid_t ruid, gid_t euid);
2864 [DllImport (LIBC, SetLastError=true)]
2865 public static extern int setregid (uint rgid, uint egid);
2868 // int seteuid(uid_t euid);
2869 [DllImport (LIBC, SetLastError=true)]
2870 public static extern int seteuid (uint euid);
2873 // int setegid(gid_t euid);
2874 [DllImport (LIBC, SetLastError=true)]
2875 public static extern int setegid (uint uid);
2878 // int setgid(gid_t gid);
2879 [DllImport (LIBC, SetLastError=true)]
2880 public static extern int setgid (uint gid);
2883 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
2884 [DllImport (LIBC, SetLastError=true)]
2885 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
2888 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
2889 [DllImport (LIBC, SetLastError=true)]
2890 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
2893 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
2894 [DllImport (LIBC, SetLastError=true)]
2895 public static extern int setresuid (uint ruid, uint euid, uint suid);
2898 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
2899 [DllImport (LIBC, SetLastError=true)]
2900 public static extern int setresgid (uint rgid, uint egid, uint sgid);
2904 // pid_t fork(void);
2905 [DllImport (LIBC, SetLastError=true)]
2906 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
2907 "shutdown code.\nUse System.Diagnostics.Process instead")]
2908 private static extern int fork ();
2911 // pid_t vfork(void);
2912 [DllImport (LIBC, SetLastError=true)]
2913 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
2914 "shutdown code.\nUse System.Diagnostics.Process instead")]
2915 private static extern int vfork ();
2918 private static object tty_lock = new object ();
2920 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
2921 private static extern IntPtr sys_ttyname (int fd);
2923 public static string ttyname (int fd)
2926 IntPtr r = sys_ttyname (fd);
2927 return UnixMarshal.PtrToString (r);
2932 // int ttyname_r(int fd, char *buf, size_t buflen);
2933 [DllImport (MPH, SetLastError=true,
2934 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
2935 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
2937 public static int ttyname_r (int fd, StringBuilder buf)
2939 return ttyname_r (fd, buf, (ulong) buf.Capacity);
2942 [DllImport (LIBC, EntryPoint="isatty")]
2943 private static extern int sys_isatty (int fd);
2945 public static bool isatty (int fd)
2947 return sys_isatty (fd) == 1;
2950 [DllImport (LIBC, SetLastError=true)]
2951 public static extern int link (string oldpath, string newpath);
2953 [DllImport (LIBC, SetLastError=true)]
2954 public static extern int symlink (string oldpath, string newpath);
2957 // int readlink(const char *path, char *buf, size_t bufsize);
2958 [DllImport (MPH, SetLastError=true,
2959 EntryPoint="Mono_Posix_Syscall_readlink")]
2960 public static extern int readlink (string path, [Out] StringBuilder buf, ulong bufsiz);
2962 public static int readlink (string path, [Out] StringBuilder buf)
2964 return readlink (path, buf, (ulong) buf.Capacity);
2967 [DllImport (LIBC, SetLastError=true)]
2968 public static extern int unlink (string pathname);
2970 [DllImport (LIBC, SetLastError=true)]
2971 public static extern int rmdir (string pathname);
2974 // pid_t tcgetpgrp(int fd);
2975 [DllImport (LIBC, SetLastError=true)]
2976 public static extern int tcgetpgrp (int fd);
2979 // int tcsetpgrp(int fd, pid_t pgrp);
2980 [DllImport (LIBC, SetLastError=true)]
2981 public static extern int tcsetpgrp (int fd, int pgrp);
2983 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
2984 private static extern IntPtr sys_getlogin ();
2986 public static string getlogin ()
2988 lock (getlogin_lock) {
2989 IntPtr r = sys_getlogin ();
2990 return UnixMarshal.PtrToString (r);
2995 // int getlogin_r(char *buf, size_t bufsize);
2996 [DllImport (MPH, SetLastError=true,
2997 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
2998 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
3000 public static int getlogin_r (StringBuilder name)
3002 return getlogin_r (name, (ulong) name.Capacity);
3005 [DllImport (LIBC, SetLastError=true)]
3006 public static extern int setlogin (string name);
3009 // int gethostname(char *name, size_t len);
3010 [DllImport (MPH, SetLastError=true,
3011 EntryPoint="Mono_Posix_Syscall_gethostname")]
3012 public static extern int gethostname ([Out] StringBuilder name, ulong len);
3014 public static int gethostname (StringBuilder name)
3016 return gethostname (name, (ulong) name.Capacity);
3020 // int gethostname(const char *name, size_t len);
3021 [DllImport (MPH, SetLastError=true,
3022 EntryPoint="Mono_Posix_Syscall_sethostname")]
3023 public static extern int sethostname (string name, ulong len);
3025 public static int sethostname (string name)
3027 return sethostname (name, (ulong) name.Length);
3030 [DllImport (MPH, SetLastError=true,
3031 EntryPoint="Mono_Posix_Syscall_gethostid")]
3032 public static extern long gethostid ();
3034 [DllImport (MPH, SetLastError=true,
3035 EntryPoint="Mono_Posix_Syscall_sethostid")]
3036 public static extern int sethostid (long hostid);
3039 // int getdomainname(char *name, size_t len);
3040 [DllImport (MPH, SetLastError=true,
3041 EntryPoint="Mono_Posix_Syscall_getdomainname")]
3042 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
3044 public static int getdomainname (StringBuilder name)
3046 return getdomainname (name, (ulong) name.Capacity);
3050 // int setdomainname(const char *name, size_t len);
3051 [DllImport (MPH, SetLastError=true,
3052 EntryPoint="Mono_Posix_Syscall_setdomainname")]
3053 public static extern int setdomainname (string name, ulong len);
3055 public static int setdomainname (string name)
3057 return setdomainname (name, (ulong) name.Length);
3060 [DllImport (LIBC, SetLastError=true)]
3061 public static extern int vhangup ();
3063 // Revoke doesn't appear to be POSIX. Include it?
3064 [DllImport (LIBC, SetLastError=true)]
3065 public static extern int revoke (string file);
3067 // TODO: profil? It's not POSIX.
3069 [DllImport (LIBC, SetLastError=true)]
3070 public static extern int acct (string filename);
3072 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
3073 private static extern IntPtr sys_getusershell ();
3075 internal static object usershell_lock = new object ();
3077 public static string getusershell ()
3079 lock (usershell_lock) {
3080 IntPtr r = sys_getusershell ();
3081 return UnixMarshal.PtrToString (r);
3085 [DllImport (MPH, SetLastError=true,
3086 EntryPoint="Mono_Posix_Syscall_setusershell")]
3087 private static extern int sys_setusershell ();
3089 public static int setusershell ()
3091 lock (usershell_lock) {
3092 return sys_setusershell ();
3096 [DllImport (MPH, SetLastError=true,
3097 EntryPoint="Mono_Posix_Syscall_endusershell")]
3098 private static extern int sys_endusershell ();
3100 public static int endusershell ()
3102 lock (usershell_lock) {
3103 return sys_endusershell ();
3108 [DllImport (LIBC, SetLastError=true)]
3109 private static extern int daemon (int nochdir, int noclose);
3111 // this implicitly forks, and thus isn't safe.
3112 private static int daemon (bool nochdir, bool noclose)
3114 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
3118 [DllImport (LIBC, SetLastError=true)]
3119 public static extern int chroot (string path);
3121 // skipping getpass(3) as the man page states:
3122 // This function is obsolete. Do not use it.
3124 [DllImport (LIBC, SetLastError=true)]
3125 public static extern int fsync (int fd);
3127 [DllImport (LIBC, SetLastError=true)]
3128 public static extern int fdatasync (int fd);
3130 [DllImport (MPH, SetLastError=true,
3131 EntryPoint="Mono_Posix_Syscall_sync")]
3132 public static extern int sync ();
3134 [DllImport (LIBC, SetLastError=true)]
3135 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
3136 "Use Unistd.sysconf (SysConf._SC_PAGESIZE).")]
3137 public static extern int getpagesize ();
3140 // int truncate(const char *path, off_t length);
3141 [DllImport (MPH, SetLastError=true,
3142 EntryPoint="Mono_Posix_Syscall_truncate")]
3143 public static extern int truncate (string path, long length);
3146 // int ftruncate(int fd, off_t length);
3147 [DllImport (MPH, SetLastError=true,
3148 EntryPoint="Mono_Posix_Syscall_ftruncate")]
3149 public static extern int ftruncate (int fd, long length);
3151 [DllImport (LIBC, SetLastError=true)]
3152 public static extern int getdtablesize ();
3154 [DllImport (LIBC, SetLastError=true)]
3155 public static extern int brk (IntPtr end_data_segment);
3157 [DllImport (LIBC, SetLastError=true)]
3158 public static extern IntPtr sbrk (IntPtr increment);
3160 // TODO: syscall(2)?
3161 // Probably safer to skip entirely.
3164 // int lockf(int fd, int cmd, off_t len);
3165 [DllImport (MPH, SetLastError=true,
3166 EntryPoint="Mono_Posix_Syscall_lockf")]
3167 public static extern int lockf (int fd, LockfCommand cmd, long len);
3169 internal static object crypt_lock = new object ();
3171 [DllImport (CRYPT, SetLastError=true, EntryPoint="crypt")]
3172 private static extern IntPtr sys_crypt (string key, string salt);
3174 public static string crypt (string key, string salt)
3177 IntPtr r = sys_crypt (key, salt);
3178 return UnixMarshal.PtrToString (r);
3182 internal static object encrypt_lock = new object ();
3184 [DllImport (MPH, SetLastError=true,
3185 EntryPoint="Mono_Posix_Syscall_encrypt")]
3186 private static extern int sys_encrypt ([In, Out] byte[] block, int edflag);
3188 public static int encrypt (byte[] block, bool decode)
3190 if (block.Length < 64)
3191 throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
3192 lock (encrypt_lock) {
3193 return sys_encrypt (block, decode ? 1 : 0);
3198 // void swab(const void *from, void *to, ssize_t n);
3199 [DllImport (MPH, SetLastError=true,
3200 EntryPoint="Mono_Posix_Syscall_swab")]
3201 public static extern int swab (IntPtr from, IntPtr to, long n);
3203 public static unsafe void swab (void* from, void* to, long n)
3205 swab ((IntPtr) from, (IntPtr) to, n);
3210 #region <utime.h> Declarations
3212 // <utime.h> -- COMPLETE
3215 [DllImport (MPH, SetLastError=true,
3216 EntryPoint="Mono_Posix_Syscall_utime")]
3217 private static extern int sys_utime (string filename, ref Utimbuf buf, int use_buf);
3219 public static int utime (string filename, ref Utimbuf buf)
3221 return sys_utime (filename, ref buf, 1);
3224 public static int utime (string filename)
3226 Utimbuf buf = new Utimbuf ();
3227 return sys_utime (filename, ref buf, 0);