Use %SYS-GETUID in %EXPAND-USER-DIRECTORY.
[iolib.git] / syscalls / ffi-types-unix.lisp
blob54180a4eae4f5581a46e234c6464ad94f8a08c98
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- Grovel definitions for *NIX systems.
4 ;;;
6 #+linux
7 (define "_GNU_SOURCE")
9 ;;; largefile support on linux
10 ;;; TODO: check if these flags are required on solaris too
11 #+linux
12 (progn
13 (define "_LARGEFILE_SOURCE")
14 (define "_LARGEFILE64_SOURCE")
15 (define "_FILE_OFFSET_BITS" 64))
17 (include "stdlib.h" "errno.h" "sys/types.h" "sys/stat.h" "sys/mman.h"
18 "fcntl.h" "signal.h" "unistd.h" "limits.h" "time.h" "sys/select.h"
19 "sys/poll.h" "sys/ioctl.h" "sys/resource.h")
21 (in-package :iolib.syscalls)
23 (ctype size-t "size_t")
24 (ctype ssize-t "ssize_t")
25 (ctype pid-t "pid_t")
26 (ctype uid-t "uid_t")
27 (ctype gid-t "gid_t")
28 (ctype off-t "off_t")
29 (ctype mode-t "mode_t")
31 (constantenum (errno-values :define-constants t)
32 ((:eperm "EPERM"))
33 ((:enoent "ENOENT"))
34 ((:esrch "ESRCH"))
35 ((:eintr "EINTR"))
36 ((:eio "EIO"))
37 ((:enxio "ENXIO"))
38 ((:e2big "E2BIG"))
39 ((:enoexec "ENOEXEC"))
40 ((:ebadf "EBADF"))
41 ((:echild "ECHILD"))
42 ((:eagain "EAGAIN"))
43 ((:enomem "ENOMEM"))
44 ((:eacces "EACCES"))
45 ((:efault "EFAULT"))
46 ((:ebusy "EBUSY"))
47 ((:eexist "EEXIST"))
48 ((:exdev "EXDEV"))
49 ((:enodev "ENODEV"))
50 ((:enotdir "ENOTDIR"))
51 ((:eisdir "EISDIR"))
52 ((:einval "EINVAL"))
53 ((:enfile "ENFILE"))
54 ((:emfile "EMFILE"))
55 ((:enotty "ENOTTY"))
56 ((:efbig "EFBIG"))
57 ((:enospc "ENOSPC"))
58 ((:espipe "ESPIPE"))
59 ((:erofs "EROFS"))
60 ((:emlink "EMLINK"))
61 ((:epipe "EPIPE"))
62 ((:edom "EDOM"))
63 ((:erange "ERANGE"))
64 ((:edeadlk "EDEADLK"))
65 ((:enametoolong "ENAMETOOLONG"))
66 ((:enolck "ENOLCK"))
67 ((:enosys "ENOSYS"))
68 ((:enotempty "ENOTEMPTY"))
69 ((:echrng "ECHRNG") :optional t)
70 ((:el2nsync "EL2NSYNC") :optional t)
71 ((:el3hlt "EL3HLT") :optional t)
72 ((:el3rst "EL3RST") :optional t)
73 ((:elnrng "ELNRNG") :optional t)
74 ((:eunatch "EUNATCH") :optional t)
75 ((:enocsi "ENOCSI") :optional t)
76 ((:el2hlt "EL2HLT") :optional t)
77 ((:ebade "EBADE") :optional t)
78 ((:ebadr "EBADR") :optional t)
79 ((:exfull "EXFULL") :optional t)
80 ((:enoano "ENOANO") :optional t)
81 ((:ebadrqc "EBADRQC") :optional t)
82 ((:ebadslt "EBADSLT") :optional t)
83 ((:edeadlock "EDEADLOCK") :optional t)
84 ((:ebfont "EBFONT") :optional t)
85 ((:enostr "ENOSTR") :optional t)
86 ((:enodata "ENODATA") :optional t)
87 ((:etime "ETIME") :optional t)
88 ((:enosr "ENOSR") :optional t)
89 ((:enopkg "ENOPKG") :optional t)
90 ((:eadv "EADV") :optional t)
91 ((:esrmnt "ESRMNT") :optional t)
92 ((:ecomm "ECOMM") :optional t)
93 ((:edotdot "EDOTDOT") :optional t)
94 ((:enotuniq "ENOTUNIQ") :optional t)
95 ((:ebadfd "EBADFD") :optional t)
96 ((:eremchg "EREMCHG") :optional t)
97 ((:elibacc "ELIBACC") :optional t)
98 ((:elibbad "ELIBBAD") :optional t)
99 ((:elibscn "ELIBSCN") :optional t)
100 ((:elibmax "ELIBMAX") :optional t)
101 ((:elibexec "ELIBEXEC") :optional t)
102 ((:eilseq "EILSEQ"))
103 ((:erestart "ERESTART") :optional t)
104 ((:estrpipe "ESTRPIPE") :optional t)
105 ((:euclean "EUCLEAN") :optional t)
106 ((:enotnam "ENOTNAM") :optional t)
107 ((:enavail "ENAVAIL") :optional t)
108 ((:eremoteio "EREMOTEIO") :optional t)
109 ((:enomedium "ENOMEDIUM") :optional t)
110 ((:emediumtype "EMEDIUMTYPE") :optional t)
111 ((:estale "ESTALE"))
112 ((:enotblk "ENOTBLK"))
113 ((:etxtbsy "ETXTBSY"))
114 ((:eusers "EUSERS"))
115 ((:eloop "ELOOP"))
116 ((:ewouldblock "EWOULDBLOCK"))
117 ((:enomsg "ENOMSG"))
118 ((:eidrm "EIDRM"))
119 ((:eproto "EPROTO"))
120 ((:emultihop "EMULTIHOP"))
121 ((:ebadmsg "EBADMSG"))
122 ((:eoverflow "EOVERFLOW"))
123 ((:edquot "EDQUOT"))
124 ((:einprogress "EINPROGRESS"))
125 ((:ealready "EALREADY"))
126 ;; TODO: These errors are related to sockets. However they
127 ;; might not be unique to them. Remove those that are unique
128 ;; and keep those that might be set elsewhere.
129 ((:eprotonosupport "EPROTONOSUPPORT"))
130 ((:esocktnosupport "ESOCKTNOSUPPORT"))
131 ((:enotsock "ENOTSOCK"))
132 ((:edestaddrreq "EDESTADDRREQ"))
133 ((:emsgsize "EMSGSIZE"))
134 ((:eprototype "EPROTOTYPE"))
135 ((:enoprotoopt "ENOPROTOOPT"))
136 ((:eremote "EREMOTE"))
137 ((:enolink "ENOLINK"))
138 ((:epfnosupport "EPFNOSUPPORT"))
139 ((:eafnosupport "EAFNOSUPPORT"))
140 ((:eaddrinuse "EADDRINUSE"))
141 ((:eaddrnotavail "EADDRNOTAVAIL"))
142 ((:enetdown "ENETDOWN"))
143 ((:enetunreach "ENETUNREACH"))
144 ((:enetreset "ENETRESET"))
145 ((:econnaborted "ECONNABORTED"))
146 ((:econnreset "ECONNRESET"))
147 ((:eisconn "EISCONN"))
148 ((:enotconn "ENOTCONN"))
149 ((:eshutdown "ESHUTDOWN"))
150 ((:etoomanyrefs "ETOOMANYREFS"))
151 ((:etimedout "ETIMEDOUT"))
152 ((:econnrefused "ECONNREFUSED"))
153 ((:ehostdown "EHOSTDOWN"))
154 ((:ehostunreach "EHOSTUNREACH"))
155 ((:enonet "ENONET") :optional t)
156 ((:enobufs "ENOBUFS"))
157 ((:eopnotsupp "EOPNOTSUPP")))
159 ;;; open()
160 (constant (o-rdonly "O_RDONLY"))
161 (constant (o-wronly "O_WRONLY"))
162 (constant (o-rdwr "O_RDWR"))
163 (constant (o-creat "O_CREAT"))
164 (constant (o-excl "O_EXCL"))
165 (constant (o-trunc "O_TRUNC"))
166 (constant (o-append "O_APPEND"))
168 (constant (o-noctty "O_NOCTTY"))
169 (constant (o-nonblock "O_NONBLOCK"))
170 (constant (o-ndelay "O_NDELAY"))
171 (constant (o-sync "O_SYNC"))
172 (constant (o-nofollow "O_NOFOLLOW"))
173 (constant (o-async "O_ASYNC"))
175 ;;; lseek()
176 (constant (seek-set "SEEK_SET"))
177 (constant (seek-cur "SEEK_CUR"))
178 (constant (seek-end "SEEK_END"))
180 ;;; access()
181 (constant (r-ok "R_OK"))
182 (constant (w-ok "W_OK"))
183 (constant (x-ok "X_OK"))
184 (constant (f-ok "F_OK"))
186 ;;;; stat()
188 (constant (s-irwxu "S_IRWXU")
189 :documentation "read, write, execute/search by owner")
190 (constant (s-irusr "S_IRUSR") :documentation "read permission, owner")
191 (constant (s-iwusr "S_IWUSR") :documentation "write permission, owner")
192 (constant (s-ixusr "S_IXUSR") :documentation "execute/search permission, owner")
193 (constant (s-ifmt "S_IFMT") :documentation "bitmask for type of entry")
194 (constant (s-ififo "S_IFIFO") :documentation "named pipe, aka fifo")
195 (constant (s-ifchr "S_IFCHR") :documentation "special character-device")
196 (constant (s-ifdir "S_IFDIR") :documentation "directory")
197 (constant (s-ifblk "S_IFBLK") :documentation "special block-device")
198 (constant (s-ifreg "S_IFREG") :documentation "regular file")
199 (constant (s-ifwht "S_IFWHT") :documentation "whiteout" :optional t)
200 (constant (s-iread "S_IREAD"))
201 (constant (s-iwrite "S_IWRITE"))
202 (constant (s-iexec "S_IEXEC"))
204 (constant (s-irwxg "S_IRWXG")
205 :documentation "read, write, execute/search by group")
206 (constant (s-irgrp "S_IRGRP") :documentation "read permission, group")
207 (constant (s-iwgrp "S_IWGRP") :documentation "write permission, group")
208 (constant (s-ixgrp "S_IXGRP")
209 :documentation "execute/search permission, group")
210 (constant (s-irwxo "S_IRWXO")
211 :documentation "read, write, execute/search by others")
212 (constant (s-iroth "S_IROTH") :documentation "read permission, others")
213 (constant (s-iwoth "S_IWOTH") :documentation "write permission, others")
214 (constant (s-ixoth "S_IXOTH")
215 :documentation "execute/search permission, others")
216 (constant (s-isuid "S_ISUID") :documentation "set-user-ID on execution")
217 (constant (s-isgid "S_ISGID") :documentation "set-group-ID on execution")
218 (constant (s-isvtx "S_ISVTX")
219 :documentation "'sticky' bit, many meanings, nonportable")
220 (constant (s-iflnk "S_IFLNK") :documentation "symbolic link")
221 (constant (s-ifsock "S_IFSOCK") :documentation "socket")
223 (constant (path-max "PATH_MAX" "MAXPATHLEN"))
225 ;;;; from unistd.h
227 (ctype useconds-t "useconds_t")
229 ;;;; from time.h
231 (ctype time-t "time_t")
232 (ctype suseconds-t "suseconds_t")
234 #-darwin
235 (progn
236 (ctype clockid-t "clockid_t")
237 (constant (clock-monotonic "CLOCK_MONOTONIC"))
238 (constant (clock-realtime "CLOCK_REALTIME")))
240 (cstruct timespec "struct timespec"
241 "UNIX time specification in seconds and nanoseconds."
242 (sec "tv_sec" :type time-t)
243 (nsec "tv_nsec" :type :long))
245 ;;;; from sys/select.h
247 (cstruct timeval "struct timeval"
248 "UNIX time specification in seconds and microseconds."
249 (sec "tv_sec" :type time-t)
250 (usec "tv_usec" :type suseconds-t))
252 ;;;; from sys/stat.h
254 (ctype dev-t "dev_t")
255 (ctype ino-t "ino_t")
257 (ctype nlink-t "nlink_t")
258 (ctype blksize-t "blksize_t")
259 (ctype blkcnt-t "blkcnt_t")
261 (cstruct stat "struct stat"
262 (dev "st_dev" :type #-mips dev-t #+mips :unsigned-long)
263 (ino "st_ino" :type ino-t)
264 (mode "st_mode" :type mode-t)
265 (nlink "st_nlink" :type nlink-t)
266 (uid "st_uid" :type uid-t)
267 (gid "st_gid" :type gid-t)
268 (rdev "st_rdev" :type #-mips dev-t #+mips :unsigned-long)
269 (size "st_size" :type off-t)
270 (blksize "st_blksize" :type blkcnt-t)
271 (blocks "st_blocks" :type blksize-t)
272 (atime "st_atime" :type time-t)
273 (mtime "st_mtime" :type time-t)
274 (ctime "st_ctime" :type time-t))
276 ;;; mmap()
277 (constant (prot-none "PROT_NONE") :documentation "mmap: no protection")
278 (constant (prot-read "PROT_READ") :documentation "mmap: read protection")
279 (constant (prot-write "PROT_WRITE") :documentation "mmap: write protection")
280 (constant (prot-exec "PROT_EXEC") :documentation "mmap: execute protection")
281 (constant (map-shared "MAP_SHARED") :documentation "mmap: shared memory")
282 (constant (map-private "MAP_PRIVATE") :documentation "mmap: private mapping")
283 (constant (map-fixed "MAP_FIXED") :documentation "mmap: map at location")
284 (constant (map-failed "MAP_FAILED") :documentation "mmap: failure")
286 ;;; poll()
288 (ctype nfds-t "nfds_t")
290 (cstruct pollfd "struct pollfd"
291 "Poll file descriptor activity specification structure."
292 (fd "fd" :type :int)
293 (events "events" :type :short)
294 (revents "revents" :type :short))
296 (constant (pollin "POLLIN"))
297 (constant (pollrdnorm "POLLRDNORM"))
298 (constant (pollrdband "POLLRDBAND"))
299 (constant (pollpri "POLLPRI"))
300 (constant (pollout "POLLOUT"))
301 (constant (pollwrnorm "POLLWRNORM"))
302 (constant (pollwrband "POLLWRBAND"))
303 (constant (pollerr "POLLERR"))
304 #-darwin (constant (pollrdhup "POLLRDHUP"))
305 (constant (pollhup "POLLHUP"))
306 (constant (pollnval "POLLNVAL"))
308 ;;; ioctl()
310 (constant (fionbio "FIONBIO"))
311 (constant (fionread "FIONREAD"))
313 ;;;; from sys/resource.h
315 (ctype rlim-t "rlim_t")
316 (ctype id-t "id_t")
318 (cstruct rlimit "struct rlimit"
319 (cur "rlim_cur" :type rlim-t)
320 (max "rlim_max" :type rlim-t))
322 (cstruct rusage "struct rusage"
323 (utime "ru_utime" :type timeval)
324 (stime "ru_stime" :type timeval)
325 (maxrss "ru_maxrss" :type :long)
326 (ixrss "ru_ixrss" :type :long)
327 (idrss "ru_idrss" :type :long)
328 (isrss "ru_isrss" :type :long)
329 (minflt "ru_minflt" :type :long)
330 (majflt "ru_majflt" :type :long)
331 (nswap "ru_nswap" :type :long)
332 (inblock "ru_inblock" :type :long)
333 (oublock "ru_oublock" :type :long)
334 (msgsnd "ru_msgsnd" :type :long)
335 (msgrcv "ru_msgrcv" :type :long)
336 (nsignals "ru_nsignals" :type :long)
337 (nvcsw "ru_nvcsw" :type :long)
338 (nivcsw "ru_nivcsw" :type :long))
340 (constant (prio-process "PRIO_PROCESS"))
341 (constant (prio-pgrp "PRIO_PGRP"))
342 (constant (prio-user "PRIO_USER"))
343 (constant (rlim-infinity "RLIM_INFINITY"))
344 (constant (rusage-self "RUSAGE_SELF"))
345 (constant (rusage-children "RUSAGE_CHILDREN"))
346 (constant (rlimit-as "RLIMIT_AS"))
347 (constant (rlimit-core "RLIMIT_CORE"))
348 (constant (rlimit-cpu "RLIMIT_CPU"))
349 (constant (rlimit-data "RLIMIT_DATA"))
350 (constant (rlimit-fsize "RLIMIT_FSIZE"))
351 (constant (rlimit-memlock "RLIMIT_MEMLOCK"))
352 (constant (rlimit-nofile "RLIMIT_NOFILE"))
353 (constant (rlimit-nproc "RLIMIT_NPROC"))
354 (constant (rlimit-rss "RLIMIT_RSS"))
355 (constant (rlimit-stack "RLIMIT_STACK"))
357 #+linux
358 (progn
359 (constant (rlim-saved-max "RLIM_SAVED_MAX"))
360 (constant (rlim-saved-cur "RLIM_SAVED_CUR"))
361 (constant (rlimit-locks "RLIMIT_LOCKS"))
362 (constant (rlimit-msgqueue "RLIMIT_MSGQUEUE"))
363 (constant (rlimit-nlimits "RLIMIT_NLIMITS"))
364 (constant (rlimit-nice "RLIMIT_NICE"))
365 (constant (rlimit-rtprio "RLIMIT_RTPRIO"))
366 (constant (rlimit-sigpending "RLIMIT_SIGPENDING")))