Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

binary stdin on Windows

4 views
Skip to first unread message

yavan...@yahoo.com

unread,
Dec 23, 2008, 2:37:42 AM12/23/08
to
It may seems strange in our age of Hunchentoot, UCW and FastCGI, but
recently I had to write a CGI program with SBCL on Windows. It wasn't
that bad - due to long computation time (BTW, involving
http://www.common-lisp.ru/oci/oco.html), the overhead was neglectable.
So, I needed binary *standard-input*, and this can be tricky, as shown
in http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/919fd8d0e3f1339e
But on Windows, there is more to it, as stdin must be opened in binary
mode, too. To possibly save others some time, I post my final
solution:

(sb-alien:define-alien-routine
"_setmode" sb-alien:int (fd sb-alien:int) (mode sb-alien:int))

(defun main ()
(-setmode 0 32768) ;O_BINARY
(let ((s (sb-sys:make-fd-stream 0 :element-type '(unsigned-byte
8))))
(do ((byte (read-byte s nil) (read-byte s nil)))
((null byte))
(format t "~x~%" byte))
(quit)))

(defun make ()
(sb-ext:save-lisp-and-die "a.out" :toplevel #'main :executable t))

Good luck,
Dmitri

0 new messages