6. File input output library¶
The FIO module exposes C++ FILE * API, file mapping, directory and file stat manipulation routines to Daslang.
All functions and symbols are in “fio” module, use require to get access to it.
require fio
6.1. Type aliases¶
-
file = FILE const?
¶
alias for the FILE const?; its there since most file functions expect exactly this type
6.2. Constants¶
-
seek_set = 0
¶
constant for fseek which sets the file pointer to the beginning of the file plus the offset.
-
seek_cur = 1
¶
constant for fseek which sets the file pointer to the current position of the file plus the offset.
-
seek_end = 2
¶
constant for fseek which sets the file pointer to the end of the file plus the offset.
-
df_magic = 0x12345678
¶
obsolete. magic number for binary_save and binary_load.
-
df_header
¶
df_header fields are
magic |
uint |
size |
int |
obsolete. header for the fsave and fload which internally use binary_save and binary_load.
6.3. Handled structures¶
-
FStat
¶
FStat fields are
is_valid |
bool |
FStat property operators are
size |
uint64 |
atime |
|
ctime |
|
mtime |
|
is_reg |
bool |
is_dir |
bool |
stat and fstat return file information in this structure.
6.5. File manipulation¶
rename (old_name:string const implicit;new_name:string const implicit) : bool
fopen (name:string const implicit;mode:string const implicit) : fio::FILE const? const
fclose (file:fio::FILE const? const implicit;context:__context const;line:__lineInfo const) : void
fflush (file:fio::FILE const? const implicit;context:__context const;line:__lineInfo const) : void
fread (file:fio::FILE const? const implicit;context:__context const;line:__lineInfo const) : string
fgets (file:fio::FILE const? const implicit;context:__context const;line:__lineInfo const) : string
ftell (file:fio::FILE const? const implicit;context:__context const;line:__lineInfo const) : int64
stat (file:string const implicit;stat:fio::FStat implicit) : bool
fopen (name:string const;mode:string const;blk:block<(f:fio::FILE const? const):void> const) : auto
fread (f:fio::FILE const? const;blk:block<(data:string const#):auto> const) : auto
fload (f:fio::FILE const? const;buf:auto(BufType) const -const) : auto
fsave (f:fio::FILE const? const;buf:auto(BufType) const) : auto
fread (f:fio::FILE const? const;buf:auto(BufType) const implicit) : auto
fread (f:fio::FILE const? const;buf:array<auto(BufType)> const implicit) : auto
fwrite (f:fio::FILE const? const;buf:auto(BufType) const implicit) : auto
fwrite (f:fio::FILE const? const;buf:array<auto(BufType)> const implicit) : auto
-
remove
(name: string const implicit)¶
remove returns bool
argument |
argument type |
---|---|
name |
string const implicit |
deletes file specified by name
-
rename
(old_name: string const implicit; new_name: string const implicit)¶
rename returns bool
argument |
argument type |
---|---|
old_name |
string const implicit |
new_name |
string const implicit |
renames file.
-
fopen
(name: string const implicit; mode: string const implicit)¶
fopen returns fio::FILE const? const
argument |
argument type |
---|---|
name |
string const implicit |
mode |
string const implicit |
equivalent to C fopen. Opens file in different modes.
-
fclose
(file: FILE const? const implicit)¶
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
equivalent to C fclose. Closes file.
-
fflush
(file: FILE const? const implicit)¶
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
equivalent to C fflush. Flushes FILE buffers.
-
fprint
(file: FILE const? const implicit; text: string const implicit)¶
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
text |
string const implicit |
same as print but outputs to file.
-
fread
(file: FILE const? const implicit)¶
fread returns string
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
reads data from file.
-
fmap
(file: FILE const? const implicit; block: block<(var arg0:array<uint8>#):void> const implicit)¶
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
block |
block<(array<uint8>#):void> const implicit |
create map view of file, i.e. maps file contents to memory. Data is available as array<uint8> inside the block.
-
fgets
(file: FILE const? const implicit)¶
fgets returns string
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
equivalent to C fgets. Reads and returns new string from the line.
-
fwrite
(file: FILE const? const implicit; text: string const implicit)¶
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
text |
string const implicit |
writes data fo file.
-
feof
(file: FILE const? const implicit)¶
feof returns bool
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
equivalent to C feof. Returns true if end of file has been reached.
-
fseek
(file: FILE const? const implicit; offset: int64 const; mode: int const)¶
fseek returns int64
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
offset |
int64 const |
mode |
int const |
equivalent to C fseek. Rewinds position of the current FILE pointer.
-
ftell
(file: FILE const? const implicit)¶
ftell returns int64
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
equivalent to C ftell. Returns current FILE pointer position.
-
fstat
(file: FILE const? const implicit; stat: FStat implicit)¶
fstat returns bool
argument |
argument type |
---|---|
file |
fio::FILE const? const implicit |
stat |
fio::FStat implicit |
equivalent to C fstat. Returns information about file, such as file size, timestamp, etc.
-
stat
(file: string const implicit; stat: FStat implicit)¶
stat returns bool
argument |
argument type |
---|---|
file |
string const implicit |
stat |
fio::FStat implicit |
same as fstat, but file is specified by file name.
-
fstdin
()¶
fstdin returns fio::FILE const? const
returns FILE pointer to standard input.
-
fstdout
()¶
fstdout returns fio::FILE const? const
returns FILE pointer to standard output.
-
fstderr
()¶
fstderr returns fio::FILE const? const
returns FILE pointer to standard error.
-
getchar
()¶
getchar returns int
equivalent to C getchar. Reads and returns next character from standard input.
-
fload
(file: file; size: int const; blk: block<(data:array<uint8> const):void> const)¶
argument |
argument type |
---|---|
file |
|
size |
int const |
blk |
block<(data:array<uint8> const):void> const |
obsolete. saves data to file.
-
fopen
(name: string const; mode: string const; blk: block<(f:FILE const? const):void> const)
fopen returns auto
argument |
argument type |
---|---|
name |
string const |
mode |
string const |
blk |
block<(f: file ):void> const |
equivalent to C fopen. Opens file in different modes.
-
stat
(path: string const)
stat returns fio::FStat
argument |
argument type |
---|---|
path |
string const |
same as fstat, but file is specified by file name.
-
fstat
(f: file)
fstat returns fio::FStat
argument |
argument type |
---|---|
f |
|
equivalent to C fstat. Returns information about file, such as file size, timestamp, etc.
-
fread
(f: file; blk: block<(data:string const#):auto> const)
fread returns auto
argument |
argument type |
---|---|
f |
|
blk |
block<(data:string const#):auto> const |
reads data from file.
-
fload
(f: file; buf: auto(BufType) const)
fload returns auto
argument |
argument type |
---|---|
f |
|
buf |
auto(BufType) const |
obsolete. saves data to file.
-
fsave
(f: file; buf: auto(BufType) const)¶
fsave returns auto
argument |
argument type |
---|---|
f |
|
buf |
auto(BufType) const |
obsolete. loads data from file.
-
fread
(f: file; buf: auto(BufType) const implicit)
fread returns auto
argument |
argument type |
---|---|
f |
|
buf |
auto(BufType) const implicit |
reads data from file.
-
fread
(f: file; buf: array<auto(BufType)> const implicit)
fread returns auto
argument |
argument type |
---|---|
f |
|
buf |
array<auto(BufType)> const implicit |
reads data from file.
-
fwrite
(f: file; buf: auto(BufType) const implicit)
fwrite returns auto
argument |
argument type |
---|---|
f |
|
buf |
auto(BufType) const implicit |
writes data fo file.
-
fwrite
(f: file; buf: array<auto(BufType)> const implicit)
fwrite returns auto
argument |
argument type |
---|---|
f |
|
buf |
array<auto(BufType)> const implicit |
writes data fo file.
6.6. Path manipulation¶
-
dir_name
(name: string const implicit)¶
dir_name returns string
argument |
argument type |
---|---|
name |
string const implicit |
equivalent to linux dirname. Splits path and returns the component preceding the final ‘/’. Trailing ‘/’ characters are not counted as part of the pathname.
-
base_name
(name: string const implicit)¶
base_name returns string
argument |
argument type |
---|---|
name |
string const implicit |
equivalent to linux basename. Splits path and returns the string up to, but not including, the final ‘/’.
-
get_full_file_name
(path: string const implicit)¶
get_full_file_name returns string
argument |
argument type |
---|---|
path |
string const implicit |
returns full name of the file in normalized form.
6.7. Directory manipulation¶
-
mkdir
(path: string const implicit)¶
mkdir returns bool
argument |
argument type |
---|---|
path |
string const implicit |
makes directory.
-
chdir
(path: string const implicit)¶
chdir returns bool
argument |
argument type |
---|---|
path |
string const implicit |
changes current directory.
-
getcwd
()¶
getcwd returns string
returns current working directory.
-
dir
(path: string const; blk: block<(filename:string const):void> const)¶
dir returns auto
argument |
argument type |
---|---|
path |
string const |
blk |
block<(filename:string const):void> const |
iterates through all files in the specified path.
6.8. OS specific routines¶
-
sleep
(msec: uint const)¶
argument |
argument type |
---|---|
msec |
uint const |
sleeps for specified number of milliseconds.
-
exit
(exitCode: int const)¶
Warning
This is unsafe operation.
argument |
argument type |
---|---|
exitCode |
int const |
equivalent to C exit. Terminates program.
-
popen
(command: string const implicit; scope: block<(arg0:FILE const? const):void> const implicit)¶
popen returns int
Warning
This is unsafe operation.
argument |
argument type |
---|---|
command |
string const implicit |
scope |
block<( fio::FILE const? const):void> const implicit |
equivalent to linux popen. Opens pipe to command.
-
popen_binary
(command: string const implicit; scope: block<(arg0:FILE const? const):void> const implicit)¶
popen_binary returns int
Warning
This is unsafe operation.
argument |
argument type |
---|---|
command |
string const implicit |
scope |
block<( fio::FILE const? const):void> const implicit |
opens pipe to command and returns FILE pointer to it, in binary mode.
-
get_env_variable
(var: string const implicit)¶
get_env_variable returns string
argument |
argument type |
---|---|
var |
string const implicit |
returns value of the environment variable.
-
sanitize_command_line
(var: string const implicit)¶
sanitize_command_line returns string
argument |
argument type |
---|---|
var |
string const implicit |
sanitizes command line arguments.