```{index} single: Fcntl; Perl module ``` # Fcntl ```{pperl-module-badges} Fcntl ``` Symbolic constants for `fcntl(2)`, `flock(2)`, `seek(2)`, and file-mode bits — everything you need to call `sysopen`, `fcntl`, `flock`, `seek`, and to interpret the mode word returned by `stat`. Import individual names, or a named group via one of the export tags: `:DEFAULT` (open and file-descriptor flags), `:flock` (advisory locks), `:seek` (whence positions), `:mode` (mode bits and `S_IS*` predicates), `:Fcompat` (BSD-style `flock` aliases). ## Open flags (sysopen) - `O_RDONLY`, `O_WRONLY`, `O_RDWR` — access mode. - `O_CREAT` — create the file if it does not exist. - `O_EXCL` — with `O_CREAT`, fail if the file already exists. - `O_TRUNC` — truncate to zero length on open. - `O_APPEND` — every write seeks to end of file first. - `O_NONBLOCK` — open without blocking; I/O returns `EAGAIN` instead. - `O_NOCTTY`, `O_NOFOLLOW`, `O_BINARY` — additional platform flags (`O_BINARY` is a no-op on Linux). ## File-descriptor control (fcntl) - `F_DUPFD` — duplicate a descriptor. - `F_GETFD`, `F_SETFD` — read / set the close-on-exec flag `FD_CLOEXEC`. - `F_GETFL`, `F_SETFL` — read / set the open-file status flags. ## Lock types (flock) - `LOCK_SH` — shared lock. - `LOCK_EX` — exclusive lock. - `LOCK_UN` — release lock. - `LOCK_NB` — OR with the above to request a non-blocking attempt. ## Seek whence - `SEEK_SET` — from start of file. - `SEEK_CUR` — from current position. - `SEEK_END` — from end of file. ## File mode bits (stat) - Type mask and values: `S_IFMT`, `S_IFREG`, `S_IFDIR`, `S_IFCHR`, `S_IFBLK`, `S_IFIFO`, `S_IFLNK`, `S_IFSOCK`. - Permission triplets: `S_IRWXU`, `S_IRWXG`, `S_IRWXO` and the per-bit `S_IRUSR` / `S_IWUSR` / `S_IXUSR` (and the `GRP`, `OTH` variants). - Setuid / setgid / sticky bits: `S_ISUID`, `S_ISGID`, `S_ISVTX`. ## Mode test helpers Function-form predicates over a stat-mode value: `S_ISREG`, `S_ISDIR`, `S_ISCHR`, `S_ISBLK`, `S_ISFIFO`, `S_ISLNK`, `S_ISSOCK`, plus `S_IFMT` (extract file-type bits) and `S_IMODE` (extract permission bits). ## Performance Every constant in this module is resolved at compile time — using `O_CREAT` in an expression costs exactly what writing the integer literal would cost. No per-call lookup. ## Functions ### Mode test helpers #### [`s_ifmt`](Fcntl/s_ifmt) Extract the file-type bits from a stat-mode value. #### [`s_imode`](Fcntl/s_imode) Extract the permission bits from a stat-mode value. #### [`s_isreg`](Fcntl/s_isreg) True if a stat-mode value names a regular file. #### [`s_isdir`](Fcntl/s_isdir) True if a stat-mode value names a directory. #### [`s_ischr`](Fcntl/s_ischr) True if a stat-mode value names a character-special device. #### [`s_isblk`](Fcntl/s_isblk) True if a stat-mode value names a block-special device. #### [`s_isfifo`](Fcntl/s_isfifo) True if a stat-mode value names a named pipe (FIFO). #### [`s_islnk`](Fcntl/s_islnk) True if a stat-mode value names a symbolic link. #### [`s_issock`](Fcntl/s_issock) True if a stat-mode value names a socket. ```{toctree} :hidden: :maxdepth: 1 Fcntl/s_ifmt Fcntl/s_imode Fcntl/s_isreg Fcntl/s_isdir Fcntl/s_ischr Fcntl/s_isblk Fcntl/s_isfifo Fcntl/s_islnk Fcntl/s_issock ```