Fcntl(3pm)
okay bestie, welcome to Fcntl(3pm) from the Perl Programmers Reference Guide β the manual page thatβs literally serving Cβs fcntl.h energy to Perl. π
π NAME π
Fcntl β various flag constants and helper functions from Cβs fcntl.h.
β¨ SYNOPSIS β¨
use Fcntl;
use Fcntl qw(:DEFAULT :flock);
use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC);
π¦ DESCRIPTION π¦
This module hands you 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.
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).
(In particular, some of theF_*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 tofcntl, 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β.
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 allLOCK_*symbols listed below.:modeβ equivalent to allS_*symbols listed below.:seekβ equivalent to allSEEK_*symbols listed below.:Fcompatβ equivalent toqw(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.
π₯ Symbols for use with fcntl π₯
F_ALLOCSPβ file storage manipulation.F_ALLOCSP64β file storage manipulation.F_DUP2FDβ duplicate a file descriptor to the number specified in the third argument tofcntl(if it refers to an open file, it is automatically closed first).F_DUPFDβ duplicate a file descriptor to the lowest unused number greater than or equal to the third argument offcntl.F_FREESPβ file storage manipulation.F_FREESP64β file storage manipulation.F_FSYNCβ synchronize file data to disk.F_FSYNC64β synchronize file data to disk.F_GETFDβ return (as a number) the set of file descriptor flags, in which the following bits may be set:FD_CLOEXECβ during a successfulexeccall, the file descriptor will be closed automatically.
F_GETFLβ return (as a number) the set of file description status flags (O_*) as set byopenandfcntl. To determine the file access mode, perform a bitwise AND with"O_ACCMODE"and see whether the result is equal toO_RDONLY,O_WRONLY, orO_RDWR.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.F_GETSIGβ return the number of the signal sent when input or output becomes possible on the filehandle. A return value of0meansSIGIO.F_NOTIFYβ file and directory change notification with signals.DN_ACCESSDN_ATTRIBDN_CREATEDN_DELETEDN_MODIFYDN_MULTISHOTDN_RENAME
F_SETFDβ set the file descriptor flags. See"F_GETFD"for the list of available flags.F_SETFLβ set the file description status flags (O_*). Only some flags can be changed this way.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.F_SETLKW64β acquire a record lock and wait for conflicting locks to be released.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.F_SETSIGβ set the number of the signal sent when input or output becomes possible on the filehandle. An argument of0meansSIGIO.F_SHAREβ set share reservation.F_UNSHAREβ remove share reservation.F_COMPATF_EXLCKF_NODNYF_POSIXF_RDACCF_RDDNYF_RWACCF_RWDNYF_SHLCKF_WRACCF_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 otherLOCK_*flags using bitwise OR).LOCK_READβ withLOCK_MAND: allow concurrent reads.LOCK_RWβ withLOCK_MAND: allow concurrent reads and writes.LOCK_SHβ request a shared lock.LOCK_UNβ release a held lock.LOCK_WRITEβ withLOCK_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".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.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.O_DEFERβ (AIX) changes to the file are kept in memory and not written to disk until the program performs an explicit$fh->sync().O_DIRECTβ perform direct I/O to/from user-space buffers; avoid caching at the OS level.O_DIRECTORYβ fail if the filename to be opened does not refer to a directory.O_DSYNCβ synchronize file data immediately, like callingfdatasync(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$!toEEXIST(this only makes sense in combination withO_CREAT).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).O_NDELAYβ compatibility symbol. UseO_NONBLOCKinstead.O_NOATIMEβ donβt update the access time of the file when reading from it.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$!toELOOP.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.)O_NOSIGPIPEβ if the file to be opened is a pipe, then donβt raiseSIGPIPEfor write operations when the read end of the pipe is closed; make the write fail withEPIPEinstead.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 asO_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 ofO_SYNCandO_DSYNCto read operations. In particular, reading from a filehandle opened withO_SYNC | O_RSYNCwill 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 callingfsync(2)after each write.O_TEMPORARYβ (Windows) delete the file when its last open file descriptor is closed.
part 2 is pulling up with the rest of this iconβs lore β this page is not done, bestie. π
O_TEXTβ (Windows only, bestie) opens the file in text mode.O_TMPFILEβ makes an unnamed temporary file β¨ the filename argument tells it which directory the unnamed file should live in.O_TRUNCβ if the file already exists, its contents get truncated to length0. gone. deleted. bye πO_TTY_INITβ if the file you're opening is a terminal that isn't already open in any process, initialize its termios parameters.O_WRONLYβ open the file for writing (only). that's it. that's the whole vibe.
Then we've got the legacy squad, the compatibility symbols β they're literally just here so old code doesn't break, so please don't come for them:
FAPPENDβ compatibility symbol. useO_APPENDinstead.FASYNCβ compatibility symbol. useO_ASYNCinstead.FCREATβ compatibility symbol. useO_CREATinstead.FDEFERβ compatibility symbol. useO_DEFERinstead.FDSYNCβ compatibility symbol. useO_DSYNCinstead.FEXCLβ compatibility symbol. useO_EXCLinstead.FLARGEFILEβ compatibility symbol. useO_LARGEFILEinstead.FNDELAYβ compatibility symbol. useO_NDELAYinstead.FNONBLOCKβ compatibility symbol. useO_NONBLOCKinstead.FRSYNCβ compatibility symbol. useO_RSYNCinstead.FSYNCβ compatibility symbol. useO_SYNCinstead.FTRUNCβ compatibility symbol. useO_TRUNCinstead.
π 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 (so likeβ¦ mostly negative, bestie π).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 withS_ISGID, iykyk)S_IEXECβ compatibility symbol. useS_IXUSRinstead.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. plot twist: this symbol can also be used as a function βS_IFMT($mode)acts like$mode & S_IFMT. the result will be equal to one of the otherS_IF*constants β¨_S_IFMTβ bit mask for extracting the file type bits. this one is an actual constant and cannot be used as a function; otherwise it's identical toS_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. useS_IRUSRinstead.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 toS_IFMT($mode) == S_IFBLK.S_ISCHRβ convenience function to check for character devices:S_ISCHR($mode)is equivalent toS_IFMT($mode) == S_IFCHR.S_ISDIRβ convenience function to check for directories:S_ISDIR($mode)is equivalent toS_IFMT($mode) == S_IFDIR.S_ISFIFOβ convenience function to check for fifos:S_ISFIFO($mode)is equivalent toS_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).S_ISLNKβ convenience function to check for symbolic links:S_ISLNK($mode)is equivalent toS_IFMT($mode) == S_IFLNK.S_ISREGβ convenience function to check for regular files:S_ISREG($mode)is equivalent toS_IFMT($mode) == S_IFREG.S_ISSOCKβ convenience function to check for sockets:S_ISSOCK($mode)is equivalent toS_IFMT($mode) == S_IFSOCK.S_ISTXTβ compatibility symbol. useS_ISVTXinstead.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. that's the "sticky bit" bestie, iconic behaviour πS_ISWHTβ convenience function to check for whiteout files:S_ISWHT($mode)is equivalent toS_IFMT($mode) == S_IFWHT.S_IWGRPβ permissions: writable by group.S_IWOTHβ permissions: writable by others.S_IWRITEβ compatibility symbol. useS_IWUSRinstead.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
chmod in perlfunc, chmod(2), fcntl in perlfunc, fcntl(2), flock in perlfunc, flock(2), seek in perlfunc, fseek(3), stat in perlfunc, stat(2), sysopen in perlfunc, open(2), sysseek in perlfunc, lseek(2)
π APPENDIX A
okay so by default, if you just say use Fcntl;, these are the symbols that get exported to you β no cap, this is the whole list:
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
and that's the whole page, bestie π«Ά go forth and fcntl responsibly. this little masterpiece is from perl v5.42.3, dated 2026-11-03 β yes she's serving Fcntl(3pm) realness, we stan an evergreen doc πβ¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms