Grovel RLIMIT_SBSIZE on FreeBSD.
[iolib.git] / syscalls / ffi-types-unix.lisp
blob32a97955a36bb25dfa3c789ff71d2b5a4e2c7120
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" "pwd.h" "grp.h"
20 "dirent.h")
22 (in-package :iolib.syscalls)
24 (ctype size-t "size_t")
25 (ctype ssize-t "ssize_t")
26 (ctype pid-t "pid_t")
27 (ctype uid-t "uid_t")
28 (ctype gid-t "gid_t")
29 (ctype off-t "off_t")
30 (ctype mode-t "mode_t")
32 (constantenum (errno-values :define-constants t)
33 ((:eperm "EPERM"))
34 ((:enoent "ENOENT"))
35 ((:esrch "ESRCH"))
36 ((:eintr "EINTR"))
37 ((:eio "EIO"))
38 ((:enxio "ENXIO"))
39 ((:e2big "E2BIG"))
40 ((:enoexec "ENOEXEC"))
41 ((:ebadf "EBADF"))
42 ((:echild "ECHILD"))
43 ((:eagain "EAGAIN"))
44 ((:enomem "ENOMEM"))
45 ((:eacces "EACCES"))
46 ((:efault "EFAULT"))
47 ((:ebusy "EBUSY"))
48 ((:eexist "EEXIST"))
49 ((:exdev "EXDEV"))
50 ((:enodev "ENODEV"))
51 ((:enotdir "ENOTDIR"))
52 ((:eisdir "EISDIR"))
53 ((:einval "EINVAL"))
54 ((:enfile "ENFILE"))
55 ((:emfile "EMFILE"))
56 ((:enotty "ENOTTY"))
57 ((:efbig "EFBIG"))
58 ((:enospc "ENOSPC"))
59 ((:espipe "ESPIPE"))
60 ((:erofs "EROFS"))
61 ((:emlink "EMLINK"))
62 ((:epipe "EPIPE"))
63 ((:edom "EDOM"))
64 ((:erange "ERANGE"))
65 ((:edeadlk "EDEADLK"))
66 ((:enametoolong "ENAMETOOLONG"))
67 ((:enolck "ENOLCK"))
68 ((:enosys "ENOSYS"))
69 ((:enotempty "ENOTEMPTY"))
70 ((:echrng "ECHRNG") :optional t)
71 ((:el2nsync "EL2NSYNC") :optional t)
72 ((:el3hlt "EL3HLT") :optional t)
73 ((:el3rst "EL3RST") :optional t)
74 ((:elnrng "ELNRNG") :optional t)
75 ((:eunatch "EUNATCH") :optional t)
76 ((:enocsi "ENOCSI") :optional t)
77 ((:el2hlt "EL2HLT") :optional t)
78 ((:ebade "EBADE") :optional t)
79 ((:ebadr "EBADR") :optional t)
80 ((:exfull "EXFULL") :optional t)
81 ((:enoano "ENOANO") :optional t)
82 ((:ebadrqc "EBADRQC") :optional t)
83 ((:ebadslt "EBADSLT") :optional t)
84 ((:edeadlock "EDEADLOCK") :optional t)
85 ((:ebfont "EBFONT") :optional t)
86 ((:enostr "ENOSTR") :optional t)
87 ((:enodata "ENODATA") :optional t)
88 ((:etime "ETIME") :optional t)
89 ((:enosr "ENOSR") :optional t)
90 ((:enopkg "ENOPKG") :optional t)
91 ((:eadv "EADV") :optional t)
92 ((:esrmnt "ESRMNT") :optional t)
93 ((:ecomm "ECOMM") :optional t)
94 ((:edotdot "EDOTDOT") :optional t)
95 ((:enotuniq "ENOTUNIQ") :optional t)
96 ((:ebadfd "EBADFD") :optional t)
97 ((:eremchg "EREMCHG") :optional t)
98 ((:elibacc "ELIBACC") :optional t)
99 ((:elibbad "ELIBBAD") :optional t)
100 ((:elibscn "ELIBSCN") :optional t)
101 ((:elibmax "ELIBMAX") :optional t)
102 ((:elibexec "ELIBEXEC") :optional t)
103 ((:eilseq "EILSEQ"))
104 ((:erestart "ERESTART") :optional t)
105 ((:estrpipe "ESTRPIPE") :optional t)
106 ((:euclean "EUCLEAN") :optional t)
107 ((:enotnam "ENOTNAM") :optional t)
108 ((:enavail "ENAVAIL") :optional t)
109 ((:eremoteio "EREMOTEIO") :optional t)
110 ((:enomedium "ENOMEDIUM") :optional t)
111 ((:emediumtype "EMEDIUMTYPE") :optional t)
112 ((:estale "ESTALE"))
113 ((:enotblk "ENOTBLK"))
114 ((:etxtbsy "ETXTBSY"))
115 ((:eusers "EUSERS"))
116 ((:eloop "ELOOP"))
117 ((:ewouldblock "EWOULDBLOCK"))
118 ((:enomsg "ENOMSG"))
119 ((:eidrm "EIDRM"))
120 ((:eproto "EPROTO"))
121 ((:emultihop "EMULTIHOP"))
122 ((:ebadmsg "EBADMSG"))
123 ((:eoverflow "EOVERFLOW"))
124 ((:edquot "EDQUOT"))
125 ((:einprogress "EINPROGRESS"))
126 ((:ealready "EALREADY"))
127 ;; TODO: These errors are related to sockets. However they
128 ;; might not be unique to them. Remove those that are unique
129 ;; and keep those that might be set elsewhere.
130 ((:eprotonosupport "EPROTONOSUPPORT"))
131 ((:esocktnosupport "ESOCKTNOSUPPORT"))
132 ((:enotsock "ENOTSOCK"))
133 ((:edestaddrreq "EDESTADDRREQ"))
134 ((:emsgsize "EMSGSIZE"))
135 ((:eprototype "EPROTOTYPE"))
136 ((:enoprotoopt "ENOPROTOOPT"))
137 ((:eremote "EREMOTE"))
138 ((:enolink "ENOLINK"))
139 ((:epfnosupport "EPFNOSUPPORT"))
140 ((:eafnosupport "EAFNOSUPPORT"))
141 ((:eaddrinuse "EADDRINUSE"))
142 ((:eaddrnotavail "EADDRNOTAVAIL"))
143 ((:enetdown "ENETDOWN"))
144 ((:enetunreach "ENETUNREACH"))
145 ((:enetreset "ENETRESET"))
146 ((:econnaborted "ECONNABORTED"))
147 ((:econnreset "ECONNRESET"))
148 ((:eisconn "EISCONN"))
149 ((:enotconn "ENOTCONN"))
150 ((:eshutdown "ESHUTDOWN"))
151 ((:etoomanyrefs "ETOOMANYREFS"))
152 ((:etimedout "ETIMEDOUT"))
153 ((:econnrefused "ECONNREFUSED"))
154 ((:ehostdown "EHOSTDOWN"))
155 ((:ehostunreach "EHOSTUNREACH"))
156 ((:enonet "ENONET") :optional t)
157 ((:enobufs "ENOBUFS"))
158 ((:eopnotsupp "EOPNOTSUPP")))
161 ;;; open()
163 (constant (o-rdonly "O_RDONLY"))
164 (constant (o-wronly "O_WRONLY"))
165 (constant (o-rdwr "O_RDWR"))
166 (constant (o-creat "O_CREAT"))
167 (constant (o-excl "O_EXCL"))
168 (constant (o-trunc "O_TRUNC"))
169 (constant (o-append "O_APPEND"))
171 (constant (o-noctty "O_NOCTTY"))
172 (constant (o-nonblock "O_NONBLOCK"))
173 (constant (o-ndelay "O_NDELAY"))
174 (constant (o-sync "O_SYNC"))
175 (constant (o-nofollow "O_NOFOLLOW"))
176 (constant (o-async "O_ASYNC"))
179 ;;; lseek()
181 (constant (seek-set "SEEK_SET"))
182 (constant (seek-cur "SEEK_CUR"))
183 (constant (seek-end "SEEK_END"))
186 ;;; access()
188 (constant (r-ok "R_OK"))
189 (constant (w-ok "W_OK"))
190 (constant (x-ok "X_OK"))
191 (constant (f-ok "F_OK"))
194 ;;;; stat()
196 (constant (s-irwxu "S_IRWXU")
197 :documentation "read, write, execute/search by owner")
198 (constant (s-irusr "S_IRUSR") :documentation "read permission, owner")
199 (constant (s-iwusr "S_IWUSR") :documentation "write permission, owner")
200 (constant (s-ixusr "S_IXUSR") :documentation "execute/search permission, owner")
201 (constant (s-ifmt "S_IFMT") :documentation "bitmask for type of entry")
202 (constant (s-ififo "S_IFIFO") :documentation "named pipe, aka fifo")
203 (constant (s-ifchr "S_IFCHR") :documentation "special character-device")
204 (constant (s-ifdir "S_IFDIR") :documentation "directory")
205 (constant (s-ifblk "S_IFBLK") :documentation "special block-device")
206 (constant (s-ifreg "S_IFREG") :documentation "regular file")
207 (constant (s-ifwht "S_IFWHT") :documentation "whiteout" :optional t)
208 (constant (s-iread "S_IREAD"))
209 (constant (s-iwrite "S_IWRITE"))
210 (constant (s-iexec "S_IEXEC"))
212 (constant (s-irwxg "S_IRWXG")
213 :documentation "read, write, execute/search by group")
214 (constant (s-irgrp "S_IRGRP") :documentation "read permission, group")
215 (constant (s-iwgrp "S_IWGRP") :documentation "write permission, group")
216 (constant (s-ixgrp "S_IXGRP")
217 :documentation "execute/search permission, group")
218 (constant (s-irwxo "S_IRWXO")
219 :documentation "read, write, execute/search by others")
220 (constant (s-iroth "S_IROTH") :documentation "read permission, others")
221 (constant (s-iwoth "S_IWOTH") :documentation "write permission, others")
222 (constant (s-ixoth "S_IXOTH")
223 :documentation "execute/search permission, others")
224 (constant (s-isuid "S_ISUID") :documentation "set-user-ID on execution")
225 (constant (s-isgid "S_ISGID") :documentation "set-group-ID on execution")
226 (constant (s-isvtx "S_ISVTX")
227 :documentation "'sticky' bit, many meanings, nonportable")
228 (constant (s-iflnk "S_IFLNK") :documentation "symbolic link")
229 (constant (s-ifsock "S_IFSOCK") :documentation "socket")
231 (constant (path-max "PATH_MAX" "MAXPATHLEN"))
234 ;;; from unistd.h
236 (ctype useconds-t "useconds_t")
239 ;;; from time.h
241 (ctype time-t "time_t")
242 (ctype suseconds-t "suseconds_t")
244 #-darwin
245 (progn
246 (ctype clockid-t "clockid_t")
247 (constant (clock-monotonic "CLOCK_MONOTONIC"))
248 (constant (clock-realtime "CLOCK_REALTIME")))
250 (cstruct timespec "struct timespec"
251 "UNIX time specification in seconds and nanoseconds."
252 (sec "tv_sec" :type time-t)
253 (nsec "tv_nsec" :type :long))
256 ;;; from sys/select.h
258 (cstruct timeval "struct timeval"
259 "UNIX time specification in seconds and microseconds."
260 (sec "tv_sec" :type time-t)
261 (usec "tv_usec" :type suseconds-t))
264 ;;; from sys/stat.h
266 (ctype dev-t "dev_t")
267 (ctype ino-t "ino_t")
269 (ctype nlink-t "nlink_t")
270 (ctype blksize-t "blksize_t")
271 (ctype blkcnt-t "blkcnt_t")
273 (cstruct stat "struct stat"
274 (dev "st_dev" :type #-mips dev-t #+mips :unsigned-long)
275 (ino "st_ino" :type ino-t)
276 (mode "st_mode" :type mode-t)
277 (nlink "st_nlink" :type nlink-t)
278 (uid "st_uid" :type uid-t)
279 (gid "st_gid" :type gid-t)
280 (rdev "st_rdev" :type #-mips dev-t #+mips :unsigned-long)
281 (size "st_size" :type off-t)
282 (blksize "st_blksize" :type blkcnt-t)
283 (blocks "st_blocks" :type blksize-t)
284 (atime "st_atime" :type time-t)
285 (mtime "st_mtime" :type time-t)
286 (ctime "st_ctime" :type time-t))
289 ;;; mmap()
291 (constant (prot-none "PROT_NONE") :documentation "mmap: no protection")
292 (constant (prot-read "PROT_READ") :documentation "mmap: read protection")
293 (constant (prot-write "PROT_WRITE") :documentation "mmap: write protection")
294 (constant (prot-exec "PROT_EXEC") :documentation "mmap: execute protection")
295 (constant (map-shared "MAP_SHARED") :documentation "mmap: shared memory")
296 (constant (map-private "MAP_PRIVATE") :documentation "mmap: private mapping")
297 (constant (map-fixed "MAP_FIXED") :documentation "mmap: map at location")
298 (constant (map-failed "MAP_FAILED") :documentation "mmap: failure")
301 ;;; poll()
303 (ctype nfds-t "nfds_t")
305 (cstruct pollfd "struct pollfd"
306 "Poll file descriptor activity specification structure."
307 (fd "fd" :type :int)
308 (events "events" :type :short)
309 (revents "revents" :type :short))
311 (constant (pollin "POLLIN"))
312 (constant (pollrdnorm "POLLRDNORM"))
313 (constant (pollrdband "POLLRDBAND"))
314 (constant (pollpri "POLLPRI"))
315 (constant (pollout "POLLOUT"))
316 (constant (pollwrnorm "POLLWRNORM"))
317 (constant (pollwrband "POLLWRBAND"))
318 (constant (pollerr "POLLERR"))
319 #+linux (constant (pollrdhup "POLLRDHUP"))
320 (constant (pollhup "POLLHUP"))
321 (constant (pollnval "POLLNVAL"))
324 ;;; from dirent.h
326 ;; Apparently POSIX 1003.1-2001 (according to linux manpages) only
327 ;; requires d_name. Sigh. I guess we should assemble some decent
328 ;; wrapper functions. No, struct members can't be optional at this
329 ;; point.
330 (cstruct dirent "struct dirent"
331 ;; POSIX actually requires this to be d_ino
332 (fileno "d_fileno" :type #-freebsd ino-t #+freebsd :uint32)
333 (type "d_type" :type :uint8)
334 (name "d_name" :type :uint8 :count :auto))
336 ;;; filetypes set in d_type slot of struct dirent
337 (constant (dt-unknown "DT_UNKNOWN"))
338 (constant (dt-fifo "DT_FIFO"))
339 (constant (dt-chr "DT_CHR"))
340 (constant (dt-dir "DT_DIR"))
341 (constant (dt-blk "DT_BLK"))
342 (constant (dt-reg "DT_REG"))
343 (constant (dt-lnk "DT_LNK"))
344 (constant (dt-sock "DT_SOCK"))
345 (constant (dt-wht "DT_WHT"))
348 ;;; ioctl()
350 (constant (fionbio "FIONBIO"))
351 (constant (fionread "FIONREAD"))
354 ;;; from sys/resource.h
356 (ctype rlim-t "rlim_t")
357 (ctype id-t "id_t")
359 (cstruct rlimit "struct rlimit"
360 (cur "rlim_cur" :type rlim-t)
361 (max "rlim_max" :type rlim-t))
363 (cstruct rusage "struct rusage"
364 (utime "ru_utime" :type timeval)
365 (stime "ru_stime" :type timeval)
366 (maxrss "ru_maxrss" :type :long)
367 (ixrss "ru_ixrss" :type :long)
368 (idrss "ru_idrss" :type :long)
369 (isrss "ru_isrss" :type :long)
370 (minflt "ru_minflt" :type :long)
371 (majflt "ru_majflt" :type :long)
372 (nswap "ru_nswap" :type :long)
373 (inblock "ru_inblock" :type :long)
374 (oublock "ru_oublock" :type :long)
375 (msgsnd "ru_msgsnd" :type :long)
376 (msgrcv "ru_msgrcv" :type :long)
377 (nsignals "ru_nsignals" :type :long)
378 (nvcsw "ru_nvcsw" :type :long)
379 (nivcsw "ru_nivcsw" :type :long))
381 (constant (prio-process "PRIO_PROCESS"))
382 (constant (prio-pgrp "PRIO_PGRP"))
383 (constant (prio-user "PRIO_USER"))
384 (constant (rlim-infinity "RLIM_INFINITY"))
385 (constant (rusage-self "RUSAGE_SELF"))
386 (constant (rusage-children "RUSAGE_CHILDREN"))
387 (constant (rlimit-as "RLIMIT_AS"))
388 (constant (rlimit-core "RLIMIT_CORE"))
389 (constant (rlimit-cpu "RLIMIT_CPU"))
390 (constant (rlimit-data "RLIMIT_DATA"))
391 (constant (rlimit-fsize "RLIMIT_FSIZE"))
392 (constant (rlimit-memlock "RLIMIT_MEMLOCK"))
393 (constant (rlimit-nofile "RLIMIT_NOFILE"))
394 (constant (rlimit-nproc "RLIMIT_NPROC"))
395 (constant (rlimit-rss "RLIMIT_RSS"))
396 (constant (rlimit-stack "RLIMIT_STACK"))
398 #+linux
399 (progn
400 (constant (rlim-saved-max "RLIM_SAVED_MAX"))
401 (constant (rlim-saved-cur "RLIM_SAVED_CUR"))
402 (constant (rlimit-locks "RLIMIT_LOCKS"))
403 (constant (rlimit-msgqueue "RLIMIT_MSGQUEUE"))
404 (constant (rlimit-nlimits "RLIMIT_NLIMITS"))
405 (constant (rlimit-nice "RLIMIT_NICE"))
406 (constant (rlimit-rtprio "RLIMIT_RTPRIO"))
407 (constant (rlimit-sigpending "RLIMIT_SIGPENDING")))
409 #+freebsd
410 (constant (rlimit-sbsize "RLIMIT_SBSIZE"))
413 ;;; from pwd.h
415 (cstruct passwd-entry "struct passwd"
416 (name "pw_name" :type :string)
417 (passwd "pw_passwd" :type :string)
418 (uid "pw_uid" :type uid-t)
419 (gid "pw_gid" :type gid-t)
420 (gecos "pw_gecos" :type :string)
421 (dir "pw_dir" :type :string)
422 (shell "pw_shell" :type :string))
425 ;;; from grp.h
427 (cstruct group-entry "struct group"
428 (name "gr_name" :type :string)
429 (passwd "gr_passwd" :type :string)
430 (gid "gr_gid" :type gid-t)
431 (mem "gr_mem" :type :pointer))