2 // Mono.Posix/Syscall.cs
5 // Miguel de Icaza (miguel@novell.com)
6 // Jonathan Pryor (jonpryor@vt.edu)
8 // (C) 2003 Novell, Inc.
9 // (C) 2004 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 // PosixConvert 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
;
62 [assembly
:Mono
.Posix
.IncludeAttribute (
63 new string [] {"sys/types.h", "sys/stat.h", "sys/poll.h", "sys/wait.h", "sys/mount.h",
64 "unistd.h", "fcntl.h", "signal.h", "poll.h", "grp.h", "errno.h"},
65 new string [] {"_GNU_SOURCE", "_XOPEN_SOURCE"}
)]
67 namespace Mono
.Posix
{
70 public enum Error
: int {
71 // errors & their values liberally copied from
72 // FC2 /usr/include/asm/errno.h
74 EPERM
= 1, // Operation not permitted
75 ENOENT
= 2, // No such file or directory
76 ESRCH
= 3, // No such process
77 EINTR
= 4, // Interrupted system call
79 ENXIO
= 6, // No such device or address
80 E2BIG
= 7, // Arg list too long
81 ENOEXEC
= 8, // Exec format error
82 EBADF
= 9, // Bad file number
83 ECHILD
= 10, // No child processes
84 EAGAIN
= 11, // Try again
85 ENOMEM
= 12, // Out of memory
86 EACCES
= 13, // Permission denied
87 EFAULT
= 14, // Bad address
88 ENOTBLK
= 15, // Block device required
89 EBUSY
= 16, // Device or resource busy
90 EEXIST
= 17, // File exists
91 EXDEV
= 18, // Cross-device link
92 ENODEV
= 19, // No such device
93 ENOTDIR
= 20, // Not a directory
94 EISDIR
= 21, // Is a directory
95 EINVAL
= 22, // Invalid argument
96 ENFILE
= 23, // File table overflow
97 EMFILE
= 24, // Too many open files
98 ENOTTY
= 25, // Not a typewriter
99 ETXTBSY
= 26, // Text file busy
100 EFBIG
= 27, // File too large
101 ENOSPC
= 28, // No space left on device
102 ESPIPE
= 29, // Illegal seek
103 EROFS
= 30, // Read-only file system
104 EMLINK
= 31, // Too many links
105 EPIPE
= 32, // Broken pipe
106 EDOM
= 33, // Math argument out of domain of func
107 ERANGE
= 34, // Math result not representable
108 EDEADLK
= 35, // Resource deadlock would occur
109 ENAMETOOLONG
= 36, // File name too long
110 ENOLCK
= 37, // No record locks available
111 ENOSYS
= 38, // Function not implemented
112 ENOTEMPTY
= 39, // Directory not empty
113 ELOOP
= 40, // Too many symbolic links encountered
114 EWOULDBLOCK
= EAGAIN
, // Operation would block
115 ENOMSG
= 42, // No message of desired type
116 EIDRM
= 43, // Identifier removed
117 ECHRNG
= 44, // Channel number out of range
118 EL2NSYNC
= 45, // Level 2 not synchronized
119 EL3HLT
= 46, // Level 3 halted
120 EL3RST
= 47, // Level 3 reset
121 ELNRNG
= 48, // Link number out of range
122 EUNATCH
= 49, // Protocol driver not attached
123 ENOCSI
= 50, // No CSI structure available
124 EL2HLT
= 51, // Level 2 halted
125 EBADE
= 52, // Invalid exchange
126 EBADR
= 53, // Invalid request descriptor
127 EXFULL
= 54, // Exchange full
128 ENOANO
= 55, // No anode
129 EBADRQC
= 56, // Invalid request code
130 EBADSLT
= 57, // Invalid slot
134 EBFONT
= 59, // Bad font file format
135 ENOSTR
= 60, // Device not a stream
136 ENODATA
= 61, // No data available
137 ETIME
= 62, // Timer expired
138 ENOSR
= 63, // Out of streams resources
139 ENONET
= 64, // Machine is not on the network
140 ENOPKG
= 65, // Package not installed
141 EREMOTE
= 66, // Object is remote
142 ENOLINK
= 67, // Link has been severed
143 EADV
= 68, // Advertise error
144 ESRMNT
= 69, // Srmount error
145 ECOMM
= 70, // Communication error on send
146 EPROTO
= 71, // Protocol error
147 EMULTIHOP
= 72, // Multihop attempted
148 EDOTDOT
= 73, // RFS specific error
149 EBADMSG
= 74, // Not a data message
150 EOVERFLOW
= 75, // Value too large for defined data type
151 ENOTUNIQ
= 76, // Name not unique on network
152 EBADFD
= 77, // File descriptor in bad state
153 EREMCHG
= 78, // Remote address changed
154 ELIBACC
= 79, // Can not access a needed shared library
155 ELIBBAD
= 80, // Accessing a corrupted shared library
156 ELIBSCN
= 81, // .lib section in a.out corrupted
157 ELIBMAX
= 82, // Attempting to link in too many shared libraries
158 ELIBEXEC
= 83, // Cannot exec a shared library directly
159 EILSEQ
= 84, // Illegal byte sequence
160 ERESTART
= 85, // Interrupted system call should be restarted
161 ESTRPIPE
= 86, // Streams pipe error
162 EUSERS
= 87, // Too many users
163 ENOTSOCK
= 88, // Socket operation on non-socket
164 EDESTADDRREQ
= 89, // Destination address required
165 EMSGSIZE
= 90, // Message too long
166 EPROTOTYPE
= 91, // Protocol wrong type for socket
167 ENOPROTOOPT
= 92, // Protocol not available
168 EPROTONOSUPPORT
= 93, // Protocol not supported
169 ESOCKTNOSUPPORT
= 94, // Socket type not supported
170 EOPNOTSUPP
= 95, // Operation not supported on transport endpoint
171 EPFNOSUPPORT
= 96, // Protocol family not supported
172 EAFNOSUPPORT
= 97, // Address family not supported by protocol
173 EADDRINUSE
= 98, // Address already in use
174 EADDRNOTAVAIL
= 99, // Cannot assign requested address
175 ENETDOWN
= 100, // Network is down
176 ENETUNREACH
= 101, // Network is unreachable
177 ENETRESET
= 102, // Network dropped connection because of reset
178 ECONNABORTED
= 103, // Software caused connection abort
179 ECONNRESET
= 104, // Connection reset by peer
180 ENOBUFS
= 105, // No buffer space available
181 EISCONN
= 106, // Transport endpoint is already connected
182 ENOTCONN
= 107, // Transport endpoint is not connected
183 ESHUTDOWN
= 108, // Cannot send after transport endpoint shutdown
184 ETOOMANYREFS
= 109, // Too many references: cannot splice
185 ETIMEDOUT
= 110, // Connection timed out
186 ECONNREFUSED
= 111, // Connection refused
187 EHOSTDOWN
= 112, // Host is down
188 EHOSTUNREACH
= 113, // No route to host
189 EALREADY
= 114, // Operation already in progress
190 EINPROGRESS
= 115, // Operation now in progress
191 ESTALE
= 116, // Stale NFS file handle
192 EUCLEAN
= 117, // Structure needs cleaning
193 ENOTNAM
= 118, // Not a XENIX named type file
194 ENAVAIL
= 119, // No XENIX semaphores available
195 EISNAM
= 120, // Is a named type file
196 EREMOTEIO
= 121, // Remote I/O error
197 EDQUOT
= 122, // Quota exceeded
199 ENOMEDIUM
= 123, // No medium found
200 EMEDIUMTYPE
= 124, // Wrong medium type
204 public enum OpenFlags
: int {
213 // Or-ed with zero or more of these
224 // These are non-Posix. Using them will result in errors/exceptions on
225 // non-supported platforms.
227 // (For example, "C-wrapped" system calls -- calls with implementation in
228 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
229 // calls will generate an exception in PosixConvert, as the value can't be
230 // converted on the target platform.)
242 public enum FilePermissions
: uint {
243 S_ISUID
= 0x0800, // Set user ID on execution
244 S_ISGID
= 0x0400, // Set gorup ID on execution
245 S_ISVTX
= 0x0200, // Save swapped text after use (sticky).
246 S_IRUSR
= 0x0100, // Read by owner
247 S_IWUSR
= 0x0080, // Write by owner
248 S_IXUSR
= 0x0040, // Execute by owner
249 S_IRGRP
= 0x0020, // Read by group
250 S_IWGRP
= 0x0010, // Write by group
251 S_IXGRP
= 0x0008, // Execute by group
252 S_IROTH
= 0x0004, // Read by other
253 S_IWOTH
= 0x0002, // Write by other
254 S_IXOTH
= 0x0001, // Execute by other
256 S_IRWXG
= (S_IRGRP
| S_IWGRP
| S_IXGRP
),
257 S_IRWXU
= (S_IRUSR
| S_IWUSR
| S_IXUSR
),
258 S_IRWXO
= (S_IROTH
| S_IWOTH
| S_IXOTH
),
259 ACCESSPERMS
= (S_IRWXU
| S_IRWXG
| S_IRWXO
), // 0777
260 ALLPERMS
= (S_ISUID
| S_ISGID
| S_ISVTX
| S_IRWXU
| S_IRWXG
| S_IRWXO
), // 07777
261 DEFFILEMODE
= (S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
), // 0666
264 // Why these are held in "mode_t" is beyond me...
265 S_IFMT
= 0xF000, // Bits which determine file type
266 S_IFDIR
= 0x4000, // Directory
267 S_IFCHR
= 0x2000, // Character device
268 S_IFBLK
= 0x6000, // Block device
269 S_IFREG
= 0x8000, // Regular file
270 S_IFIFO
= 0x1000, // FIFO
271 S_IFLNK
= 0xA000, // Symbolic link
272 S_IFSOCK
= 0xC000, // Socket
275 public struct Flock
{
276 public LockType l_type
; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
277 public SeekFlags l_whence
; // How to interpret l_start
278 public /* off_t */ long l_start
; // Starting offset for lock
279 public /* off_t */ long l_len
; // Number of bytes to lock
280 public /* pid_t */ int l_pid
; // PID of process blocking our lock (F_GETLK only)
284 public enum FcntlCommand
: int {
285 // Form /usr/include/bits/fcntl.h
286 F_DUPFD
= 0, // Duplicate file descriptor.
287 F_GETFD
= 1, // Get file descriptor flags.
288 F_SETFD
= 2, // Set file descriptor flags.
289 F_GETFL
= 3, // Get file status flags.
290 F_SETFL
= 4, // Set file status flags.
291 F_GETLK
= 12, // Get record locking info. [64]
292 F_SETLK
= 13, // Set record locking info (non-blocking). [64]
293 F_SETLKW
= 14, // Set record locking info (blocking). [64]
294 F_SETOWN
= 8, // Set owner of socket (receiver of SIGIO).
295 F_GETOWN
= 9, // Get owner of socket (receiver of SIGIO).
296 F_SETSIG
= 10, // Set number of signal to be sent.
297 F_GETSIG
= 11, // Get number of signal to be sent.
298 F_SETLEASE
= 1024, // Set a lease.
299 F_GETLEASE
= 1025, // Enquire what lease is active.
300 F_NOTIFY
= 1026, // Required notifications on a directory
304 public enum LockType
: short {
305 F_RDLCK
= 0, // Read lock.
306 F_WRLCK
= 1, // Write lock.
307 F_UNLCK
= 2, // Remove lock.
311 public enum SeekFlags
: short {
312 // values liberally copied from /usr/include/unistd.h
313 SEEK_SET
= 0, // Seek from beginning of file.
314 SEEK_CUR
= 1, // Seek from current position.
315 SEEK_END
= 2, // Seek from end of file.
317 L_SET
= SEEK_SET
, // BSD alias for SEEK_SET
318 L_INCR
= SEEK_CUR
, // BSD alias for SEEK_CUR
319 L_XTND
= SEEK_END
, // BSD alias for SEEK_END
323 public enum DirectoryNotifyFlags
: int {
324 // from /usr/include/bits/fcntl.h
325 DN_ACCESS
= 0x00000001, // File accessed.
326 DN_MODIFY
= 0x00000002, // File modified.
327 DN_CREATE
= 0x00000004, // File created.
328 DN_DELETE
= 0x00000008, // File removed.
329 DN_RENAME
= 0x00000010, // File renamed.
330 DN_ATTRIB
= 0x00000020, // File changed attributes.
331 DN_MULTISHOT
= unchecked ((int)0x80000000), // Don't remove notifier
335 public enum PosixFadviseAdvice
: int {
336 POSIX_FADV_NORMAL
= 0, // No further special treatment.
337 POSIX_FADV_RANDOM
= 1, // Expect random page references.
338 POSIX_FADV_SEQUENTIAL
= 2, // Expect sequential page references.
339 POSIX_FADV_WILLNEED
= 3, // Will need these pages.
340 POSIX_FADV_DONTNEED
= 4, // Don't need these pages.
341 POSIX_FADV_NOREUSE
= 5, // Data will be accessed once.
345 public enum PosixMadviseAdvice
: int {
346 POSIX_MADV_NORMAL
= 0, // No further special treatment.
347 POSIX_MADV_RANDOM
= 1, // Expect random page references.
348 POSIX_MADV_SEQUENTIAL
= 2, // Expect sequential page references.
349 POSIX_MADV_WILLNEED
= 3, // Will need these pages.
350 POSIX_MADV_DONTNEED
= 4, // Don't need these pages.
354 public enum Signum
: int {
355 SIGHUP
= 1, // Hangup (POSIX).
356 SIGINT
= 2, // Interrupt (ANSI).
357 SIGQUIT
= 3, // Quit (POSIX).
358 SIGILL
= 4, // Illegal instruction (ANSI).
359 SIGTRAP
= 5, // Trace trap (POSIX).
360 SIGABRT
= 6, // Abort (ANSI).
361 SIGIOT
= 6, // IOT trap (4.2 BSD).
362 SIGBUS
= 7, // BUS error (4.2 BSD).
363 SIGFPE
= 8, // Floating-point exception (ANSI).
364 SIGKILL
= 9, // Kill, unblockable (POSIX).
365 SIGUSR1
= 10, // User-defined signal 1 (POSIX).
366 SIGSEGV
= 11, // Segmentation violation (ANSI).
367 SIGUSR2
= 12, // User-defined signal 2 (POSIX).
368 SIGPIPE
= 13, // Broken pipe (POSIX).
369 SIGALRM
= 14, // Alarm clock (POSIX).
370 SIGTERM
= 15, // Termination (ANSI).
371 SIGSTKFLT
= 16, // Stack fault.
372 SIGCLD
= SIGCHLD
, // Same as SIGCHLD (System V).
373 SIGCHLD
= 17, // Child status has changed (POSIX).
374 SIGCONT
= 18, // Continue (POSIX).
375 SIGSTOP
= 19, // Stop, unblockable (POSIX).
376 SIGTSTP
= 20, // Keyboard stop (POSIX).
377 SIGTTIN
= 21, // Background read from tty (POSIX).
378 SIGTTOU
= 22, // Background write to tty (POSIX).
379 SIGURG
= 23, // Urgent condition on socket (4.2 BSD).
380 SIGXCPU
= 24, // CPU limit exceeded (4.2 BSD).
381 SIGXFSZ
= 25, // File size limit exceeded (4.2 BSD).
382 SIGVTALRM
= 26, // Virtual alarm clock (4.2 BSD).
383 SIGPROF
= 27, // Profiling alarm clock (4.2 BSD).
384 SIGWINCH
= 28, // Window size change (4.3 BSD, Sun).
385 SIGPOLL
= SIGIO
, // Pollable event occurred (System V).
386 SIGIO
= 29, // I/O now possible (4.2 BSD).
387 SIGPWR
= 30, // Power failure restart (System V).
388 SIGSYS
= 31, // Bad system call.
393 public enum MountFlags
: ulong {
394 MS_RDONLY
= 1, // Mount read-only.
395 MS_NOSUID
= 2, // Ignore suid and sgid bits.
396 MS_NODEV
= 4, // Disallow access to device special files.
397 MS_NOEXEC
= 8, // Disallow program execution.
398 MS_SYNCHRONOUS
= 16, // Writes are synced at once.
399 MS_REMOUNT
= 32, // Alter flags of a mounted FS.
400 MS_MANDLOCK
= 64, // Allow mandatory locks on an FS.
401 S_WRITE
= 128, // Write on file/directory/symlink.
402 S_APPEND
= 256, // Append-only file.
403 S_IMMUTABLE
= 512, // Immutable file.
404 MS_NOATIME
= 1024, // Do not update access times.
405 MS_NODIRATIME
= 2048, // Do not update directory access times.
406 MS_BIND
= 4096, // Bind directory at different place.
407 MS_RMT_MASK
= (MS_RDONLY
| MS_MANDLOCK
),
408 MS_MGC_VAL
= 0xc0ed0000, // Magic flag number to indicate "new" flags
409 MS_MGC_MSK
= 0xffff0000, // Magic flag number mask
413 public enum UmountFlags
: int {
414 MNT_FORCE
= 1, // Force unmount even if busy
415 MNT_DETACH
, // Perform a lazy unmount.
419 public enum WaitOptions
: int {
420 WNOHANG
= 1, // Don't block waiting
421 WUNTRACED
= 2, // Report status of stopped children
425 public enum AccessMode
: int {
433 public enum PathConf
: int {
440 _PC_CHOWN_RESTRICTED
,
448 _PC_REC_INCR_XFER_SIZE
,
449 _PC_REC_MAX_XFER_SIZE
,
450 _PC_REC_MIN_XFER_SIZE
,
458 public enum SysConf
: int {
468 _SC_REALTIME_SIGNALS
,
469 _SC_PRIORITY_SCHEDULING
,
478 _SC_MEMORY_PROTECTION
,
481 _SC_SHARED_MEMORY_OBJECTS
,
484 _SC_AIO_PRIO_DELTA_MAX
,
495 /* Values for the argument to `sysconf'
496 corresponding to _POSIX2_* symbols. */
501 _SC_COLL_WEIGHTS_MAX
,
506 _SC_CHARCLASS_NAME_MAX
,
522 _SC_IOV_MAX
= _SC_UIO_MAXIOV
,
523 _SC_PII_INTERNET_STREAM
,
524 _SC_PII_INTERNET_DGRAM
,
529 /* Values according to POSIX 1003.1c (POSIX threads). */
531 _SC_THREAD_SAFE_FUNCTIONS
,
532 _SC_GETGR_R_SIZE_MAX
,
533 _SC_GETPW_R_SIZE_MAX
,
536 _SC_THREAD_DESTRUCTOR_ITERATIONS
,
538 _SC_THREAD_STACK_MIN
,
539 _SC_THREAD_THREADS_MAX
,
540 _SC_THREAD_ATTR_STACKADDR
,
541 _SC_THREAD_ATTR_STACKSIZE
,
542 _SC_THREAD_PRIORITY_SCHEDULING
,
543 _SC_THREAD_PRIO_INHERIT
,
544 _SC_THREAD_PRIO_PROTECT
,
545 _SC_THREAD_PROCESS_SHARED
,
546 _SC_NPROCESSORS_CONF
,
547 _SC_NPROCESSORS_ONLN
,
553 _SC_XOPEN_XCU_VERSION
,
588 _SC_XBS5_ILP32_OFF32
,
589 _SC_XBS5_ILP32_OFFBIG
,
591 _SC_XBS5_LPBIG_OFFBIG
,
594 _SC_XOPEN_REALTIME_THREADS
,
599 _SC_C_LANG_SUPPORT_R
,
605 _SC_DEVICE_SPECIFIC_R
,
616 _SC_READER_WRITER_LOCKS
,
624 _SC_THREAD_SPORADIC_SERVER
,
626 _SC_SYSTEM_DATABASE_R
,
628 _SC_TYPED_MEMORY_OBJECTS
,
632 _SC_2_PBS_ACCOUNTING
,
638 _SC_2_PBS_CHECKPOINT
,
645 _SC_TRACE_EVENT_FILTER
,
648 _SC_LEVEL1_ICACHE_SIZE
,
649 _SC_LEVEL1_ICACHE_ASSOC
,
650 _SC_LEVEL1_ICACHE_LINESIZE
,
651 _SC_LEVEL1_DCACHE_SIZE
,
652 _SC_LEVEL1_DCACHE_ASSOC
,
653 _SC_LEVEL1_DCACHE_LINESIZE
,
654 _SC_LEVEL2_CACHE_SIZE
,
655 _SC_LEVEL2_CACHE_ASSOC
,
656 _SC_LEVEL2_CACHE_LINESIZE
,
657 _SC_LEVEL3_CACHE_SIZE
,
658 _SC_LEVEL3_CACHE_ASSOC
,
659 _SC_LEVEL3_CACHE_LINESIZE
,
660 _SC_LEVEL4_CACHE_SIZE
,
661 _SC_LEVEL4_CACHE_ASSOC
,
662 _SC_LEVEL4_CACHE_LINESIZE
666 public enum ConfStr
: int {
667 _CS_PATH
, /* The default search path. */
668 _CS_V6_WIDTH_RESTRICTED_ENVS
,
669 _CS_GNU_LIBC_VERSION
,
670 _CS_GNU_LIBPTHREAD_VERSION
,
671 _CS_LFS_CFLAGS
= 1000,
679 _CS_XBS5_ILP32_OFF32_CFLAGS
= 1100,
680 _CS_XBS5_ILP32_OFF32_LDFLAGS
,
681 _CS_XBS5_ILP32_OFF32_LIBS
,
682 _CS_XBS5_ILP32_OFF32_LINTFLAGS
,
683 _CS_XBS5_ILP32_OFFBIG_CFLAGS
,
684 _CS_XBS5_ILP32_OFFBIG_LDFLAGS
,
685 _CS_XBS5_ILP32_OFFBIG_LIBS
,
686 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS
,
687 _CS_XBS5_LP64_OFF64_CFLAGS
,
688 _CS_XBS5_LP64_OFF64_LDFLAGS
,
689 _CS_XBS5_LP64_OFF64_LIBS
,
690 _CS_XBS5_LP64_OFF64_LINTFLAGS
,
691 _CS_XBS5_LPBIG_OFFBIG_CFLAGS
,
692 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS
,
693 _CS_XBS5_LPBIG_OFFBIG_LIBS
,
694 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS
,
695 _CS_POSIX_V6_ILP32_OFF32_CFLAGS
,
696 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS
,
697 _CS_POSIX_V6_ILP32_OFF32_LIBS
,
698 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS
,
699 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
,
700 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
,
701 _CS_POSIX_V6_ILP32_OFFBIG_LIBS
,
702 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS
,
703 _CS_POSIX_V6_LP64_OFF64_CFLAGS
,
704 _CS_POSIX_V6_LP64_OFF64_LDFLAGS
,
705 _CS_POSIX_V6_LP64_OFF64_LIBS
,
706 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS
,
707 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
,
708 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
,
709 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
,
710 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
714 public enum LockFlags
: int {
715 F_ULOCK
= 0, // Unlock a previously locked region.
716 F_LOCK
= 1, // Lock a region for exclusive use.
717 F_TLOCK
= 2, // Test and lock a region for exclusive use.
718 F_TEST
= 3, // Test a region for other process locks.
722 public enum PollEvents
: short {
723 POLLIN
= 0x0001, // There is data to read
724 POLLPRI
= 0x0002, // There is urgent data to read
725 POLLOUT
= 0x0004, // Writing now will not block
726 POLLERR
= 0x0008, // Error condition
727 POLLHUP
= 0x0010, // Hung up
728 POLLNVAL
= 0x0020, // Invalid request; fd not open
729 // XPG4.2 definitions (via _XOPEN_SOURCE)
730 POLLRDNORM
= 0x0040, // Normal data bay be read
731 POLLRDBAND
= 0x0080, // Priority data may be read
732 POLLWRNORM
= 0x0100, // Writing now will not block
733 POLLWRBAND
= 0x0200, // Priority data may be written
736 [StructLayout(LayoutKind
.Sequential
)]
737 public struct Pollfd
{
739 public PollEvents events
;
740 public PollEvents revents
;
745 public /* ino_t */ ulong d_ino
;
746 public /* off_t */ long d_off
;
747 public ushort d_reclen
;
749 public string d_name
;
751 public override string ToString ()
759 public string gr_name
;
760 public string gr_passwd
;
761 public /* gid_t */ uint gr_gid
;
762 public string[] gr_mem
;
764 // Generate string in /etc/group format
765 public override string ToString ()
767 StringBuilder sb
= new StringBuilder ();
768 sb
.AppendFormat ("{0}:{1}:{2}:", gr_name
, gr_passwd
, gr_gid
);
769 GetMembers (sb
, gr_mem
);
770 return sb
.ToString ();
773 private static void GetMembers (StringBuilder sb
, string[] members
)
775 if (members
.Length
> 0)
776 sb
.Append (members
[0]);
777 for (int i
= 1; i
< members
.Length
; ++i
) {
779 sb
.Append (members
[i
]);
786 public string pw_name
;
787 public string pw_passwd
;
788 public /* uid_t */ uint pw_uid
;
789 public /* gid_t */ uint pw_gid
;
790 public string pw_gecos
;
791 public string pw_dir
;
792 public string pw_shell
;
794 // Generate string in /etc/passwd format
795 public override string ToString ()
797 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
798 pw_name
, pw_passwd
, pw_uid
, pw_gid
, pw_gecos
, pw_dir
, pw_shell
);
803 public /* dev_t */ ulong st_dev
; // device
804 public /* ino_t */ ulong st_ino
; // inode
805 public FilePermissions st_mode
; // protection
806 private uint _padding_
; // padding for structure alignment
807 public /* nlink_t */ ulong st_nlink
; // number of hard links
808 public /* uid_t */ uint st_uid
; // user ID of owner
809 public /* gid_t */ uint st_gid
; // group ID of owner
810 public /* dev_t */ ulong st_rdev
; // device type (if inode device)
811 public /* off_t */ long st_size
; // total size, in bytes
812 public /* blksize_t */ long st_blksize
; // blocksize for filesystem I/O
813 public /* blkcnt_t */ long st_blocks
; // number of blocks allocated
814 public /* time_t */ long st_atime
; // time of last access
815 public /* time_t */ long st_mtime
; // time of last modification
816 public /* time_t */ long st_ctime
; // time of last status change
820 // Convention: Functions *not* part of the standard C library AND part of
821 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
823 // For example, the man page should be similar to:
825 // CONFORMING TO (or CONFORMS TO)
826 // XPG2, SUSv2, POSIX, etc.
828 // BSD- and GNU-specific exports can also be placed here.
830 // The only methods in here should be:
831 // (1) low-level functions
832 // (2) "Trivial" function overloads. For example, if the parameters to a
833 // function are related (e.g. getgroups(2))
834 // (3) The return type SHOULD NOT be changed. If you want to provide a
835 // convenient function with a nicer return type, place it into one of
836 // the Posix* wrapper classes, and give it a .NET-styled name.
837 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
838 // - If you're wrapping *broken* methods which make assumptions about
839 // input data, such as that an argument refers to N bytes of data.
840 // This is currently limited to cuserid(3) and encrypt(3).
841 // - If you call functions which themselves generate exceptions.
842 // This is the case for using PosixConvert, which will throw an
843 // exception if an invalid/unsupported value is used.
845 public sealed class Syscall
: Stdlib
847 private const string LIBC
= "libc";
848 private const string MPH
= "MonoPosixHelper";
849 private const string CRYPT
= "crypt";
851 private Syscall () {}
857 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
858 // aio_return(3), aio_suspend(3), aio_write(3)
860 // Then update PosixStream.BeginRead to use the aio* functions.
866 [DllImport (LIBC
, SetLastError
=true)]
867 public static extern IntPtr
opendir (string name
);
869 [DllImport (LIBC
, SetLastError
=true)]
870 public static extern int closedir (IntPtr dir
);
873 // void seekdir (DIR *dir, off_t offset);
874 // Slight modification. Returns -1 on error, 0 on success.
875 [DllImport (MPH
, SetLastError
=true,
876 EntryPoint
="Mono_Posix_Syscall_seekdir")]
877 public static extern int seekdir (IntPtr dir
, long offset
);
880 // off_t telldir(DIR *dir);
881 [DllImport (MPH
, SetLastError
=true,
882 EntryPoint
="Mono_Posix_Syscall_telldir")]
883 public static extern long telldir (IntPtr dir
);
885 [DllImport (LIBC
, SetLastError
=true)]
886 public static extern void rewinddir (IntPtr dir
);
888 private struct _Dirent
{
889 public /* ino_t */ ulong d_ino
;
890 public /* off_t */ long d_off
;
891 public ushort d_reclen
;
893 public IntPtr d_name
;
896 private static void CopyDirent (Dirent to
, ref _Dirent
from)
899 to
.d_ino
= from.d_ino
;
900 to
.d_off
= from.d_off
;
901 to
.d_reclen
= from.d_reclen
;
902 to
.d_type
= from.d_type
;
903 if (from.d_name
!= IntPtr
.Zero
)
904 to
.d_name
= PosixMarshal
.PtrToString (from.d_name
);
909 Stdlib
.free (from.d_name
);
910 from.d_name
= IntPtr
.Zero
;
914 [DllImport (MPH
, SetLastError
=true,
915 EntryPoint
="Mono_Posix_Syscall_readdir")]
916 private static extern int sys_readdir (IntPtr dir
, out _Dirent dentry
);
918 public static Dirent
readdir (IntPtr dir
)
921 int r
= sys_readdir (dir
, out dentry
);
924 Dirent d
= new Dirent ();
925 CopyDirent (d
, ref dentry
);
929 [DllImport (MPH
, SetLastError
=true,
930 EntryPoint
="Mono_Posix_Syscall_readdir_r")]
931 private static extern int sys_readdir_r (IntPtr dirp
, out _Dirent entry
, out IntPtr result
);
933 public static int readdir_r (IntPtr dirp
, Dirent entry
, out IntPtr result
)
942 int r
= sys_readdir_r (dirp
, out _d
, out result
);
944 if (r
== 0 && result
!= IntPtr
.Zero
) {
945 CopyDirent (entry
, ref _d
);
951 [DllImport (LIBC
, SetLastError
=true)]
952 public static extern int dirfd (IntPtr dir
);
958 public static Error
GetLastError ()
960 int errno
= Marshal
.GetLastWin32Error ();
961 return PosixConvert
.ToError (errno
);
964 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_SetLastError")]
965 private static extern void SetLastError (int error
);
967 public static void SetLastError (Error error
)
969 int _error
= PosixConvert
.FromError (error
);
970 SetLastError (_error
);
974 // int strerror_r(int errnum, char *buf, size_t n);
975 [DllImport (LIBC
, SetLastError
=true,
976 EntryPoint
="Mono_Posix_Syscall_strerror_r")]
977 private static extern int sys_strerror_r (int errnum
,
978 [Out
] StringBuilder buf
, ulong n
);
980 public static int strerror_r (Error errnum
, StringBuilder buf
, ulong n
)
982 int e
= PosixConvert
.FromError (errnum
);
983 return sys_strerror_r (e
, buf
, n
);
986 public static int strerror_r (Error errnum
, StringBuilder buf
)
988 return strerror_r (errnum
, buf
, (ulong) buf
.Capacity
);
991 public static string strerror_r (Error errnum
)
993 StringBuilder buf
= new StringBuilder (16);
997 r
= strerror_r (errnum
, buf
);
998 } while (r
== -1 && GetLastError() == Error
.ERANGE
);
1001 return "** Unknown error code: " + ((int) errnum
) + "**";
1002 return buf
.ToString();
1008 [DllImport (MPH
, SetLastError
=true,
1009 EntryPoint
="Mono_Posix_Syscall_fcntl")]
1010 public static extern int fcntl (int fd
, FcntlCommand cmd
);
1012 [DllImport (MPH
, SetLastError
=true,
1013 EntryPoint
="Mono_Posix_Syscall_fcntl_arg")]
1014 public static extern int fcntl (int fd
, FcntlCommand cmd
, long arg
);
1016 [DllImport (MPH
, SetLastError
=true,
1017 EntryPoint
="Mono_Posix_Syscall_fcntl_lock")]
1018 public static extern int fcntl (int fd
, FcntlCommand cmd
, ref Flock
@lock);
1020 [DllImport (MPH
, SetLastError
=true,
1021 EntryPoint
="Mono_Posix_Syscall_open")]
1022 public static extern int open (string pathname
, OpenFlags flags
);
1024 [DllImport (MPH
, SetLastError
=true,
1025 EntryPoint
="Mono_Posix_Syscall_open_mode")]
1026 public static extern int open (string pathname
, OpenFlags flags
, FilePermissions mode
);
1028 [DllImport (MPH
, SetLastError
=true,
1029 EntryPoint
="Mono_Posix_Syscall_creat")]
1030 public static extern int creat (string pathname
, FilePermissions mode
);
1033 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
1034 [DllImport (MPH
, SetLastError
=true,
1035 EntryPoint
="Mono_Posix_Syscall_posix_fadvise")]
1036 public static extern int posix_fadvise (int fd
, long offset
,
1037 long len
, PosixFadviseAdvice advice
);
1039 // posix_fallocate(P)
1040 // int posix_fallocate(int fd, off_t offset, size_t len);
1041 [DllImport (MPH
, SetLastError
=true,
1042 EntryPoint
="Mono_Posix_Syscall_posix_fallocate")]
1043 public static extern int posix_fallocate (int fd
, long offset
, long len
);
1050 // int setgroups (size_t size, const gid_t *list);
1051 [DllImport (MPH
, SetLastError
=true,
1052 EntryPoint
="Mono_Posix_Syscall_setgroups")]
1053 public static extern int setgroups (ulong size
, uint[] list
);
1055 public static int setgroups (uint [] list
)
1057 return setgroups ((ulong) list
.Length
, list
);
1060 private struct _Group
1062 public IntPtr gr_name
;
1063 public IntPtr gr_passwd
;
1064 public /* gid_t */ uint gr_gid
;
1065 public int _gr_nmem_
;
1066 public IntPtr gr_mem
;
1067 public IntPtr _gr_buf_
;
1070 private static void CopyGroup (Group to
, ref _Group
from)
1073 to
.gr_gid
= from.gr_gid
;
1074 to
.gr_name
= PosixMarshal
.PtrToString (from.gr_name
);
1075 to
.gr_passwd
= PosixMarshal
.PtrToString (from.gr_passwd
);
1076 to
.gr_mem
= PosixMarshal
.PtrToStringArray (from._gr_nmem_
, from.gr_mem
);
1079 Stdlib
.free (from.gr_mem
);
1080 Stdlib
.free (from._gr_buf_
);
1081 from.gr_mem
= IntPtr
.Zero
;
1082 from._gr_buf_
= IntPtr
.Zero
;
1086 [DllImport (MPH
, SetLastError
=true,
1087 EntryPoint
="Mono_Posix_Syscall_getgrnam")]
1088 private static extern int sys_getgrnam (string name
, out _Group
group);
1090 public static Group
getgrnam (string name
)
1093 int r
= sys_getgrnam (name
, out group);
1096 Group gr
= new Group ();
1097 CopyGroup (gr
, ref group);
1102 // struct group *getgrgid(gid_t gid);
1103 [DllImport (MPH
, SetLastError
=true,
1104 EntryPoint
="Mono_Posix_Syscall_getgrgid")]
1105 private static extern int sys_getgrgid (uint uid
, out _Group
group);
1107 public static Group
getgrgid (uint uid
)
1110 int r
= sys_getgrgid (uid
, out group);
1113 Group gr
= new Group ();
1114 CopyGroup (gr
, ref group);
1118 [DllImport (MPH
, SetLastError
=true,
1119 EntryPoint
="Mono_Posix_Syscall_getgrnam_r")]
1120 private static extern int sys_getgrnam_r (string name
, out _Group grbuf
, out IntPtr grbufp
);
1122 public static int getgrnam_r (string name
, Group grbuf
, out Group grbufp
)
1127 int r
= sys_getgrnam_r (name
, out group, out _grbufp
);
1128 if (r
== 0 && _grbufp
!= IntPtr
.Zero
) {
1129 CopyGroup (grbuf
, ref group);
1136 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
1137 // size_t buflen, struct group **gbufp);
1138 [DllImport (MPH
, SetLastError
=true,
1139 EntryPoint
="Mono_Posix_Syscall_getgrgid_r")]
1140 private static extern int sys_getgrgid_r (uint uid
, out _Group grbuf
, out IntPtr grbufp
);
1142 public static int getgrgid_r (uint uid
, Group grbuf
, out Group grbufp
)
1147 int r
= sys_getgrgid_r (uid
, out group, out _grbufp
);
1148 if (r
== 0 && _grbufp
!= IntPtr
.Zero
) {
1149 CopyGroup (grbuf
, ref group);
1155 [DllImport (MPH
, SetLastError
=true,
1156 EntryPoint
="Mono_Posix_Syscall_getgrent")]
1157 private static extern int sys_getgrent (out _Group grbuf
);
1159 public static Group
getgrent ()
1162 int r
= sys_getgrent (out group);
1165 Group gr
= new Group();
1166 CopyGroup (gr
, ref group);
1170 [DllImport (LIBC
, SetLastError
=true)]
1171 public static extern void setgrent ();
1173 [DllImport (LIBC
, SetLastError
=true)]
1174 public static extern void endgrent ();
1176 [DllImport (MPH
, SetLastError
=true,
1177 EntryPoint
="Mono_Posix_Syscall_fgetgrent")]
1178 private static extern int sys_fgetgrent (IntPtr stream
, out _Group grbuf
);
1180 public static Group
fgetgrent (IntPtr stream
)
1183 int r
= sys_fgetgrent (stream
, out group);
1186 Group gr
= new Group ();
1187 CopyGroup (gr
, ref group);
1194 private struct _Passwd
1196 public IntPtr pw_name
;
1197 public IntPtr pw_passwd
;
1198 public /* uid_t */ uint pw_uid
;
1199 public /* gid_t */ uint pw_gid
;
1200 public IntPtr pw_gecos
;
1201 public IntPtr pw_dir
;
1202 public IntPtr pw_shell
;
1203 public IntPtr _pw_buf_
;
1206 private static void CopyPasswd (Passwd to
, ref _Passwd
from)
1209 to
.pw_name
= PosixMarshal
.PtrToString (from.pw_name
);
1210 to
.pw_passwd
= PosixMarshal
.PtrToString (from.pw_passwd
);
1211 to
.pw_uid
= from.pw_uid
;
1212 to
.pw_gid
= from.pw_gid
;
1213 to
.pw_gecos
= PosixMarshal
.PtrToString (from.pw_gecos
);
1214 to
.pw_dir
= PosixMarshal
.PtrToString (from.pw_dir
);
1215 to
.pw_shell
= PosixMarshal
.PtrToString (from.pw_shell
);
1218 Stdlib
.free (from._pw_buf_
);
1219 from._pw_buf_
= IntPtr
.Zero
;
1223 [DllImport (MPH
, SetLastError
=true,
1224 EntryPoint
="Mono_Posix_Syscall_getpwnam")]
1225 private static extern int sys_getpwnam (string name
, out _Passwd passwd
);
1227 public static Passwd
getpwnam (string name
)
1230 int r
= sys_getpwnam (name
, out passwd
);
1233 Passwd pw
= new Passwd ();
1234 CopyPasswd (pw
, ref passwd
);
1239 // struct passwd *getpwnuid(uid_t uid);
1240 [DllImport (MPH
, SetLastError
=true,
1241 EntryPoint
="Mono_Posix_Syscall_getpwuid")]
1242 private static extern int sys_getpwuid (uint uid
, out _Passwd passwd
);
1244 public static Passwd
getpwuid (uint uid
)
1247 int r
= sys_getpwuid (uid
, out passwd
);
1250 Passwd pw
= new Passwd ();
1251 CopyPasswd (pw
, ref passwd
);
1255 [DllImport (MPH
, SetLastError
=true,
1256 EntryPoint
="Mono_Posix_Syscall_getpwnam_r")]
1257 private static extern int sys_getpwnam_r (string name
, out _Passwd pwbuf
, out IntPtr pwbufp
);
1259 public static int getpwnam_r (string name
, Passwd pwbuf
, out Passwd pwbufp
)
1264 int r
= sys_getpwnam_r (name
, out passwd
, out _pwbufp
);
1265 if (r
== 0 && _pwbufp
!= IntPtr
.Zero
) {
1266 CopyPasswd (pwbuf
, ref passwd
);
1273 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
1274 // buflen, struct passwd **pwbufp);
1275 [DllImport (MPH
, SetLastError
=true,
1276 EntryPoint
="Mono_Posix_Syscall_getpwuid_r")]
1277 private static extern int sys_getpwuid_r (uint uid
, out _Passwd pwbuf
, out IntPtr pwbufp
);
1279 public static int getpwuid_r (uint uid
, Passwd pwbuf
, out Passwd pwbufp
)
1284 int r
= sys_getpwuid_r (uid
, out passwd
, out _pwbufp
);
1285 if (r
== 0 && _pwbufp
!= IntPtr
.Zero
) {
1286 CopyPasswd (pwbuf
, ref passwd
);
1292 [DllImport (MPH
, SetLastError
=true,
1293 EntryPoint
="Mono_Posix_Syscall_getpwent")]
1294 private static extern int sys_getpwent (out _Passwd pwbuf
);
1296 public static Passwd
getpwent ()
1299 int r
= sys_getpwent (out passwd
);
1302 Passwd pw
= new Passwd ();
1303 CopyPasswd (pw
, ref passwd
);
1307 [DllImport (LIBC
, SetLastError
=true)]
1308 public static extern void setpwent ();
1310 [DllImport (LIBC
, SetLastError
=true)]
1311 public static extern void endpwent ();
1313 [DllImport (MPH
, SetLastError
=true,
1314 EntryPoint
="Mono_Posix_Syscall_fgetpwent")]
1315 private static extern int sys_fgetpwent (IntPtr stream
, out _Passwd pwbuf
);
1317 public static Passwd
fgetpwent (IntPtr stream
)
1320 int r
= sys_fgetpwent (stream
, out passwd
);
1323 Passwd pw
= new Passwd ();
1324 CopyPasswd (pw
, ref passwd
);
1331 [DllImport (LIBC
, SetLastError
=true)]
1332 private static extern void psignal (int sig
, string s
);
1334 public static void psignal (Signum sig
, string s
)
1336 int signum
= PosixConvert
.FromSignum (sig
);
1337 psignal (signum
, s
);
1341 // int kill(pid_t pid, int sig);
1342 [DllImport (LIBC
, SetLastError
=true)]
1343 private static extern int sys_kill (int pid
, int sig
);
1345 public static int kill (int pid
, Signum sig
)
1347 int _sig
= PosixConvert
.FromSignum (sig
);
1348 return sys_kill (pid
, _sig
);
1351 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="strsignal")]
1352 private static extern IntPtr
sys_strsignal (int sig
);
1354 public static IntPtr
sys_strsignal (Signum sig
)
1356 int s
= PosixConvert
.FromSignum (sig
);
1357 return sys_strsignal (s
);
1360 public static string strsignal (Signum sig
)
1362 IntPtr r
= sys_strsignal (sig
);
1363 return PosixMarshal
.PtrToString (r
);
1366 // TODO: sigaction(2)
1367 // TODO: sigsuspend(2)
1368 // TODO: sigpending(2)
1374 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_L_ctermid")]
1375 private static extern int _L_ctermid ();
1377 public static readonly int L_ctermid
= _L_ctermid ();
1379 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_L_cuserid")]
1380 private static extern int _L_cuserid ();
1382 public static readonly int L_cuserid
= _L_cuserid ();
1384 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="cuserid")]
1385 private static extern IntPtr
sys_cuserid ([Out
] StringBuilder
@string);
1387 [Obsolete ("\"Nobody knows precisely what cuserid() does... DO NOT USE cuserid()." +
1388 "`string' must hold L_cuserid characters. Use Unistd.getlogin_r instead.")]
1389 public static string cuserid (StringBuilder
@string)
1391 if (@string.Capacity
< L_cuserid
) {
1392 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
1394 IntPtr r
= sys_cuserid (@string);
1395 return PosixMarshal
.PtrToString (r
);
1401 [DllImport (LIBC
, SetLastError
=true)]
1402 public static extern int ttyslot ();
1404 [DllImport (CRYPT
, SetLastError
=true)]
1405 public static extern void setkey (string key
);
1412 // int posix_madvise(void *addr, size_t len, int advice);
1413 [DllImport (MPH
, SetLastError
=true,
1414 EntryPoint
="Mono_Posix_Syscall_posix_madvise")]
1415 public static extern int posix_madvise (IntPtr addr
, ulong len
,
1416 PosixMadviseAdvice advice
);
1421 [DllImport (MPH
, SetLastError
=true,
1422 EntryPoint
="Mono_Posix_Syscall_mount")]
1423 public static extern int mount (string source
, string target
,
1424 string filesystemtype
, MountFlags mountflags
, string data
);
1426 [DllImport (MPH
, SetLastError
=true,
1427 EntryPoint
="Mono_Posix_Syscall_umount")]
1428 public static extern int umount (string target
);
1430 [DllImport (MPH
, SetLastError
=true,
1431 EntryPoint
="Mono_Posix_Syscall_umount2")]
1432 private static extern int sys_umount2 (string target
, int flags
);
1434 public static int umount2 (string target
, UmountFlags flags
)
1436 int _flags
= PosixConvert
.FromUmountFlags (flags
);
1437 return sys_umount2 (target
, _flags
);
1443 private struct _pollfd
{
1445 public short events
;
1446 public short revents
;
1449 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="poll")]
1450 private static extern int sys_poll (_pollfd
[] ufds
, uint nfds
, int timeout
);
1452 public static int poll (Pollfd
[] fds
, uint nfds
, int timeout
)
1454 if (fds
.Length
< nfds
)
1455 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
1457 _pollfd
[] send
= new _pollfd
[nfds
];
1459 for (int i
= 0; i
< send
.Length
; i
++) {
1460 send
[i
].fd
= fds
[i
].fd
;
1461 send
[i
].events
= PosixConvert
.FromPollEvents (fds
[i
].events
);
1464 int r
= sys_poll (send
, nfds
, timeout
);
1466 for (int i
= 0; i
< send
.Length
; i
++) {
1467 fds
[i
].revents
= PosixConvert
.ToPollEvents (send
[i
].revents
);
1473 public static int poll (Pollfd
[] fds
, int timeout
)
1475 return poll (fds
, (uint) fds
.Length
, timeout
);
1488 // TODO: setrlimit(2)
1489 // TODO: getrlimit(2)
1490 // TODO: getrusage(2)
1496 [DllImport (MPH
, SetLastError
=true,
1497 EntryPoint
="Mono_Posix_Syscall_sendfile")]
1498 public static extern long sendfile (int out_fd
, int in_fd
,
1499 ref long offset
, ulong count
);
1504 [DllImport (MPH
, SetLastError
=true,
1505 EntryPoint
="Mono_Posix_Syscall_stat")]
1506 public static extern int stat (string file_name
, out Stat buf
);
1508 [DllImport (MPH
, SetLastError
=true,
1509 EntryPoint
="Mono_Posix_Syscall_fstat")]
1510 public static extern int fstat (int filedes
, out Stat buf
);
1512 [DllImport (MPH
, SetLastError
=true,
1513 EntryPoint
="Mono_Posix_Syscall_lstat")]
1514 public static extern int lstat (string file_name
, out Stat buf
);
1516 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="chmod")]
1517 private static extern int sys_chmod (string path
, uint mode
);
1519 public static int chmod (string path
, FilePermissions mode
)
1521 uint _mode
= PosixConvert
.FromFilePermissions (mode
);
1522 return sys_chmod (path
, _mode
);
1525 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="fchmod")]
1526 private static extern int sys_fchmod (int filedes
, uint mode
);
1528 public static int fchmod (int filedes
, FilePermissions mode
)
1530 uint _mode
= PosixConvert
.FromFilePermissions (mode
);
1531 return sys_fchmod (filedes
, _mode
);
1534 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="umask")]
1535 private static extern int sys_umask (uint mask
);
1537 public static int umask (FilePermissions mask
)
1539 uint _mask
= PosixConvert
.FromFilePermissions (mask
);
1540 return sys_umask (_mask
);
1543 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="mkdir")]
1544 public static extern int sys_mkdir (string oldpath
, uint mode
);
1546 public static int mkdir (string oldpath
, FilePermissions mode
)
1548 uint _mode
= PosixConvert
.FromFilePermissions (mode
);
1549 return sys_mkdir (oldpath
, _mode
);
1558 // TODO: gettimeofday(2)
1559 // TODO: settimeofday(2)
1578 // pid_t wait(int *status);
1579 [DllImport (LIBC
, SetLastError
=true)]
1580 public static extern int wait (out int status
);
1583 // pid_t waitpid(pid_t pid, int *status, int options);
1584 [DllImport (LIBC
, SetLastError
=true)]
1585 private static extern int waitpid (int pid
, out int status
, int options
);
1587 public static int waitpid (int pid
, out int status
, WaitOptions options
)
1589 int _options
= PosixConvert
.FromWaitOptions (options
);
1590 return waitpid (pid
, out status
, _options
);
1593 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_WIFEXITED")]
1594 private static extern int _WIFEXITED (int status
);
1596 public static bool WIFEXITED (int status
)
1598 return _WIFEXITED (status
) != 0;
1601 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_WEXITSTATUS")]
1602 public static extern int WEXITSTATUS (int status
);
1604 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_WIFSIGNALED")]
1605 private static extern int _WIFSIGNALED (int status
);
1607 public static bool WIFSIGNALED (int status
)
1609 return _WIFSIGNALED (status
) != 0;
1612 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_WTERMSIG")]
1613 private static extern int _WTERMSIG (int status
);
1615 public static Signum
WTERMSIG (int status
)
1617 int r
= _WTERMSIG (status
);
1618 return PosixConvert
.ToSignum (r
);
1621 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_WIFSTOPPED")]
1622 private static extern int _WIFSTOPPED (int status
);
1624 public static bool WIFSTOPPED (int status
)
1626 return _WIFSTOPPED (status
) != 0;
1629 [DllImport (MPH
, EntryPoint
="Mono_Posix_Syscall_WSTOPSIG")]
1630 private static extern int _WSTOPSIG (int status
);
1632 public static Signum
WSTOPSIG (int status
)
1634 int r
= _WSTOPSIG (status
);
1635 return PosixConvert
.ToSignum (r
);
1643 // int stime(time_t *t);
1644 [DllImport (MPH
, SetLastError
=true,
1645 EntryPoint
="Mono_Posix_Syscall_stime")]
1646 public static extern int stime (ref long t
);
1649 // time_t time(time_t *t);
1650 [DllImport (MPH
, SetLastError
=true,
1651 EntryPoint
="Mono_Posix_Syscall_time")]
1652 public static extern long time (out long t
);
1663 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="access")]
1664 private static extern int sys_access (string pathname
, int mode
);
1666 public static int access (string pathname
, AccessMode mode
)
1668 int _mode
= PosixConvert
.FromAccessMode (mode
);
1669 return sys_access (pathname
, _mode
);
1673 // off_t lseek(int filedes, off_t offset, int whence);
1674 [DllImport (MPH
, SetLastError
=true,
1675 EntryPoint
="Mono_Posix_Syscall_lseek")]
1676 public static extern long lseek (int fd
, long offset
, SeekFlags whence
);
1678 [DllImport (LIBC
, SetLastError
=true)]
1679 public static extern int close (int fd
);
1682 // ssize_t read(int fd, void *buf, size_t count);
1683 [DllImport (MPH
, SetLastError
=true,
1684 EntryPoint
="Mono_Posix_Syscall_read")]
1685 public static extern long read (int fd
, IntPtr buf
, ulong count
);
1687 public static unsafe long read (int fd
, void *buf
, ulong count
)
1689 return read (fd
, (IntPtr
) buf
, count
);
1693 // ssize_t write(int fd, const void *buf, size_t count);
1694 [DllImport (MPH
, SetLastError
=true,
1695 EntryPoint
="Mono_Posix_Syscall_write")]
1696 public static extern long write (int fd
, IntPtr buf
, ulong count
);
1698 public static unsafe long write (int fd
, void *buf
, ulong count
)
1700 return write (fd
, (IntPtr
) buf
, count
);
1704 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
1705 [DllImport (MPH
, SetLastError
=true,
1706 EntryPoint
="Mono_Posix_Syscall_pread")]
1707 public static extern long pread (int fd
, IntPtr buf
, ulong count
, long offset
);
1709 public static unsafe long pread (int fd
, void *buf
, ulong count
, long offset
)
1711 return pread (fd
, (IntPtr
) buf
, count
, offset
);
1715 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
1716 [DllImport (MPH
, SetLastError
=true,
1717 EntryPoint
="Mono_Posix_Syscall_pwrite")]
1718 public static extern long pwrite (int fd
, IntPtr buf
, ulong count
, long offset
);
1720 public static unsafe long pwrite (int fd
, void *buf
, ulong count
, long offset
)
1722 return pwrite (fd
, (IntPtr
) buf
, count
, offset
);
1725 [DllImport (MPH
, SetLastError
=true,
1726 EntryPoint
="Mono_Posix_Syscall_pipe")]
1727 public static extern int pipe (out int reading
, out int writing
);
1729 public static int pipe (int[] filedes
)
1731 if (filedes
== null || filedes
.Length
!= 2) {
1735 int reading
, writing
;
1736 int r
= pipe (out reading
, out writing
);
1737 filedes
[0] = reading
;
1738 filedes
[1] = writing
;
1742 [DllImport (LIBC
, SetLastError
=true)]
1743 public static extern uint alarm (uint seconds
);
1745 [DllImport (LIBC
, SetLastError
=true)]
1746 public static extern int sleep (uint seconds
);
1748 [DllImport (LIBC
, SetLastError
=true)]
1749 public static extern uint ualarm (uint usecs
, uint interval
);
1751 [DllImport (LIBC
, SetLastError
=true)]
1752 public static extern int pause ();
1755 // int chown(const char *path, uid_t owner, gid_t group);
1756 [DllImport (LIBC
, SetLastError
=true)]
1757 public static extern int chown (string path
, uint owner
, uint group);
1760 // int fchown(int fd, uid_t owner, gid_t group);
1761 [DllImport (LIBC
, SetLastError
=true)]
1762 public static extern int fchown (int fd
, uint owner
, uint group);
1765 // int lchown(const char *path, uid_t owner, gid_t group);
1766 [DllImport (LIBC
, SetLastError
=true)]
1767 public static extern int lchown (string path
, uint owner
, uint group);
1769 [DllImport (LIBC
, SetLastError
=true)]
1770 public static extern int chdir (string path
);
1772 [DllImport (LIBC
, SetLastError
=true)]
1773 public static extern int fchdir (int fd
);
1776 // char *getcwd(char *buf, size_t size);
1777 [DllImport (MPH
, SetLastError
=true,
1778 EntryPoint
="Mono_Posix_Syscall_getcwd")]
1779 public static extern IntPtr
getcwd ([Out
] StringBuilder buf
, ulong size
);
1781 public static StringBuilder
getcwd (StringBuilder buf
)
1783 getcwd (buf
, (ulong) buf
.Capacity
);
1787 // getwd(2) is deprecated; don't expose it.
1789 [DllImport (LIBC
, SetLastError
=true)]
1790 public static extern int dup (int fd
);
1792 [DllImport (LIBC
, SetLastError
=true)]
1793 public static extern int dup2 (int fd
, int fd2
);
1795 // TODO: does Mono marshal arrays properly?
1796 [DllImport (LIBC
, SetLastError
=true)]
1797 public static extern int execve (string path
, string[] argv
, string[] envp
);
1799 [DllImport (LIBC
, SetLastError
=true)]
1800 public static extern int execv (string path
, string[] argv
);
1802 // TODO: execle, execl
1803 [DllImport (LIBC
, SetLastError
=true)]
1804 public static extern int execvp (string path
, string[] argv
);
1806 [DllImport (LIBC
, SetLastError
=true)]
1807 public static extern int nice (int inc
);
1809 [DllImport (LIBC
, SetLastError
=true)]
1810 public static extern int _exit (int status
);
1812 [DllImport (MPH
, SetLastError
=true,
1813 EntryPoint
="Mono_Posix_Syscall_fpathconf")]
1814 public static extern long fpathconf (int filedes
, PathConf name
);
1816 [DllImport (MPH
, SetLastError
=true,
1817 EntryPoint
="Mono_Posix_Syscall_pathconf")]
1818 public static extern long pathconf (string path
, PathConf name
);
1820 [DllImport (MPH
, SetLastError
=true,
1821 EntryPoint
="Mono_Posix_Syscall_sysconf")]
1822 public static extern long sysconf (SysConf name
);
1825 // size_t confstr(int name, char *buf, size_t len);
1826 [DllImport (MPH
, SetLastError
=true,
1827 EntryPoint
="Mono_Posix_Syscall_confstr")]
1828 public static extern ulong confstr (ConfStr name
, [Out
] StringBuilder buf
, ulong len
);
1831 // pid_t getpid(void);
1832 [DllImport (LIBC
, SetLastError
=true)]
1833 public static extern int getpid ();
1836 // int setpgid(pid_t pid, pid_t pgid);
1837 [DllImport (LIBC
, SetLastError
=true)]
1838 public static extern int setpgid (int pid
, int pgid
);
1841 // pid_t getpgid(pid_t pid);
1842 [DllImport (LIBC
, SetLastError
=true)]
1843 public static extern int getpgid (int pid
);
1845 [DllImport (LIBC
, SetLastError
=true)]
1846 public static extern int setpgrp ();
1849 // pid_t getpgrp(void);
1850 [DllImport (LIBC
, SetLastError
=true)]
1851 public static extern int getpgrp ();
1854 // pid_t setsid(void);
1855 [DllImport (LIBC
, SetLastError
=true)]
1856 public static extern int setsid ();
1859 // pid_t getsid(pid_t pid);
1860 [DllImport (LIBC
, SetLastError
=true)]
1861 public static extern int getsid (int pid
);
1864 // uid_t getuid(void);
1865 [DllImport (LIBC
, SetLastError
=true)]
1866 public static extern uint getuid ();
1869 // uid_t geteuid(void);
1870 [DllImport (LIBC
, SetLastError
=true)]
1871 public static extern uint geteuid ();
1874 // gid_t getgid(void);
1875 [DllImport (LIBC
, SetLastError
=true)]
1876 public static extern uint getgid ();
1879 // gid_t getgid(void);
1880 [DllImport (LIBC
, SetLastError
=true)]
1881 public static extern uint getegid ();
1884 // int getgroups(int size, gid_t list[]);
1885 [DllImport (LIBC
, SetLastError
=true)]
1886 public static extern int getgroups (int size
, uint[] list
);
1888 public static int getgroups (uint[] list
)
1890 return getgroups (list
.Length
, list
);
1894 // int setuid(uid_t uid);
1895 [DllImport (LIBC
, SetLastError
=true)]
1896 public static extern int setuid (uint uid
);
1899 // int setreuid(uid_t ruid, uid_t euid);
1900 [DllImport (LIBC
, SetLastError
=true)]
1901 public static extern int setreuid (uint ruid
, uint euid
);
1904 // int setregid(gid_t ruid, gid_t euid);
1905 [DllImport (LIBC
, SetLastError
=true)]
1906 public static extern int setregid (uint rgid
, uint egid
);
1909 // int seteuid(uid_t euid);
1910 [DllImport (LIBC
, SetLastError
=true)]
1911 public static extern int seteuid (uint euid
);
1914 // int setegid(gid_t euid);
1915 [DllImport (LIBC
, SetLastError
=true)]
1916 public static extern int setegid (uint uid
);
1919 // int setgid(gid_t gid);
1920 [DllImport (LIBC
, SetLastError
=true)]
1921 public static extern int setgid (uint gid
);
1924 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
1925 [DllImport (LIBC
, SetLastError
=true)]
1926 public static extern int getresuid (out uint ruid
, out uint euid
, out uint suid
);
1929 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
1930 [DllImport (LIBC
, SetLastError
=true)]
1931 public static extern int getresgid (out uint rgid
, out uint egid
, out uint sgid
);
1934 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1935 [DllImport (LIBC
, SetLastError
=true)]
1936 public static extern int setresuid (uint ruid
, uint euid
, uint suid
);
1939 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
1940 [DllImport (LIBC
, SetLastError
=true)]
1941 public static extern int setresgid (uint rgid
, uint egid
, uint sgid
);
1944 // pid_t fork(void);
1945 [DllImport (LIBC
, SetLastError
=true)]
1946 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
1947 "shutdown code.\nUse System.Diagnostics.Process instead")]
1948 public static extern int fork ();
1951 // pid_t vfork(void);
1952 [DllImport (LIBC
, SetLastError
=true)]
1953 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
1954 "shutdown code.\nUse System.Diagnostics.Process instead")]
1955 public static extern int vfork ();
1957 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="ttyname")]
1958 [Obsolete ("Not re-entrant. Use ttyname_r instead.")]
1959 public static extern IntPtr
sys_ttyname (int fd
);
1961 [Obsolete ("Not re-entrant. Use ttyname_r instead.")]
1962 public static string ttyname (int fd
)
1964 IntPtr r
= sys_ttyname (fd
);
1965 return PosixMarshal
.PtrToString (r
);
1969 // int ttyname_r(int fd, char *buf, size_t buflen);
1970 [DllImport (MPH
, SetLastError
=true,
1971 EntryPoint
="Mono_Posix_Syscall_ttyname_r")]
1972 public static extern int ttyname_r (int fd
, [Out
] StringBuilder buf
, ulong buflen
);
1974 public static int ttyname_r (int fd
, StringBuilder buf
)
1976 return ttyname_r (fd
, buf
, (ulong) buf
.Capacity
);
1979 [DllImport (LIBC
, EntryPoint
="isatty")]
1980 private static extern int sys_isatty (int fd
);
1982 public static bool isatty (int fd
)
1984 return sys_isatty (fd
) == 1;
1987 [DllImport (LIBC
, SetLastError
=true)]
1988 public static extern int link (string oldpath
, string newpath
);
1990 [DllImport (LIBC
, SetLastError
=true)]
1991 public static extern int symlink (string oldpath
, string newpath
);
1994 // int readlink(const char *path, char *buf, size_t bufsize);
1995 [DllImport (MPH
, SetLastError
=true,
1996 EntryPoint
="Mono_Posix_Syscall_readlink")]
1997 public static extern int readlink (string path
, [Out
] StringBuilder buf
, ulong bufsiz
);
1999 public static int readlink (string path
, [Out
] StringBuilder buf
)
2001 return readlink (path
, buf
, (ulong) buf
.Capacity
);
2004 [DllImport (LIBC
, SetLastError
=true)]
2005 public static extern int unlink (string pathname
);
2007 [DllImport (LIBC
, SetLastError
=true)]
2008 public static extern int rmdir (string pathname
);
2011 // pid_t tcgetpgrp(int fd);
2012 [DllImport (LIBC
, SetLastError
=true)]
2013 public static extern int tcgetpgrp (int fd
);
2016 // int tcsetpgrp(int fd, pid_t pgrp);
2017 [DllImport (LIBC
, SetLastError
=true)]
2018 public static extern int tcsetpgrp (int fd
, int pgrp
);
2020 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="getlogin")]
2021 [Obsolete ("Not re-entrant. Use getlogin_r instead.")]
2022 public static extern IntPtr
sys_getlogin ();
2024 [Obsolete ("Not re-entrant. Use getlogin_r instead.")]
2025 public static string getlogin ()
2027 IntPtr r
= sys_getlogin ();
2028 return PosixMarshal
.PtrToString (r
);
2032 // int getlogin_r(char *buf, size_t bufsize);
2033 [DllImport (MPH
, SetLastError
=true,
2034 EntryPoint
="Mono_Posix_Syscall_getlogin_r")]
2035 public static extern int getlogin_r ([Out
] StringBuilder name
, ulong bufsize
);
2037 public static int getlogin_r (StringBuilder name
)
2039 return getlogin_r (name
, (ulong) name
.Capacity
);
2043 // int gethostname(char *name, size_t len);
2044 [DllImport (MPH
, SetLastError
=true,
2045 EntryPoint
="Mono_Posix_Syscall_gethostname")]
2046 public static extern int gethostname ([Out
] StringBuilder name
, ulong len
);
2048 public static int gethostname (StringBuilder name
)
2050 return gethostname (name
, (ulong) name
.Capacity
);
2054 // int gethostname(const char *name, size_t len);
2055 [DllImport (MPH
, SetLastError
=true,
2056 EntryPoint
="Mono_Posix_Syscall_gethostname")]
2057 public static extern int sethostname (string name
, ulong len
);
2059 public static int sethostname (string name
)
2061 return sethostname (name
, (ulong) name
.Length
);
2064 [DllImport (MPH
, SetLastError
=true,
2065 EntryPoint
="Mono_Posix_Syscall_gethostid")]
2066 public static extern long gethostid ();
2068 [DllImport (MPH
, SetLastError
=true,
2069 EntryPoint
="Mono_Posix_Syscall_sethostid")]
2070 public static extern int sethostid (long hostid
);
2073 // int getdomainname(char *name, size_t len);
2074 [DllImport (MPH
, SetLastError
=true,
2075 EntryPoint
="Mono_Posix_Syscall_getdomainname")]
2076 public static extern int getdomainname ([Out
] StringBuilder name
, ulong len
);
2078 public static int getdomainname (StringBuilder name
)
2080 return getdomainname (name
, (ulong) name
.Capacity
);
2084 // int setdomainname(const char *name, size_t len);
2085 [DllImport (MPH
, SetLastError
=true,
2086 EntryPoint
="Mono_Posix_Syscall_setdomainname")]
2087 public static extern int setdomainname (string name
, ulong len
);
2089 public static int setdomainname (string name
)
2091 return setdomainname (name
, (ulong) name
.Length
);
2094 [DllImport (LIBC
, SetLastError
=true)]
2095 public static extern int vhangup ();
2097 // Revoke doesn't appear to be POSIX. Include it?
2098 [DllImport (LIBC
, SetLastError
=true)]
2099 public static extern int revoke (string file
);
2101 // TODO: profil? It's not POSIX.
2103 [DllImport (LIBC
, SetLastError
=true)]
2104 public static extern int acct (string filename
);
2106 [DllImport (LIBC
, SetLastError
=true, EntryPoint
="getusershell")]
2107 public static extern IntPtr
sys_getusershell ();
2109 public static string getusershell ()
2111 IntPtr r
= sys_getusershell ();
2112 return PosixMarshal
.PtrToString (r
);
2115 [DllImport (LIBC
, SetLastError
=true)]
2116 public static extern void setusershell ();
2118 [DllImport (LIBC
, SetLastError
=true)]
2119 public static extern void endusershell ();
2121 [DllImport (LIBC
, SetLastError
=true)]
2122 private static extern int daemon (int nochdir
, int noclose
);
2124 public static int daemon (bool nochdir
, bool noclose
)
2126 return daemon (nochdir
? 1 : 0, noclose
? 1 : 0);
2129 [DllImport (LIBC
, SetLastError
=true)]
2130 public static extern int chroot (string path
);
2132 // skipping getpass(3) as the man page states:
2133 // This function is obsolete. Do not use it.
2135 [DllImport (LIBC
, SetLastError
=true)]
2136 public static extern int fsync (int fd
);
2138 [DllImport (LIBC
, SetLastError
=true)]
2139 public static extern int fdatasync (int fd
);
2141 [DllImport (LIBC
, SetLastError
=true)]
2142 public static extern void sync ();
2144 [DllImport (LIBC
, SetLastError
=true)]
2145 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
2146 "Use Unistd.sysconf (SysConf._SC_PAGESIZE).")]
2147 public static extern int getpagesize ();
2150 // int truncate(const char *path, off_t length);
2151 [DllImport (MPH
, SetLastError
=true,
2152 EntryPoint
="Mono_Posix_Syscall_truncate")]
2153 public static extern int truncate (string path
, long length
);
2156 // int ftruncate(int fd, off_t length);
2157 [DllImport (MPH
, SetLastError
=true,
2158 EntryPoint
="Mono_Posix_Syscall_ftruncate")]
2159 public static extern int ftruncate (int fd
, long length
);
2161 [DllImport (LIBC
, SetLastError
=true)]
2162 public static extern int getdtablesize ();
2164 [DllImport (LIBC
, SetLastError
=true)]
2165 public static extern int brk (IntPtr end_data_segment
);
2167 [DllImport (LIBC
, SetLastError
=true)]
2168 public static extern IntPtr
sbrk (IntPtr increment
);
2170 // TODO: syscall(2)?
2171 // Probably safer to skip entirely.
2174 // int lockf(int fd, int cmd, off_t len);
2175 [DllImport (MPH
, SetLastError
=true,
2176 EntryPoint
="Mono_Posix_Syscall_lockf")]
2177 public static extern int lockf (int fd
, LockFlags cmd
, long len
);
2179 [DllImport (CRYPT
, SetLastError
=true, EntryPoint
=CRYPT
)]
2180 public static extern IntPtr
sys_crypt (string key
, string salt
);
2182 public static string crypt (string key
, string salt
)
2184 IntPtr r
= sys_crypt (key
, salt
);
2185 return PosixMarshal
.PtrToString (r
);
2188 [DllImport (CRYPT
, SetLastError
=true, EntryPoint
="encrypt")]
2189 private static extern void sys_encrypt ([In
, Out
] byte[] block
, int edflag
);
2191 public static void encrypt (byte[] block
, bool decode
)
2193 if (block
.Length
< 64)
2194 throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
2195 sys_encrypt (block
, decode
? 1 : 0);
2199 // void swab(const void *from, void *to, ssize_t n);
2200 [DllImport (MPH
, SetLastError
=true,
2201 EntryPoint
="Mono_Posix_Syscall_swab")]
2202 public static extern void swab (IntPtr
from, IntPtr to
, long n
);
2204 public static unsafe void swab (void* from, void* to
, long n
)
2206 swab ((IntPtr
) from, (IntPtr
) to
, n
);