IO
is a module for performing I/O operations. Most functions found in this module are wrappers around the C standard library.
Raw
Module
wrappers for functions from the C standard library. Consider using a more carpesque function from IO when it exists. For detailed documentation please consult the documentation of your system (e.g. under Linux try man fprint).
color
(Fn [Color.Id] ())
(color cid)
sets the output color using ANSI coloration based on a color id cid
.
colorize
(Fn [Color.Id, (Ref String a)] ())
(colorize cid s)
wraps a string in ANSI coloration based on a color id cid
and prints it.
fgetc
(Fn [(Ptr FILE)] (Result Char String))
(fgetc file)
gets a character from a file pointer (thin wrapper for the C standard library).
getenv
(Fn [(Ref String a)] (Maybe String))
(getenv s)
gets the value of an environment variable (Carp-style wrapper for the C standard library)
open-file
(Fn [(Ref String a), (Ref String b)] (Result (Ptr FILE) String))
(open-file filename mode)
opens a file by name using a mode (e.g. [r]ead, [w]rite, [a]ppend), [rb] read binary...). See fopen() in the C standard library for a detailed description of valid parameters.
read->EOF
(Fn [(Ref String a)] (Result String String))
(read->EOF filename)
reads a file given by name until the End-Of-File character is reached. Please consider using read-file instead, even though this works fine for UTF-8 encoded input files.
read-file
(Fn [(Ref String a)] (Result String String))
(read-file filename)
Reads the content of a file into a (Result String String). It is intended for text files, since the way to determine the length of a String is to use strlen() which probably will be inaccurate for binaries.
unsafe-read-file
(Fn [(Ref String a)] String)
returns the contents of a file passed as argument as a string. Note: there is no way to distinguish the output for an empty file and a missing file!
write-file
(Fn [(Ref String a), (Ref String b)] (Result Bool String))
(write-file content file-name)
Writes a string into a (text) file, overwriting it if it already exists.