Add INLINE declamations for foreign wrappers.
[iolib/alendvai.git] / syscalls / ffi-wrappers-unix.lisp
blob44c6f8ca29dde9c85638c072b35bb3db763a96e9
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- FFI wrappers.
4 ;;;
6 (in-package :iolib.syscalls)
8 (define "_XOPEN_SOURCE" 600)
9 (c "#if defined(__linux__)")
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 (declaim (inline %sys-lseek))
26 (defwrapper ("lseek" %sys-lseek)
27 ("off_t" (return-wrapper off-t :error-generator signal-posix-error))
28 (fildes :int)
29 (offset off-t)
30 (whence :int))
32 (declaim (inline %sys-truncate))
33 (defwrapper ("truncate" %sys-truncate)
34 ("int" (return-wrapper :int :error-generator signal-posix-error/restart))
35 (path ("const char*" filename-designator))
36 (length off-t))
38 (declaim (inline %sys-ftruncate))
39 (defwrapper ("ftruncate" %sys-ftruncate)
40 ("int" (return-wrapper :int :error-generator signal-posix-error/restart))
41 (fd :int)
42 (length off-t))
44 (declaim (inline %sys-mmap))
45 (defwrapper ("mmap" %sys-mmap)
46 ("void*" (return-wrapper :pointer :error-generator signal-posix-error))
47 (start :pointer)
48 (length size-t)
49 (prot :int)
50 (flags :int)
51 (fd :int)
52 (offset off-t))
54 (declaim (inline %%sys-stat))
55 (defwrapper ("stat" %%sys-stat)
56 ("int" (return-wrapper :int :error-generator signal-posix-error))
57 (file-name ("const char*" filename-designator))
58 (buf ("struct stat*" :pointer)))
60 (declaim (inline %%sys-fstat))
61 (defwrapper ("fstat" %%sys-fstat)
62 ("int" (return-wrapper :int :error-generator signal-posix-error))
63 (filedes :int)
64 (buf ("struct stat*" :pointer)))
66 (declaim (inline %%sys-lstat))
67 (defwrapper ("lstat" %%sys-lstat)
68 ("int" (return-wrapper :int :error-generator signal-posix-error))
69 (file-name ("const char*" filename-designator))
70 (buf ("struct stat*" :pointer)))
72 (declaim (inline %sys-pread))
73 (defwrapper ("pread" %sys-pread)
74 ("ssize_t" (return-wrapper ssize-t :error-generator signal-posix-error/restart))
75 (fd :int)
76 (buf :pointer)
77 (count size-t)
78 (offset off-t))
80 (declaim (inline %sys-pwrite))
81 (defwrapper ("pwrite" %sys-pwrite)
82 ("ssize_t" (return-wrapper ssize-t :error-generator signal-posix-error/restart))
83 (fd :int)
84 (buf :pointer)
85 (count size-t)
86 (offset off-t))
89 ;;;-----------------------------------------------------------------------------
90 ;;; ERRNO-related functions
91 ;;;-----------------------------------------------------------------------------
93 (declaim (inline %sys-errno))
94 (defwrapper* ("iolib_get_errno" %sys-errno) :int
96 "return errno;")
98 (declaim (inline %%sys-set-errno))
99 (defwrapper* ("iolib_set_errno" %%sys-set-errno) :int
100 ((value :int))
101 "errno = value;"
102 "return errno;")
104 (declaim (inline %sys-strerror-r))
105 (defwrapper ("strerror_r" %sys-strerror-r)
106 ("int" (return-wrapper :int :error-generator signal-posix-error))
107 (errnum :int)
108 (buf :string)
109 (buflen size-t))