Fcntl(3perl)

πŸ’– NAME πŸ’–

Fcntl(3perl) β€” various flag constants and helper functions from C's fcntl.h. This is the page from the Perl Programmers Reference Guide, and bestie, it's lowkey a whole toolbox. 🧰✨


✨ SYNOPSIS ✨

use Fcntl;
use Fcntl qw(:DEFAULT :flock);
use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so this module provides flags and helper functions for use with chmod in perlfunc (S_*), fcntl in perlfunc (F_*), flock in perlfunc (LOCK_*), seek in perlfunc (SEEK_*), stat in perlfunc (S_*), sysopen in perlfunc (O_*), and sysseek in perlfunc (SEEK_*). They correspond to the C macros defined in fcntl.h. Periodt. 🌈

Not all symbols are available on all systems. Except where noted otherwise, the constants and functions provided by this module will throw a runtime exception if the corresponding C macro is not available. Consult your system documentation to see the full description of each symbol and whether it is available on your platform: chmod(2), fcntl(2), flock(2), lseek(2), open(2), stat(2). No cap, read your platform docs. πŸ’…

(In particular, some of the F_* symbols are highly non-portable because they only exist on a single platform or require system-specific C data structures to be passed as the third argument to fcntl, which can't be portably constructed in pure Perl.) 😭


πŸ‘‘ EXPORTED SYMBOLS πŸ‘‘

🌸 Default exports and export tags 🌸

The full list of default exports can be found below in "APPENDIX A". Go look, bestie, it's right there. ✨

In addition, the following export tags are available (see Exporter for more information on export tags):

  • :DEFAULT β€” Equivalent to the list of default export symbols (see "APPENDIX A").
  • :flock β€” Equivalent to all LOCK_* symbols listed below.
  • :mode β€” Equivalent to all S_* symbols listed below.
  • :seek β€” Equivalent to all SEEK_* symbols listed below.
  • :Fcompat β€” Equivalent to qw(FAPPEND FASYNC FCREAT FDEFER FDSYNC FEXCL FLARGEFILE FNDELAY FNONBLOCK FRSYNC FSYNC FTRUNC). These only exist for compatibility with old code (if your platform defines them at all) and should not be used in new code. It's giving legacy, ngl. 🫠

πŸ”₯ Symbols for use with fcntl πŸ”₯

  • F_ALLOCSP β€” File storage manipulation. very allocate, much storage ✨
  • F_ALLOCSP64 β€” File storage manipulation. same vibe, 64-bit energy πŸ’«
  • F_DUP2FD β€” Duplicate a file descriptor to the number specified in the third argument to fcntl (if it refers to an open file, it is automatically closed first). dup and replace, slay. πŸ’…
  • F_DUPFD β€” Duplicate a file descriptor to the lowest unused number greater than or equal to the third argument of fcntl.
  • F_FREESP β€” File storage manipulation. free that space πŸ¦‹
  • F_FREESP64 β€” File storage manipulation. free that space, but 64 πŸ¦‹
  • F_FSYNC β€” Synchronize file data to disk. sync it, bestie πŸ”„
  • F_FSYNC64 β€” Synchronize file data to disk. sync it, but 64 πŸ”„
  • F_GETFD β€” Return (as a number) the set of file descriptor flags, in which the following bits may be set:
    • FD_CLOEXEC β€” During a successful exec call, the file descriptor will be closed automatically. auto-close on exec, iconic. πŸ‘‘
  • F_GETFL β€” Return (as a number) the set of file description status flags (O_*) as set by open and fcntl. To determine the file access mode, perform a bitwise AND with O_ACCMODE and see whether the result is equal to O_RDONLY, O_WRONLY, or O_RDWR. bitwise detective work, iykyk. πŸ•΅οΈβ€β™€οΈ
  • F_GETLEASE β€” Indicate the type of lease associated with the filehandle (if any) by returning one of the following flags:
    • F_RDLCK β€” A read lease. πŸ“–
    • F_WRLCK β€” A write lease. ✍️
    • F_UNLCK β€” No lease. 🚫
  • F_GETLK β€” Test for the existence of record locks on the file. πŸ”’
  • F_GETLK64 β€” Test for the existence of record locks on the file. πŸ”’
  • F_GETOWN β€” Return the ID of the process (as a positive number) or group (as a negative number) that is currently receiving signals for events on the file descriptor.
  • F_GETPIPE_SZ β€” Return the capacity of the pipe associated with the filehandle. pipe capacity check, cute. πŸͺˆ
  • F_GETSIG β€” Return the number of the signal sent when input or output becomes possible on the filehandle. A return value of 0 means SIGIO.
  • F_NOTIFY β€” File and directory change notification with signals.
    • DN_ACCESS
    • DN_ATTRIB
    • DN_CREATE
    • DN_DELETE
    • DN_MODIFY
    • DN_MULTISHOT
    • DN_RENAME
  • F_SETFD β€” Set the file descriptor flags. See F_GETFD for the list of available flags. set the flags, bestie. πŸ’…
  • F_SETFL β€” Set the file description status flags (O_*). Only some flags can be changed this way. only some, don't get it twisted. ⚠️
  • F_SETLEASE β€” Set a file lease as specified by the third fnctl argument, which must be one of the following:
    • F_RDLCK β€” Set a read lease. πŸ“–
    • F_WRLCK β€” Set a write lease. ✍️
    • F_UNLCK β€” Remove a lease. 🧹
  • F_SETLK β€” Acquire a record lock. πŸ”
  • F_SETLK64 β€” Acquire a record lock. πŸ”
  • F_SETLKW β€” Acquire a record lock and wait for conflicting locks to be released. wait for it… ⏳
  • F_SETLKW64 β€” Acquire a record lock and wait for conflicting locks to be released. wait for it… 64 ⏳
  • F_SETOWN β€” Set the ID of the process (as a positive number) or group (as a negative number) that will receive signals for events on the file descriptor.
  • F_SETPIPE_SZ β€” Set the capacity of the pipe associated with the filehandle. Return the actual capacity reserved for the pipe, which may be higher than requested. may be higher, no promises. πŸͺˆ
  • F_SETSIG β€” Set the number of the signal sent when input or output becomes possible on the filehandle. An argument of 0 means SIGIO.
  • F_SHARE β€” Set share reservation. 🀝
  • F_UNSHARE β€” Remove share reservation. βœ‚οΈ
  • F_COMPAT
  • F_EXLCK
  • F_NODNY
  • F_POSIX
  • F_RDACC
  • F_RDDNY
  • F_RWACC
  • F_RWDNY
  • F_SHLCK
  • F_WRACC
  • F_WRDNY

🐚 Symbols for use with flock 🐚

  • LOCK_EX β€” Request an exclusive lock. πŸ‘‘
  • LOCK_MAND β€” Request a mandatory lock. πŸ’ͺ
  • LOCK_NB β€” Make lock request non-blocking (can be combined with other LOCK_* flags using bitwise OR). no waiting, we move. πŸƒβ€β™€οΈ
  • LOCK_READ β€” With LOCK_MAND: Allow concurrent reads. πŸ“–
  • LOCK_RW β€” With LOCK_MAND: Allow concurrent reads and writes. πŸ“–βœοΈ
  • LOCK_SH β€” Request a shared lock. 🀝
  • LOCK_UN β€” Release a held lock. πŸ”“
  • LOCK_WRITE β€” With LOCK_MAND: Allow concurrent writes. ✍️

🌈 Symbols for use with sysopen 🌈

  • O_ACCMODE β€” Bit mask for extracting the file access mode (read-only, write-only, or read/write) from the other flags. This is mainly useful in combination with F_GETFL. mask it up. 🎭
  • O_ALIAS β€” (Mac OS) Open alias file (instead of the file that the alias refers to). 🍎
  • O_ALT_IO β€” (NetBSD) Use alternative I/O semantics. 🐑
  • O_APPEND β€” Open the file in append mode. Writes always go to the end of the file. end of the line, literally. πŸ“
  • O_ASYNC β€” Enable signal-based I/O. When the file becomes readable or writable, a signal is sent. πŸ“‘
  • O_BINARY β€” (Windows) Open the file in binary mode. πŸͺŸ
  • O_CREAT β€” If the file to be opened does not exist yet, create it. manifest it. ✨
  • O_DEFER β€” (AIX) Changes to the file are kept in memory and not written to disk until the program performs an explicit $fh->sync(). deferred till you sync, bestie. 🧠
  • O_DIRECT β€” Perform direct I/O to/from user-space buffers; avoid caching at the OS level. straight to the source. 🎯
  • O_DIRECTORY β€” Fail if the filename to be opened does not refer to a directory. πŸ“
  • O_DSYNC β€” Synchronize file data immediately, like calling fdatasync(2) after each write. πŸ”„
  • O_EVTONLY β€” (Mac OS) Open the file for event notifications, not reading or writing. πŸ””
  • O_EXCL β€” If the file already exists, fail and set $! to EEXIST (this only makes sense in combination with O_CREAT). exclusive much? 🚫
  • O_EXLOCK β€” When the file is opened, atomically obtain an exclusive lock. πŸ”
  • O_IGNORE_CTTY β€” (Hurd) If the file to be opened is the controlling terminal for this process, don't recognize it as such. Operations on this filehandle won't trigger job control signals. πŸ›‘
  • O_LARGEFILE β€” On 32-bit platforms, allow opening files whose size exceeds 2 GiB (2,147,483,647 bytes). big file energy. 🐘
  • O_NDELAY β€” Compatibility symbol. Use O_NONBLOCK instead. old and busted, use the new one. 🫠
  • O_NOATIME β€” Don't update the access time of the file when reading from it. leave that timestamp alone. ⏰
  • O_NOCTTY β€” If the process does not have a controlling terminal and the file to be opened is a terminal device, don't make it the controlling terminal of the process. πŸ–₯️
  • O_NOFOLLOW β€” If the final component of the filename is a symbolic link, fail and set $! to ELOOP. no symlink following, periodt. 🚫
  • O_NOINHERIT β€” (Windows) Don't let child processes inherit the opened file descriptor. πŸ‘Ά
  • O_NOLINK β€” (Hurd) If the file to be opened is a symbolic link, don't follow it; open the link itself. πŸ”—
  • O_NONBLOCK β€” Open the file in non-blocking mode. Neither the open itself nor any read/write operations on the filehandle will block. (This is mainly useful for pipes and sockets. It has no effect on regular files.) no blocking allowed. πŸƒβ€β™€οΈ
  • O_NOSIGPIPE β€” If the file to be opened is a pipe, then don't raise SIGPIPE for write operations when the read end of the pipe is closed; make the write fail with EPIPE instead. 🚰
  • O_NOTRANS β€” (Hurd) If the file to be opened is specially translated, don't invoke the translator; open the bare file itself. 🧚
  • O_RANDOM β€” (Windows) Indicate that the program intends to access the file contents randomly (without a predictable pattern). This is an optimization hint for the file cache (but may cause excessive memory use on large files). 🎲
  • O_RAW β€” (Windows) Same as O_BINARY. πŸͺŸ
  • O_RDONLY β€” Open the file for reading (only). πŸ“–
  • O_RDWR β€” Open the file for reading and writing. πŸ“–βœοΈ
  • O_RSRC β€” (Mac OS) Open the resource fork of the file. 🍎
  • O_RSYNC β€” Extend the effects of O_SYNC and O_DSYNC to read operations. In particular, reading from a filehandle opened with O_SYNC | O_RSYNC will wait until the access time of the file has been modified on disk. πŸ”„
  • O_SEQUENTIAL β€” (Windows) Indicate that the program intends to access the file contents sequentially. This is an optimization hint for the file cache. πŸͺŸ
  • O_SHLOCK β€” When the file is opened, atomically obtain a shared lock. 🀝
  • O_SYMLINK β€” If the file to be opened is a symbolic link, don't follow it; open the link itself. πŸ”—
  • O_SYNC β€” Synchronize file data and metadata immediately, like calling fsync(2) after each write. πŸ”„
  • O_TEMPORARY β€” (Windows) Delete the file when its last open file descriptor is closed. πŸͺŸπŸ—‘️
  • O_TEXT β€” (Windows girlies only πŸͺŸ) open the file in text mode.
  • O_TMPFILE β€” create an unnamed temporary file ✨. The filename argument is where you tell it which directory the unnamed file should be chillin' in.
  • O_TRUNC β€” if the file already exists, truncate its contents to length 0. say bye to everything in there 😭
  • O_TTY_INIT β€” if the file you're opening is a terminal that isn't already open in any process, this initializes its termios parameters. glow up for your tty πŸ’…
  • O_WRONLY β€” open the file for writing (only). no reading allowed, it's giving one-way street 🚦

okay bestie, now we hit the vintage aisle β€” these next ones are all compatibility symbols, meaning they're the old names kept around for the girlies with ancient code. they all just point at their modern counterpart:

  • FAPPEND β€” compatibility symbol. use O_APPEND instead.
  • FASYNC β€” compatibility symbol. use O_ASYNC instead.
  • FCREAT β€” compatibility symbol. use O_CREAT instead.
  • FDEFER β€” compatibility symbol. use O_DEFER instead.
  • FDSYNC β€” compatibility symbol. use O_DSYNC instead.
  • FEXCL β€” compatibility symbol. use O_EXCL instead.
  • FLARGEFILE β€” compatibility symbol. use O_LARGEFILE instead.
  • FNDELAY β€” compatibility symbol. use O_NDELAY instead.
  • FNONBLOCK β€” compatibility symbol. use O_NONBLOCK instead.
  • FRSYNC β€” compatibility symbol. use O_RSYNC instead.
  • FSYNC β€” compatibility symbol. use O_SYNC instead.
  • FTRUNC β€” compatibility symbol. use O_TRUNC instead.

πŸ¦‹ Symbols for use with seek and sysseek πŸ¦‹

  • SEEK_CUR β€” file offsets are relative to the current position in the file.
  • SEEK_END β€” file offsets are relative to the end of the file (i.e. mostly negative πŸ“‰).
  • SEEK_SET β€” file offsets are absolute (i.e. relative to the beginning of the file).

🌸 Symbols for use with stat and chmod 🌸

  • S_ENFMT β€” enforce mandatory file locks. (this symbol typically shares its value with S_ISGID, they're twins fr.)
  • S_IEXEC β€” compatibility symbol. use S_IXUSR instead.
  • S_IFBLK β€” file type: block device.
  • S_IFCHR β€” file type: character device.
  • S_IFDIR β€” file type: directory.
  • S_IFIFO β€” file type: fifo/pipe.
  • S_IFLNK β€” file type: symbolic link.
  • S_IFMT β€” bit mask for extracting the file type bits. this one can also be used as a function: S_IFMT($mode) acts like $mode & S_IFMT. the result will be equal to one of the other S_IF* constants. iconic duality πŸ’…
  • _S_IFMT β€” bit mask for extracting the file type bits. this symbol is an actual constant and cannot be used as a function; otherwise it's identical to S_IFMT.
  • S_IFREG β€” file type: regular file.
  • S_IFSOCK β€” file type: socket.
  • S_IFWHT β€” file type: whiteout file (used to mark the absence/deletion of a file in overlays).
  • S_IMODE β€” function for extracting the permission bits from a file mode.
  • S_IREAD β€” compatibility symbol. use S_IRUSR instead.
  • S_IRGRP β€” permissions: readable by group.
  • S_IROTH β€” permissions: readable by others.
  • S_IRUSR β€” permissions: readable by owner.
  • S_IRWXG β€” bit mask for extracting group permissions.
  • S_IRWXO β€” bit mask for extracting other permissions.
  • S_IRWXU β€” bit mask for extracting owner ("user") permissions.
  • S_ISBLK β€” convenience function to check for block devices: S_ISBLK($mode) is equivalent to S_IFMT($mode) == S_IFBLK.
  • S_ISCHR β€” convenience function to check for character devices: S_ISCHR($mode) is equivalent to S_IFMT($mode) == S_IFCHR.
  • S_ISDIR β€” convenience function to check for directories: S_ISDIR($mode) is equivalent to S_IFMT($mode) == S_IFDIR.
  • S_ISFIFO β€” convenience function to check for fifos: S_ISFIFO($mode) is equivalent to S_IFMT($mode) == S_IFIFO.
  • S_ISGID β€” permissions: set effective group ID from file (when running executables); mandatory locking (on non-group-executable files); new files inherit their group from the directory (on directories). three jobs, one bit, she's booked and busy πŸ‘‘
  • S_ISLNK β€” convenience function to check for symbolic links: S_ISLNK($mode) is equivalent to S_IFMT($mode) == S_IFLNK.
  • S_ISREG β€” convenience function to check for regular files: S_ISREG($mode) is equivalent to S_IFMT($mode) == S_IFREG.
  • S_ISSOCK β€” convenience function to check for sockets: S_ISSOCK($mode) is equivalent to S_IFMT($mode) == S_IFSOCK.
  • S_ISTXT β€” compatibility symbol. use S_ISVTX instead.
  • S_ISUID β€” permissions: set effective user ID from file (when running executables).
  • S_ISVTX β€” permissions: files in this directory can only be deleted/renamed by their owner (or the directory's owner), even if other users have write permissions to the directory (the "sticky bit" ✨).
  • S_ISWHT β€” convenience function to check for whiteout files: S_ISWHT($mode) is equivalent to S_IFMT($mode) == S_IFWHT.
  • S_IWGRP β€” permissions: writable by group.
  • S_IWOTH β€” permissions: writable by others.
  • S_IWRITE β€” compatibility symbol. use S_IWUSR instead.
  • S_IWUSR β€” permissions: writable by owner.
  • S_IXGRP β€” permissions: executable/searchable by group.
  • S_IXOTH β€” permissions: executable/searchable by others.
  • S_IXUSR β€” permissions: executable/searchable by owner.

πŸ’– SEE ALSO πŸ’–

go read these next, they're the extended universe bestie:


πŸŽ€ APPENDIX A πŸŽ€

so, by default, if you just say use Fcntl; β€” no extra vibes, no arguments β€” the following symbols get exported to you automatically:

FD_CLOEXEC
F_ALLOCSP
F_ALLOCSP64
F_COMPAT
F_DUP2FD
F_DUPFD
F_EXLCK
F_FREESP
F_FREESP64
F_FSYNC
F_FSYNC64
F_GETFD
F_GETFL
F_GETLK
F_GETLK64
F_GETOWN
F_NODNY
F_POSIX
F_RDACC
F_RDDNY
F_RDLCK
F_RWACC
F_RWDNY
F_SETFD
F_SETFL
F_SETLK
F_SETLK64
F_SETLKW
F_SETLKW64
F_SETOWN
F_SHARE
F_SHLCK
F_UNLCK
F_UNSHARE
F_WRACC
F_WRDNY
F_WRLCK
O_ACCMODE
O_ALIAS
O_APPEND
O_ASYNC
O_BINARY
O_CREAT
O_DEFER
O_DIRECT
O_DIRECTORY
O_DSYNC
O_EXCL
O_EXLOCK
O_LARGEFILE
O_NDELAY
O_NOCTTY
O_NOFOLLOW
O_NOINHERIT
O_NONBLOCK
O_RANDOM
O_RAW
O_RDONLY
O_RDWR
O_RSRC
O_RSYNC
O_SEQUENTIAL
O_SHLOCK
O_SYNC
O_TEMPORARY
O_TEXT
O_TRUNC
O_WRONLY

that's the whole page bestie, you made it to the end 🫢 this came from perl v5.44.0, dated 2026-10-17, and the page is Fcntl(3perl) β€” go forth and fcntl responsibly, mwah πŸ’‹

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms