hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

stdfd.ha (1355B)


      1 // License: MPL-2.0
      2 // (c) 2022 Alexey Yerin <yyp@disroot.org>
      3 // (c) 2021 Drew DeVault <sir@cmpwn.com>
      4 use bufio;
      5 use io;
      6 use rt;
      7 
      8 export let stdin_bufio: bufio::bufstream = bufio::bufstream {
      9 	source = 0,
     10 	...
     11 };
     12 
     13 export let stdout_bufio: bufio::bufstream = bufio::bufstream {
     14 	source = 1,
     15 	...
     16 };
     17 
     18 // The standard input. This handle is buffered.
     19 export let stdin: io::handle = rt::STDIN_FILENO; // initialized by init_stdfd
     20 
     21 // The standard input, as an [[io::file]]. This handle is unbuffered.
     22 export let stdin_file: io::file = rt::STDIN_FILENO;
     23 
     24 // The standard output. This handle is buffered.
     25 export let stdout: io::handle = rt::STDOUT_FILENO; // initialized by init_stdfd
     26 
     27 // The standard output, as an [[io::file]]. This handle is unbuffered.
     28 export let stdout_file: io::file = rt::STDOUT_FILENO;
     29 
     30 // The standard error.
     31 export let stderr: io::file = rt::STDERR_FILENO;
     32 
     33 // The recommended buffer size for reading from disk.
     34 export def BUFSIZ: size = 4096; // 4 KiB
     35 
     36 @init fn init_stdfd() void = {
     37 	static let stdinbuf: [BUFSIZ]u8 = [0...];
     38 	stdin_bufio = bufio::buffered(stdin_file, stdinbuf, []);
     39 	stdin = &stdin_bufio;
     40 
     41 	static let stdoutbuf: [BUFSIZ]u8 = [0...];
     42 	stdout_bufio = bufio::buffered(stdout_file, [], stdoutbuf);
     43 	stdout = &stdout_bufio;
     44 };
     45 
     46 @fini fn fini_stdfd() void = {
     47 	// Flush any pending writes
     48 	io::close(stdout): void;
     49 };