Class Stdio.Stat

Description

This object is used to represent file status information from e.g. file_stat().

It contains the following items usually found in a C struct stat:

mode

File mode (see mknod(2)).

size

File size in bytes.

uid

User ID of the file's owner.

gid

Group ID of the file's owner.

atime

Time of last access in seconds since 00:00:00 UTC, 1970-01-01.

mtime

Time of last data modification.

ctime

Time of last file status change.

atime_nsec

Time of last access in nanoseconds, added to atime to get sub-second time

mtime_nsec

Time of last modification in nanoseconds, added to mtime to get sub-second time

ctime_nsec

Time of last file status change in nanoseconds, added to ctime to get sub-second time

ino

Inode number.

nlink

Number of links.

dev

ID of the device containing a directory entry for this file.

rdev

ID of the device.

It also contains some items that correspond to the C IS* macros:

isreg

Set if the file is a regular file.

isdir

Set if the file is a directory.

islnk

Set if the file is a symbolic link. Note that symbolic links are normally followed by the stat functions, so this might only be set if you turn that off, e.g. by giving a nonzero second argument to file_stat().

isfifo

Set if the file is a FIFO (aka named pipe).

issock

Set if the file is a socket.

ischr

Set if the file is a character device.

isblk

Set if the file is a block device.

There are also some items that provide alternative representations of the above:

type

The type as a string, can be any of "reg", "dir", "lnk", "fifo", "sock", "chr", "blk", and "unknown".

mode_string

The file mode encoded as a string in ls -l style, e.g. "drwxr-xr-x".

Note that some items might not exist or have meaningful values on some platforms.

Additionally, the object may be initialized from or casted to an array on the form of a 'traditional' LPC stat-array, and it's also possible to index the object directly with integers as if it were such an array. The stat-array has this format:

Array
int 0

File mode, same as mode.

int 1

If zero or greater, the file is a regular file and this is its size in bytes. If less than zero it gives the type: -2=directory, -3=symlink and -4=device.

int 2

Time of last access, same as atime.

int 3

Time of last data modification, same as mtime.

int 4

Time of last file status change, same as ctime.

int 5

User ID of the file's owner, same as uid.

int 6

Group ID of the file's owner, same as gid.

It's possible to modify the stat struct by assigning values to the items. They essentially work as variables, although some of them affect others, e.g. setting isdir clears isreg and setting mode_string changes many of the other items.


Method create

Stdio.Stat Stdio.Stat(void|object|array stat)

Description

A new Stdio.Stat object can be initialized in two ways:

  • stat is an object, typically another Stdio.Stat. The stat info is copied from the object by getting the values of mode, size, atime, mtime, ctime, uid, gid, dev, ino, nlink, and rdev.

  • stat is a seven element array on the 'traditional' LPC stat-array form (see the class doc).