Name

SPVM::Sys::IO - IO System Call

Usage

use Sys::IO;

Description

Sys::IO is the class for the file IO.

Class Methods

stdin

static method stdin : Sys::IO::FileStream ();

Returns stdin.

stdout

static method stdout : Sys::IO::FileStream ();

Returns stdout.

stderr

static method stderr : Sys::IO::FileStream ();

Returns stderr.

spvm_stdin

static method spvm_stdin : Sys::IO::FileStream ();

Returns the stdin opened by the SPVM language.

spvm_stdout

static method spvm_stdout : Sys::IO::FileStream ();

Returns the stdout opened by the SPVM language.

spvm_stderr

static method spvm_stderr : Sys::IO::FileStream ();

Returns the stderr opened by the SPVM language.

fopen

static method fopen : Sys::IO::FileStream ($path : string, $mode : string);

Calls the fopen function and returns its return value.

Exceptions:

$path must be defined. Otherwise an exception is thrown.

$mode must be defined. Otherwise an exception is thrown.

If the fopen function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

fdopen

static method fdopen : Sys::IO::FileStream ($fd : int, $mode : string);

Calls the fdopen function and returns its return value.

Exceptions:

$fd must be greater than or equal to 0. Otherwise an exception is thrown.

$mode must be defined. Otherwise an exception is thrown.

If the fdopen function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

fileno

static method fileno : int ($stream : Sys::IO::FileStream);

Calls the fileno function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

If the fileno function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

fread

static method fread : int ($ptr : mutable string, $size : int, $nmemb : int, $stream : Sys::IO::FileStream, $ptr_offset : int = 0);

Calls the fread function and returns its return value.

Exceptions:

$ptr must be defined. Otherwise an exception is thrown.

$size must be more than or equal to 0. Otherwise an exception is thrown.

$nmemb must be more than or equal to 0. Otherwise an exception is thrown.

$stream must be defined. Otherwise an exception is thrown.

$nmemb * $size must be less than or equal to the length of $ptr - $ptr_offset. Otherwise an exception is thrown.

feof

static method feof : int ($stream : Sys::IO::FileStream);

Calls the feof function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

ferror

static method ferror : int ($stream : Sys::IO::FileStream);

Calls the ferror function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

clearerr

static method clearerr : void ($stream : Sys::IO::FileStream);

Calls the clearerr function.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

getc

static method getc : int ($stream : Sys::IO::FileStream);

Calls the getc function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

ungetc

static method ungetc : int ($c : int, $stream : Sys::IO::FileStream);

Calls the ungetc function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

If the ungetc function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

fgets

static method fgets : mutable string ($s : mutable string, $size : int, $stream : Sys::IO::FileStream, $s_offset : int = 0);

Calls the fgets function and returns its return value.

Exceptions:

$s must be defined. Otherwise an exception is thrown.

$size must be more than or equal to 0. Otherwise an exception is thrown.

$stream must be defined. Otherwise an exception is thrown.

$size must be less than the length of $s - $s_offset. Otherwise an exception is thrown.

fwrite

static method fwrite : int ($ptr : string, $size : int, $nmemb : int, $stream : Sys::IO::FileStream, $ptr_offset : int = 0);

Calls the fwrite function and returns its return value.

Exceptions:

$ptr must be defined. Otherwise an exception is thrown.

$size must be more than or equal to 0. Otherwise an exception is thrown.

$nmemb must be more than or equal to 0. Otherwise an exception is thrown.

$stream must be defined. Otherwise an exception is thrown.

$nmemb * $size must be less than or equal to the length of $ptr - $ptr_offset. Otherwise an exception is thrown.

fclose

static method fclose : int ($stream : Sys::IO::FileStream);

Calls the fclose function and returns its return value.

If successful, the closed field is set to 1.

Exceptions:

$stream must be defined

If the fclose function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

fseek

static method fseek : int ($stream : Sys::IO::FileStream, $offset : long, $whence : int);

Calls the fseek function and returns its return value.

See Sys::IO::Constant about constant values given to $whence.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

$offset must be greater than or equal to 0. Otherwise an exception is thrown.

If the fseek function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

ftell

static method ftell : long ($stream : Sys::IO::FileStream);

Calls the ftell function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

If the ftell function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

fflush

static method fflush : int ($stream : Sys::IO::FileStream);

Calls the fflush function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

If the fflush function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

freopen

static method freopen : Sys::IO::FileStream ($path : string, $mode : string, $stream : Sys::IO::FileStream);

Calls the freopen function and returns its return value.

Exceptions:

$path must be defined. Otherwise an exception is thrown.

$mode must be defined. Otherwise an exception is thrown.

$stream must be defined. Otherwise an exception is thrown.

If the freopen function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

setvbuf

static method setvbuf : int ($stream : Sys::IO::FileStream, $buf : mutable string, $mode : int, $size : int);

Calls the setvbuf function and returns its return value.

See Sys::IO::Constant about constant values given to $mode.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

If $buf is defined, $size must be greater than or equal to 0. Otherwise an exception is thrown.

If $buf is defined, $size must be less than or equal to the length of $buf. Otherwise an exception is thrown.

If the setvbuf function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

setbuf

static method setbuf : void ($stream : Sys::IO::FileStream, $buf : mutable string);

Calls the "setvbuf" method given the following mode $mode and size $size.

If $buf is defined, $mode is set to _IOFBF, otherwise _IONBF.

$size is BUFSIZ.

setbuffer

static method setbuffer : void ($stream : Sys::IO::FileStream, $buf : mutable string, $size : int);

Calls the "setvbuf" method given the following mode $mode.

If $buf is defined, $mode is set to _IOFBF, otherwise _IONBF.

setlinebuf

static method setlinebuf : void ($stream : Sys::IO::FileStream);

Calls the "setvbuf" method given the following buffer $buf and mode $mode.

$buf is undef.

$mode is _IOLBF.

$size is BUFSIZ.

fsync

static method fsync : int ($fd : int);

fsync() transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the file descriptor fd to the disk device (or other permanent storage device) so that all changed information can be retrieved even after the system crashed or was rebooted.

See fsync(2) - Linux man page in Linux.

Exceptions:

flock

static method flock : int ($fd : int, $operation : int);

Apply or remove an advisory lock on the open file specified by fd. The argument operation is one of the following:

See the flock function in Linux.

See Sys::IO::Constant about the constant value for the operation.

Exceptions:

mkdir

static method mkdir : int ($path : string, $mode : int);

mkdir() attempts to create a directory named pathname.

See the mkdir function in Linux.

See Sys::IO::Constant about the constant value for the mode.

Exceptions:

umask

static method umask : int ($mode : int);

umask() sets the calling process's file mode creation mask (umask) to mask & 0777 (i.e., only the file permission bits of mask are used), and returns the previous value of the mask.

See the umask function in Linux.

Exceptions:

rmdir

static method rmdir : int ($path : string);

rmdir() deletes a directory, which must be empty.

See the rmdir function in Linux.

Exceptions:

static method unlink : int ($pathname : string);

unlink() deletes a name from the file system. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse.

See the unlink function in Linux.

Exceptions:

rename

static method rename : int ($oldpath : string, $newpath : string);

rename() renames a file, moving it between directories if required. Any other hard links to the file (as created using link(2)) are unaffected. Open file descriptors for oldpath are also unaffected.

See the rename function in Linux.

Exceptions:

getcwd

static method getcwd : mutable string ($buf : mutable string, $size : int);

The getcwd() function copies an absolute pathname of the current working directory to the array pointed to by buf, which is of length size.

See the getcwd function in Linux.

Exceptions:

_getdcwd

static method _getdcwd : mutable string ($drive : int, $buffer : mutable string, $maxlen : int);

Gets the full path of the current working directory on the specified drive.

See the _getdcwd function in the case of Windows.

Exceptions:

realpath

static method realpath : mutable string ($path : string, $resolved_path : mutable string);

realpath() expands all symbolic links and resolves references to /./, /../ and extra '/' characters in the null-terminated string named by path to produce a canonicalized absolute pathname. The resulting pathname is stored as a null-terminated string, up to a maximum of PATH_MAX bytes, in the buf pointed to by resolved_path. The resulting path will have no symbolic link, /./ or /../ components.

See the realpath function in Linux.

Exceptions:

_fullpath

native static method _fullpath : mutable string ($absPath : mutable string, $relPath : string, $maxLength : int);

Creates an absolute or full path name for the specified relative path name.

See the _fullpath function in the case of Windows.

Exceptions:

chdir

static method chdir : int ($path : string);

chdir() changes the current working directory of the calling process to the directory specified in path.

See the chdir function in Linux.

Exceptions:

chmod

static method chmod : int ($path : string, $mode :int);

chmod() changes the permissions of the file specified whose pathname is given in path, which is dereferenced if it is a symbolic link.

See the chmod function in Linux.

See Sys::IO::Constant about the constant value for the mode.

Exceptions:

chown

static method chown : int ($path : string, $owner : int, $group : int);

chown() changes the ownership of the file specified by path, which is dereferenced if it is a symbolic link.

See the chown function in Linux.

Exceptions:

truncate

static method truncate : int ($path : string, $length : long);

The truncate() and ftruncate() functions cause the regular file named by path or referenced by fd to be truncated to a size of precisely length bytes.

See the truncate function in Linux.

Exceptions:

static method symlink : int ($oldpath : string, $newpath : string);

symlink() creates a symbolic link named newpath which contains the string oldpath.

See the symlink function in Linux.

Exceptions:

static method readlink : int ($path : string, $buf : mutable string, $bufsiz : int);

readlink() places the contents of the symbolic link path in the buf buf, which has size bufsiz. readlink() does not append a null byte to buf. It will truncate the contents (to a length of bufsiz characters), in case the buf is too small to hold all of the contents.

See the readlink function in Linux.

Exceptions:

native static method get_readlink_buffer_size : int ($path : string);

Gets the "readlink" needed buffer size.

Exceptions:

opendir

static method opendir : Sys::IO::DirStream ($dir : string);

The opendir() function opens a directory stream corresponding to the directory name, and returns a pointer to the directory stream. The stream is positioned at the first entry in the directory.

See the opendir function in Linux.

The return value is a Sys::IO::DirStream object.

Exceptions:

closedir

static method closedir : int ($dirp : Sys::IO::DirStream);

The closedir() function closes the directory stream associated with dirp. A successful call to closedir() also closes the underlying file descriptor associated with dirp. The directory stream descriptor dirp is not available after this call.

See the closedir function in Linux.

The directory stream is a Sys::IO::DirStream object.

Exceptions:

readdir

static method readdir : Sys::IO::Dirent ($dirp : Sys::IO::DirStream); # Non-thead safe

The readdir() function returns a pointer to a dirent structure representing the next directory entry in the directory stream pointed to by dirp. It returns NULL on reaching the end of the directory stream or if an error occurred.

See the readdir function in Linux.

The directory stream is a Sys::IO::DirStream object.

The return value is a Sys::IO::Dirent object.

Exceptions:

rewinddir

static method rewinddir : void ($dirp : Sys::IO::DirStream);

The rewinddir() function resets the position of the directory stream dirp to the beginning of the directory.

See the rewinddir function in Linux.

The directory stream is a Sys::IO::DirStream object.

Exceptions:

telldir

static method telldir : long ($dirp : Sys::IO::DirStream);

The telldir() function returns the current location associated with the directory stream dirp.

See the telldir function in Linux.

The directory stream is a Sys::IO::DirStream object.

Exceptions:

seekdir

static method seekdir : void ($dirp : Sys::IO::DirStream, $offset : long);

The seekdir() function sets the location in the directory stream from which the next readdir(2) call will start. seekdir() should be used with an offset returned by telldir(3). See the seekdir function in Linux.

The directory stream is a Sys::IO::DirStream object.

Exceptions:

access

static method access : int ($pathname : string, $mode : int);

access() checks whether the calling process can access the file pathname. If pathname is a symbolic link, it is dereferenced.

See the access function in Linux.

See Sys::IO::Constant about the constant value for the mode.

Exceptions:

eaccess

static method eaccess : int ($pathname : string, $mode : int);

eaccess() checks whether the calling process can eaccess the file pathname. If pathname is a symbolic link, it is dereferenced.

See the eaccess function in Linux.

See Sys::IO::Constant about the constant value for the $mode.

Exceptions:

faccessat

static method faccessat : int ($dirfd : int, $pathname : string, $mode : int, $flags : int);

check user's permissions of a file relative to a directory file descriptor.

See the faccessat function in Linux.

See Sys::IO::Constant about the constant value for the $mode and $flag.

Exceptions:

fcntl

static method fcntl : int ($fd : int, $command : int, $command_arg : object of Int|Sys::IO::Flock|object = undef);

fcntl() performs one of the operations described below on the open file descriptor fd. The operation is determined by cmd.

See the lstat function in Linux.

The command argument can receive a Sys::IO::Flock object.

Exceptions:

ftruncate

static method ftruncate : int ($fd : int, $length : long);

The ftruncate() functions cause the regular file named by referenced by fd to be truncated to a size of precisely length bytes.

See ftruncate(2) - Linux man page in Linux.

Exceptions:

open

static method open : int ($path : string, $flags : int, $mode : int = 0);

Given a pathname for a file, open() returns a file descriptor, a small, nonnegative integer for use in subsequent system calls (read(2), write(2), lseek(2), fcntl(2), etc.). The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process.

See the open function in Linux.

See Sys::IO::Constant about the constant value for the flags and the mode.

Exceptions:

read

static method read : int ($fd : int, $buf : mutable string, $count : int, $buf_offset : int = 0);

read() attempts to read up to count bytes from file descriptor fd into the buf starting at buf + buf_offset.

See the read function in Linux.

Exceptions:

write

static method write : int ($fd : int, $buf : string, $count : int, $buf_offset : int = 0);

write() writes up to count bytes from the buf pointed buf + buf_offset to the file referred to by the file descriptor fd.

See the write function in Linux.

Exceptions:

lseek

static method lseek : long ($fd : int, $offset : long, $whence : int);

The lseek() function repositions the offset of the open file associated with the file descriptor fd to the argument offset according to the directive whence as follows:

See the lseek function in Linux.

See Sys::IO::Constant about the constant value for the whence.

Exceptions:

close

static method close : int ($fd : int);

close() closes a file descriptor, so that it no longer refers to any file and may be reused. Any record locks (see fcntl(2)) held on the file it was associated with, and owned by the process, are removed (regardless of the file descriptor that was used to obtain the lock).

See the close function in Linux.

Exceptions:

popen

static method popen : Sys::IO::FileStream ($command : string, $type : string);

Calls the popen function and returns its return value.

Exceptions:

$command must be defined. Otherwise an exception is thrown.

$type must be defined. Otherwise an exception is thrown.

If the popen function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

Exceptions:

_popen

static method _popen : Sys::IO::FileStream ($command : string, $type : string);

Calls the _popen function and returns its return value.

Exceptions:

$command must be defined. Otherwise an exception is thrown.

$type must be defined. Otherwise an exception is thrown.

If the _popen function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

Exceptions:

pclose

static method pclose : int ($stream : Sys::IO::FileStream);

Calls the pclose function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

If the pclose function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

Exceptions:

_pclose

static method _pclose : int ($stream : Sys::IO::FileStream);

Calls the _pclose function and returns its return value.

Exceptions:

$stream must be defined. Otherwise an exception is thrown.

If the _pclose function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License