1 (in-package :sb-posix-internal)
3 ;;; some explanation may be necessary. The namestring "[foo]"
4 ;;; denotes a wild pathname. When there's a file on the disk whose
5 ;;; Unix name is "[foo]", the appropriate CL namestring for it is
6 ;;; "\\[foo]". So, don't call NAMESTRING, instead call a function
7 ;;; that gets us the Unix name
8 (defun native-filename (pathname)
9 (let ((directory (pathname-directory pathname))
10 (name (pathname-name pathname))
11 (type (pathname-type pathname)))
12 (with-output-to-string (s nil :element-type 'base-char)
14 (string (write-string directory s))
16 (when (eq (car directory) :absolute)
18 (dolist (piece (cdr directory))
20 (string (write-string piece s) (write-char #\/ s))
21 ((member :up) (write-string "../" s))))))
24 (string (write-string name s)))
27 (string (write-char #\. s) (write-string type s))))))
29 (define-designator filename c-string
31 (native-filename (translate-logical-pathname filename)))
34 (define-designator file-descriptor (integer 32)
35 (file-stream (sb-sys:fd-stream-fd file-descriptor))
36 (fixnum file-descriptor))
38 (define-designator sap-or-nil sb-sys:system-area-pointer
39 (null (sb-sys:int-sap 0))
40 (sb-sys:system-area-pointer sap-or-nil))
42 (define-designator alien-pointer-to-anything-or-nil (* t)
43 (null (sb-alien:sap-alien (sb-sys:int-sap 0) (* t)))
44 ((alien (* t)) alien-pointer-to-anything-or-nil))
46 (defun lisp-for-c-symbol (s)
47 (intern (substitute #\- #\_ (string-upcase s)) :sb-posix))
49 (defmacro define-call-internally (lisp-name c-name return-type error-predicate &rest arguments)
50 (if (sb-fasl::foreign-symbol-address-as-integer-or-nil
51 (sb-vm:extern-alien-name c-name))
53 (declaim (inline ,lisp-name))
54 (defun ,lisp-name ,(mapcar #'car arguments)
55 (let ((r (alien-funcall
58 (function ,return-type
61 (gethash (cadr x) *designator-types* (cadr x)))
64 (if (nth-value 1 (gethash (cadr x) *designator-types*))
65 `(,(intern (symbol-name (cadr x)) :sb-posix)
69 (if (,error-predicate r) (syscall-error) r))))
70 `(sb-int:style-warn "Didn't find definition for ~S" ,c-name)))
72 (defmacro define-call (name return-type error-predicate &rest arguments)
73 (let ((lisp-name (lisp-for-c-symbol name)))
75 (export ',lisp-name :sb-posix)
76 (define-call-internally ,lisp-name ,name ,return-type ,error-predicate ,@arguments))))
78 (defmacro define-entry-point (name arglist &body body)
79 (let ((lisp-name (lisp-for-c-symbol name)))
81 (export ',lisp-name :sb-posix)
82 (declaim (inline ,lisp-name))
83 (defun ,lisp-name ,arglist