2005-05-04 15:51:38 -04:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: io-internals
|
2005-12-17 09:55:00 -05:00
|
|
|
USING: errors kernel kernel-internals namespaces io strings ;
|
2005-05-04 15:51:38 -04:00
|
|
|
|
|
|
|
! Simple wrappers for ANSI C I/O functions, used for
|
|
|
|
! bootstrapping only.
|
|
|
|
|
|
|
|
! More elaborate platform-specific I/O code is used on Unix and
|
|
|
|
! Windows; see library/unix and library/win32.
|
|
|
|
|
2005-12-16 21:12:35 -05:00
|
|
|
TUPLE: c-stream in out ;
|
2005-05-04 15:51:38 -04:00
|
|
|
|
2005-07-17 14:48:55 -04:00
|
|
|
M: c-stream stream-write1 ( char stream -- )
|
2005-12-16 21:12:35 -05:00
|
|
|
>r ch>string r> stream-write ;
|
2005-07-17 14:48:55 -04:00
|
|
|
|
2005-12-16 21:12:35 -05:00
|
|
|
M: c-stream stream-write ( str stream -- )
|
|
|
|
c-stream-out fwrite ;
|
2005-05-04 15:51:38 -04:00
|
|
|
|
2005-07-19 22:29:57 -04:00
|
|
|
M: c-stream stream-read1 ( stream -- char/f )
|
2005-06-19 00:23:01 -04:00
|
|
|
c-stream-in dup [ fgetc ] when ;
|
2005-05-04 15:51:38 -04:00
|
|
|
|
|
|
|
M: c-stream stream-flush ( stream -- )
|
|
|
|
c-stream-out [ fflush ] when* ;
|
|
|
|
|
|
|
|
M: c-stream stream-close ( stream -- )
|
|
|
|
dup c-stream-in [ fclose ] when*
|
|
|
|
c-stream-out [ fclose ] when* ;
|
|
|
|
|
|
|
|
: init-io ( -- )
|
2005-12-16 21:12:35 -05:00
|
|
|
13 getenv f <c-stream> <line-reader>
|
|
|
|
f 14 getenv <c-stream> <plain-writer>
|
|
|
|
<duplex-stream> stdio set ;
|
2005-05-04 15:51:38 -04:00
|
|
|
|
2005-08-23 15:50:32 -04:00
|
|
|
: io-multiplex ( ms -- ) drop ;
|
|
|
|
|
2005-06-19 17:50:35 -04:00
|
|
|
IN: io
|
2005-05-04 15:51:38 -04:00
|
|
|
|
|
|
|
: <file-reader> ( path -- stream )
|
2005-12-16 21:12:35 -05:00
|
|
|
"rb" fopen f <c-stream> <line-reader> ;
|
2005-05-04 15:51:38 -04:00
|
|
|
|
|
|
|
: <file-writer> ( path -- stream )
|
2005-12-16 21:12:35 -05:00
|
|
|
"wb" fopen f swap <c-stream> <plain-writer> ;
|
2005-05-04 15:51:38 -04:00
|
|
|
|
|
|
|
TUPLE: client-stream host port ;
|
|
|
|
|
|
|
|
: c-stream-error
|
|
|
|
"C-streams I/O does not support this feature" throw ;
|
|
|
|
|
|
|
|
: <client> c-stream-error ;
|
|
|
|
: <server> c-stream-error ;
|
|
|
|
: accept c-stream-error ;
|