Name
SPVM::Sys::IO - IO System Call
Usage
use Sys::IO;
Description
Sys::IO
is the class for the file IO.
Class Methods
open
static method open : int ($path : string, $flags : int, $mode = 0 : int);
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 detail of the open function in the case of Linux.
See Sys::IO::Constant about the constant value for the flags and the mode.
read
static method read : int ($fd : int, $buf : mutable string, $count : int);
read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf.
See the detail of the read function in the case of Linux.
write
static method write : int ($fd : int, $buffer : string, $count : int);
write() writes up to count bytes from the buffer pointed buf to the file referred to by the file descriptor fd.
See the detail of the write function in the case of Linux.
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 detail of the lseek function in the case of Linux.
See Sys::IO::Constant about the constant value for the whence.
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 detail of the close function in the case of Linux.
fopen
static method fopen : Sys::IO::FileStream ($path : string, $mode : string);
The fopen() function opens the file whose name is the string pointed to by path and associates a stream with it.
See the detail of the fopen function in the case of Linux.
The return value is a Sys::IO::FileStream object.
fdopen
static method fdopen : Sys::IO::FileStream ($fd : int, $mode : string);
The fdopen() function associates a stream with the existing file descriptor, fd. The mode of the stream (one of the values "r", "r+", "w", "w+", "a", "a+") must be compatible with the mode of the file descriptor. The file position indicator of the new stream is set to that belonging to fd, and the error and end-of-file indicators are cleared. Modes "w" or "w+" do not cause truncation of the file. The file descriptor is not dup'ed, and will be closed when the stream created by fdopen() is closed. The result of applying fdopen() to a shared memory object is undefined.
See the detail of the fdopen function in the case of Linux.
The return value is a Sys::IO::FileStream object.
fileno
static method fileno : int ($stream : Sys::IO::FileStream);
The function fileno() examines the argument stream and returns its integer descriptor.
See the detail of the fileno function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
fread
static method fread : int ($ptr : mutable string, $size : int, $nmemb : int, $stream : Sys::IO::FileStream);
The function fread() reads nmemb elements of data, each size bytes long, from the stream pointed to by stream, storing them at the location given by ptr.
See the detail of the fread function in the case of Linux.
feof
static method feof : int ($stream : Sys::IO::FileStream);
The function feof() tests the end-of-file indicator for the stream pointed to by stream, returning nonzero if it is set. The end-of-file indicator can only be cleared by the function clearerr().
See the detail of the feof function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
ferror
static method ferror : int ($stream : Sys::IO::FileStream);
The function ferror() tests the error indicator for the stream pointed to by stream, returning nonzero if it is set. The error indicator can only be reset by the clearerr() function.
See the detail of the ferror function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
clearerr
static method clearerr : void ($stream : Sys::IO::FileStream);
The function clearerr() clears the end-of-file and error indicators for the stream pointed to by stream.
See the detail of the clearerr function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
getc
static method getc : int ($stream : Sys::IO::FileStream);
getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more than once.
See the detail of the getc function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
fgets
static method fgets : mutable string ($s : mutable string, $size : int, $stream : Sys::IO::FileStream);
fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte (aq\0aq) is stored after the last character in the buffer.
See the detail of the fgets function in the case of Linux.
fwrite
static method fwrite : int ($ptr : string, $size : int, $nmemb : int, $stream : Sys::IO::FileStream);
The function fwrite() writes nmemb elements of data, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr.
See the detail of the fread function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
fseek
static method fseek : int ($stream : Sys::IO::FileStream, $offset : long, $whence : int);
The fseek() function sets the file position indicator for the stream pointed to by stream. The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively. A successful call to the fseek() function clears the end-of-file indicator for the stream and undoes any effects of the ungetc(3) function on the same stream.
See the detail of the fseek function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
See Sys::IO::Constant about the constant value for the whence.
ftell
static method ftell : long ($stream : Sys::IO::FileStream);
The ftell() function obtains the current value of the file position indicator for the stream pointed to by stream.
See the detail of the ftell function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
fclose
static method fclose : int ($stream : Sys::IO::FileStream);
The fclose() function flushes the stream pointed to by fp (writing any buffered output data using fflush(3)) and closes the underlying file descriptor.
See the detail of the fclose function in the case of Linux.
The file stream is a Sys::IO::FileStream object.
fflush
static method fflush : int ($stream : Sys::IO::FileStream);
For output streams, fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underlying write function. For input streams, fflush() discards any buffered data that has been fetched from the underlying file, but has not been consumed by the application. The open status of the stream is unaffected.
See the detail of the fflush function in the case of Linux.
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 detail of the flock function in the case of Linux.
See Sys::IO::Constant about the constant value for the operation.
mkdir
static method mkdir : int ($path : string, $mode : int);
mkdir() attempts to create a directory named pathname.
See the detail of the mkdir function in the case of Linux.
See Sys::IO::Constant about the constant value for the mode.
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 detail of the umask function in the case of Linux.
rmdir
static method rmdir : int ($path : string);
rmdir() deletes a directory, which must be empty.
See the detail of the rmdir function in the case of Linux.
unlink
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 detail of the unlink function in the case of Linux.
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 detail of the rename function in the case of Linux.
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 detail of the getcwd function in the case of Linux.
_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 detail of the _getdcwd function in the case of Windows.
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 buffer pointed to by resolved_path. The resulting path will have no symbolic link, /./ or /../ components.
See the detail of the realpath function in the case of Linux.
_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 detail of the _fullpath function in the case of Windows.
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 detail of the chdir function in the case of Linux.
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 detail of the chmod function in the case of Linux.
See Sys::IO::Constant about the constant value for the mode.
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 detail of the chown function in the case of Linux.
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 detail of the truncate function in the case of Linux.
readlink
static method readlink : int ($path : string, $buffer : mutable string, $buffer_size : int);
readlink() places the contents of the symbolic link path in the buffer 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 buffer is too small to hold all of the contents.
See the detail of the readlink function in the case of Linux.
symlink
static method symlink : int ($oldpath : string, $newpath : string);
symlink() creates a symbolic link named newpath which contains the string oldpath.
See the detail of the symlink function in the case of Linux.
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 detail of the opendir function in the case of Linux.
The return value is a Sys::IO::DirStream object.
closedir
static method closedir : int ($dir_stream : 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 detail of the closedir function in the case of Linux.
The directory stream is a Sys::IO::DirStream object.
readdir
static method readdir : Sys::IO::Dirent ($dir_stream : 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 detail of the readdir function in the case of Linux.
The directory stream is a Sys::IO::DirStream object.
The return value is a Sys::IO::Dirent object. =head2 rewinddir
static method rewinddir : void ($dir_stream : Sys::IO::DirStream);
The rewinddir() function resets the position of the directory stream dirp to the beginning of the directory.
See the detail of the rewinddir function in the case of Linux.
The directory stream is a Sys::IO::DirStream object.
telldir
static method telldir : long ($dir_stream : Sys::IO::DirStream);
The telldir() function returns the current location associated with the directory stream dirp.
See the detail of the telldir function in the case of Linux.
The directory stream is a Sys::IO::DirStream object.
seekdir
static method seekdir : void ($dir_stream : 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 detail of the seekdir function in the case of Linux.
The directory stream is a Sys::IO::DirStream object.
utime
static method utime : int ($filename : string, $times : Sys::IO::Utimbuf);
The utime() system call changes the access and modification times of the inode specified by filename to the actime and modtime fields of times respectively.
See the detail of the utime function in the case of Linux.
The buffer is a Sys::IO::Utimbuf object.
access
static method access : int ($path : 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 detail of the access function in the case of Linux.
See Sys::IO::Constant about the constant value for the mode.
stat
static method stat : int ($path : string, $stat : Sys::IO::Stat);
These functions return information about a file. No permissions are required on the file itself, but-in the case of stat() and lstat() - execute (search) permission is required on all of the directories in path that lead to the file.
stat() stats the file pointed to by path and fills in buf.
See the detail of the stat function in the case of Linux.
The stat is Sys::IO::Stat object.
lstat
static method lstat : int ($path : string, $stat : Sys::IO::Stat);
These functions return information about a file. No permissions are required on the file itself, but-in the case of stat() and lstat() - execute (search) permission is required on all of the directories in path that lead to the file.
lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to.
See the detail of the lstat function in the case of Linux.
The stat is Sys::IO::Stat object.
fcntl
static method fcntl : int ($fd : int, $command : int, $command_arg = undef : object of Int|Sys::IO::Flock|object);
fcntl() performs one of the operations described below on the open file descriptor fd. The operation is determined by cmd.
See the detail of the lstat function in the case of Linux.
The command argument can receive a Sys::IO::Flock object.
ioctl
static method ioctl : int ($fd : int, $request : int, $request_arg_ref = undef : object of Byte|Short|Int|Long|Float|Double|object);
The ioctl() function manipulates the underlying device parameters of special files. In particular, many operating characteristics of character special files (e.g., terminals) may be controlled with ioctl() requests. The argument d must be an open file descriptor.
See the detail of the ioctl function in the case of Linux.
poll
static method poll : int ($fds : Sys::IO::PollfdArray, $nfds : int, $timeout : int);
poll() performs a similar task to select(2): it waits for one of a set of file descriptors to become ready to perform I/O.
See the detail of the poll function in the case of Linux.
The file discritors are a Sys::IO::PollfdArray object.