2 // Mono.Unix/Syscall.cs
5 // Miguel de Icaza (miguel@novell.com)
6 // Jonathan Pryor (jonpryor@vt.edu)
8 // (C) 2003 Novell, Inc.
9 // (C) 2004-2005 Jonathan Pryor
11 // This file implements the low-level syscall interface to the POSIX
14 // This file tries to stay close to the low-level API as much as possible
15 // using enumerations, structures and in a few cases, using existing .NET
18 // Implementation notes:
20 // Since the values for the various constants on the API changes
21 // from system to system (even Linux on different architectures will
22 // have different values), we define our own set of values, and we
23 // use a set of C helper routines to map from the constants we define
24 // to the values of the native OS.
26 // Bitfields are flagged with the [Map] attribute, and a helper program
27 // generates a set of routines that we can call to convert from our value
28 // definitions to the value definitions expected by the OS; see
29 // UnixConvert for the conversion routines.
31 // Methods that require tuning are bound as `private sys_NAME' methods
32 // and then a `NAME' method is exposed.
34 // Deprecated Warning:
36 // This class is deprecated, and exists only for backward compatibility
37 // with development versions of Mono 1.1.x. It will be removed with
38 // Mono 1.2. Migrate to the Mono.Unix.Native types, or use the Unix*
39 // wrapper classes instead.
41 // The [Map] attributes have been removed. However, since the type names
42 // are identical to those in Mono.Unix.Native, the MonoPosixHelper methods
43 // will continue to exist and function correctly.
47 // Permission is hereby granted, free of charge, to any person obtaining
48 // a copy of this software and associated documentation files (the
49 // "Software"), to deal in the Software without restriction, including
50 // without limitation the rights to use, copy, modify, merge, publish,
51 // distribute, sublicense, and/or sell copies of the Software, and to
52 // permit persons to whom the Software is furnished to do so, subject to
53 // the following conditions:
55 // The above copyright notice and this permission notice shall be
56 // included in all copies or substantial portions of the Software.
58 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
59 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
61 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
62 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
63 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
64 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68 using System.Collections;
69 using System.Runtime.InteropServices;
78 [CLSCompliant (false)]
79 [Obsolete ("Use Mono.Unix.Native.SyslogOptions")]
80 public enum SyslogOptions {
81 LOG_PID = 0x01, // log the pid with each message
82 LOG_CONS = 0x02, // log on the console if errors in sending
83 LOG_ODELAY = 0x04, // delay open until first syslog (default)
84 LOG_NDELAY = 0x08, // don't delay open
85 LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
86 LOG_PERROR = 0x20 // log to stderr as well
89 [CLSCompliant (false)]
90 [Obsolete ("Use Mono.Unix.Native.SyslogFacility")]
91 public enum SyslogFacility {
94 [Obsolete ("use SyslogFacility.LOG_USER")]
104 LOG_AUTHPRIV = 10 << 3,
106 LOG_LOCAL0 = 16 << 3,
107 LOG_LOCAL1 = 17 << 3,
108 LOG_LOCAL2 = 18 << 3,
109 LOG_LOCAL3 = 19 << 3,
110 LOG_LOCAL4 = 20 << 3,
111 LOG_LOCAL5 = 21 << 3,
112 LOG_LOCAL6 = 22 << 3,
113 LOG_LOCAL7 = 23 << 3,
116 [CLSCompliant (false)]
117 [Obsolete ("Use Mono.Unix.Native.SyslogLevel")]
118 public enum SyslogLevel {
119 LOG_EMERG = 0, // system is unusable
120 LOG_ALERT = 1, // action must be taken immediately
121 LOG_CRIT = 2, // critical conditions
122 LOG_ERR = 3, // warning conditions
123 LOG_WARNING = 4, // warning conditions
124 LOG_NOTICE = 5, // normal but significant condition
125 LOG_INFO = 6, // informational
126 LOG_DEBUG = 7 // debug-level messages
130 [CLSCompliant (false)]
131 [Obsolete ("Use Mono.Unix.Native.OpenFlags")]
132 public enum OpenFlags : int {
136 O_RDONLY = 0x00000000,
137 O_WRONLY = 0x00000001,
141 // Or-ed with zero or more of these
143 O_CREAT = 0x00000040,
145 O_NOCTTY = 0x00000100,
146 O_TRUNC = 0x00000200,
147 O_APPEND = 0x00000400,
148 O_NONBLOCK = 0x00000800,
152 // These are non-Posix. Using them will result in errors/exceptions on
153 // non-supported platforms.
155 // (For example, "C-wrapped" system calls -- calls with implementation in
156 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
157 // calls will generate an exception in UnixConvert, as the value can't be
158 // converted on the target platform.)
161 O_NOFOLLOW = 0x00020000,
162 O_DIRECTORY = 0x00010000,
163 O_DIRECT = 0x00004000,
164 O_ASYNC = 0x00002000,
165 O_LARGEFILE = 0x00008000
170 [CLSCompliant (false)]
171 [Obsolete ("Use Mono.Unix.Native.FilePermissions")]
172 public enum FilePermissions : uint {
173 S_ISUID = 0x0800, // Set user ID on execution
174 S_ISGID = 0x0400, // Set gorup ID on execution
175 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
176 S_IRUSR = 0x0100, // Read by owner
177 S_IWUSR = 0x0080, // Write by owner
178 S_IXUSR = 0x0040, // Execute by owner
179 S_IRGRP = 0x0020, // Read by group
180 S_IWGRP = 0x0010, // Write by group
181 S_IXGRP = 0x0008, // Execute by group
182 S_IROTH = 0x0004, // Read by other
183 S_IWOTH = 0x0002, // Write by other
184 S_IXOTH = 0x0001, // Execute by other
186 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
187 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
188 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
189 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
190 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
191 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
194 // Why these are held in "mode_t" is beyond me...
195 S_IFMT = 0xF000, // Bits which determine file type
196 S_IFDIR = 0x4000, // Directory
197 S_IFCHR = 0x2000, // Character device
198 S_IFBLK = 0x6000, // Block device
199 S_IFREG = 0x8000, // Regular file
200 S_IFIFO = 0x1000, // FIFO
201 S_IFLNK = 0xA000, // Symbolic link
202 S_IFSOCK = 0xC000, // Socket
205 [CLSCompliant (false)]
206 [Obsolete ("Use Mono.Unix.Native.FcntlCommand")]
207 public enum FcntlCommand : int {
208 // Form /usr/include/bits/fcntl.h
209 F_DUPFD = 0, // Duplicate file descriptor.
210 F_GETFD = 1, // Get file descriptor flags.
211 F_SETFD = 2, // Set file descriptor flags.
212 F_GETFL = 3, // Get file status flags.
213 F_SETFL = 4, // Set file status flags.
214 F_GETLK = 12, // Get record locking info. [64]
215 F_SETLK = 13, // Set record locking info (non-blocking). [64]
216 F_SETLKW = 14, // Set record locking info (blocking). [64]
217 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
218 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
219 F_SETSIG = 10, // Set number of signal to be sent.
220 F_GETSIG = 11, // Get number of signal to be sent.
221 F_SETLEASE = 1024, // Set a lease.
222 F_GETLEASE = 1025, // Enquire what lease is active.
223 F_NOTIFY = 1026, // Required notifications on a directory
226 [CLSCompliant (false)]
227 [Obsolete ("Use Mono.Unix.Native.LockType")]
228 public enum LockType : short {
229 F_RDLCK = 0, // Read lock.
230 F_WRLCK = 1, // Write lock.
231 F_UNLCK = 2, // Remove lock.
234 [CLSCompliant (false)]
235 [Obsolete ("Use Mono.Unix.Native.SeekFlags")]
236 public enum SeekFlags : short {
237 // values liberally copied from /usr/include/unistd.h
238 SEEK_SET = 0, // Seek from beginning of file.
239 SEEK_CUR = 1, // Seek from current position.
240 SEEK_END = 2, // Seek from end of file.
242 L_SET = SEEK_SET, // BSD alias for SEEK_SET
243 L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
244 L_XTND = SEEK_END, // BSD alias for SEEK_END
248 [CLSCompliant (false)]
249 [Obsolete ("Use Mono.Unix.Native.DirectoryNotifyFlags")]
250 public enum DirectoryNotifyFlags : int {
251 // from /usr/include/bits/fcntl.h
252 DN_ACCESS = 0x00000001, // File accessed.
253 DN_MODIFY = 0x00000002, // File modified.
254 DN_CREATE = 0x00000004, // File created.
255 DN_DELETE = 0x00000008, // File removed.
256 DN_RENAME = 0x00000010, // File renamed.
257 DN_ATTRIB = 0x00000020, // File changed attributes.
258 DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
261 [CLSCompliant (false)]
262 [Obsolete ("Use Mono.Unix.Native.PosixFadviseAdvice")]
263 public enum PosixFadviseAdvice : int {
264 POSIX_FADV_NORMAL = 0, // No further special treatment.
265 POSIX_FADV_RANDOM = 1, // Expect random page references.
266 POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
267 POSIX_FADV_WILLNEED = 3, // Will need these pages.
268 POSIX_FADV_DONTNEED = 4, // Don't need these pages.
269 POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
272 [CLSCompliant (false)]
273 [Obsolete ("Use Mono.Unix.Native.PosixMadviseAdvice")]
274 public enum PosixMadviseAdvice : int {
275 POSIX_MADV_NORMAL = 0, // No further special treatment.
276 POSIX_MADV_RANDOM = 1, // Expect random page references.
277 POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
278 POSIX_MADV_WILLNEED = 3, // Will need these pages.
279 POSIX_MADV_DONTNEED = 4, // Don't need these pages.
282 [CLSCompliant (false)]
283 [Obsolete ("Use Mono.Unix.Native.Signum")]
284 public enum Signum : int {
285 SIGHUP = 1, // Hangup (POSIX).
286 SIGINT = 2, // Interrupt (ANSI).
287 SIGQUIT = 3, // Quit (POSIX).
288 SIGILL = 4, // Illegal instruction (ANSI).
289 SIGTRAP = 5, // Trace trap (POSIX).
290 SIGABRT = 6, // Abort (ANSI).
291 SIGIOT = 6, // IOT trap (4.2 BSD).
292 SIGBUS = 7, // BUS error (4.2 BSD).
293 SIGFPE = 8, // Floating-point exception (ANSI).
294 SIGKILL = 9, // Kill, unblockable (POSIX).
295 SIGUSR1 = 10, // User-defined signal 1 (POSIX).
296 SIGSEGV = 11, // Segmentation violation (ANSI).
297 SIGUSR2 = 12, // User-defined signal 2 (POSIX).
298 SIGPIPE = 13, // Broken pipe (POSIX).
299 SIGALRM = 14, // Alarm clock (POSIX).
300 SIGTERM = 15, // Termination (ANSI).
301 SIGSTKFLT = 16, // Stack fault.
302 SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
303 SIGCHLD = 17, // Child status has changed (POSIX).
304 SIGCONT = 18, // Continue (POSIX).
305 SIGSTOP = 19, // Stop, unblockable (POSIX).
306 SIGTSTP = 20, // Keyboard stop (POSIX).
307 SIGTTIN = 21, // Background read from tty (POSIX).
308 SIGTTOU = 22, // Background write to tty (POSIX).
309 SIGURG = 23, // Urgent condition on socket (4.2 BSD).
310 SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
311 SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
312 SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
313 SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
314 SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
315 SIGPOLL = SIGIO, // Pollable event occurred (System V).
316 SIGIO = 29, // I/O now possible (4.2 BSD).
317 SIGPWR = 30, // Power failure restart (System V).
318 SIGSYS = 31, // Bad system call.
323 [CLSCompliant (false)]
324 [Obsolete ("Use Mono.Unix.Native.WaitOptions")]
325 public enum WaitOptions : int {
326 WNOHANG = 1, // Don't block waiting
327 WUNTRACED = 2, // Report status of stopped children
331 [CLSCompliant (false)]
332 [Obsolete ("Use Mono.Unix.Native.AccessModes")]
333 public enum AccessMode : int {
340 [CLSCompliant (false)]
341 [Obsolete ("Use Mono.Unix.Native.PathConf")]
342 public enum PathConf : int {
349 _PC_CHOWN_RESTRICTED,
357 _PC_REC_INCR_XFER_SIZE,
358 _PC_REC_MAX_XFER_SIZE,
359 _PC_REC_MIN_XFER_SIZE,
366 [CLSCompliant (false)]
367 [Obsolete ("Use Mono.Unix.Native.SysConf")]
368 public enum SysConf : int {
378 _SC_REALTIME_SIGNALS,
379 _SC_PRIORITY_SCHEDULING,
388 _SC_MEMORY_PROTECTION,
391 _SC_SHARED_MEMORY_OBJECTS,
394 _SC_AIO_PRIO_DELTA_MAX,
405 /* Values for the argument to `sysconf'
406 corresponding to _POSIX2_* symbols. */
411 _SC_COLL_WEIGHTS_MAX,
416 _SC_CHARCLASS_NAME_MAX,
432 _SC_IOV_MAX = _SC_UIO_MAXIOV,
433 _SC_PII_INTERNET_STREAM,
434 _SC_PII_INTERNET_DGRAM,
439 /* Values according to POSIX 1003.1c (POSIX threads). */
441 _SC_THREAD_SAFE_FUNCTIONS,
442 _SC_GETGR_R_SIZE_MAX,
443 _SC_GETPW_R_SIZE_MAX,
446 _SC_THREAD_DESTRUCTOR_ITERATIONS,
448 _SC_THREAD_STACK_MIN,
449 _SC_THREAD_THREADS_MAX,
450 _SC_THREAD_ATTR_STACKADDR,
451 _SC_THREAD_ATTR_STACKSIZE,
452 _SC_THREAD_PRIORITY_SCHEDULING,
453 _SC_THREAD_PRIO_INHERIT,
454 _SC_THREAD_PRIO_PROTECT,
455 _SC_THREAD_PROCESS_SHARED,
456 _SC_NPROCESSORS_CONF,
457 _SC_NPROCESSORS_ONLN,
463 _SC_XOPEN_XCU_VERSION,
498 _SC_XBS5_ILP32_OFF32,
499 _SC_XBS5_ILP32_OFFBIG,
501 _SC_XBS5_LPBIG_OFFBIG,
504 _SC_XOPEN_REALTIME_THREADS,
509 _SC_C_LANG_SUPPORT_R,
515 _SC_DEVICE_SPECIFIC_R,
526 _SC_READER_WRITER_LOCKS,
534 _SC_THREAD_SPORADIC_SERVER,
536 _SC_SYSTEM_DATABASE_R,
538 _SC_TYPED_MEMORY_OBJECTS,
542 _SC_2_PBS_ACCOUNTING,
548 _SC_2_PBS_CHECKPOINT,
555 _SC_TRACE_EVENT_FILTER,
558 _SC_LEVEL1_ICACHE_SIZE,
559 _SC_LEVEL1_ICACHE_ASSOC,
560 _SC_LEVEL1_ICACHE_LINESIZE,
561 _SC_LEVEL1_DCACHE_SIZE,
562 _SC_LEVEL1_DCACHE_ASSOC,
563 _SC_LEVEL1_DCACHE_LINESIZE,
564 _SC_LEVEL2_CACHE_SIZE,
565 _SC_LEVEL2_CACHE_ASSOC,
566 _SC_LEVEL2_CACHE_LINESIZE,
567 _SC_LEVEL3_CACHE_SIZE,
568 _SC_LEVEL3_CACHE_ASSOC,
569 _SC_LEVEL3_CACHE_LINESIZE,
570 _SC_LEVEL4_CACHE_SIZE,
571 _SC_LEVEL4_CACHE_ASSOC,
572 _SC_LEVEL4_CACHE_LINESIZE
575 [CLSCompliant (false)]
576 [Obsolete ("Use Mono.Unix.Native.ConfStr")]
577 public enum ConfStr : int {
578 _CS_PATH, /* The default search path. */
579 _CS_V6_WIDTH_RESTRICTED_ENVS,
580 _CS_GNU_LIBC_VERSION,
581 _CS_GNU_LIBPTHREAD_VERSION,
582 _CS_LFS_CFLAGS = 1000,
590 _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
591 _CS_XBS5_ILP32_OFF32_LDFLAGS,
592 _CS_XBS5_ILP32_OFF32_LIBS,
593 _CS_XBS5_ILP32_OFF32_LINTFLAGS,
594 _CS_XBS5_ILP32_OFFBIG_CFLAGS,
595 _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
596 _CS_XBS5_ILP32_OFFBIG_LIBS,
597 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
598 _CS_XBS5_LP64_OFF64_CFLAGS,
599 _CS_XBS5_LP64_OFF64_LDFLAGS,
600 _CS_XBS5_LP64_OFF64_LIBS,
601 _CS_XBS5_LP64_OFF64_LINTFLAGS,
602 _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
603 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
604 _CS_XBS5_LPBIG_OFFBIG_LIBS,
605 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
606 _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
607 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
608 _CS_POSIX_V6_ILP32_OFF32_LIBS,
609 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
610 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
611 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
612 _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
613 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
614 _CS_POSIX_V6_LP64_OFF64_CFLAGS,
615 _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
616 _CS_POSIX_V6_LP64_OFF64_LIBS,
617 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
618 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
619 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
620 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
621 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
624 [CLSCompliant (false)]
625 [Obsolete ("Use Mono.Unix.Native.LockfCommand")]
626 public enum LockfCommand : int {
627 F_ULOCK = 0, // Unlock a previously locked region.
628 F_LOCK = 1, // Lock a region for exclusive use.
629 F_TLOCK = 2, // Test and lock a region for exclusive use.
630 F_TEST = 3, // Test a region for other process locks.
634 [CLSCompliant (false)]
635 [Obsolete ("Use Mono.Unix.Native.PollEvents")]
636 public enum PollEvents : short {
637 POLLIN = 0x0001, // There is data to read
638 POLLPRI = 0x0002, // There is urgent data to read
639 POLLOUT = 0x0004, // Writing now will not block
640 POLLERR = 0x0008, // Error condition
641 POLLHUP = 0x0010, // Hung up
642 POLLNVAL = 0x0020, // Invalid request; fd not open
643 // XPG4.2 definitions (via _XOPEN_SOURCE)
644 POLLRDNORM = 0x0040, // Normal data bay be read
645 POLLRDBAND = 0x0080, // Priority data may be read
646 POLLWRNORM = 0x0100, // Writing now will not block
647 POLLWRBAND = 0x0200, // Priority data may be written
651 [CLSCompliant (false)]
652 [Obsolete ("Use Mono.Unix.Native.XattrFlags")]
653 public enum XattrFlags : int {
660 [CLSCompliant (false)]
661 [Obsolete ("Use Mono.Unix.Native.MountFlags")]
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 [Obsolete ("Use Mono.Unix.Native.MmapFlags")]
678 public enum MmapFlags : int {
679 MAP_SHARED = 0x01, // Share changes.
680 MAP_PRIVATE = 0x02, // Changes are private.
681 MAP_TYPE = 0x0f, // Mask for type of mapping.
682 MAP_FIXED = 0x10, // Interpret addr exactly.
684 MAP_ANONYMOUS = 0x20, // Don't use a file.
685 MAP_ANON = MAP_ANONYMOUS,
687 // These are Linux-specific.
688 MAP_GROWSDOWN = 0x00100, // Stack-like segment.
689 MAP_DENYWRITE = 0x00800, // ETXTBSY
690 MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
691 MAP_LOCKED = 0x02000, // Lock the mapping.
692 MAP_NORESERVE = 0x04000, // Don't check for reservations.
693 MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
694 MAP_NONBLOCK = 0x10000, // Do not block on IO.
698 [CLSCompliant (false)]
699 [Obsolete ("Use Mono.Unix.Native.MmapProts")]
700 public enum MmapProt : int {
701 PROT_READ = 0x1, // Page can be read.
702 PROT_WRITE = 0x2, // Page can be written.
703 PROT_EXEC = 0x4, // Page can be executed.
704 PROT_NONE = 0x0, // Page can not be accessed.
705 PROT_GROWSDOWN = 0x01000000, // Extend change to start of
706 // growsdown vma (mprotect only).
707 PROT_GROWSUP = 0x02000000, // Extend change to start of
708 // growsup vma (mprotect only).
712 [CLSCompliant (false)]
713 [Obsolete ("Use Mono.Unix.Native.MsyncFlags")]
714 public enum MsyncFlags : int {
715 MS_ASYNC = 0x1, // Sync memory asynchronously.
716 MS_SYNC = 0x4, // Synchronous memory sync.
717 MS_INVALIDATE = 0x2, // Invalidate the caches.
721 [CLSCompliant (false)]
722 [Obsolete ("Use Mono.Unix.Native.MlockallFlags")]
723 public enum MlockallFlags : int {
724 MCL_CURRENT = 0x1, // Lock all currently mapped pages.
725 MCL_FUTURE = 0x2, // Lock all additions to address
729 [CLSCompliant (false)]
730 [Obsolete ("Use Mono.Unix.Native.MremapFlags")]
731 public enum MremapFlags : ulong {
732 MREMAP_MAYMOVE = 0x1,
739 [CLSCompliant (false)]
740 [Obsolete ("Use Mono.Unix.Native.Flock")]
741 public struct Flock {
742 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
743 public SeekFlags l_whence; // How to interpret l_start
744 public /* off_t */ long l_start; // Starting offset for lock
745 public /* off_t */ long l_len; // Number of bytes to lock
746 public /* pid_t */ int l_pid; // PID of process blocking our lock (F_GETLK only)
749 [CLSCompliant (false)]
750 [Obsolete ("Use Mono.Unix.Native.Pollfd")]
751 [StructLayout(LayoutKind.Sequential)]
752 public struct Pollfd {
754 public PollEvents events;
755 public PollEvents revents;
758 [Obsolete ("Use Mono.Unix.Native.Stat")]
760 [CLSCompliant (false)]
761 public /* dev_t */ ulong st_dev; // device
762 [CLSCompliant (false)]
763 public /* ino_t */ ulong st_ino; // inode
764 [CLSCompliant (false)]
765 public FilePermissions st_mode; // protection
766 private uint _padding_; // padding for structure alignment
767 [CLSCompliant (false)]
768 public /* nlink_t */ ulong st_nlink; // number of hard links
769 [CLSCompliant (false)]
770 public /* uid_t */ uint st_uid; // user ID of owner
771 [CLSCompliant (false)]
772 public /* gid_t */ uint st_gid; // group ID of owner
773 [CLSCompliant (false)]
774 public /* dev_t */ ulong st_rdev; // device type (if inode device)
775 public /* off_t */ long st_size; // total size, in bytes
776 public /* blksize_t */ long st_blksize; // blocksize for filesystem I/O
777 public /* blkcnt_t */ long st_blocks; // number of blocks allocated
778 public /* time_t */ long st_atime; // time of last access
779 public /* time_t */ long st_mtime; // time of last modification
780 public /* time_t */ long st_ctime; // time of last status change
783 [CLSCompliant (false)]
784 [Obsolete ("Use Mono.Unix.Native.Statvfs")]
785 public struct Statvfs {
786 public ulong f_bsize; // file system block size
787 public ulong f_frsize; // fragment size
788 public /* fsblkcnt_t */ ulong f_blocks; // size of fs in f_frsize units
789 public /* fsblkcnt_t */ ulong f_bfree; // # free blocks
790 public /* fsblkcnt_t */ ulong f_bavail; // # free blocks for non-root
791 public /* fsfilcnt_t */ ulong f_files; // # inodes
792 public /* fsfilcnt_t */ ulong f_ffree; // # free inodes
793 public /* fsfilcnt_t */ ulong f_favail; // # free inodes for non-root
794 public ulong f_fsid; // file system id
795 public MountFlags f_flag; // mount flags
796 public ulong f_namemax; // maximum filename length
799 [Obsolete ("Use Mono.Unix.Native.Timeval")]
800 public struct Timeval {
801 public /* time_t */ long tv_sec; // seconds
802 public /* suseconds_t */ long tv_usec; // microseconds
805 [Obsolete ("Use Mono.Unix.Native.Timezone")]
806 public struct Timezone {
807 public int tz_minuteswest; // minutes W of Greenwich
808 private int tz_dsttime; // type of dst correction (OBSOLETE)
811 [Obsolete ("Use Mono.Unix.Native.Utimbuf")]
812 public struct Utimbuf {
813 public /* time_t */ long actime; // access time
814 public /* time_t */ long modtime; // modification time
821 [Obsolete ("Use Mono.Unix.Native.Dirent")]
822 public sealed class Dirent
824 [CLSCompliant (false)]
825 public /* ino_t */ ulong d_ino;
826 public /* off_t */ long d_off;
827 [CLSCompliant (false)]
828 public ushort d_reclen;
830 public string d_name;
832 public override int GetHashCode ()
834 return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
835 d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
836 d_name.GetHashCode ();
839 public override bool Equals (object obj)
841 if (obj == null || GetType() != obj.GetType())
843 Dirent d = (Dirent) obj;
844 return d.d_ino == d_ino && d.d_off == d_off &&
845 d.d_reclen == d_reclen && d.d_type == d_type &&
849 public override string ToString ()
854 public static bool operator== (Dirent lhs, Dirent rhs)
856 return Object.Equals (lhs, rhs);
859 public static bool operator!= (Dirent lhs, Dirent rhs)
861 return !Object.Equals (lhs, rhs);
865 [Obsolete ("Use Mono.Unix.Native.Fstab")]
866 public sealed class Fstab
868 public string fs_spec;
869 public string fs_file;
870 public string fs_vfstype;
871 public string fs_mntops;
872 public string fs_type;
874 public int fs_passno;
876 public override int GetHashCode ()
878 return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
879 fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
880 fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
883 public override bool Equals (object obj)
885 if (obj == null || GetType() != obj.GetType())
887 Fstab f = (Fstab) obj;
888 return f.fs_spec == fs_spec && f.fs_file == fs_file &&
889 f.fs_vfstype == fs_vfstype && f.fs_mntops == fs_mntops &&
890 f.fs_type == fs_type && f.fs_freq == fs_freq &&
891 f.fs_passno == fs_passno;
894 public override string ToString ()
899 public static bool operator== (Fstab lhs, Fstab rhs)
901 return Object.Equals (lhs, rhs);
904 public static bool operator!= (Fstab lhs, Fstab rhs)
906 return !Object.Equals (lhs, rhs);
910 [Obsolete ("Use Mono.Unix.Native.Group")]
911 public sealed class Group
913 public string gr_name;
914 public string gr_passwd;
915 [CLSCompliant (false)]
916 public /* gid_t */ uint gr_gid;
917 public string[] gr_mem;
919 public override int GetHashCode ()
922 for (int i = 0; i < gr_mem.Length; ++i)
923 memhc ^= gr_mem[i].GetHashCode ();
925 return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
926 gr_gid.GetHashCode () ^ memhc;
929 public override bool Equals (object obj)
931 if (obj == null || GetType() != obj.GetType())
933 Group g = (Group) obj;
934 if (g.gr_gid != gr_gid)
936 if (g.gr_gid == gr_gid && g.gr_name == gr_name &&
937 g.gr_passwd == gr_passwd) {
938 if (g.gr_mem == gr_mem)
940 if (g.gr_mem == null || gr_mem == null)
942 if (g.gr_mem.Length != gr_mem.Length)
944 for (int i = 0; i < gr_mem.Length; ++i)
945 if (gr_mem[i] != g.gr_mem[i])
952 // Generate string in /etc/group format
953 public override string ToString ()
955 StringBuilder sb = new StringBuilder ();
956 sb.AppendFormat ("{0}:{1}:{2}:", gr_name, gr_passwd, gr_gid);
957 GetMembers (sb, gr_mem);
958 return sb.ToString ();
961 private static void GetMembers (StringBuilder sb, string[] members)
963 if (members.Length > 0)
964 sb.Append (members[0]);
965 for (int i = 1; i < members.Length; ++i) {
967 sb.Append (members[i]);
971 public static bool operator== (Group lhs, Group rhs)
973 return Object.Equals (lhs, rhs);
976 public static bool operator!= (Group lhs, Group rhs)
978 return !Object.Equals (lhs, rhs);
982 [Obsolete ("Use Mono.Unix.Native.Passwd")]
983 public sealed class Passwd
985 public string pw_name;
986 public string pw_passwd;
987 [CLSCompliant (false)]
988 public /* uid_t */ uint pw_uid;
989 [CLSCompliant (false)]
990 public /* gid_t */ uint pw_gid;
991 public string pw_gecos;
992 public string pw_dir;
993 public string pw_shell;
995 public override int GetHashCode ()
997 return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
998 pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
999 pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
1000 pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
1003 public override bool Equals (object obj)
1005 if (obj == null || GetType() != obj.GetType())
1007 Passwd p = (Passwd) obj;
1008 return p.pw_uid == pw_uid && p.pw_gid == pw_gid && p.pw_name == pw_name &&
1009 p.pw_passwd == pw_passwd && p.pw_gecos == pw_gecos &&
1010 p.pw_dir == pw_dir && p.pw_shell == pw_shell;
1013 // Generate string in /etc/passwd format
1014 public override string ToString ()
1016 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
1017 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
1020 public static bool operator== (Passwd lhs, Passwd rhs)
1022 return Object.Equals (lhs, rhs);
1025 public static bool operator!= (Passwd lhs, Passwd rhs)
1027 return !Object.Equals (lhs, rhs);
1032 // Convention: Functions *not* part of the standard C library AND part of
1033 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
1035 // For example, the man page should be similar to:
1037 // CONFORMING TO (or CONFORMS TO)
1038 // XPG2, SUSv2, POSIX, etc.
1040 // BSD- and GNU-specific exports can also be placed here.
1042 // Non-POSIX/XPG/etc. functions can also be placed here if:
1043 // (a) They'd be likely to be covered in a Steven's-like book
1044 // (b) The functions would be present in libc.so (or equivalent).
1046 // If a function has its own library, that's a STRONG indicator that the
1047 // function should get a different binding, probably in its own assembly,
1048 // so that package management can work sanely. (That is, we'd like to avoid
1049 // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
1050 // run, and libFooLib.so doesn't exist. That would be confusing.)
1052 // The only methods in here should be:
1053 // (1) low-level functions
1054 // (2) "Trivial" function overloads. For example, if the parameters to a
1055 // function are related (e.g. getgroups(2))
1056 // (3) The return type SHOULD NOT be changed. If you want to provide a
1057 // convenience function with a nicer return type, place it into one of
1058 // the Unix* wrapper classes, and give it a .NET-styled name.
1059 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
1060 // - If you're wrapping *broken* methods which make assumptions about
1061 // input data, such as that an argument refers to N bytes of data.
1062 // This is currently limited to cuserid(3) and encrypt(3).
1063 // - If you call functions which themselves generate exceptions.
1064 // This is the case for using UnixConvert, which will throw an
1065 // exception if an invalid/unsupported value is used.
1067 // Naming Conventions:
1068 // - Syscall method names should have the same name as the function being
1069 // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
1070 // consult the appropriate man page if necessary.
1071 // - Methods need not have the same arguments IF this simplifies or
1072 // permits correct usage. The current example is syslog, in which
1073 // syslog(3)'s single `priority' argument is split into SyslogFacility
1074 // and SyslogLevel arguments.
1075 // - Type names (structures, classes, enumerations) are always PascalCased.
1076 // - Enumerations are named as <MethodName><ArgumentName>, and are located
1077 // in the Mono.Unix namespace. For readability, if ArgumentName is
1078 // "cmd", use Command instead. For example, fcntl(2) takes a
1079 // FcntlCommand argument. This naming convention is to provide an
1080 // assocation between an enumeration and where it should be used, and
1081 // allows a single method to accept multiple different enumerations
1082 // (see mmap(2), which takes MmapProt and MmapFlags).
1083 // - EXCEPTION: if an enumeration is shared between multiple different
1084 // methods, AND/OR the "obvious" enumeration name conflicts with an
1085 // existing .NET type, a more appropriate name should be used.
1086 // Example: FilePermissions
1087 // - Enumerations should have the [Map] and (optional) [Flgas] attributes.
1088 // [Map] is required for make-map to find the type and generate the
1089 // appropriate UnixConvert conversion functions.
1090 // - Enumeration contents should match the original Unix names. This helps
1091 // with documentation (the existing man pages are still useful), and is
1092 // required for use with the make-map generation program.
1093 // - Structure names should be the PascalCased version of the actual
1094 // structure name (struct flock ==> Flock). Structure members should
1095 // have the same names, or a (reasonably) portable subset (Dirent being
1096 // the poster child for questionable members).
1097 // - Whether the managed type should be a reference type (class) or a
1098 // value type (struct) should be determined on a case-by-case basis:
1099 // if you ever need to be able to use NULL for it (such as with Dirent,
1100 // Group, Passwd, as these are method return types and `null' is used
1101 // to signify the end), it should be a reference type; otherwise, use
1102 // your discretion, and keep any expected usage patterns in mind.
1103 // - Syscall should be a Single Point Of Truth (SPOT). There should be
1104 // only ONE way to do anything. By convention, the Linux function names
1105 // are used, but that need not always be the case (use your discretion).
1106 // It SHOULD NOT be required that developers know what platform they're
1107 // on, and choose among a set of similar functions. In short, anything
1108 // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
1109 // we can afford to clean things up whenever possible.
1111 // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
1112 // statvfs(2). MonoPosixHelper will "thunk" between the two,
1113 // exporting a statvfs that works across platforms.
1114 // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
1115 // instead provides getvfsent(3). MonoPosixHelper provides wrappers
1116 // to convert getvfsent(3) into Fstab data.
1117 // - Exception: If it isn't possible to cleanly wrap platforms, then the
1118 // method shouldn't be exported. The user will be expected to do their
1119 // own platform check and their own DllImports.
1120 // Examples: mount(2), umount(2), etc.
1121 // - Note: if a platform doesn't support a function AT ALL, the
1122 // MonoPosixHelper wrapper won't be compiled, resulting in a
1123 // EntryPointNotFoundException. This is also consistent with a missing
1124 // P/Invoke into libc.so.
1126 [CLSCompliant (false)]
1127 [Obsolete ("Use Mono.Unix.Native.Syscall")]
1128 public sealed class Syscall : Stdlib
1130 new internal const string LIBC = "libc";
1131 private const string CRYPT = "crypt";
1133 private Syscall () {}
1139 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
1140 // aio_return(3), aio_suspend(3), aio_write(3)
1142 // Then update UnixStream.BeginRead to use the aio* functions.
1145 #region <attr/xattr.h> Declarations
1147 // <attr/xattr.h> -- COMPLETE
1151 // int setxattr (const char *path, const char *name,
1152 // const void *value, size_t size, int flags);
1153 [DllImport (MPH, SetLastError=true,
1154 EntryPoint="Mono_Posix_Syscall_setxattr")]
1155 public static extern int setxattr (string path, string name, byte[] value, ulong size, XattrFlags flags);
1157 public static int setxattr (string path, string name, byte [] value, ulong size)
1159 return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1162 public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
1164 return setxattr (path, name, value, (ulong) value.Length, flags);
1167 public static int setxattr (string path, string name, byte [] value)
1169 return setxattr (path, name, value, (ulong) value.Length);
1173 // int lsetxattr (const char *path, const char *name,
1174 // const void *value, size_t size, int flags);
1175 [DllImport (MPH, SetLastError=true,
1176 EntryPoint="Mono_Posix_Syscall_lsetxattr")]
1177 public static extern int lsetxattr (string path, string name, byte[] value, ulong size, XattrFlags flags);
1179 public static int lsetxattr (string path, string name, byte [] value, ulong size)
1181 return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1184 public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
1186 return lsetxattr (path, name, value, (ulong) value.Length, flags);
1189 public static int lsetxattr (string path, string name, byte [] value)
1191 return lsetxattr (path, name, value, (ulong) value.Length);
1195 // int fsetxattr (int fd, const char *name,
1196 // const void *value, size_t size, int flags);
1197 [DllImport (MPH, SetLastError=true,
1198 EntryPoint="Mono_Posix_Syscall_fsetxattr")]
1199 public static extern int fsetxattr (int fd, string name, byte[] value, ulong size, XattrFlags flags);
1201 public static int fsetxattr (int fd, string name, byte [] value, ulong size)
1203 return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
1206 public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
1208 return fsetxattr (fd, name, value, (ulong) value.Length, flags);
1211 public static int fsetxattr (int fd, string name, byte [] value)
1213 return fsetxattr (fd, name, value, (ulong) value.Length);
1217 // ssize_t getxattr (const char *path, const char *name,
1218 // void *value, size_t size);
1219 [DllImport (MPH, SetLastError=true,
1220 EntryPoint="Mono_Posix_Syscall_getxattr")]
1221 public static extern long getxattr (string path, string name, byte[] value, ulong size);
1223 public static long getxattr (string path, string name, byte [] value)
1225 return getxattr (path, name, value, (ulong) value.Length);
1228 public static long getxattr (string path, string name, out byte [] value)
1231 long size = getxattr (path, name, value, 0);
1235 value = new byte [size];
1236 return getxattr (path, name, value, (ulong) size);
1240 // ssize_t lgetxattr (const char *path, const char *name,
1241 // void *value, size_t size);
1242 [DllImport (MPH, SetLastError=true,
1243 EntryPoint="Mono_Posix_Syscall_lgetxattr")]
1244 public static extern long lgetxattr (string path, string name, byte[] value, ulong size);
1246 public static long lgetxattr (string path, string name, byte [] value)
1248 return lgetxattr (path, name, value, (ulong) value.Length);
1251 public static long lgetxattr (string path, string name, out byte [] value)
1254 long size = lgetxattr (path, name, value, 0);
1258 value = new byte [size];
1259 return lgetxattr (path, name, value, (ulong) size);
1263 // ssize_t fgetxattr (int fd, const char *name, void *value, size_t size);
1264 [DllImport (MPH, SetLastError=true,
1265 EntryPoint="Mono_Posix_Syscall_fgetxattr")]
1266 public static extern long fgetxattr (int fd, string name, byte[] value, ulong size);
1268 public static long fgetxattr (int fd, string name, byte [] value)
1270 return fgetxattr (fd, name, value, (ulong) value.Length);
1273 public static long fgetxattr (int fd, string name, out byte [] value)
1276 long size = fgetxattr (fd, name, value, 0);
1280 value = new byte [size];
1281 return fgetxattr (fd, name, value, (ulong) size);
1285 // ssize_t listxattr (const char *path, char *list, size_t size);
1286 [DllImport (MPH, SetLastError=true,
1287 EntryPoint="Mono_Posix_Syscall_listxattr")]
1288 public static extern long listxattr (string path, byte[] list, ulong size);
1290 // Slight modification: returns 0 on success, negative on error
1291 public static long listxattr (string path, Encoding encoding, out string [] values)
1294 long size = listxattr (path, null, 0);
1296 values = new string [0];
1300 byte[] list = new byte [size];
1301 long ret = listxattr (path, list, (ulong) size);
1305 string [] output = encoding.GetString (list).Split((char) 0);
1306 values = new string [output.Length - 1];
1307 Array.Copy (output, 0, values, 0, output.Length - 1);
1312 // ssize_t llistxattr (const char *path, char *list, size_t size);
1313 [DllImport (MPH, SetLastError=true,
1314 EntryPoint="Mono_Posix_Syscall_llistxattr")]
1315 public static extern long llistxattr (string path, byte[] list, ulong size);
1317 // Slight modification: returns 0 on success, negative on error
1318 public static long llistxattr (string path, Encoding encoding, out string [] values)
1321 long size = llistxattr (path, null, 0);
1323 values = new string [0];
1327 byte[] list = new byte [size];
1328 long ret = llistxattr (path, list, (ulong) size);
1332 string [] output = encoding.GetString (list).Split((char) 0);
1333 values = new string [output.Length - 1];
1334 Array.Copy (output, 0, values, 0, output.Length - 1);
1339 // ssize_t flistxattr (int fd, char *list, size_t size);
1340 [DllImport (MPH, SetLastError=true,
1341 EntryPoint="Mono_Posix_Syscall_flistxattr")]
1342 public static extern long flistxattr (int fd, byte[] list, ulong size);
1344 // Slight modification: returns 0 on success, negative on error
1345 public static long flistxattr (int fd, Encoding encoding, out string [] values)
1348 long size = flistxattr (fd, null, 0);
1350 values = new string [0];
1354 byte[] list = new byte [size];
1355 long ret = flistxattr (fd, list, (ulong) size);
1359 string [] output = encoding.GetString (list).Split((char) 0);
1360 values = new string [output.Length - 1];
1361 Array.Copy (output, 0, values, 0, output.Length - 1);
1365 [DllImport (MPH, SetLastError=true,
1366 EntryPoint="Mono_Posix_Syscall_removexattr")]
1367 public static extern int removexattr (string path, string name);
1369 [DllImport (MPH, SetLastError=true,
1370 EntryPoint="Mono_Posix_Syscall_lremovexattr")]
1371 public static extern int lremovexattr (string path, string name);
1373 [DllImport (MPH, SetLastError=true,
1374 EntryPoint="Mono_Posix_Syscall_fremovexattr")]
1375 public static extern int fremovexattr (int fd, string name);
1378 #region <dirent.h> Declarations
1382 // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
1384 [DllImport (LIBC, SetLastError=true)]
1385 public static extern IntPtr opendir (string name);
1387 [DllImport (LIBC, SetLastError=true)]
1388 public static extern int closedir (IntPtr dir);
1391 // void seekdir (DIR *dir, off_t offset);
1392 // Slight modification. Returns -1 on error, 0 on success.
1393 [DllImport (MPH, SetLastError=true,
1394 EntryPoint="Mono_Posix_Syscall_seekdir")]
1395 public static extern int seekdir (IntPtr dir, long offset);
1398 // off_t telldir(DIR *dir);
1399 [DllImport (MPH, SetLastError=true,
1400 EntryPoint="Mono_Posix_Syscall_telldir")]
1401 public static extern long telldir (IntPtr dir);
1403 [DllImport (LIBC, SetLastError=true)]
1404 public static extern void rewinddir (IntPtr dir);
1406 private struct _Dirent {
1407 public /* ino_t */ ulong d_ino;
1408 public /* off_t */ long d_off;
1409 public ushort d_reclen;
1411 public IntPtr d_name;
1414 private static void CopyDirent (Dirent to, ref _Dirent from)
1417 to.d_ino = from.d_ino;
1418 to.d_off = from.d_off;
1419 to.d_reclen = from.d_reclen;
1420 to.d_type = from.d_type;
1421 to.d_name = UnixMarshal.PtrToString (from.d_name);
1424 Stdlib.free (from.d_name);
1425 from.d_name = IntPtr.Zero;
1429 [DllImport (MPH, SetLastError=true,
1430 EntryPoint="Mono_Posix_Syscall_readdir")]
1431 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
1433 public static Dirent readdir (IntPtr dir)
1436 int r = sys_readdir (dir, out dentry);
1439 Dirent d = new Dirent ();
1440 CopyDirent (d, ref dentry);
1444 [DllImport (MPH, SetLastError=true,
1445 EntryPoint="Mono_Posix_Syscall_readdir_r")]
1446 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
1448 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
1454 entry.d_name = null;
1457 int r = sys_readdir_r (dirp, out _d, out result);
1459 if (r == 0 && result != IntPtr.Zero) {
1460 CopyDirent (entry, ref _d);
1466 [DllImport (LIBC, SetLastError=true)]
1467 public static extern int dirfd (IntPtr dir);
1470 #region <fcntl.h> Declarations
1472 // <fcntl.h> -- COMPLETE
1475 [DllImport (MPH, SetLastError=true,
1476 EntryPoint="Mono_Posix_Syscall_fcntl")]
1477 public static extern int fcntl (int fd, FcntlCommand cmd);
1479 [DllImport (MPH, SetLastError=true,
1480 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
1481 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
1483 public static int fcntl (int fd, FcntlCommand cmd, DirectoryNotifyFlags arg)
1485 if (cmd != FcntlCommand.F_NOTIFY) {
1486 SetLastError (Error.EINVAL);
1489 long _arg = UnixConvert.FromDirectoryNotifyFlags (arg);
1490 return fcntl (fd, FcntlCommand.F_NOTIFY, _arg);
1493 [DllImport (MPH, SetLastError=true,
1494 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
1495 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
1497 [DllImport (MPH, SetLastError=true,
1498 EntryPoint="Mono_Posix_Syscall_open")]
1499 public static extern int open (string pathname, OpenFlags flags);
1502 // int open(const char *pathname, int flags, mode_t mode);
1503 [DllImport (MPH, SetLastError=true,
1504 EntryPoint="Mono_Posix_Syscall_open_mode")]
1505 public static extern int open (string pathname, OpenFlags flags, FilePermissions mode);
1508 // int creat(const char *pathname, mode_t mode);
1509 [DllImport (MPH, SetLastError=true,
1510 EntryPoint="Mono_Posix_Syscall_creat")]
1511 public static extern int creat (string pathname, FilePermissions mode);
1514 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
1515 [DllImport (MPH, SetLastError=true,
1516 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
1517 public static extern int posix_fadvise (int fd, long offset,
1518 long len, PosixFadviseAdvice advice);
1520 // posix_fallocate(P)
1521 // int posix_fallocate(int fd, off_t offset, size_t len);
1522 [DllImport (MPH, SetLastError=true,
1523 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
1524 public static extern int posix_fallocate (int fd, long offset, ulong len);
1527 #region <fstab.h> Declarations
1529 // <fstab.h> -- COMPLETE
1531 private struct _Fstab {
1532 public IntPtr fs_spec;
1533 public IntPtr fs_file;
1534 public IntPtr fs_vfstype;
1535 public IntPtr fs_mntops;
1536 public IntPtr fs_type;
1538 public int fs_passno;
1539 public IntPtr _fs_buf_;
1542 private static void CopyFstab (Fstab to, ref _Fstab from)
1545 to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
1546 to.fs_file = UnixMarshal.PtrToString (from.fs_file);
1547 to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
1548 to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
1549 to.fs_type = UnixMarshal.PtrToString (from.fs_type);
1550 to.fs_freq = from.fs_freq;
1551 to.fs_passno = from.fs_passno;
1554 Stdlib.free (from._fs_buf_);
1555 from._fs_buf_ = IntPtr.Zero;
1559 internal static object fstab_lock = new object ();
1561 [DllImport (MPH, SetLastError=true,
1562 EntryPoint="Mono_Posix_Syscall_endfsent")]
1563 private static extern void sys_endfsent ();
1565 public static void endfsent ()
1572 [DllImport (MPH, SetLastError=true,
1573 EntryPoint="Mono_Posix_Syscall_getfsent")]
1574 private static extern int sys_getfsent (out _Fstab fs);
1576 public static Fstab getfsent ()
1581 r = sys_getfsent (out fsbuf);
1585 Fstab fs = new Fstab ();
1586 CopyFstab (fs, ref fsbuf);
1590 [DllImport (MPH, SetLastError=true,
1591 EntryPoint="Mono_Posix_Syscall_getfsfile")]
1592 private static extern int sys_getfsfile (string mount_point, out _Fstab fs);
1594 public static Fstab getfsfile (string mount_point)
1599 r = sys_getfsfile (mount_point, out fsbuf);
1603 Fstab fs = new Fstab ();
1604 CopyFstab (fs, ref fsbuf);
1608 [DllImport (MPH, SetLastError=true,
1609 EntryPoint="Mono_Posix_Syscall_getfsspec")]
1610 private static extern int sys_getfsspec (string special_file, out _Fstab fs);
1612 public static Fstab getfsspec (string special_file)
1617 r = sys_getfsspec (special_file, out fsbuf);
1621 Fstab fs = new Fstab ();
1622 CopyFstab (fs, ref fsbuf);
1626 [DllImport (MPH, SetLastError=true,
1627 EntryPoint="Mono_Posix_Syscall_setfsent")]
1628 private static extern int sys_setfsent ();
1630 public static int setfsent ()
1633 return sys_setfsent ();
1639 #region <grp.h> Declarations
1643 // TODO: putgrent(3), fgetgrent_r(), getgrouplist(2), initgroups(3)
1646 // int setgroups (size_t size, const gid_t *list);
1647 [DllImport (MPH, SetLastError=true,
1648 EntryPoint="Mono_Posix_Syscall_setgroups")]
1649 public static extern int setgroups (ulong size, uint[] list);
1651 public static int setgroups (uint [] list)
1653 return setgroups ((ulong) list.Length, list);
1656 private struct _Group
1658 public IntPtr gr_name;
1659 public IntPtr gr_passwd;
1660 public /* gid_t */ uint gr_gid;
1661 public int _gr_nmem_;
1662 public IntPtr gr_mem;
1663 public IntPtr _gr_buf_;
1666 private static void CopyGroup (Group to, ref _Group from)
1669 to.gr_gid = from.gr_gid;
1670 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
1671 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
1672 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
1675 Stdlib.free (from.gr_mem);
1676 Stdlib.free (from._gr_buf_);
1677 from.gr_mem = IntPtr.Zero;
1678 from._gr_buf_ = IntPtr.Zero;
1682 internal static object grp_lock = new object ();
1684 [DllImport (MPH, SetLastError=true,
1685 EntryPoint="Mono_Posix_Syscall_getgrnam")]
1686 private static extern int sys_getgrnam (string name, out _Group group);
1688 public static Group getgrnam (string name)
1693 r = sys_getgrnam (name, out group);
1697 Group gr = new Group ();
1698 CopyGroup (gr, ref group);
1703 // struct group *getgrgid(gid_t gid);
1704 [DllImport (MPH, SetLastError=true,
1705 EntryPoint="Mono_Posix_Syscall_getgrgid")]
1706 private static extern int sys_getgrgid (uint uid, out _Group group);
1708 public static Group getgrgid (uint uid)
1713 r = sys_getgrgid (uid, out group);
1717 Group gr = new Group ();
1718 CopyGroup (gr, ref group);
1722 [DllImport (MPH, SetLastError=true,
1723 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
1724 private static extern int sys_getgrnam_r (string name, out _Group grbuf, out IntPtr grbufp);
1726 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
1731 int r = sys_getgrnam_r (name, out group, out _grbufp);
1732 if (r == 0 && _grbufp != IntPtr.Zero) {
1733 CopyGroup (grbuf, ref group);
1740 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
1741 // size_t buflen, struct group **gbufp);
1742 [DllImport (MPH, SetLastError=true,
1743 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
1744 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
1746 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
1751 int r = sys_getgrgid_r (uid, out group, out _grbufp);
1752 if (r == 0 && _grbufp != IntPtr.Zero) {
1753 CopyGroup (grbuf, ref group);
1759 [DllImport (MPH, SetLastError=true,
1760 EntryPoint="Mono_Posix_Syscall_getgrent")]
1761 private static extern int sys_getgrent (out _Group grbuf);
1763 public static Group getgrent ()
1768 r = sys_getgrent (out group);
1772 Group gr = new Group();
1773 CopyGroup (gr, ref group);
1777 [DllImport (LIBC, SetLastError=true, EntryPoint="setgrent")]
1778 private static extern void sys_setgrent ();
1780 public static void setgrent ()
1787 [DllImport (LIBC, SetLastError=true, EntryPoint="endgrent")]
1788 private static extern void sys_endgrent ();
1790 public static void endgrent ()
1797 [DllImport (MPH, SetLastError=true,
1798 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
1799 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
1801 public static Group fgetgrent (IntPtr stream)
1806 r = sys_fgetgrent (stream, out group);
1810 Group gr = new Group ();
1811 CopyGroup (gr, ref group);
1816 #region <pwd.h> Declarations
1820 // TODO: putpwent(3), fgetpwent_r()
1822 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
1824 private struct _Passwd
1826 public IntPtr pw_name;
1827 public IntPtr pw_passwd;
1828 public /* uid_t */ uint pw_uid;
1829 public /* gid_t */ uint pw_gid;
1830 public IntPtr pw_gecos;
1831 public IntPtr pw_dir;
1832 public IntPtr pw_shell;
1833 public IntPtr _pw_buf_;
1836 private static void CopyPasswd (Passwd to, ref _Passwd from)
1839 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
1840 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
1841 to.pw_uid = from.pw_uid;
1842 to.pw_gid = from.pw_gid;
1843 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
1844 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
1845 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
1848 Stdlib.free (from._pw_buf_);
1849 from._pw_buf_ = IntPtr.Zero;
1853 internal static object pwd_lock = new object ();
1855 [DllImport (MPH, SetLastError=true,
1856 EntryPoint="Mono_Posix_Syscall_getpwnam")]
1857 private static extern int sys_getpwnam (string name, out _Passwd passwd);
1859 public static Passwd getpwnam (string name)
1864 r = sys_getpwnam (name, out passwd);
1868 Passwd pw = new Passwd ();
1869 CopyPasswd (pw, ref passwd);
1874 // struct passwd *getpwnuid(uid_t uid);
1875 [DllImport (MPH, SetLastError=true,
1876 EntryPoint="Mono_Posix_Syscall_getpwuid")]
1877 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
1879 public static Passwd getpwuid (uint uid)
1884 r = sys_getpwuid (uid, out passwd);
1888 Passwd pw = new Passwd ();
1889 CopyPasswd (pw, ref passwd);
1893 [DllImport (MPH, SetLastError=true,
1894 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
1895 private static extern int sys_getpwnam_r (string name, out _Passwd pwbuf, out IntPtr pwbufp);
1897 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
1902 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
1903 if (r == 0 && _pwbufp != IntPtr.Zero) {
1904 CopyPasswd (pwbuf, ref passwd);
1911 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
1912 // buflen, struct passwd **pwbufp);
1913 [DllImport (MPH, SetLastError=true,
1914 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
1915 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
1917 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
1922 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
1923 if (r == 0 && _pwbufp != IntPtr.Zero) {
1924 CopyPasswd (pwbuf, ref passwd);
1930 [DllImport (MPH, SetLastError=true,
1931 EntryPoint="Mono_Posix_Syscall_getpwent")]
1932 private static extern int sys_getpwent (out _Passwd pwbuf);
1934 public static Passwd getpwent ()
1939 r = sys_getpwent (out passwd);
1943 Passwd pw = new Passwd ();
1944 CopyPasswd (pw, ref passwd);
1948 [DllImport (LIBC, SetLastError=true, EntryPoint="setpwent")]
1949 private static extern void sys_setpwent ();
1951 public static void setpwent ()
1958 [DllImport (LIBC, SetLastError=true, EntryPoint="endpwent")]
1959 private static extern void sys_endpwent ();
1961 public static void endpwent ()
1968 [DllImport (MPH, SetLastError=true,
1969 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
1970 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
1972 public static Passwd fgetpwent (IntPtr stream)
1977 r = sys_fgetpwent (stream, out passwd);
1981 Passwd pw = new Passwd ();
1982 CopyPasswd (pw, ref passwd);
1987 #region <signal.h> Declarations
1991 [DllImport (LIBC, SetLastError=true)]
1992 private static extern void psignal (int sig, string s);
1994 public static void psignal (Signum sig, string s)
1996 int signum = UnixConvert.FromSignum (sig);
1997 psignal (signum, s);
2001 // int kill(pid_t pid, int sig);
2002 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
2003 private static extern int sys_kill (int pid, int sig);
2005 public static int kill (int pid, Signum sig)
2007 int _sig = UnixConvert.FromSignum (sig);
2008 return sys_kill (pid, _sig);
2011 private static object signal_lock = new object ();
2013 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
2014 private static extern IntPtr sys_strsignal (int sig);
2016 public static string strsignal (Signum sig)
2018 int s = UnixConvert.FromSignum (sig);
2019 lock (signal_lock) {
2020 IntPtr r = sys_strsignal (s);
2021 return UnixMarshal.PtrToString (r);
2025 // TODO: sigaction(2)
2026 // TODO: sigsuspend(2)
2027 // TODO: sigpending(2)
2031 #region <stdio.h> Declarations
2035 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
2036 private static extern int _L_ctermid ();
2038 public static readonly int L_ctermid = _L_ctermid ();
2040 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
2041 private static extern int _L_cuserid ();
2043 public static readonly int L_cuserid = _L_cuserid ();
2045 internal static object getlogin_lock = new object ();
2047 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
2048 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
2050 [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
2051 "DO NOT USE cuserid().\n" +
2052 "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
2053 public static string cuserid (StringBuilder @string)
2055 if (@string.Capacity < L_cuserid) {
2056 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
2058 lock (getlogin_lock) {
2059 IntPtr r = sys_cuserid (@string);
2060 return UnixMarshal.PtrToString (r);
2066 #region <stdlib.h> Declarations
2070 [DllImport (LIBC, SetLastError=true)]
2071 public static extern int mkstemp (StringBuilder template);
2073 [DllImport (LIBC, SetLastError=true)]
2074 public static extern int ttyslot ();
2076 [DllImport (CRYPT, SetLastError=true)]
2077 public static extern void setkey (string key);
2081 #region <string.h> Declarations
2087 // int strerror_r(int errnum, char *buf, size_t n);
2088 [DllImport (MPH, SetLastError=true,
2089 EntryPoint="Mono_Posix_Syscall_strerror_r")]
2090 private static extern int sys_strerror_r (int errnum,
2091 [Out] StringBuilder buf, ulong n);
2093 public static int strerror_r (Error errnum, StringBuilder buf, ulong n)
2095 int e = UnixConvert.FromError (errnum);
2096 return sys_strerror_r (e, buf, n);
2099 public static int strerror_r (Error errnum, StringBuilder buf)
2101 return strerror_r (errnum, buf, (ulong) buf.Capacity);
2106 #region <sys/mman.h> Declarations
2112 // int posix_madvise(void *addr, size_t len, int advice);
2113 [DllImport (MPH, SetLastError=true,
2114 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
2115 public static extern int posix_madvise (IntPtr addr, ulong len,
2116 PosixMadviseAdvice advice);
2118 public static readonly IntPtr MAP_FAILED = unchecked((IntPtr)(-1));
2120 [DllImport (MPH, SetLastError=true,
2121 EntryPoint="Mono_Posix_Syscall_mmap")]
2122 public static extern IntPtr mmap (IntPtr start, ulong length,
2123 MmapProt prot, MmapFlags flags, int fd, long offset);
2125 [DllImport (MPH, SetLastError=true,
2126 EntryPoint="Mono_Posix_Syscall_munmap")]
2127 public static extern int munmap (IntPtr start, ulong length);
2129 [DllImport (MPH, SetLastError=true,
2130 EntryPoint="Mono_Posix_Syscall_mprotect")]
2131 public static extern int mprotect (IntPtr start, ulong len, MmapProt prot);
2133 [DllImport (MPH, SetLastError=true,
2134 EntryPoint="Mono_Posix_Syscall_msync")]
2135 public static extern int msync (IntPtr start, ulong len, MsyncFlags flags);
2137 [DllImport (MPH, SetLastError=true,
2138 EntryPoint="Mono_Posix_Syscall_mlock")]
2139 public static extern int mlock (IntPtr start, ulong len);
2141 [DllImport (MPH, SetLastError=true,
2142 EntryPoint="Mono_Posix_Syscall_munlock")]
2143 public static extern int munlock (IntPtr start, ulong len);
2145 [DllImport (LIBC, SetLastError=true, EntryPoint="mlockall")]
2146 private static extern int sys_mlockall (int flags);
2148 public static int mlockall (MlockallFlags flags)
2150 int _flags = UnixConvert.FromMlockallFlags (flags);
2151 return sys_mlockall (_flags);
2154 [DllImport (LIBC, SetLastError=true)]
2155 public static extern int munlockall ();
2157 [DllImport (MPH, SetLastError=true,
2158 EntryPoint="Mono_Posix_Syscall_mremap")]
2159 public static extern IntPtr mremap (IntPtr old_address, ulong old_size,
2160 ulong new_size, MremapFlags flags);
2162 [DllImport (MPH, SetLastError=true,
2163 EntryPoint="Mono_Posix_Syscall_mincore")]
2164 public static extern int mincore (IntPtr start, ulong length, byte[] vec);
2166 [DllImport (MPH, SetLastError=true,
2167 EntryPoint="Mono_Posix_Syscall_remap_file_pages")]
2168 public static extern int remap_file_pages (IntPtr start, ulong size,
2169 MmapProt prot, long pgoff, MmapFlags flags);
2173 #region <sys/poll.h> Declarations
2175 // <sys/poll.h> -- COMPLETE
2178 private struct _pollfd {
2180 public short events;
2181 public short revents;
2184 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
2185 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
2187 public static int poll (Pollfd [] fds, uint nfds, int timeout)
2189 if (fds.Length < nfds)
2190 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
2192 _pollfd[] send = new _pollfd[nfds];
2194 for (int i = 0; i < send.Length; i++) {
2195 send [i].fd = fds [i].fd;
2196 send [i].events = UnixConvert.FromPollEvents (fds [i].events);
2199 int r = sys_poll (send, nfds, timeout);
2201 for (int i = 0; i < send.Length; i++) {
2202 fds [i].revents = UnixConvert.ToPollEvents (send [i].revents);
2208 public static int poll (Pollfd [] fds, int timeout)
2210 return poll (fds, (uint) fds.Length, timeout);
2223 // TODO: setrlimit(2)
2224 // TODO: getrlimit(2)
2225 // TODO: getrusage(2)
2229 #region <sys/sendfile.h> Declarations
2231 // <sys/sendfile.h> -- COMPLETE
2234 [DllImport (MPH, SetLastError=true,
2235 EntryPoint="Mono_Posix_Syscall_sendfile")]
2236 public static extern long sendfile (int out_fd, int in_fd,
2237 ref long offset, ulong count);
2241 #region <sys/stat.h> Declarations
2243 // <sys/stat.h> -- COMPLETE
2245 [DllImport (MPH, SetLastError=true,
2246 EntryPoint="Mono_Posix_Syscall_stat")]
2247 public static extern int stat (string file_name, out Stat buf);
2249 [DllImport (MPH, SetLastError=true,
2250 EntryPoint="Mono_Posix_Syscall_fstat")]
2251 public static extern int fstat (int filedes, out Stat buf);
2253 [DllImport (MPH, SetLastError=true,
2254 EntryPoint="Mono_Posix_Syscall_lstat")]
2255 public static extern int lstat (string file_name, out Stat buf);
2258 // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
2259 // All take FilePermissions
2262 // int chmod(const char *path, mode_t mode);
2263 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
2264 private static extern int sys_chmod (string path, uint mode);
2266 public static int chmod (string path, FilePermissions mode)
2268 uint _mode = UnixConvert.FromFilePermissions (mode);
2269 return sys_chmod (path, _mode);
2273 // int chmod(int filedes, mode_t mode);
2274 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
2275 private static extern int sys_fchmod (int filedes, uint mode);
2277 public static int fchmod (int filedes, FilePermissions mode)
2279 uint _mode = UnixConvert.FromFilePermissions (mode);
2280 return sys_fchmod (filedes, _mode);
2284 // mode_t umask(mode_t mask);
2285 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
2286 private static extern uint sys_umask (uint mask);
2288 public static FilePermissions umask (FilePermissions mask)
2290 uint _mask = UnixConvert.FromFilePermissions (mask);
2291 uint r = sys_umask (_mask);
2292 return UnixConvert.ToFilePermissions (r);
2296 // int mkdir(const char *pathname, mode_t mode);
2297 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
2298 private static extern int sys_mkdir (string oldpath, uint mode);
2300 public static int mkdir (string oldpath, FilePermissions mode)
2302 uint _mode = UnixConvert.FromFilePermissions (mode);
2303 return sys_mkdir (oldpath, _mode);
2307 // int mknod (const char *pathname, mode_t mode, dev_t dev);
2308 [DllImport (MPH, SetLastError=true,
2309 EntryPoint="Mono_Posix_Syscall_mknod")]
2310 public static extern int mknod (string pathname, FilePermissions mode, ulong dev);
2313 // int mkfifo(const char *pathname, mode_t mode);
2314 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
2315 private static extern int sys_mkfifo (string pathname, uint mode);
2317 public static int mkfifo (string pathname, FilePermissions mode)
2319 uint _mode = UnixConvert.FromFilePermissions (mode);
2320 return sys_mkfifo (pathname, _mode);
2325 #region <sys/stat.h> Declarations
2330 [DllImport (MPH, SetLastError=true,
2331 EntryPoint="Mono_Posix_Syscall_statvfs")]
2332 public static extern int statvfs (string path, out Statvfs buf);
2334 [DllImport (MPH, SetLastError=true,
2335 EntryPoint="Mono_Posix_Syscall_fstatvfs")]
2336 public static extern int fstatvfs (int fd, out Statvfs buf);
2340 #region <sys/time.h> Declarations
2344 // TODO: adjtime(), getitimer(2), setitimer(2), lutimes(), futimes()
2346 [DllImport (MPH, SetLastError=true,
2347 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2348 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
2350 [DllImport (MPH, SetLastError=true,
2351 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2352 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
2354 public static int gettimeofday (out Timeval tv)
2356 return gettimeofday (out tv, IntPtr.Zero);
2359 [DllImport (MPH, SetLastError=true,
2360 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2361 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
2363 public static int gettimeofday (out Timezone tz)
2365 return gettimeofday (IntPtr.Zero, out tz);
2368 [DllImport (MPH, SetLastError=true,
2369 EntryPoint="Mono_Posix_Syscall_settimeofday")]
2370 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
2372 [DllImport (MPH, SetLastError=true,
2373 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2374 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
2376 public static int settimeofday (ref Timeval tv)
2378 return settimeofday (ref tv, IntPtr.Zero);
2381 [DllImport (MPH, SetLastError=true,
2382 EntryPoint="Mono_Posix_Syscall_utimes")]
2383 public static extern int utimes (string filename, ref Timeval tvp);
2405 #region <sys/wait.h> Declarations
2411 // pid_t wait(int *status);
2412 [DllImport (LIBC, SetLastError=true)]
2413 public static extern int wait (out int status);
2416 // pid_t waitpid(pid_t pid, int *status, int options);
2417 [DllImport (LIBC, SetLastError=true)]
2418 private static extern int waitpid (int pid, out int status, int options);
2420 public static int waitpid (int pid, out int status, WaitOptions options)
2422 int _options = UnixConvert.FromWaitOptions (options);
2423 return waitpid (pid, out status, _options);
2426 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
2427 private static extern int _WIFEXITED (int status);
2429 public static bool WIFEXITED (int status)
2431 return _WIFEXITED (status) != 0;
2434 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
2435 public static extern int WEXITSTATUS (int status);
2437 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
2438 private static extern int _WIFSIGNALED (int status);
2440 public static bool WIFSIGNALED (int status)
2442 return _WIFSIGNALED (status) != 0;
2445 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
2446 private static extern int _WTERMSIG (int status);
2448 public static Signum WTERMSIG (int status)
2450 int r = _WTERMSIG (status);
2451 return UnixConvert.ToSignum (r);
2454 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
2455 private static extern int _WIFSTOPPED (int status);
2457 public static bool WIFSTOPPED (int status)
2459 return _WIFSTOPPED (status) != 0;
2462 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
2463 private static extern int _WSTOPSIG (int status);
2465 public static Signum WSTOPSIG (int status)
2467 int r = _WSTOPSIG (status);
2468 return UnixConvert.ToSignum (r);
2477 #region <syslog.h> Declarations
2482 [DllImport (LIBC, EntryPoint="openlog")]
2483 private static extern void sys_openlog (IntPtr ident, int option, int facility);
2485 public static void openlog (IntPtr ident, SyslogOptions option,
2486 SyslogFacility defaultFacility)
2488 int _option = UnixConvert.FromSyslogOptions (option);
2489 int _facility = UnixConvert.FromSyslogFacility (defaultFacility);
2491 sys_openlog (ident, _option, _facility);
2494 [DllImport (LIBC, EntryPoint="syslog")]
2495 private static extern void sys_syslog (int priority, string message);
2497 public static void syslog (SyslogFacility facility, SyslogLevel level, string message)
2499 int _facility = UnixConvert.FromSyslogFacility (facility);
2500 int _level = UnixConvert.FromSyslogLevel (level);
2501 sys_syslog (_facility | _level, GetSyslogMessage (message));
2504 public static void syslog (SyslogLevel level, string message)
2506 int _level = UnixConvert.FromSyslogLevel (level);
2507 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 void syslog (SyslogFacility facility, SyslogLevel level,
2518 string format, params object[] parameters)
2520 int _facility = UnixConvert.FromSyslogFacility (facility);
2521 int _level = UnixConvert.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 XPrintfFunctions.syslog (_parameters);
2530 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
2531 "Use syslog(SyslogLevel, string) instead.")]
2532 public static void syslog (SyslogLevel level, string format,
2533 params object[] parameters)
2535 int _level = UnixConvert.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 XPrintfFunctions.syslog (_parameters);
2545 public static extern void closelog ();
2547 [DllImport (LIBC, EntryPoint="setlogmask")]
2548 private static extern int sys_setlogmask (int mask);
2550 public static int setlogmask (SyslogLevel mask)
2552 int _mask = UnixConvert.FromSyslogLevel (mask);
2553 return sys_setlogmask (_mask);
2558 #region <time.h> Declarations
2565 // int stime(time_t *t);
2566 [DllImport (MPH, SetLastError=true,
2567 EntryPoint="Mono_Posix_Syscall_stime")]
2568 public static extern int stime (ref long t);
2571 // time_t time(time_t *t);
2572 [DllImport (MPH, SetLastError=true,
2573 EntryPoint="Mono_Posix_Syscall_time")]
2574 public static extern long time (out long t);
2584 #region <unistd.h> Declarations
2588 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
2589 // other TODOs listed below.
2591 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
2592 private static extern int sys_access (string pathname, int mode);
2594 public static int access (string pathname, AccessMode mode)
2596 int _mode = UnixConvert.FromAccessMode (mode);
2597 return sys_access (pathname, _mode);
2601 // off_t lseek(int filedes, off_t offset, int whence);
2602 [DllImport (MPH, SetLastError=true,
2603 EntryPoint="Mono_Posix_Syscall_lseek")]
2604 private static extern long sys_lseek (int fd, long offset, int whence);
2606 public static long lseek (int fd, long offset, SeekFlags whence)
2608 short _whence = UnixConvert.FromSeekFlags (whence);
2609 return sys_lseek (fd, offset, _whence);
2612 [DllImport (LIBC, SetLastError=true)]
2613 public static extern int close (int fd);
2616 // ssize_t read(int fd, void *buf, size_t count);
2617 [DllImport (MPH, SetLastError=true,
2618 EntryPoint="Mono_Posix_Syscall_read")]
2619 public static extern long read (int fd, IntPtr buf, ulong count);
2621 public static unsafe long read (int fd, void *buf, ulong count)
2623 return read (fd, (IntPtr) buf, count);
2627 // ssize_t write(int fd, const void *buf, size_t count);
2628 [DllImport (MPH, SetLastError=true,
2629 EntryPoint="Mono_Posix_Syscall_write")]
2630 public static extern long write (int fd, IntPtr buf, ulong count);
2632 public static unsafe long write (int fd, void *buf, ulong count)
2634 return write (fd, (IntPtr) buf, count);
2638 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
2639 [DllImport (MPH, SetLastError=true,
2640 EntryPoint="Mono_Posix_Syscall_pread")]
2641 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
2643 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
2645 return pread (fd, (IntPtr) buf, count, offset);
2649 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
2650 [DllImport (MPH, SetLastError=true,
2651 EntryPoint="Mono_Posix_Syscall_pwrite")]
2652 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
2654 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
2656 return pwrite (fd, (IntPtr) buf, count, offset);
2659 [DllImport (MPH, SetLastError=true,
2660 EntryPoint="Mono_Posix_Syscall_pipe")]
2661 public static extern int pipe (out int reading, out int writing);
2663 public static int pipe (int[] filedes)
2665 if (filedes == null || filedes.Length != 2) {
2669 int reading, writing;
2670 int r = pipe (out reading, out writing);
2671 filedes[0] = reading;
2672 filedes[1] = writing;
2676 [DllImport (LIBC, SetLastError=true)]
2677 public static extern uint alarm (uint seconds);
2679 [DllImport (LIBC, SetLastError=true)]
2680 public static extern uint sleep (uint seconds);
2682 [DllImport (LIBC, SetLastError=true)]
2683 public static extern uint ualarm (uint usecs, uint interval);
2685 [DllImport (LIBC, SetLastError=true)]
2686 public static extern int pause ();
2689 // int chown(const char *path, uid_t owner, gid_t group);
2690 [DllImport (LIBC, SetLastError=true)]
2691 public static extern int chown (string path, uint owner, uint group);
2694 // int fchown(int fd, uid_t owner, gid_t group);
2695 [DllImport (LIBC, SetLastError=true)]
2696 public static extern int fchown (int fd, uint owner, uint group);
2699 // int lchown(const char *path, uid_t owner, gid_t group);
2700 [DllImport (LIBC, SetLastError=true)]
2701 public static extern int lchown (string path, uint owner, uint group);
2703 [DllImport (LIBC, SetLastError=true)]
2704 public static extern int chdir (string path);
2706 [DllImport (LIBC, SetLastError=true)]
2707 public static extern int fchdir (int fd);
2710 // char *getcwd(char *buf, size_t size);
2711 [DllImport (MPH, SetLastError=true,
2712 EntryPoint="Mono_Posix_Syscall_getcwd")]
2713 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
2715 public static StringBuilder getcwd (StringBuilder buf)
2717 getcwd (buf, (ulong) buf.Capacity);
2721 // getwd(2) is deprecated; don't expose it.
2723 [DllImport (LIBC, SetLastError=true)]
2724 public static extern int dup (int fd);
2726 [DllImport (LIBC, SetLastError=true)]
2727 public static extern int dup2 (int fd, int fd2);
2729 // TODO: does Mono marshal arrays properly?
2730 [DllImport (LIBC, SetLastError=true)]
2731 public static extern int execve (string path, string[] argv, string[] envp);
2733 [DllImport (LIBC, SetLastError=true)]
2734 public static extern int fexecve (int fd, string[] argv, string[] envp);
2736 [DllImport (LIBC, SetLastError=true)]
2737 public static extern int execv (string path, string[] argv);
2739 // TODO: execle, execl, execlp
2740 [DllImport (LIBC, SetLastError=true)]
2741 public static extern int execvp (string path, string[] argv);
2743 [DllImport (LIBC, SetLastError=true)]
2744 public static extern int nice (int inc);
2746 [DllImport (LIBC, SetLastError=true)]
2747 public static extern int _exit (int status);
2749 [DllImport (MPH, SetLastError=true,
2750 EntryPoint="Mono_Posix_Syscall_fpathconf")]
2751 public static extern long fpathconf (int filedes, PathConf name);
2753 [DllImport (MPH, SetLastError=true,
2754 EntryPoint="Mono_Posix_Syscall_pathconf")]
2755 public static extern long pathconf (string path, PathConf name);
2757 [DllImport (MPH, SetLastError=true,
2758 EntryPoint="Mono_Posix_Syscall_sysconf")]
2759 public static extern long sysconf (SysConf name);
2762 // size_t confstr(int name, char *buf, size_t len);
2763 [DllImport (MPH, SetLastError=true,
2764 EntryPoint="Mono_Posix_Syscall_confstr")]
2765 public static extern ulong confstr (ConfStr name, [Out] StringBuilder buf, ulong len);
2768 // pid_t getpid(void);
2769 [DllImport (LIBC, SetLastError=true)]
2770 public static extern int getpid ();
2773 // pid_t getppid(void);
2774 [DllImport (LIBC, SetLastError=true)]
2775 public static extern int getppid ();
2778 // int setpgid(pid_t pid, pid_t pgid);
2779 [DllImport (LIBC, SetLastError=true)]
2780 public static extern int setpgid (int pid, int pgid);
2783 // pid_t getpgid(pid_t pid);
2784 [DllImport (LIBC, SetLastError=true)]
2785 public static extern int getpgid (int pid);
2787 [DllImport (LIBC, SetLastError=true)]
2788 public static extern int setpgrp ();
2791 // pid_t getpgrp(void);
2792 [DllImport (LIBC, SetLastError=true)]
2793 public static extern int getpgrp ();
2796 // pid_t setsid(void);
2797 [DllImport (LIBC, SetLastError=true)]
2798 public static extern int setsid ();
2801 // pid_t getsid(pid_t pid);
2802 [DllImport (LIBC, SetLastError=true)]
2803 public static extern int getsid (int pid);
2806 // uid_t getuid(void);
2807 [DllImport (LIBC, SetLastError=true)]
2808 public static extern uint getuid ();
2811 // uid_t geteuid(void);
2812 [DllImport (LIBC, SetLastError=true)]
2813 public static extern uint geteuid ();
2816 // gid_t getgid(void);
2817 [DllImport (LIBC, SetLastError=true)]
2818 public static extern uint getgid ();
2821 // gid_t getgid(void);
2822 [DllImport (LIBC, SetLastError=true)]
2823 public static extern uint getegid ();
2826 // int getgroups(int size, gid_t list[]);
2827 [DllImport (LIBC, SetLastError=true)]
2828 public static extern int getgroups (int size, uint[] list);
2830 public static int getgroups (uint[] list)
2832 return getgroups (list.Length, list);
2836 // int setuid(uid_t uid);
2837 [DllImport (LIBC, SetLastError=true)]
2838 public static extern int setuid (uint uid);
2841 // int setreuid(uid_t ruid, uid_t euid);
2842 [DllImport (LIBC, SetLastError=true)]
2843 public static extern int setreuid (uint ruid, uint euid);
2846 // int setregid(gid_t ruid, gid_t euid);
2847 [DllImport (LIBC, SetLastError=true)]
2848 public static extern int setregid (uint rgid, uint egid);
2851 // int seteuid(uid_t euid);
2852 [DllImport (LIBC, SetLastError=true)]
2853 public static extern int seteuid (uint euid);
2856 // int setegid(gid_t euid);
2857 [DllImport (LIBC, SetLastError=true)]
2858 public static extern int setegid (uint uid);
2861 // int setgid(gid_t gid);
2862 [DllImport (LIBC, SetLastError=true)]
2863 public static extern int setgid (uint gid);
2866 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
2867 [DllImport (LIBC, SetLastError=true)]
2868 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
2871 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
2872 [DllImport (LIBC, SetLastError=true)]
2873 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
2876 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
2877 [DllImport (LIBC, SetLastError=true)]
2878 public static extern int setresuid (uint ruid, uint euid, uint suid);
2881 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
2882 [DllImport (LIBC, SetLastError=true)]
2883 public static extern int setresgid (uint rgid, uint egid, uint sgid);
2886 // pid_t fork(void);
2887 [DllImport (LIBC, SetLastError=true)]
2888 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
2889 "shutdown code.\nUse System.Diagnostics.Process instead")]
2890 private static extern int fork ();
2893 // pid_t vfork(void);
2894 [DllImport (LIBC, SetLastError=true)]
2895 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
2896 "shutdown code.\nUse System.Diagnostics.Process instead")]
2897 private static extern int vfork ();
2899 private static object tty_lock = new object ();
2901 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
2902 private static extern IntPtr sys_ttyname (int fd);
2904 public static string ttyname (int fd)
2907 IntPtr r = sys_ttyname (fd);
2908 return UnixMarshal.PtrToString (r);
2913 // int ttyname_r(int fd, char *buf, size_t buflen);
2914 [DllImport (MPH, SetLastError=true,
2915 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
2916 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
2918 public static int ttyname_r (int fd, StringBuilder buf)
2920 return ttyname_r (fd, buf, (ulong) buf.Capacity);
2923 [DllImport (LIBC, EntryPoint="isatty")]
2924 private static extern int sys_isatty (int fd);
2926 public static bool isatty (int fd)
2928 return sys_isatty (fd) == 1;
2931 [DllImport (LIBC, SetLastError=true)]
2932 public static extern int link (string oldpath, string newpath);
2934 [DllImport (LIBC, SetLastError=true)]
2935 public static extern int symlink (string oldpath, string newpath);
2938 // int readlink(const char *path, char *buf, size_t bufsize);
2939 [DllImport (MPH, SetLastError=true,
2940 EntryPoint="Mono_Posix_Syscall_readlink")]
2941 public static extern int readlink (string path, [Out] StringBuilder buf, ulong bufsiz);
2943 public static int readlink (string path, [Out] StringBuilder buf)
2945 return readlink (path, buf, (ulong) buf.Capacity);
2948 [DllImport (LIBC, SetLastError=true)]
2949 public static extern int unlink (string pathname);
2951 [DllImport (LIBC, SetLastError=true)]
2952 public static extern int rmdir (string pathname);
2955 // pid_t tcgetpgrp(int fd);
2956 [DllImport (LIBC, SetLastError=true)]
2957 public static extern int tcgetpgrp (int fd);
2960 // int tcsetpgrp(int fd, pid_t pgrp);
2961 [DllImport (LIBC, SetLastError=true)]
2962 public static extern int tcsetpgrp (int fd, int pgrp);
2964 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
2965 private static extern IntPtr sys_getlogin ();
2967 public static string getlogin ()
2969 lock (getlogin_lock) {
2970 IntPtr r = sys_getlogin ();
2971 return UnixMarshal.PtrToString (r);
2976 // int getlogin_r(char *buf, size_t bufsize);
2977 [DllImport (MPH, SetLastError=true,
2978 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
2979 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
2981 public static int getlogin_r (StringBuilder name)
2983 return getlogin_r (name, (ulong) name.Capacity);
2986 [DllImport (LIBC, SetLastError=true)]
2987 public static extern int setlogin (string name);
2990 // int gethostname(char *name, size_t len);
2991 [DllImport (MPH, SetLastError=true,
2992 EntryPoint="Mono_Posix_Syscall_gethostname")]
2993 public static extern int gethostname ([Out] StringBuilder name, ulong len);
2995 public static int gethostname (StringBuilder name)
2997 return gethostname (name, (ulong) name.Capacity);
3001 // int gethostname(const char *name, size_t len);
3002 [DllImport (MPH, SetLastError=true,
3003 EntryPoint="Mono_Posix_Syscall_sethostname")]
3004 public static extern int sethostname (string name, ulong len);
3006 public static int sethostname (string name)
3008 return sethostname (name, (ulong) name.Length);
3011 [DllImport (MPH, SetLastError=true,
3012 EntryPoint="Mono_Posix_Syscall_gethostid")]
3013 public static extern long gethostid ();
3015 [DllImport (MPH, SetLastError=true,
3016 EntryPoint="Mono_Posix_Syscall_sethostid")]
3017 public static extern int sethostid (long hostid);
3020 // int getdomainname(char *name, size_t len);
3021 [DllImport (MPH, SetLastError=true,
3022 EntryPoint="Mono_Posix_Syscall_getdomainname")]
3023 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
3025 public static int getdomainname (StringBuilder name)
3027 return getdomainname (name, (ulong) name.Capacity);
3031 // int setdomainname(const char *name, size_t len);
3032 [DllImport (MPH, SetLastError=true,
3033 EntryPoint="Mono_Posix_Syscall_setdomainname")]
3034 public static extern int setdomainname (string name, ulong len);
3036 public static int setdomainname (string name)
3038 return setdomainname (name, (ulong) name.Length);
3041 [DllImport (LIBC, SetLastError=true)]
3042 public static extern int vhangup ();
3044 // Revoke doesn't appear to be POSIX. Include it?
3045 [DllImport (LIBC, SetLastError=true)]
3046 public static extern int revoke (string file);
3048 // TODO: profil? It's not POSIX.
3050 [DllImport (LIBC, SetLastError=true)]
3051 public static extern int acct (string filename);
3053 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
3054 private static extern IntPtr sys_getusershell ();
3056 internal static object usershell_lock = new object ();
3058 public static string getusershell ()
3060 lock (usershell_lock) {
3061 IntPtr r = sys_getusershell ();
3062 return UnixMarshal.PtrToString (r);
3066 [DllImport (LIBC, SetLastError=true, EntryPoint="setusershell")]
3067 private static extern void sys_setusershell ();
3069 public static void setusershell ()
3071 lock (usershell_lock) {
3072 sys_setusershell ();
3076 [DllImport (LIBC, SetLastError=true, EntryPoint="endusershell")]
3077 private static extern void sys_endusershell ();
3079 public static void endusershell ()
3081 lock (usershell_lock) {
3082 sys_endusershell ();
3086 [DllImport (LIBC, SetLastError=true)]
3087 private static extern int daemon (int nochdir, int noclose);
3089 public static int daemon (bool nochdir, bool noclose)
3091 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
3094 [DllImport (LIBC, SetLastError=true)]
3095 public static extern int chroot (string path);
3097 // skipping getpass(3) as the man page states:
3098 // This function is obsolete. Do not use it.
3100 [DllImport (LIBC, SetLastError=true)]
3101 public static extern int fsync (int fd);
3103 [DllImport (LIBC, SetLastError=true)]
3104 public static extern int fdatasync (int fd);
3106 [DllImport (LIBC, SetLastError=true)]
3107 public static extern void sync ();
3109 [DllImport (LIBC, SetLastError=true)]
3110 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
3111 "Use Unistd.sysconf (SysConf._SC_PAGESIZE).")]
3112 public static extern int getpagesize ();
3115 // int truncate(const char *path, off_t length);
3116 [DllImport (MPH, SetLastError=true,
3117 EntryPoint="Mono_Posix_Syscall_truncate")]
3118 public static extern int truncate (string path, long length);
3121 // int ftruncate(int fd, off_t length);
3122 [DllImport (MPH, SetLastError=true,
3123 EntryPoint="Mono_Posix_Syscall_ftruncate")]
3124 public static extern int ftruncate (int fd, long length);
3126 [DllImport (LIBC, SetLastError=true)]
3127 public static extern int getdtablesize ();
3129 [DllImport (LIBC, SetLastError=true)]
3130 public static extern int brk (IntPtr end_data_segment);
3132 [DllImport (LIBC, SetLastError=true)]
3133 public static extern IntPtr sbrk (IntPtr increment);
3135 // TODO: syscall(2)?
3136 // Probably safer to skip entirely.
3139 // int lockf(int fd, int cmd, off_t len);
3140 [DllImport (MPH, SetLastError=true,
3141 EntryPoint="Mono_Posix_Syscall_lockf")]
3142 public static extern int lockf (int fd, LockfCommand cmd, long len);
3144 internal static object crypt_lock = new object ();
3146 [DllImport (CRYPT, SetLastError=true, EntryPoint="crypt")]
3147 private static extern IntPtr sys_crypt (string key, string salt);
3149 public static string crypt (string key, string salt)
3152 IntPtr r = sys_crypt (key, salt);
3153 return UnixMarshal.PtrToString (r);
3157 internal static object encrypt_lock = new object ();
3159 [DllImport (CRYPT, SetLastError=true, EntryPoint="encrypt")]
3160 private static extern void sys_encrypt ([In, Out] byte[] block, int edflag);
3162 public static void encrypt (byte[] block, bool decode)
3164 if (block.Length < 64)
3165 throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
3166 lock (encrypt_lock) {
3167 sys_encrypt (block, decode ? 1 : 0);
3172 // void swab(const void *from, void *to, ssize_t n);
3173 [DllImport (MPH, SetLastError=true,
3174 EntryPoint="Mono_Posix_Syscall_swab")]
3175 public static extern void swab (IntPtr from, IntPtr to, long n);
3177 public static unsafe void swab (void* from, void* to, long n)
3179 swab ((IntPtr) from, (IntPtr) to, n);
3184 #region <utime.h> Declarations
3186 // <utime.h> -- COMPLETE
3189 [DllImport (MPH, SetLastError=true,
3190 EntryPoint="Mono_Posix_Syscall_utime")]
3191 private static extern int sys_utime (string filename, ref Utimbuf buf, int use_buf);
3193 public static int utime (string filename, ref Utimbuf buf)
3195 return sys_utime (filename, ref buf, 1);
3198 public static int utime (string filename)
3200 Utimbuf buf = new Utimbuf ();
3201 return sys_utime (filename, ref buf, 0);