Add IOLIB.SYSCALLS package.
[iolib/alendvai.git] / syscalls / ffi-wrappers-unix.lisp
blob9abf82e97109301caff27cd46bb34278c6ce91e1
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- FFI wrappers.
4 ;;;
6 (in-package :iolib.syscalls)
8 (c "#if defined(__linux__)")
9 (define "_XOPEN_SOURCE" 600)
10 (define "_LARGEFILE_SOURCE")
11 (define "_LARGEFILE64_SOURCE")
12 (define "_FILE_OFFSET_BITS" 64)
13 (c "#endif")
15 (include "string.h" "errno.h" "sys/types.h" "sys/stat.h"
16 "unistd.h" "sys/mman.h")
19 ;;;-----------------------------------------------------------------------------
20 ;;; Large-file support
21 ;;;-----------------------------------------------------------------------------
23 ;;; FIXME: this is only necessary on Linux right?
25 (defwrapper ("lseek" %sys-lseek)
26 ("off_t" off-t)
27 (fildes ("int" :int))
28 (offset ("off_t" off-t))
29 (whence :int))
31 (defwrapper ("truncate" %sys-truncate)
32 ("int" (return-wrapper :int :error-generator return-posix-error/restart))
33 (path ("const char*" filename-designator))
34 (length ("off_t" off-t)))
36 (defwrapper ("ftruncate" %sys-ftruncate)
37 ("int" (return-wrapper :int :error-generator return-posix-error/restart))
38 (fd ("int" :int))
39 (length ("off_t" off-t)))
41 (defwrapper ("mmap" %sys-mmap)
42 ("void*" :pointer)
43 (start :pointer)
44 (length ("size_t" size-t))
45 (prot :int)
46 (flags :int)
47 (fd ("int" :int))
48 (offset ("off_t" off-t)))
50 (defwrapper ("stat" %%sys-stat)
51 ("int" :int)
52 (file-name ("const char*" filename-designator))
53 (buf ("struct stat*" :pointer)))
55 (defwrapper ("fstat" %%sys-fstat)
56 ("int" :int)
57 (filedes ("int" :int))
58 (buf ("struct stat*" :pointer)))
60 (defwrapper ("lstat" %%sys-lstat)
61 ("int" :int)
62 (file-name ("const char*" filename-designator))
63 (buf ("struct stat*" :pointer)))
65 (defwrapper ("pread" %sys-pread)
66 ("ssize_t" (return-wrapper ssize-t :error-generator return-posix-error/restart))
67 (fd ("int" :int))
68 (buf :pointer)
69 (count ("size_t" size-t))
70 (offset ("off_t" off-t)))
72 (defwrapper ("pwrite" %sys-pwrite)
73 ("ssize_t" (return-wrapper ssize-t :error-generator return-posix-error/restart))
74 (fd ("int" :int))
75 (buf :pointer)
76 (count ("size_t" size-t))
77 (offset ("off_t" off-t)))
80 ;;;-----------------------------------------------------------------------------
81 ;;; ERRNO-related functions
82 ;;;-----------------------------------------------------------------------------
84 (defwrapper* "get_errno" :int ()
85 "return errno;")
87 (defwrapper* "set_errno" :int ((value :int))
88 "errno = value;"
89 "return errno;")
91 (defwrapper ("strerror_r" %sys-strerror-r)
92 :int
93 (errnum :int)
94 (buf :string)
95 (buflen ("size_t" size-t)))