While the code below is undoubtedly an ugly vile hack, this is what I came up with on the spur of the moment. One things that makes me a bit unhappy aside from the fixed length buffer and the sloppy error handling* is that I'm not completely comfortable with read in this context. I'm not sure it's a great idea to assume that any of the file contents parse nicely as lisp data.
- Code: Select all
(defun read-from-kernel-pseudo-file (file-name
&optional (max-read 256))
(with-open-file (in file-name)
(let ((buf (make-array max-read
:element-type '(unsigned-byte 8))))
(let ((actual (sb-unix:unix-read (sb-sys:fd-stream-fd in)
(if (null actual)
(error "Bad Unix read()")
(sb-ext:octets-to-string (subseq buf 0 actual))))))))
* Remedy left as an exercise for the reader.