3 (define-designator filename c-string
5 (sb-ext:native-namestring (translate-logical-pathname filename)))
8 (define-designator file-descriptor (integer 32)
9 (file-stream (sb-sys:fd-stream-fd file-descriptor))
10 (fixnum file-descriptor))
12 (define-designator sap-or-nil sb-sys:system-area-pointer
13 (null (sb-sys:int-sap 0))
14 (sb-sys:system-area-pointer sap-or-nil))
16 (define-designator alien-pointer-to-anything-or-nil (* t)
17 (null (sb-alien:sap-alien (sb-sys:int-sap 0) (* t)))
18 ((alien (* t)) alien-pointer-to-anything-or-nil))
20 (defun lisp-for-c-symbol (name)
23 (lisp-for-c-symbol (car name)))
25 (let ((root (if (eql #\_ (char name 0)) (subseq name 1) name)))
26 (intern (substitute #\- #\_ (string-upcase root)) :sb-posix)))))
28 (defun real-c-name (name)
31 (destructuring-bind (name &rest options) name
34 ((member :largefile options)
35 (format nil "~a_largefile" name))
41 (defmacro define-call-internally (lisp-name c-name return-type error-predicate
43 (if (sb-sys:find-foreign-symbol-address c-name)
45 (declaim (inline ,lisp-name))
46 (defun ,lisp-name ,(mapcar #'car arguments)
47 (let ((r (alien-funcall
50 (function ,return-type
61 `(,(intern (symbol-name (cadr x))
66 (if (,error-predicate r) (syscall-error) r))))
67 `(sb-int:style-warn "Didn't find definition for ~S" ,c-name)))
69 (defmacro define-call (name return-type error-predicate &rest arguments)
70 (let ((lisp-name (lisp-for-c-symbol name))
71 (real-c-name (real-c-name name)))
73 (export ',lisp-name :sb-posix)
74 (define-call-internally ,lisp-name
80 (defmacro define-entry-point (name arglist &body body)
81 (let ((lisp-name (lisp-for-c-symbol name)))
83 (export ',lisp-name :sb-posix)
84 (declaim (inline ,lisp-name))
85 (defun ,lisp-name ,arglist