1 USING: help.markup help.syntax io io.files threads
2 strings byte-arrays io.streams.plain ;
5 ARTICLE: "io.streams.c" "ANSI C streams"
6 "C streams are found in the " { $vocab-link "io.streams.c" } " vocabulary; they are " { $link "stream-protocol" } " implementations which read and write C " { $snippet "FILE*" } " handles."
11 "Underlying primitives used to implement the above:"
20 "The three standard file handles:"
30 { $values { "handle" "a C FILE* handle" } { "stream" "a new stream" } }
31 { $description "Creates a stream which reads data by calling C standard library functions." }
32 { $notes "Usually C streams are only used during bootstrap, and non-blocking OS-specific I/O routines are used during normal operation." } ;
35 { $values { "handle" "a C FILE* handle" } { "stream" "a new stream" } }
36 { $description "Creates a stream which writes data by calling C standard library functions." }
37 { $notes "Usually C streams are only used during bootstrap, and non-blocking OS-specific I/O routines are used during normal operation." } ;
40 { $values { "path" "a pathname string" } { "mode" "an access mode specifier" } { "alien" "a C FILE* handle" } }
41 { $description "Opens a file named by " { $snippet "path" } ". The " { $snippet "mode" } " parameter should be something like " { $snippet "\"r\"" } " or " { $snippet "\"rw\"" } "; consult the " { $snippet "fopen(3)" } " manual page for details." }
42 { $errors "Throws an error if the file could not be opened." }
43 { $notes "User code should call " { $link <file-reader> } " or " { $link <file-writer> } " to get a high level stream." } ;
45 HELP: fwrite ( string alien -- )
46 { $values { "string" "a string" } { "alien" "a C FILE* handle" } }
47 { $description "Writes a string of text to a C FILE* handle." }
48 { $errors "Throws an error if the output operation failed." } ;
50 HELP: fflush ( alien -- )
51 { $values { "alien" "a C FILE* handle" } }
52 { $description "Forces pending output on a C FILE* handle to complete." }
53 { $errors "Throws an error if the output operation failed." } ;
55 HELP: fclose ( alien -- )
56 { $values { "alien" "a C FILE* handle" } }
57 { $description "Closes a C FILE* handle." } ;
59 HELP: fgetc ( alien -- ch/f )
60 { $values { "alien" "a C FILE* handle" } { "ch/f" "a character or " { $link f } } }
61 { $description "Reads a single character from a C FILE* handle, and outputs " { $link f } " on end of file." }
62 { $errors "Throws an error if the input operation failed." } ;
64 HELP: fread ( n alien -- str/f )
65 { $values { "n" "a positive integer" } { "alien" "a C FILE* handle" } { "str/f" "a string or " { $link f } } }
66 { $description "Reads a sequence of characters from a C FILE* handle, and outputs " { $link f } " on end of file." }
67 { $errors "Throws an error if the input operation failed." } ;
70 { $values { "alien" "a C FILE* handle" } }
71 { $description "Outputs the console standard input file handle." } ;
74 { $values { "alien" "a C FILE* handle" } }
75 { $description "Outputs the console standard output file handle." } ;
78 { $values { "alien" "a C FILE* handle" } }
79 { $description "Outputs the console standard error file handle." } ;