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 PathConf : 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 SysConf : 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 ConfStr : 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 (LIBC, SetLastError=true)]
1395 public static extern void rewinddir (IntPtr dir);
1397 private struct _Dirent {
1398 public /* ino_t */ ulong d_ino;
1399 public /* off_t */ long d_off;
1400 public ushort d_reclen;
1402 public IntPtr d_name;
1405 private static void CopyDirent (Dirent to, ref _Dirent from)
1408 to.d_ino = from.d_ino;
1409 to.d_off = from.d_off;
1410 to.d_reclen = from.d_reclen;
1411 to.d_type = from.d_type;
1412 to.d_name = UnixMarshal.PtrToString (from.d_name);
1415 Stdlib.free (from.d_name);
1416 from.d_name = IntPtr.Zero;
1420 [DllImport (MPH, SetLastError=true,
1421 EntryPoint="Mono_Posix_Syscall_readdir")]
1422 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
1424 public static Dirent readdir (IntPtr dir)
1427 int r = sys_readdir (dir, out dentry);
1430 Dirent d = new Dirent ();
1431 CopyDirent (d, ref dentry);
1435 [DllImport (MPH, SetLastError=true,
1436 EntryPoint="Mono_Posix_Syscall_readdir_r")]
1437 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
1439 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
1445 entry.d_name = null;
1448 int r = sys_readdir_r (dirp, out _d, out result);
1450 if (r == 0 && result != IntPtr.Zero) {
1451 CopyDirent (entry, ref _d);
1457 [DllImport (LIBC, SetLastError=true)]
1458 public static extern int dirfd (IntPtr dir);
1461 #region <fcntl.h> Declarations
1463 // <fcntl.h> -- COMPLETE
1466 [DllImport (MPH, SetLastError=true,
1467 EntryPoint="Mono_Posix_Syscall_fcntl")]
1468 public static extern int fcntl (int fd, FcntlCommand cmd);
1470 [DllImport (MPH, SetLastError=true,
1471 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
1472 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
1474 public static int fcntl (int fd, FcntlCommand cmd, DirectoryNotifyFlags arg)
1476 if (cmd != FcntlCommand.F_NOTIFY) {
1477 SetLastError (Errno.EINVAL);
1480 long _arg = NativeConvert.FromDirectoryNotifyFlags (arg);
1481 return fcntl (fd, FcntlCommand.F_NOTIFY, _arg);
1484 [DllImport (MPH, SetLastError=true,
1485 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
1486 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
1488 [DllImport (MPH, SetLastError=true,
1489 EntryPoint="Mono_Posix_Syscall_open")]
1490 public static extern int open (string pathname, OpenFlags flags);
1493 // int open(const char *pathname, int flags, mode_t mode);
1494 [DllImport (MPH, SetLastError=true,
1495 EntryPoint="Mono_Posix_Syscall_open_mode")]
1496 public static extern int open (string pathname, OpenFlags flags, FilePermissions mode);
1499 // int creat(const char *pathname, mode_t mode);
1500 [DllImport (MPH, SetLastError=true,
1501 EntryPoint="Mono_Posix_Syscall_creat")]
1502 public static extern int creat (string pathname, FilePermissions mode);
1505 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
1506 [DllImport (MPH, SetLastError=true,
1507 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
1508 public static extern int posix_fadvise (int fd, long offset,
1509 long len, PosixFadviseAdvice advice);
1511 // posix_fallocate(P)
1512 // int posix_fallocate(int fd, off_t offset, size_t len);
1513 [DllImport (MPH, SetLastError=true,
1514 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
1515 public static extern int posix_fallocate (int fd, long offset, ulong len);
1518 #region <fstab.h> Declarations
1520 // <fstab.h> -- COMPLETE
1522 private struct _Fstab {
1523 public IntPtr fs_spec;
1524 public IntPtr fs_file;
1525 public IntPtr fs_vfstype;
1526 public IntPtr fs_mntops;
1527 public IntPtr fs_type;
1529 public int fs_passno;
1530 public IntPtr _fs_buf_;
1533 private static void CopyFstab (Fstab to, ref _Fstab from)
1536 to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
1537 to.fs_file = UnixMarshal.PtrToString (from.fs_file);
1538 to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
1539 to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
1540 to.fs_type = UnixMarshal.PtrToString (from.fs_type);
1541 to.fs_freq = from.fs_freq;
1542 to.fs_passno = from.fs_passno;
1545 Stdlib.free (from._fs_buf_);
1546 from._fs_buf_ = IntPtr.Zero;
1550 internal static object fstab_lock = new object ();
1552 [DllImport (MPH, SetLastError=true,
1553 EntryPoint="Mono_Posix_Syscall_endfsent")]
1554 private static extern void sys_endfsent ();
1556 public static void endfsent ()
1563 [DllImport (MPH, SetLastError=true,
1564 EntryPoint="Mono_Posix_Syscall_getfsent")]
1565 private static extern int sys_getfsent (out _Fstab fs);
1567 public static Fstab getfsent ()
1572 r = sys_getfsent (out fsbuf);
1576 Fstab fs = new Fstab ();
1577 CopyFstab (fs, ref fsbuf);
1581 [DllImport (MPH, SetLastError=true,
1582 EntryPoint="Mono_Posix_Syscall_getfsfile")]
1583 private static extern int sys_getfsfile (string mount_point, out _Fstab fs);
1585 public static Fstab getfsfile (string mount_point)
1590 r = sys_getfsfile (mount_point, out fsbuf);
1594 Fstab fs = new Fstab ();
1595 CopyFstab (fs, ref fsbuf);
1599 [DllImport (MPH, SetLastError=true,
1600 EntryPoint="Mono_Posix_Syscall_getfsspec")]
1601 private static extern int sys_getfsspec (string special_file, out _Fstab fs);
1603 public static Fstab getfsspec (string special_file)
1608 r = sys_getfsspec (special_file, out fsbuf);
1612 Fstab fs = new Fstab ();
1613 CopyFstab (fs, ref fsbuf);
1617 [DllImport (MPH, SetLastError=true,
1618 EntryPoint="Mono_Posix_Syscall_setfsent")]
1619 private static extern int sys_setfsent ();
1621 public static int setfsent ()
1624 return sys_setfsent ();
1630 #region <grp.h> Declarations
1634 // TODO: putgrent(3), fgetgrent_r(), getgrouplist(2), initgroups(3)
1637 // int setgroups (size_t size, const gid_t *list);
1638 [DllImport (MPH, SetLastError=true,
1639 EntryPoint="Mono_Posix_Syscall_setgroups")]
1640 public static extern int setgroups (ulong size, uint[] list);
1642 public static int setgroups (uint [] list)
1644 return setgroups ((ulong) list.Length, list);
1647 private struct _Group
1649 public IntPtr gr_name;
1650 public IntPtr gr_passwd;
1651 public /* gid_t */ uint gr_gid;
1652 public int _gr_nmem_;
1653 public IntPtr gr_mem;
1654 public IntPtr _gr_buf_;
1657 private static void CopyGroup (Group to, ref _Group from)
1660 to.gr_gid = from.gr_gid;
1661 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
1662 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
1663 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
1666 Stdlib.free (from.gr_mem);
1667 Stdlib.free (from._gr_buf_);
1668 from.gr_mem = IntPtr.Zero;
1669 from._gr_buf_ = IntPtr.Zero;
1673 internal static object grp_lock = new object ();
1675 [DllImport (MPH, SetLastError=true,
1676 EntryPoint="Mono_Posix_Syscall_getgrnam")]
1677 private static extern int sys_getgrnam (string name, out _Group group);
1679 public static Group getgrnam (string name)
1684 r = sys_getgrnam (name, out group);
1688 Group gr = new Group ();
1689 CopyGroup (gr, ref group);
1694 // struct group *getgrgid(gid_t gid);
1695 [DllImport (MPH, SetLastError=true,
1696 EntryPoint="Mono_Posix_Syscall_getgrgid")]
1697 private static extern int sys_getgrgid (uint uid, out _Group group);
1699 public static Group getgrgid (uint uid)
1704 r = sys_getgrgid (uid, out group);
1708 Group gr = new Group ();
1709 CopyGroup (gr, ref group);
1713 [DllImport (MPH, SetLastError=true,
1714 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
1715 private static extern int sys_getgrnam_r (string name, out _Group grbuf, out IntPtr grbufp);
1717 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
1722 int r = sys_getgrnam_r (name, out group, out _grbufp);
1723 if (r == 0 && _grbufp != IntPtr.Zero) {
1724 CopyGroup (grbuf, ref group);
1731 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
1732 // size_t buflen, struct group **gbufp);
1733 [DllImport (MPH, SetLastError=true,
1734 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
1735 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
1737 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
1742 int r = sys_getgrgid_r (uid, out group, out _grbufp);
1743 if (r == 0 && _grbufp != IntPtr.Zero) {
1744 CopyGroup (grbuf, ref group);
1750 [DllImport (MPH, SetLastError=true,
1751 EntryPoint="Mono_Posix_Syscall_getgrent")]
1752 private static extern int sys_getgrent (out _Group grbuf);
1754 public static Group getgrent ()
1759 r = sys_getgrent (out group);
1763 Group gr = new Group();
1764 CopyGroup (gr, ref group);
1768 [DllImport (LIBC, SetLastError=true, EntryPoint="setgrent")]
1769 private static extern void sys_setgrent ();
1771 public static void setgrent ()
1778 [DllImport (LIBC, SetLastError=true, EntryPoint="endgrent")]
1779 private static extern void sys_endgrent ();
1781 public static void endgrent ()
1788 [DllImport (MPH, SetLastError=true,
1789 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
1790 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
1792 public static Group fgetgrent (IntPtr stream)
1797 r = sys_fgetgrent (stream, out group);
1801 Group gr = new Group ();
1802 CopyGroup (gr, ref group);
1807 #region <pwd.h> Declarations
1811 // TODO: putpwent(3), fgetpwent_r()
1813 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
1815 private struct _Passwd
1817 public IntPtr pw_name;
1818 public IntPtr pw_passwd;
1819 public /* uid_t */ uint pw_uid;
1820 public /* gid_t */ uint pw_gid;
1821 public IntPtr pw_gecos;
1822 public IntPtr pw_dir;
1823 public IntPtr pw_shell;
1824 public IntPtr _pw_buf_;
1827 private static void CopyPasswd (Passwd to, ref _Passwd from)
1830 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
1831 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
1832 to.pw_uid = from.pw_uid;
1833 to.pw_gid = from.pw_gid;
1834 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
1835 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
1836 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
1839 Stdlib.free (from._pw_buf_);
1840 from._pw_buf_ = IntPtr.Zero;
1844 internal static object pwd_lock = new object ();
1846 [DllImport (MPH, SetLastError=true,
1847 EntryPoint="Mono_Posix_Syscall_getpwnam")]
1848 private static extern int sys_getpwnam (string name, out _Passwd passwd);
1850 public static Passwd getpwnam (string name)
1855 r = sys_getpwnam (name, out passwd);
1859 Passwd pw = new Passwd ();
1860 CopyPasswd (pw, ref passwd);
1865 // struct passwd *getpwnuid(uid_t uid);
1866 [DllImport (MPH, SetLastError=true,
1867 EntryPoint="Mono_Posix_Syscall_getpwuid")]
1868 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
1870 public static Passwd getpwuid (uint uid)
1875 r = sys_getpwuid (uid, out passwd);
1879 Passwd pw = new Passwd ();
1880 CopyPasswd (pw, ref passwd);
1884 [DllImport (MPH, SetLastError=true,
1885 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
1886 private static extern int sys_getpwnam_r (string name, out _Passwd pwbuf, out IntPtr pwbufp);
1888 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
1893 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
1894 if (r == 0 && _pwbufp != IntPtr.Zero) {
1895 CopyPasswd (pwbuf, ref passwd);
1902 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
1903 // buflen, struct passwd **pwbufp);
1904 [DllImport (MPH, SetLastError=true,
1905 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
1906 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
1908 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
1913 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
1914 if (r == 0 && _pwbufp != IntPtr.Zero) {
1915 CopyPasswd (pwbuf, ref passwd);
1921 [DllImport (MPH, SetLastError=true,
1922 EntryPoint="Mono_Posix_Syscall_getpwent")]
1923 private static extern int sys_getpwent (out _Passwd pwbuf);
1925 public static Passwd getpwent ()
1930 r = sys_getpwent (out passwd);
1934 Passwd pw = new Passwd ();
1935 CopyPasswd (pw, ref passwd);
1939 [DllImport (LIBC, SetLastError=true, EntryPoint="setpwent")]
1940 private static extern void sys_setpwent ();
1942 public static void setpwent ()
1949 [DllImport (LIBC, SetLastError=true, EntryPoint="endpwent")]
1950 private static extern void sys_endpwent ();
1952 public static void endpwent ()
1959 [DllImport (MPH, SetLastError=true,
1960 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
1961 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
1963 public static Passwd fgetpwent (IntPtr stream)
1968 r = sys_fgetpwent (stream, out passwd);
1972 Passwd pw = new Passwd ();
1973 CopyPasswd (pw, ref passwd);
1978 #region <signal.h> Declarations
1982 [DllImport (LIBC, SetLastError=true)]
1983 private static extern void psignal (int sig, string s);
1985 public static void psignal (Signum sig, string s)
1987 int signum = NativeConvert.FromSignum (sig);
1988 psignal (signum, s);
1992 // int kill(pid_t pid, int sig);
1993 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
1994 private static extern int sys_kill (int pid, int sig);
1996 public static int kill (int pid, Signum sig)
1998 int _sig = NativeConvert.FromSignum (sig);
1999 return sys_kill (pid, _sig);
2002 private static object signal_lock = new object ();
2004 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
2005 private static extern IntPtr sys_strsignal (int sig);
2007 public static string strsignal (Signum sig)
2009 int s = NativeConvert.FromSignum (sig);
2010 lock (signal_lock) {
2011 IntPtr r = sys_strsignal (s);
2012 return UnixMarshal.PtrToString (r);
2016 // TODO: sigaction(2)
2017 // TODO: sigsuspend(2)
2018 // TODO: sigpending(2)
2022 #region <stdio.h> Declarations
2026 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
2027 private static extern int _L_ctermid ();
2029 public static readonly int L_ctermid = _L_ctermid ();
2031 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
2032 private static extern int _L_cuserid ();
2034 public static readonly int L_cuserid = _L_cuserid ();
2036 internal static object getlogin_lock = new object ();
2038 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
2039 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
2041 [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
2042 "DO NOT USE cuserid().\n" +
2043 "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
2044 public static string cuserid (StringBuilder @string)
2046 if (@string.Capacity < L_cuserid) {
2047 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
2049 lock (getlogin_lock) {
2050 IntPtr r = sys_cuserid (@string);
2051 return UnixMarshal.PtrToString (r);
2057 #region <stdlib.h> Declarations
2061 [DllImport (LIBC, SetLastError=true)]
2062 public static extern int mkstemp (StringBuilder template);
2064 [DllImport (LIBC, SetLastError=true)]
2065 public static extern int ttyslot ();
2067 [DllImport (CRYPT, SetLastError=true)]
2068 public static extern void setkey (string key);
2072 #region <string.h> Declarations
2078 // int strerror_r(int errnum, char *buf, size_t n);
2079 [DllImport (MPH, SetLastError=true,
2080 EntryPoint="Mono_Posix_Syscall_strerror_r")]
2081 private static extern int sys_strerror_r (int errnum,
2082 [Out] StringBuilder buf, ulong n);
2084 public static int strerror_r (Errno errnum, StringBuilder buf, ulong n)
2086 int e = NativeConvert.FromErrno (errnum);
2087 return sys_strerror_r (e, buf, n);
2090 public static int strerror_r (Errno errnum, StringBuilder buf)
2092 return strerror_r (errnum, buf, (ulong) buf.Capacity);
2097 #region <sys/mman.h> Declarations
2103 // int posix_madvise(void *addr, size_t len, int advice);
2104 [DllImport (MPH, SetLastError=true,
2105 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
2106 public static extern int posix_madvise (IntPtr addr, ulong len,
2107 PosixMadviseAdvice advice);
2109 public static readonly IntPtr MAP_FAILED = unchecked((IntPtr)(-1));
2111 [DllImport (MPH, SetLastError=true,
2112 EntryPoint="Mono_Posix_Syscall_mmap")]
2113 public static extern IntPtr mmap (IntPtr start, ulong length,
2114 MmapProts prot, MmapFlags flags, int fd, long offset);
2116 [DllImport (MPH, SetLastError=true,
2117 EntryPoint="Mono_Posix_Syscall_munmap")]
2118 public static extern int munmap (IntPtr start, ulong length);
2120 [DllImport (MPH, SetLastError=true,
2121 EntryPoint="Mono_Posix_Syscall_mprotect")]
2122 public static extern int mprotect (IntPtr start, ulong len, MmapProts prot);
2124 [DllImport (MPH, SetLastError=true,
2125 EntryPoint="Mono_Posix_Syscall_msync")]
2126 public static extern int msync (IntPtr start, ulong len, MsyncFlags flags);
2128 [DllImport (MPH, SetLastError=true,
2129 EntryPoint="Mono_Posix_Syscall_mlock")]
2130 public static extern int mlock (IntPtr start, ulong len);
2132 [DllImport (MPH, SetLastError=true,
2133 EntryPoint="Mono_Posix_Syscall_munlock")]
2134 public static extern int munlock (IntPtr start, ulong len);
2136 [DllImport (LIBC, SetLastError=true, EntryPoint="mlockall")]
2137 private static extern int sys_mlockall (int flags);
2139 public static int mlockall (MlockallFlags flags)
2141 int _flags = NativeConvert.FromMlockallFlags (flags);
2142 return sys_mlockall (_flags);
2145 [DllImport (LIBC, SetLastError=true)]
2146 public static extern int munlockall ();
2148 [DllImport (MPH, SetLastError=true,
2149 EntryPoint="Mono_Posix_Syscall_mremap")]
2150 public static extern IntPtr mremap (IntPtr old_address, ulong old_size,
2151 ulong new_size, MremapFlags flags);
2153 [DllImport (MPH, SetLastError=true,
2154 EntryPoint="Mono_Posix_Syscall_mincore")]
2155 public static extern int mincore (IntPtr start, ulong length, byte[] vec);
2157 [DllImport (MPH, SetLastError=true,
2158 EntryPoint="Mono_Posix_Syscall_remap_file_pages")]
2159 public static extern int remap_file_pages (IntPtr start, ulong size,
2160 MmapProts prot, long pgoff, MmapFlags flags);
2164 #region <sys/poll.h> Declarations
2166 // <sys/poll.h> -- COMPLETE
2169 private struct _pollfd {
2171 public short events;
2172 public short revents;
2175 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
2176 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
2178 public static int poll (Pollfd [] fds, uint nfds, int timeout)
2180 if (fds.Length < nfds)
2181 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
2183 _pollfd[] send = new _pollfd[nfds];
2185 for (int i = 0; i < send.Length; i++) {
2186 send [i].fd = fds [i].fd;
2187 send [i].events = NativeConvert.FromPollEvents (fds [i].events);
2190 int r = sys_poll (send, nfds, timeout);
2192 for (int i = 0; i < send.Length; i++) {
2193 fds [i].revents = NativeConvert.ToPollEvents (send [i].revents);
2199 public static int poll (Pollfd [] fds, int timeout)
2201 return poll (fds, (uint) fds.Length, timeout);
2214 // TODO: setrlimit(2)
2215 // TODO: getrlimit(2)
2216 // TODO: getrusage(2)
2220 #region <sys/sendfile.h> Declarations
2222 // <sys/sendfile.h> -- COMPLETE
2225 [DllImport (MPH, SetLastError=true,
2226 EntryPoint="Mono_Posix_Syscall_sendfile")]
2227 public static extern long sendfile (int out_fd, int in_fd,
2228 ref long offset, ulong count);
2232 #region <sys/stat.h> Declarations
2234 // <sys/stat.h> -- COMPLETE
2236 [DllImport (MPH, SetLastError=true,
2237 EntryPoint="Mono_Posix_Syscall_stat")]
2238 public static extern int stat (string file_name, out Stat buf);
2240 [DllImport (MPH, SetLastError=true,
2241 EntryPoint="Mono_Posix_Syscall_fstat")]
2242 public static extern int fstat (int filedes, out Stat buf);
2244 [DllImport (MPH, SetLastError=true,
2245 EntryPoint="Mono_Posix_Syscall_lstat")]
2246 public static extern int lstat (string file_name, out Stat buf);
2249 // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
2250 // All take FilePermissions
2253 // int chmod(const char *path, mode_t mode);
2254 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
2255 private static extern int sys_chmod (string path, uint mode);
2257 public static int chmod (string path, FilePermissions mode)
2259 uint _mode = NativeConvert.FromFilePermissions (mode);
2260 return sys_chmod (path, _mode);
2264 // int chmod(int filedes, mode_t mode);
2265 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
2266 private static extern int sys_fchmod (int filedes, uint mode);
2268 public static int fchmod (int filedes, FilePermissions mode)
2270 uint _mode = NativeConvert.FromFilePermissions (mode);
2271 return sys_fchmod (filedes, _mode);
2275 // mode_t umask(mode_t mask);
2276 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
2277 private static extern uint sys_umask (uint mask);
2279 public static FilePermissions umask (FilePermissions mask)
2281 uint _mask = NativeConvert.FromFilePermissions (mask);
2282 uint r = sys_umask (_mask);
2283 return NativeConvert.ToFilePermissions (r);
2287 // int mkdir(const char *pathname, mode_t mode);
2288 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
2289 private static extern int sys_mkdir (string oldpath, uint mode);
2291 public static int mkdir (string oldpath, FilePermissions mode)
2293 uint _mode = NativeConvert.FromFilePermissions (mode);
2294 return sys_mkdir (oldpath, _mode);
2298 // int mknod (const char *pathname, mode_t mode, dev_t dev);
2299 [DllImport (MPH, SetLastError=true,
2300 EntryPoint="Mono_Posix_Syscall_mknod")]
2301 public static extern int mknod (string pathname, FilePermissions mode, ulong dev);
2304 // int mkfifo(const char *pathname, mode_t mode);
2305 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
2306 private static extern int sys_mkfifo (string pathname, uint mode);
2308 public static int mkfifo (string pathname, FilePermissions mode)
2310 uint _mode = NativeConvert.FromFilePermissions (mode);
2311 return sys_mkfifo (pathname, _mode);
2316 #region <sys/stat.h> Declarations
2321 [DllImport (MPH, SetLastError=true,
2322 EntryPoint="Mono_Posix_Syscall_statvfs")]
2323 public static extern int statvfs (string path, out Statvfs buf);
2325 [DllImport (MPH, SetLastError=true,
2326 EntryPoint="Mono_Posix_Syscall_fstatvfs")]
2327 public static extern int fstatvfs (int fd, out Statvfs buf);
2331 #region <sys/time.h> Declarations
2335 // TODO: adjtime(), getitimer(2), setitimer(2), lutimes(), futimes()
2337 [DllImport (MPH, SetLastError=true,
2338 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2339 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
2341 [DllImport (MPH, SetLastError=true,
2342 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2343 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
2345 public static int gettimeofday (out Timeval tv)
2347 return gettimeofday (out tv, IntPtr.Zero);
2350 [DllImport (MPH, SetLastError=true,
2351 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2352 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
2354 public static int gettimeofday (out Timezone tz)
2356 return gettimeofday (IntPtr.Zero, out tz);
2359 [DllImport (MPH, SetLastError=true,
2360 EntryPoint="Mono_Posix_Syscall_settimeofday")]
2361 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
2363 [DllImport (MPH, SetLastError=true,
2364 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2365 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
2367 public static int settimeofday (ref Timeval tv)
2369 return settimeofday (ref tv, IntPtr.Zero);
2372 [DllImport (MPH, SetLastError=true,
2373 EntryPoint="Mono_Posix_Syscall_utimes")]
2374 public static extern int utimes (string filename, ref Timeval tvp);
2396 #region <sys/wait.h> Declarations
2402 // pid_t wait(int *status);
2403 [DllImport (LIBC, SetLastError=true)]
2404 public static extern int wait (out int status);
2407 // pid_t waitpid(pid_t pid, int *status, int options);
2408 [DllImport (LIBC, SetLastError=true)]
2409 private static extern int waitpid (int pid, out int status, int options);
2411 public static int waitpid (int pid, out int status, WaitOptions options)
2413 int _options = NativeConvert.FromWaitOptions (options);
2414 return waitpid (pid, out status, _options);
2417 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
2418 private static extern int _WIFEXITED (int status);
2420 public static bool WIFEXITED (int status)
2422 return _WIFEXITED (status) != 0;
2425 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
2426 public static extern int WEXITSTATUS (int status);
2428 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
2429 private static extern int _WIFSIGNALED (int status);
2431 public static bool WIFSIGNALED (int status)
2433 return _WIFSIGNALED (status) != 0;
2436 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
2437 private static extern int _WTERMSIG (int status);
2439 public static Signum WTERMSIG (int status)
2441 int r = _WTERMSIG (status);
2442 return NativeConvert.ToSignum (r);
2445 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
2446 private static extern int _WIFSTOPPED (int status);
2448 public static bool WIFSTOPPED (int status)
2450 return _WIFSTOPPED (status) != 0;
2453 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
2454 private static extern int _WSTOPSIG (int status);
2456 public static Signum WSTOPSIG (int status)
2458 int r = _WSTOPSIG (status);
2459 return NativeConvert.ToSignum (r);
2468 #region <syslog.h> Declarations
2473 [DllImport (LIBC, EntryPoint="openlog")]
2474 private static extern void sys_openlog (IntPtr ident, int option, int facility);
2476 public static void openlog (IntPtr ident, SyslogOptions option,
2477 SyslogFacility defaultFacility)
2479 int _option = NativeConvert.FromSyslogOptions (option);
2480 int _facility = NativeConvert.FromSyslogFacility (defaultFacility);
2482 sys_openlog (ident, _option, _facility);
2485 [DllImport (LIBC, EntryPoint="syslog")]
2486 private static extern void sys_syslog (int priority, string message);
2488 public static void syslog (SyslogFacility facility, SyslogLevel level, string message)
2490 int _facility = NativeConvert.FromSyslogFacility (facility);
2491 int _level = NativeConvert.FromSyslogLevel (level);
2492 sys_syslog (_facility | _level, GetSyslogMessage (message));
2495 public static void syslog (SyslogLevel level, string message)
2497 int _level = NativeConvert.FromSyslogLevel (level);
2498 sys_syslog (_level, GetSyslogMessage (message));
2501 private static string GetSyslogMessage (string message)
2503 return UnixMarshal.EscapeFormatString (message, new char[]{'m'});
2506 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
2507 "Use syslog(SyslogFacility, SyslogLevel, string) instead.")]
2508 public static void syslog (SyslogFacility facility, SyslogLevel level,
2509 string format, params object[] parameters)
2511 int _facility = NativeConvert.FromSyslogFacility (facility);
2512 int _level = NativeConvert.FromSyslogLevel (level);
2514 object[] _parameters = new object[checked(parameters.Length+2)];
2515 _parameters [0] = _facility | _level;
2516 _parameters [1] = format;
2517 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
2518 XPrintfFunctions.syslog (_parameters);
2521 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
2522 "Use syslog(SyslogLevel, string) instead.")]
2523 public static void syslog (SyslogLevel level, string format,
2524 params object[] parameters)
2526 int _level = NativeConvert.FromSyslogLevel (level);
2528 object[] _parameters = new object[checked(parameters.Length+2)];
2529 _parameters [0] = _level;
2530 _parameters [1] = format;
2531 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
2532 XPrintfFunctions.syslog (_parameters);
2536 public static extern void closelog ();
2538 [DllImport (LIBC, EntryPoint="setlogmask")]
2539 private static extern int sys_setlogmask (int mask);
2541 public static int setlogmask (SyslogLevel mask)
2543 int _mask = NativeConvert.FromSyslogLevel (mask);
2544 return sys_setlogmask (_mask);
2549 #region <time.h> Declarations
2556 // int stime(time_t *t);
2557 [DllImport (MPH, SetLastError=true,
2558 EntryPoint="Mono_Posix_Syscall_stime")]
2559 public static extern int stime (ref long t);
2562 // time_t time(time_t *t);
2563 [DllImport (MPH, SetLastError=true,
2564 EntryPoint="Mono_Posix_Syscall_time")]
2565 public static extern long time (out long t);
2575 #region <unistd.h> Declarations
2579 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
2580 // other TODOs listed below.
2582 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
2583 private static extern int sys_access (string pathname, int mode);
2585 public static int access (string pathname, AccessModes mode)
2587 int _mode = NativeConvert.FromAccessModes (mode);
2588 return sys_access (pathname, _mode);
2592 // off_t lseek(int filedes, off_t offset, int whence);
2593 [DllImport (MPH, SetLastError=true,
2594 EntryPoint="Mono_Posix_Syscall_lseek")]
2595 private static extern long sys_lseek (int fd, long offset, int whence);
2597 public static long lseek (int fd, long offset, SeekFlags whence)
2599 short _whence = NativeConvert.FromSeekFlags (whence);
2600 return sys_lseek (fd, offset, _whence);
2603 [DllImport (LIBC, SetLastError=true)]
2604 public static extern int close (int fd);
2607 // ssize_t read(int fd, void *buf, size_t count);
2608 [DllImport (MPH, SetLastError=true,
2609 EntryPoint="Mono_Posix_Syscall_read")]
2610 public static extern long read (int fd, IntPtr buf, ulong count);
2612 public static unsafe long read (int fd, void *buf, ulong count)
2614 return read (fd, (IntPtr) buf, count);
2618 // ssize_t write(int fd, const void *buf, size_t count);
2619 [DllImport (MPH, SetLastError=true,
2620 EntryPoint="Mono_Posix_Syscall_write")]
2621 public static extern long write (int fd, IntPtr buf, ulong count);
2623 public static unsafe long write (int fd, void *buf, ulong count)
2625 return write (fd, (IntPtr) buf, count);
2629 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
2630 [DllImport (MPH, SetLastError=true,
2631 EntryPoint="Mono_Posix_Syscall_pread")]
2632 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
2634 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
2636 return pread (fd, (IntPtr) buf, count, offset);
2640 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
2641 [DllImport (MPH, SetLastError=true,
2642 EntryPoint="Mono_Posix_Syscall_pwrite")]
2643 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
2645 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
2647 return pwrite (fd, (IntPtr) buf, count, offset);
2650 [DllImport (MPH, SetLastError=true,
2651 EntryPoint="Mono_Posix_Syscall_pipe")]
2652 public static extern int pipe (out int reading, out int writing);
2654 public static int pipe (int[] filedes)
2656 if (filedes == null || filedes.Length != 2) {
2660 int reading, writing;
2661 int r = pipe (out reading, out writing);
2662 filedes[0] = reading;
2663 filedes[1] = writing;
2667 [DllImport (LIBC, SetLastError=true)]
2668 public static extern uint alarm (uint seconds);
2670 [DllImport (LIBC, SetLastError=true)]
2671 public static extern uint sleep (uint seconds);
2673 [DllImport (LIBC, SetLastError=true)]
2674 public static extern uint ualarm (uint usecs, uint interval);
2676 [DllImport (LIBC, SetLastError=true)]
2677 public static extern int pause ();
2680 // int chown(const char *path, uid_t owner, gid_t group);
2681 [DllImport (LIBC, SetLastError=true)]
2682 public static extern int chown (string path, uint owner, uint group);
2685 // int fchown(int fd, uid_t owner, gid_t group);
2686 [DllImport (LIBC, SetLastError=true)]
2687 public static extern int fchown (int fd, uint owner, uint group);
2690 // int lchown(const char *path, uid_t owner, gid_t group);
2691 [DllImport (LIBC, SetLastError=true)]
2692 public static extern int lchown (string path, uint owner, uint group);
2694 [DllImport (LIBC, SetLastError=true)]
2695 public static extern int chdir (string path);
2697 [DllImport (LIBC, SetLastError=true)]
2698 public static extern int fchdir (int fd);
2701 // char *getcwd(char *buf, size_t size);
2702 [DllImport (MPH, SetLastError=true,
2703 EntryPoint="Mono_Posix_Syscall_getcwd")]
2704 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
2706 public static StringBuilder getcwd (StringBuilder buf)
2708 getcwd (buf, (ulong) buf.Capacity);
2712 // getwd(2) is deprecated; don't expose it.
2714 [DllImport (LIBC, SetLastError=true)]
2715 public static extern int dup (int fd);
2717 [DllImport (LIBC, SetLastError=true)]
2718 public static extern int dup2 (int fd, int fd2);
2720 // TODO: does Mono marshal arrays properly?
2721 [DllImport (LIBC, SetLastError=true)]
2722 public static extern int execve (string path, string[] argv, string[] envp);
2724 [DllImport (LIBC, SetLastError=true)]
2725 public static extern int fexecve (int fd, string[] argv, string[] envp);
2727 [DllImport (LIBC, SetLastError=true)]
2728 public static extern int execv (string path, string[] argv);
2730 // TODO: execle, execl, execlp
2731 [DllImport (LIBC, SetLastError=true)]
2732 public static extern int execvp (string path, string[] argv);
2734 [DllImport (LIBC, SetLastError=true)]
2735 public static extern int nice (int inc);
2737 [DllImport (LIBC, SetLastError=true)]
2738 [CLSCompliant (false)]
2739 public static extern int _exit (int status);
2741 [DllImport (MPH, SetLastError=true,
2742 EntryPoint="Mono_Posix_Syscall_fpathconf")]
2743 public static extern long fpathconf (int filedes, PathConf name);
2745 [DllImport (MPH, SetLastError=true,
2746 EntryPoint="Mono_Posix_Syscall_pathconf")]
2747 public static extern long pathconf (string path, PathConf name);
2749 [DllImport (MPH, SetLastError=true,
2750 EntryPoint="Mono_Posix_Syscall_sysconf")]
2751 public static extern long sysconf (SysConf name);
2754 // size_t confstr(int name, char *buf, size_t len);
2755 [DllImport (MPH, SetLastError=true,
2756 EntryPoint="Mono_Posix_Syscall_confstr")]
2757 public static extern ulong confstr (ConfStr name, [Out] StringBuilder buf, ulong len);
2760 // pid_t getpid(void);
2761 [DllImport (LIBC, SetLastError=true)]
2762 public static extern int getpid ();
2765 // pid_t getppid(void);
2766 [DllImport (LIBC, SetLastError=true)]
2767 public static extern int getppid ();
2770 // int setpgid(pid_t pid, pid_t pgid);
2771 [DllImport (LIBC, SetLastError=true)]
2772 public static extern int setpgid (int pid, int pgid);
2775 // pid_t getpgid(pid_t pid);
2776 [DllImport (LIBC, SetLastError=true)]
2777 public static extern int getpgid (int pid);
2779 [DllImport (LIBC, SetLastError=true)]
2780 public static extern int setpgrp ();
2783 // pid_t getpgrp(void);
2784 [DllImport (LIBC, SetLastError=true)]
2785 public static extern int getpgrp ();
2788 // pid_t setsid(void);
2789 [DllImport (LIBC, SetLastError=true)]
2790 public static extern int setsid ();
2793 // pid_t getsid(pid_t pid);
2794 [DllImport (LIBC, SetLastError=true)]
2795 public static extern int getsid (int pid);
2798 // uid_t getuid(void);
2799 [DllImport (LIBC, SetLastError=true)]
2800 public static extern uint getuid ();
2803 // uid_t geteuid(void);
2804 [DllImport (LIBC, SetLastError=true)]
2805 public static extern uint geteuid ();
2808 // gid_t getgid(void);
2809 [DllImport (LIBC, SetLastError=true)]
2810 public static extern uint getgid ();
2813 // gid_t getgid(void);
2814 [DllImport (LIBC, SetLastError=true)]
2815 public static extern uint getegid ();
2818 // int getgroups(int size, gid_t list[]);
2819 [DllImport (LIBC, SetLastError=true)]
2820 public static extern int getgroups (int size, uint[] list);
2822 public static int getgroups (uint[] list)
2824 return getgroups (list.Length, list);
2828 // int setuid(uid_t uid);
2829 [DllImport (LIBC, SetLastError=true)]
2830 public static extern int setuid (uint uid);
2833 // int setreuid(uid_t ruid, uid_t euid);
2834 [DllImport (LIBC, SetLastError=true)]
2835 public static extern int setreuid (uint ruid, uint euid);
2838 // int setregid(gid_t ruid, gid_t euid);
2839 [DllImport (LIBC, SetLastError=true)]
2840 public static extern int setregid (uint rgid, uint egid);
2843 // int seteuid(uid_t euid);
2844 [DllImport (LIBC, SetLastError=true)]
2845 public static extern int seteuid (uint euid);
2848 // int setegid(gid_t euid);
2849 [DllImport (LIBC, SetLastError=true)]
2850 public static extern int setegid (uint uid);
2853 // int setgid(gid_t gid);
2854 [DllImport (LIBC, SetLastError=true)]
2855 public static extern int setgid (uint gid);
2858 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
2859 [DllImport (LIBC, SetLastError=true)]
2860 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
2863 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
2864 [DllImport (LIBC, SetLastError=true)]
2865 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
2868 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
2869 [DllImport (LIBC, SetLastError=true)]
2870 public static extern int setresuid (uint ruid, uint euid, uint suid);
2873 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
2874 [DllImport (LIBC, SetLastError=true)]
2875 public static extern int setresgid (uint rgid, uint egid, uint sgid);
2878 // pid_t fork(void);
2879 [DllImport (LIBC, SetLastError=true)]
2880 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
2881 "shutdown code.\nUse System.Diagnostics.Process instead")]
2882 private static extern int fork ();
2885 // pid_t vfork(void);
2886 [DllImport (LIBC, SetLastError=true)]
2887 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
2888 "shutdown code.\nUse System.Diagnostics.Process instead")]
2889 private static extern int vfork ();
2891 private static object tty_lock = new object ();
2893 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
2894 private static extern IntPtr sys_ttyname (int fd);
2896 public static string ttyname (int fd)
2899 IntPtr r = sys_ttyname (fd);
2900 return UnixMarshal.PtrToString (r);
2905 // int ttyname_r(int fd, char *buf, size_t buflen);
2906 [DllImport (MPH, SetLastError=true,
2907 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
2908 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
2910 public static int ttyname_r (int fd, StringBuilder buf)
2912 return ttyname_r (fd, buf, (ulong) buf.Capacity);
2915 [DllImport (LIBC, EntryPoint="isatty")]
2916 private static extern int sys_isatty (int fd);
2918 public static bool isatty (int fd)
2920 return sys_isatty (fd) == 1;
2923 [DllImport (LIBC, SetLastError=true)]
2924 public static extern int link (string oldpath, string newpath);
2926 [DllImport (LIBC, SetLastError=true)]
2927 public static extern int symlink (string oldpath, string newpath);
2930 // int readlink(const char *path, char *buf, size_t bufsize);
2931 [DllImport (MPH, SetLastError=true,
2932 EntryPoint="Mono_Posix_Syscall_readlink")]
2933 public static extern int readlink (string path, [Out] StringBuilder buf, ulong bufsiz);
2935 public static int readlink (string path, [Out] StringBuilder buf)
2937 return readlink (path, buf, (ulong) buf.Capacity);
2940 [DllImport (LIBC, SetLastError=true)]
2941 public static extern int unlink (string pathname);
2943 [DllImport (LIBC, SetLastError=true)]
2944 public static extern int rmdir (string pathname);
2947 // pid_t tcgetpgrp(int fd);
2948 [DllImport (LIBC, SetLastError=true)]
2949 public static extern int tcgetpgrp (int fd);
2952 // int tcsetpgrp(int fd, pid_t pgrp);
2953 [DllImport (LIBC, SetLastError=true)]
2954 public static extern int tcsetpgrp (int fd, int pgrp);
2956 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
2957 private static extern IntPtr sys_getlogin ();
2959 public static string getlogin ()
2961 lock (getlogin_lock) {
2962 IntPtr r = sys_getlogin ();
2963 return UnixMarshal.PtrToString (r);
2968 // int getlogin_r(char *buf, size_t bufsize);
2969 [DllImport (MPH, SetLastError=true,
2970 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
2971 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
2973 public static int getlogin_r (StringBuilder name)
2975 return getlogin_r (name, (ulong) name.Capacity);
2978 [DllImport (LIBC, SetLastError=true)]
2979 public static extern int setlogin (string name);
2982 // int gethostname(char *name, size_t len);
2983 [DllImport (MPH, SetLastError=true,
2984 EntryPoint="Mono_Posix_Syscall_gethostname")]
2985 public static extern int gethostname ([Out] StringBuilder name, ulong len);
2987 public static int gethostname (StringBuilder name)
2989 return gethostname (name, (ulong) name.Capacity);
2993 // int gethostname(const char *name, size_t len);
2994 [DllImport (MPH, SetLastError=true,
2995 EntryPoint="Mono_Posix_Syscall_sethostname")]
2996 public static extern int sethostname (string name, ulong len);
2998 public static int sethostname (string name)
3000 return sethostname (name, (ulong) name.Length);
3003 [DllImport (MPH, SetLastError=true,
3004 EntryPoint="Mono_Posix_Syscall_gethostid")]
3005 public static extern long gethostid ();
3007 [DllImport (MPH, SetLastError=true,
3008 EntryPoint="Mono_Posix_Syscall_sethostid")]
3009 public static extern int sethostid (long hostid);
3012 // int getdomainname(char *name, size_t len);
3013 [DllImport (MPH, SetLastError=true,
3014 EntryPoint="Mono_Posix_Syscall_getdomainname")]
3015 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
3017 public static int getdomainname (StringBuilder name)
3019 return getdomainname (name, (ulong) name.Capacity);
3023 // int setdomainname(const char *name, size_t len);
3024 [DllImport (MPH, SetLastError=true,
3025 EntryPoint="Mono_Posix_Syscall_setdomainname")]
3026 public static extern int setdomainname (string name, ulong len);
3028 public static int setdomainname (string name)
3030 return setdomainname (name, (ulong) name.Length);
3033 [DllImport (LIBC, SetLastError=true)]
3034 public static extern int vhangup ();
3036 // Revoke doesn't appear to be POSIX. Include it?
3037 [DllImport (LIBC, SetLastError=true)]
3038 public static extern int revoke (string file);
3040 // TODO: profil? It's not POSIX.
3042 [DllImport (LIBC, SetLastError=true)]
3043 public static extern int acct (string filename);
3045 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
3046 private static extern IntPtr sys_getusershell ();
3048 internal static object usershell_lock = new object ();
3050 public static string getusershell ()
3052 lock (usershell_lock) {
3053 IntPtr r = sys_getusershell ();
3054 return UnixMarshal.PtrToString (r);
3058 [DllImport (LIBC, SetLastError=true, EntryPoint="setusershell")]
3059 private static extern void sys_setusershell ();
3061 public static void setusershell ()
3063 lock (usershell_lock) {
3064 sys_setusershell ();
3068 [DllImport (LIBC, SetLastError=true, EntryPoint="endusershell")]
3069 private static extern void sys_endusershell ();
3071 public static void endusershell ()
3073 lock (usershell_lock) {
3074 sys_endusershell ();
3078 [DllImport (LIBC, SetLastError=true)]
3079 private static extern int daemon (int nochdir, int noclose);
3081 public static int daemon (bool nochdir, bool noclose)
3083 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
3086 [DllImport (LIBC, SetLastError=true)]
3087 public static extern int chroot (string path);
3089 // skipping getpass(3) as the man page states:
3090 // This function is obsolete. Do not use it.
3092 [DllImport (LIBC, SetLastError=true)]
3093 public static extern int fsync (int fd);
3095 [DllImport (LIBC, SetLastError=true)]
3096 public static extern int fdatasync (int fd);
3098 [DllImport (LIBC, SetLastError=true)]
3099 public static extern void sync ();
3101 [DllImport (LIBC, SetLastError=true)]
3102 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
3103 "Use Unistd.sysconf (SysConf._SC_PAGESIZE).")]
3104 public static extern int getpagesize ();
3107 // int truncate(const char *path, off_t length);
3108 [DllImport (MPH, SetLastError=true,
3109 EntryPoint="Mono_Posix_Syscall_truncate")]
3110 public static extern int truncate (string path, long length);
3113 // int ftruncate(int fd, off_t length);
3114 [DllImport (MPH, SetLastError=true,
3115 EntryPoint="Mono_Posix_Syscall_ftruncate")]
3116 public static extern int ftruncate (int fd, long length);
3118 [DllImport (LIBC, SetLastError=true)]
3119 public static extern int getdtablesize ();
3121 [DllImport (LIBC, SetLastError=true)]
3122 public static extern int brk (IntPtr end_data_segment);
3124 [DllImport (LIBC, SetLastError=true)]
3125 public static extern IntPtr sbrk (IntPtr increment);
3127 // TODO: syscall(2)?
3128 // Probably safer to skip entirely.
3131 // int lockf(int fd, int cmd, off_t len);
3132 [DllImport (MPH, SetLastError=true,
3133 EntryPoint="Mono_Posix_Syscall_lockf")]
3134 public static extern int lockf (int fd, LockfCommand cmd, long len);
3136 internal static object crypt_lock = new object ();
3138 [DllImport (CRYPT, SetLastError=true, EntryPoint="crypt")]
3139 private static extern IntPtr sys_crypt (string key, string salt);
3141 public static string crypt (string key, string salt)
3144 IntPtr r = sys_crypt (key, salt);
3145 return UnixMarshal.PtrToString (r);
3149 internal static object encrypt_lock = new object ();
3151 [DllImport (CRYPT, SetLastError=true, EntryPoint="encrypt")]
3152 private static extern void sys_encrypt ([In, Out] byte[] block, int edflag);
3154 public static void encrypt (byte[] block, bool decode)
3156 if (block.Length < 64)
3157 throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
3158 lock (encrypt_lock) {
3159 sys_encrypt (block, decode ? 1 : 0);
3164 // void swab(const void *from, void *to, ssize_t n);
3165 [DllImport (MPH, SetLastError=true,
3166 EntryPoint="Mono_Posix_Syscall_swab")]
3167 public static extern void swab (IntPtr from, IntPtr to, long n);
3169 public static unsafe void swab (void* from, void* to, long n)
3171 swab ((IntPtr) from, (IntPtr) to, n);
3176 #region <utime.h> Declarations
3178 // <utime.h> -- COMPLETE
3181 [DllImport (MPH, SetLastError=true,
3182 EntryPoint="Mono_Posix_Syscall_utime")]
3183 private static extern int sys_utime (string filename, ref Utimbuf buf, int use_buf);
3185 public static int utime (string filename, ref Utimbuf buf)
3187 return sys_utime (filename, ref buf, 1);
3190 public static int utime (string filename)
3192 Utimbuf buf = new Utimbuf ();
3193 return sys_utime (filename, ref buf, 0);