+;;; shared C-struct-to-multiple-VALUES conversion for the stat(2)
+;;; family of Unix system calls
+;;;
+;;; FIXME: I think this should probably not be INLINE. However, when
+;;; this was not inline, it seemed to cause memory corruption
+;;; problems. My first guess is that it's a bug in the FFI code, where
+;;; the WITH-ALIEN expansion doesn't deal well with being wrapped
+;;; around a call to a function returning >10 values. But I didn't try
+;;; to figure it out, just inlined it as a quick fix. Perhaps someone
+;;; who's motivated to debug the FFI code can go over the DISASSEMBLE
+;;; output in the not-inlined case and see whether there's a problem,
+;;; and maybe even find a fix..
+(declaim (inline %extract-stat-results))
+(defun %extract-stat-results (wrapped-stat)
+ (declare (type (alien (* (struct wrapped_stat))) wrapped-stat))
+ (values t
+ (slot wrapped-stat 'st-dev)
+ (slot wrapped-stat 'st-ino)
+ (slot wrapped-stat 'st-mode)
+ (slot wrapped-stat 'st-nlink)
+ (slot wrapped-stat 'st-uid)
+ (slot wrapped-stat 'st-gid)
+ (slot wrapped-stat 'st-rdev)
+ ;; FIXME: OpenBSD has a 64-bit st_size slot, which is
+ ;; basically a good thing, except that it is too
+ ;; 21st-century for sbcl-0.6.12.8's FFI to handle. As a
+ ;; quick kludgy workaround, we return a 0 placeholder from
+ ;; this function, and downstream we stub out the FILE-LENGTH
+ ;; operation (which is the only place that SBCL actually
+ ;; uses the SIZE value returned from any UNIX-STAT-ish call).
+ #!+openbsd 0
+ #!-openbsd (slot wrapped-stat 'st-size)
+ (slot wrapped-stat 'st-atime)
+ (slot wrapped-stat 'st-mtime)
+ (slot wrapped-stat 'st-ctime)
+ (slot wrapped-stat 'st-blksize)
+ (slot wrapped-stat 'st-blocks)))
+
+;;; Unix system calls in the stat(2) family are implemented as calls
+;;; to C-level wrapper functions which copy all the raw "struct
+;;; stat" slots into the system-independent wrapped_stat format.
+;;; stat(2) <-> stat_wrapper()
+;;; fstat(2) <-> fstat_wrapper()
+;;; lstat(2) <-> lstat_wrapper()