Name
SPVM::Sys - System Calls for File IO, User, Process, Signal, Socket
Description
SPVM::Sys
is the Sys
class in SPVM language. It provides system calls such as file IO, user manipulation, process, socket, time,
This class provides methods compatible with functions related to system calls provided by Perl.
This distribution contains many modules for system calls such as Sys::IO, Sys::Socket, Sys::Process. See "Modules".
Methods compatible with file IO, sockets, file paths, current directory, select, and poll are implemented as other modules such as IO::File, IO::Socket, Cwd. See "See Also".
Usage
use Sys;
Sys->mkdir("foo");
Sys->rmdir("foo");
my $path = Sys->env("PATH");
my $process_id = Sys->getpid;
Class Methods
env
static method env : string ($name : string);
Gets an environment variable. The same as getting of the Perl $ENV{$name}.
osname
static method osname : string ()
Gets OS name. The same as Perl $^O.
Currently the following OS names are supported.
linux
darwin
MSWin32
freebsd
openbsd
solaris
A
static method A : double ($file : string);
Script start time minus file access time, in days. The same as Perl -A.
C
static method C : double ($file : string);
Script start time minus file inode change time, in days. The same as Perl -C.
M
static method M : double ($file : string);
Script start time minus file modification time, in days. The same as Perl -M.
O
static method O : int ($file : string);
File is owned by real uid. The same as Perl -O.
R
static method R : int ($file : string);
File is readable by real uid/gid. The same as Perl -R.
S
static method S : int ($file : string);
File is a socket. The same as Perl -S.
W
static method W : int ($file : string);
File is writable by real uid/gid. The same as Perl -W.
X
static method X : int ($file : string);
File is executable by real uid/gid. The same as Perl -X.
b
static method b : int ($file : string);
File is a block special file. The same as Perl -b.
c
static method c : int ($file : string);
File is a character special file. The same as Perl -c.
d
static method d : int ($file : string);
File is a directory. The same as Perl -d.
e
static method e : int ($file : string);
File exists. The same as Perl -e.
f
static method f : int ($file : string);
File is a plain file. The same as Perl -f.
g
static method g : int ($file : string);
File has setgid bit set. The same as Perl -g.
k
static method k : int ($file : string);
File has sticky bit set. The same as Perl -k.
l
static method l : int ($file : string);
File is a symbolic link (false if symlinks aren't supported by the file system). The same as Perl -l.
o
static method o : int ($file : string);
File is owned by effective uid. The same as Perl -l.
p
static method p : int ($file : string);
File is a named pipe (FIFO), or Filehandle is a pipe. The same as Perl -p.
r
static method r : int ($file : string);
File is readable by effective uid/gid. The same as Perl -r.
s
static method s : long ($file : string);
File has nonzero size (returns size in bytes). The same as Perl -s.
u
static method u : int ($file : string);
File has setuid bit set. The same as Perl -u.
w
static method w : int ($file : string);
File is writable by effective uid/gid. The same as Perl -u.
x
static method x : int ($file : string);
File is executable by effective uid/gid. The same as Perl -x.
z
static method z : int ($file : string);
File has zero size (is empty). The same as Perl -z.
time
static method time : long ();
Returns the number of non-leap seconds since whatever time the system considers to be the epoch, suitable for feeding to gmtime and localtime. The same as the Perl time.
localtime
static method localtime : Sys::Time::Tm ($time : long);
Converts a time as returned by the time function to a Sys::Time::Tm object with the time analyzed for the local time zone. The same as the Perl localtime.
gmtime
static method gmtime : Sys::Time::Tm ($time : long);
Works just like localtime, but the returned values are localized for the standard Greenwich time zone. The same as the Perl gmtime.
process_id
static method process_id : int ();
Gets the process number of the running this program. The same as the Perl $$.
stat
static method stat : Sys::IO::Stat ($path : string);
Creates a Sys::IO::Stat object and calls the stat method in the Sys::IO::Stat class.
And returns the a Sys::IO::Stat object.
fstat
static method fstat : Sys::IO::Stat ($fd : int);
Creates a Sys::IO::Stat object and calls the fstat method in the Sys::IO::Stat class.
And returns the a Sys::IO::Stat object.
chdir
static method chdir : int ($path : string);
Changes the working directory to $path. The same as the Perl chdir function.
If succeed, returns 1.
chmod
static method chmod : int ($mode :int, $path : string);
Changes the permissions of a file. The same as the Perl chmod function.
If succeed, returns 1.
mkdir
static method mkdir : int ($path : string, $mode : int);
Creates the directory specified by $path and $mode. The same as the Perl mkdir function.
If succeed, returns 1.
umask
static method umask : int ($mode : int);
Sets the umask for the process to $mode and returns the previous value. The same as the Perl umask function.
rmdir
static method rmdir : int ($path : string);
Deletes the directory specified by $path. The same as the Perl rmdir function.
If succeed, returns 1.
opendir
static method opendir : int ($dh_ref : Sys::IO::DirStream[], $dir : string);
Calls the opendir method in the Sys::Socket class.
The return value is set to $dh_ref->[0].
If succeed, returns 1.
closedir
static method closedir : int ($dirp : Sys::IO::DirStream);
Calls the opendir method in the Sys::Socket class.
If succeed, returns 1.
close
static method close : int ($stream : Sys::IO::FileStream);
Calls the opendir method in the Sys::Socket class.
If succedd, returns 1.
unlink
static method unlink : int ($pathname : string);
Deletes a file. The same as the Perl unlink function.
If succeed, returns 1.
rename
static method rename : int ($oldpath : string, $newpath : string);
Changes the name of a file. The same as the Perl rename function.
If succeed, returns 1.
readlink
static method readlink : int ($file : string);
Returns the value of a symbolic link. The same as the Perl readlink function.
symlink
static method symlink : int ($oldpath : string, $newpath : string);
Creates a $newpath symbolically linked to $oldpath. The same as the Perl symlink function.
If succeed, returns 1.
sleep
static method sleep : int ($seconds : int);
Causes the program to sleep for $seconds seconds. The same as the Perl sleep.
ioctl
static method ioctl : int ($fd : int, $request : int, $request_arg_ref : object of byte[]|short[]|int[]|long[]|float[]|double[]|object = undef);
Calls the ioctlsocket method in the Sys::Ioctl class in Windows.
Calls the ioctl method in the Sys::Ioctl class in other systems.
select
static method select : int ($readfds : Sys::Select::Fd_set, $writefds : Sys::Select::Fd_set, $exceptfds : Sys::Select::Fd_set, $timeout : Sys::Time::Timeval);
Calls the select method in the Sys::Select class with $ndfs set to 1024.
bind
static method bind : int ($sockfd : int, $addr : Sys::Socket::Sockaddr);
The next argument $addrlen is set to the size of $addr.
Calls the bind method in the Sys::Socket class with $addrlen.
If succeed, returns 1.
listen
static method listen : int ($sockfd : int, $backlog : int);
Calls the listen method in the Sys::Socket class.
If succeed, returns 1.
accept
static method accept : Sys::Socket::Sockaddr ($new_sockfd_ref : int*, $sockfd : int);
The next argument $addrlen is set to 128.
Calls the accept method in the Sys::Socket class with $addrlen, and returns $addr.
The original return value is set to $$new_sockfd_ref.
connect
static method connect : int ($sockfd : int, $addr : Sys::Socket::Sockaddr);
The next argument $addrlen is set to the size of $addr.
Calls the connect method in the Sys::Socket class with $addrlen.
If succeed, returns 1.
getpeername
static method getpeername : Sys::Socket::Sockaddr ($sockfd : int);
The next argument $addrlen is set to 128.
Calls the getpeername method in the Sys::Socket class.
The return valus is convert to a child Sys::Socket::Sockaddr object using to_family_sockaddr method in the Sys:Socket|SPVM::Sys::Socket class.
getsockname
static method getsockname : Sys::Socket::Sockaddr ($sockfd : int)
The next argument $addrlen is set to 128.
Calls the getsockname method in the Sys::Socket class.
The return valus is convert to a child Sys::Socket::Sockaddr object using to_family_sockaddr method in the Sys:Socket|SPVM::Sys::Socket class.
recv
static method recv : int ($sockfd : int, $buf : mutable string, $len : int, $flags : int, $buf_offset : int = 0);
Calls the recv method in the Sys::Socket class.
send
static method send : int ($sockfd : int, $buf : string, $flags : int, $addr : Sys::Socket::Sockaddr = undef, $len : int = -1, $buf_offset : int = 0)
If $addr is defined, calls the sendto method in the Sys::Socket class.
Otherwise calls the send method in the Sys::Socket class.
If $len is less than 0, The length of $buffer is set to $len.
shutdown
static method shutdown : int ($sockfd : int, $how : int);
Calls the shutdown method in the Sys::Socket class.
If succeed, returns 1.
socket
static method socket : void ($sockfd_ref : int*, $domain : int, $type : int, $protocol : int);
Calls the socket method in the Sys::Socket class with $domain, $type, $protocal, and the return value is set to $$sockfd_ref.
socketpair
static method socketpair : int ($sock_fd1_ref : int*, $sock_fd2_ref : int*, $domain : int, $type : int, $protocol : int);
Creates a new int array with the length 2 for the next argument $pair.
Calls the socketpair method in the Sys::Socket class with $pair, and the $$sock_fd1_ref is set the first element of $pair, and the $$sock_fd2_ref is set the second element of $pair, nad
If succeed, returns 1.
setsockopt
static method setsockopt : int ($sockfd : int, $level : int, $optname : int, $optval : object of string|Int);
If $optval is the Int type, a string for the next argument $optval is created by the length 4.
If $optval is the string type, a string that for the next argument $optval is created by the length of $optval.
Calls the getsockopt method in the Sys::Socket class with $optval and $optlen.
If succeed, returns 1.
Exceptions:
$optval must be defined. Otherwise an exception is thrown.
The type of $optval must be Int or string. Otherwise an exception is thrown.
getsockopt
static method getsockopt : string ($sockfd : int, $level : int, $optname : int, $optlen : int = -1);
If $optlen is less than 0, it is set to 4.
A string for the next argument $optval is created by the length $optlen.
Calls the getsockopt method in the Sys::Socket class with $optval and $optlen, and $optval set by this method is returnd.
truncate
static method truncate : int ($fd : int, $legnth : long);
Calls the ftruncate method in the Sys::IO class.
If succeed, returns 1.
sysread
static method sysread : int ($fd : int, $buf : mutable string, $count : int, $buf_offset : int = 0);
Calls the read method in the Sys::IO class.
syswrite
static method syswrite : int ($fd : int, $buf : string, $count : int = -1, $buf_offset : int = 0);
Calls the write method in the Sys::IO class.
eof
static method eof : int ($stream : Sys::IO::Stream);
Calls the feof method in the Sys::IO class.
fileno
static method fileno : int ($stream : Sys::IO::Stream);
Calls the fileno method in the Sys::IO class.
readline
static method readline : mutable string ($stream : Sys::IO::FileStream);
Calls the readline method in the Sys::IO class.
getc
static method getc : int ($stream : Sys::IO::FileStream);
Calls the getc method in the Sys::IO class.
flock
static method flock : int ($fd : int, $operation : int);
Calls the flock method in the Sys::IO class.
If succeed, returns 1.
static method print : int ($stream : Sys::IO::FileStream, $string : string);
Calls the fwrite method in the Sys::IO class given the length of $string.
If succeed, returns 1.
say
static method say : int ($stream : Sys::IO::FileStream, $string : string);
Calls the fwrite method in the Sys::IO class given the length of $string and \n
.
If succeed, returns 1.
printf
static method printf : int ($stream, $format : string, $args : object[])
Calls the "print" method after creating formatted string given $stream and $args using the sprintf method in the Format class.
read
static method read : int ($stream : Sys::IO::FileStream, $buf : mutable string, $count : int, $buf_offset : int = 0);
Calls the fread method in the Sys::IO class.
rewinddir
static method rewinddir : void ($dirp : Sys::IO::DirStream);
Calls the rewinddir method in the Sys::IO class.
readdir
static method readdir : Sys::IO::Dirent ($dirp : Sys::IO::DirStream);
Calls the readdir method in the Sys::IO class.
seek
static method seek : int ($stream : Sys::IO::FileStream, $offset : long, $whence : int);
Calls the fseek method in the Sys::IO class.
If succeed, returns 1.
sysseek
static method sysseek : long ($fd : int, $offset : long, $whence : int);
Calls the lseek method in the Sys::IO class.
If succeed, returns 1.
tell
static method tell : long ($stream : Sys::IO::FileStream);
Calls the ftell method in the Sys::IO class.
telldir
static method telldir : long ($dirp : Sys::IO::DirStream);
Calls the telldir method in the Sys::IO class.
lstat
static method lstat : Sys::IO::Stat ($path : string);
Creates a Sys::IO::Stat object and calls the lstat method in the Sys::IO::Stat class.
And returns the a Sys::IO::Stat object.
utime
static method utime : int ($atime : long, $mtime : long, $filename : string);
Unless $atime < 0 and $mtime < 0, creates a Sys::IO::Utimbuf object.
And calls the utime method in the Sys::IO class.
chown
static method chown : int ($owner : int, $group : int, $path : string);
Calls the chown method in the Sys::IO class.
If succeed, returns 1.
fcntl
static method fcntl : int ($fd : int, $command : int, $command_arg : object of Int|Sys::IO::Flock|object = undef);
Calls the fcntl method in the Sys::IO class.
open
static method open : int ($stream_ref : Sys::IO::FileStream[], $open_mode : string, $file_name : string);
$open_mode is replaced by the following logic.
if ($open_mode eq "<") {
$open_mode = "rb";
}
elsif ($open_mode eq ">") {
$open_mode = "wb";
}
elsif ($open_mode eq ">>") {
$open_mode = "wa";
}
elsif ($open_mode eq "+<") {
$open_mode = "r+b";
}
elsif ($open_mode eq "+>") {
$open_mode = "w+b";
}
elsif ($open_mode eq "+>>") {
$open_mode = "a+b";
}
Calls the fopen method in the Sys::IO class.
The return values is set to $stream_ref->[0].
If succeed, returns 1.
Exceptions:
$stream_ref must be defined. Otherwise an exception is thrown.
The length of \$stream_ref must be equal to 1. Otherwise an exception is thrown.
fdopen
static method fdopen : int ($stream_ref : Sys::IO::FileStream[], $open_mode : string, $fd : int);
$open_mode is replaced by the following logic.
if ($open_mode eq "<") {
$open_mode = "rb";
}
elsif ($open_mode eq ">") {
$open_mode = "wb";
}
elsif ($open_mode eq ">>") {
$open_mode = "wa";
}
elsif ($open_mode eq "+<") {
$open_mode = "r+b";
}
elsif ($open_mode eq "+>") {
$open_mode = "w+b";
}
elsif ($open_mode eq "+>>") {
$open_mode = "a+b";
}
Calls the fdopen method in the Sys::IO class.
The return values is set to $stream_ref->[0].
If succeed, returns 1.
Exceptions:
$stream_ref must be defined. Otherwise an exception is thrown.
The length of \$stream_ref must be equal to 1. Otherwise an exception is thrown.
sysopen
static method sysopen : Sys::IO::FileStream ($fd_ref : int*, $path : string, $flags : int, $mode : int = 0);
Calls the open method in the Sys::IO class.
say
static method say : int ($stream : Sys::IO::FileStream, $string : string);
Calls the "print" method adding \n
to the end of $string.
STDIN
static method STDIN : Sys::IO::FileStream ();
Calls the stdin method in the Sys::IO class.
STDOUT
static method STDOUT : Sys::IO::FileStream ();
Calls the stdout method in the Sys::IO class.
STDERR
static method STDERR : Sys::IO::FileStream ();
Calls the stderr method in the Sys::IO class.
signal
static method signal : void ($signum : int, $handler_name : string);
If $handler_name is "DEFAULT", $handler is set to the return value of the "SIG_DFL" method.
If $handler_name is "IGNORE", $handler is set to the return value of the "SIG_IGN" method.
And calls the signal method in the Sys::Signal class.
kill
static method kill : int ($sig : int, $pid : int);
Calls the kill method in the Sys::Signal class.
If succeed, returns 1.
pipe
static method pipe : int ($pipe_fds : int[]);
Calls the pipe method in the Sys::Process class.
Set FD_CLOEXEC
flag to the opened filed descriptors.
If succeed, returns 1.
Modules
Sys::Env
Sys::Env
Sys::IO
Sys::IO
Sys::IO::Constant
Sys::IO::Dirent
Sys::IO::DirStream
Sys::IO::FileStream
Sys::IO::Flock
Sys::IO::Stat
Sys::IO::Utimbuf
Sys::Ioctl
Sys::Ioctl
Sys::Ioctl::Constant
Sys::OS
Sys::OS
Sys::Poll
Sys::Poll
Sys::Poll::Constant
Sys::Poll::PollfdArray
Sys::Process
Sys::Process
Sys::Process::Constant
Sys::Select
Sys::Select
Sys::Select::Constant
Sys::Select::Fd_set
Sys::Signal
Sys::Signal
Sys::Signal::Constant
Sys::Signal::Handler
Sys::Signal::Handler::Default
Sys::Signal::Handler::Ignore
Sys::Signal::Handler::Monitor
Sys::Signal::Handler::Unknown
Sys::Socket
Sys::Socket::Util
Sys::Socket
Sys::Socket::Addrinfo
Sys::Socket::AddrinfoLinkedList
Sys::Socket::Constant
Sys::Socket::Error
Sys::Socket::Error::InetInvalidNetworkAddress
Sys::Socket::In6_addr
Sys::Socket::In_addr
Sys::Socket::In_addr_base
Sys::Socket::Ip_mreq
Sys::Socket::Ip_mreq_source
Sys::Socket::Ipv6_mreq
Sys::Socket::Sockaddr
Sys::Socket::Sockaddr::In
Sys::Socket::Sockaddr::In6
Sys::Socket::Sockaddr::Interface
Sys::Socket::Sockaddr::Storage
Sys::Socket::Sockaddr::Un
Sys::Time
Sys::Time
Sys::Time::Constant
Sys::Time::Itimerval
Sys::Time::Timespec
Sys::Time::Timeval
Sys::Time::Timezone
Sys::Time::Tms
Sys::Time::Tms
Sys::User
Sys::User
Sys::User::Group
Sys::User::Passwd
Sys::FileTest
Sys::FileTest (Deparecated)
See Also
IO::File
IO::Socket
IO::Select
IO::Poll
File::Spec
Cwd
Author
Yuki Kimoto(https://github.com/yuki-kimoto)
Contributors
Gabor Szabo(https://github.com/szabgab)
Repository
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License