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 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. 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 tofcntl(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 offcntl.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 successfulexeccall, 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 byopenandfcntl. To determine the file access mode, perform a bitwise AND withO_ACCMODEand see whether the result is equal toO_RDONLY,O_WRONLY, orO_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 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. SeeF_GETFDfor 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 thirdfnctlargument, 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 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). no waiting, we move. πββοΈ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 withF_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 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). 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 exceeds2GiB (2,147,483,647bytes). big file energy. πO_NDELAYβ Compatibility symbol. UseO_NONBLOCKinstead. 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$!toELOOP. 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 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. πͺποΈ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. 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 (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 withS_ISGID, they're twins fr.)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. 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 otherS_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 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). three jobs, one bit, she's booked and busy π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 (the "sticky bit" β¨).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 π
go read these next, they're the extended universe bestie:
chmodin perlfunc,chmod(2)fcntlin perlfunc,fcntl(2)flockin perlfunc,flock(2)seekin perlfunc,fseek(3)statin perlfunc,stat(2)sysopenin perlfunc,open(2)sysseekin perlfunc,lseek(2)
π 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