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.

If the return value is less than $nmemb and ferror(stream) is non-zero, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

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.

If the return value is EOF and ferror(stream) is non-zero, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

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 return value is EOF and ferror(stream) is non-zero, an exception is thrown.

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.

If the return value is less than $nmemb and ferror(stream) is non-zero, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

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.

open

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

Calls the open function and returns its return value.

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

Exceptions:

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

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

read

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

Calls the read function and returns its return value.

Exceptions:

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

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

$count must be less than the length of $buf - $buf_offset. Otherwise an exception is thrown.

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

write

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

Calls the write function and returns its return value.

Exceptions:

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

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

$count must be less than the length of $buf - $buf_offset. Otherwise an exception is thrown.

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

lseek

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

Calls the lseek function and returns its return value.

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

Exceptions:

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

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

close

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

Calls the close function and returns its return value.

Exceptions:

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

fsync

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

Calls the fsync function and returns its return value.

Exceptions:

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

fcntl

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

Calls the fcntl function and returns its return value.

Exceptions:

$command_arg must be an instance of the Int class or Sys::IO::Flock class.

ftruncate

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

Calls the ftruncate function and returns its return value.

Exceptions:

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

flock

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

Calls the flock function and returns its return value.

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

Exceptions:

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

access

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

Calls the access function and returns its return value.

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

Exceptions:

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

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

faccessat

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

Calls the faccessat function and returns its return value.

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

Exceptions:

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

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

eaccess

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

Calls the "faccessat" method given the following $dirfd and $flag.

$dirfd is AT_FDCWD.

$flag is AT_EACCESS.

truncate

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

Calls the truncate function and returns its return value.

Exceptions:

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

$length must be less than or equal to 0.

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

mkdir

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

Windows:

Calls the _mkdir function and return its return value.

OS other than Windows:

Calls the mkdir function and return its return value.

Exceptions:

If the mkdir(or _mkdir) function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

umask

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

Calls the umask function and return its return value.

rmdir

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

Calls the rmdir function and return its return value.

Exceptions:

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

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

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

Calls the unlink function and return its return value.

Exceptions:

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

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

rename

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

Calls the rename function and return its return value.

Exceptions:

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

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

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

getcwd

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

Calls the getcwd function and return its return value.

Exceptions:

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

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

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

_getdcwd

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

Calls the _getdcwd function and return its return value.

Exceptions:

$maxlen must be greater than 0. Otherwise an exception is thrown.

$maxlen must be less than or equal to the lenght of $buffer. Otherwise an exception is thrown.

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

realpath

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

Calls the realpath function and return its return value.

Exceptions:

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

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

_fullpath

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

Calls the _fullpath function and return its return value.

Exceptions:

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

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

chdir

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

Calls the chdir function and return its return value.

Exceptions:

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

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

chmod

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

Calls the chmod function and return its return value.

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

Exceptions:

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

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

chown

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

Calls the chown and return its return value.

Exceptions:

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

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

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

Calls the symlink function and return its return value.

Exceptions:

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

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

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

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

Calls the readlink function and return its return value.

Exceptions:

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

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

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

$bufsiz must be less than or equal to the length of $buf. Otherwise an exception is thrown.

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

opendir

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

Calls the opendir function and return its return value.

Exceptions:

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

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

closedir

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

Calls the closedir function and return its return value.

Exceptions:

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

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

readdir

static method readdir : Sys::IO::Dirent ($dirp : Sys::IO::DirStream);

Calls the readdir function and return its return value.

Exceptions:

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

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

rewinddir

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

Calls the rewinddir function.

Exceptions:

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

telldir

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

Calls the telldir function and return its return value.

Exceptions:

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

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

seekdir

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

Calls the seekdir function and return its return value.

Exceptions:

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

$offset must be less than or equal to 0.

popen

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

Calls the popen function and returns its return value.

Sys::IO::FileStream#is_pipe field is set to 1.

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.

Sys::IO::FileStream#is_pipe field is set to 1.

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