Next: gauche.generator
- Generators, Previous: gauche.dictionary
- Dictionary framework, Up: Library modules - Gauche extensions [Contents][Index]
gauche.fcntl
- Low-level file operationsProvides interface for low-level filesystem operations,
including fcntl(2)
.
{gauche.fcntl}
Performs certain operation on the file specified by port-or-fd,
which should be a port object or an integer
that specifies a system file descriptor. If it is a port, it must
be associated to the opened file (i.e. port-type
returns file
, see Common port operations).
The operation is specified by an integer operation. Several variables are defined for valid operation.
F_GETFD
¶Returns flags associated to the file descriptor of port-or-fd.
The optional argument arg is not used. The return value is
an integer whose definition is system specific, except one flag,
FD_CLOEXEC
, which indicates the file descriptor should be
closed on exec
. See the manual entry of fcntl(2)
of
your system for the details.
F_SETFD
¶Sets the file descriptor flags given as arg to port-or-fd.
For example, the portable way of setting FL_CLOEXEC
flag is
as follows:
(sys-fcntl port F_SETFD (logior FD_CLOEXEC (sys-fcntl port F_GETFD)))
F_GETFL
¶Returns flags associated to the open files specified by port-or-fd. The flags includes the following information:
O_ACCMODE
,
it’s either one of O_RDONLY
, O_WRONLY
or O_RDWR
.
O_CREAT
, O_EXCL
and/or
O_TRUNC
.
O_APPEND
fork
.
O_NONBLOCK
.
O_NOCTTY
.
ELOOP
when the pathname is a symbolink link.
The system may define system-specific flags.
F_SETFL
¶Sets flags to the open files specified by port-or-fd.
Among the flags listed above, only O_NONBLOCK
and O_APPEND
can be changed.
Note that F_GETFD
/F_SETFD
concern flags associated
to the file descriptor itself, while F_GETFL
/F_SETFL
concern flags associated to the opened file itself. This makes difference
when more than one file descriptor points to the same opened file.
F_DUPFD
¶Creates new file descriptor that points to the same file referred by port-or-fd. An integer must be provided as arg, and that specifies the minimum value of file descriptor to be assigned.
F_GETLK
¶The third argument must be provided and be an instance of <sys-flock>
object described below. It searches the lock information specified by
arg, and modifies arg accordingly.
F_SETLK
¶F_SETLKW
The third argument must be provided and be an instance of <sys-flock>
object described below. Sets the advisory file lock according to
arg. If the lock is successfully obtained, #t
is returned.
If the other process has the lock conflicting the request,
F_SETLK
returns #f
, while F_SETLKW
waits until
the lock is available.
F_GETOWN
¶Returns the process id or process group that will receive SIGIO and SIGURG signals for events on the file descriptor. Process group is indicated by a negative value. This flag is only available on the systems that has this feature (BSD and Linux have this).
F_SETOWN
¶Sets the process id or process group that will receive SIGIO and SIGURG signals for events on the file descriptor. Process group is indicated by a negative value. This flag is only available on the systems that has this feature (BSD and Linux have this). Check out fcntl(2) manpage of your system for the details.
Other value for operation causes an error.
{gauche.fcntl}
A structure represents POSIX advisory record locking.
Advisory record locking means the system may not prevents the process
from operating on files that it doesn’t have an appropriate lock.
All the processes are expected to use fcntl
to check locks
before it operates on the files that may be shared.
The following slots are defined.
Note that fcntl
lock is per-process, per-file. If you try
to lock the same file more than once within the same process, it always
succeeds. But it’s not a recursive lock, so the process loses
any locks to the file as soon as any of such lock is released,
or any of such file is closed. It makes fcntl
lock difficult
to use in libraries. See with-lock-file
(see Lock files) for
an alternative way to realize inter-process locks.
An integer represents lock type. Following variables are predefined for the valid values:
Indicates from where start
is measured.
The offset of beginning of the locked region.
The number of bytes to lock. Zero means “until EOF”.
An integer process id that holding the lock; used only by F_GETLK
.
{gauche.fcntl}
A low-level interface corresponds to POSIX open().
Open a file named by path, and returns an integer file descriptor.
The file descriptor should be closed with sys-close
,
or can be turned into a port by open-{input|output}-fd-oprt
and to be closed when the port is closed.
This is provided for the code that needs to deal with low-level fd.
Unless absolutely necessary, user code should use
high-level open-{input|output}-file
.
The flags argument is a logical ior of
bitmasks O_RDONLY
, O_WRONLY
, O_RDWR
,
O_APPEND
, O_CREAT
, O_EXCL
, O_TRUNC
,
O_CLOEXEC
, O_NOCTTY
, O_NOFOLLOW
,
O_NONBLOCK
and O_ASYNC
. Either one of
O_RDONLY
, O_WRONLY
or O_RDWR
must present.
The mode argument specifies the permission bits
when a new file is created. The default is #o664
.
{gauche.fcntl}
Interface to POSIX statvfs
and fstatvfs
.
Returns information about the filesystem where path, or
a file associated to port-or-fd, as <sys-statvfs>
instance
described below.
These procedures are only defined if the system supports them.
You can use the feature identifier gauche.sys.statvfs
for the availability (see Feature conditional).
(cond-expand [gauche.sys.statvfs (... code using sys-statvfs ...)] [else (... alternative code ...)])
{gauche.fcntl}
POSIX struct statvfs
.
This class is only defined if a feature gauche.sys.statvfs
is
provided.
Filesystem block size.
Fragment size.
Number of blocks, number of free blocks, and number of free blocks
for unprivileged users, in frsize
units.
Number of inodes, number of free inodes, and number of free inodes for unprivileged users.
An exact integer filesystem ID.
An exact integer, logical IOR of the bitflags.
Portable bitflag values is provided with constants
ST_NOSUID
a ST_RDONLY
.
Maximum filename length.
{gauche.fcntl}
Bitflag values that can be used in flag
slot of <sys-statvfs>
.
These constants are only defined if a feature gauche.sys.statvfs
is
provided.
If ST_NOSUID
bit is on, suid and sgid bits of the files on this
filesystem are ignored by exec(3)
.
If ST_RDONLY
bit is on, the filesystem is mounted read-only.
Next: gauche.generator
- Generators, Previous: gauche.dictionary
- Dictionary framework, Up: Library modules - Gauche extensions [Contents][Index]