Fcntl - various flag constants and helper functions from C's fcntl.h
use Fcntl;use Fcntl qw(:DEFAULT :flock);use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC);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 infcntl.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 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 tofcntl, which can't be portably constructed in pure Perl.)
The full list of default exports can be found below in"APPENDIX A".
In addition, the following export tags are available (seeExporter for more information on export tags):
:DEFAULTEquivalent to the list of default export symbols (see"APPENDIX A").
:flockEquivalent to all LOCK_* symbols listed below.
:modeEquivalent to all S_* symbols listed below.
:seekEquivalent to all SEEK_* symbols listed below.
:FcompatEquivalent 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.
fcntlF_ALLOCSPFile storage manipulation.
F_ALLOCSP64File storage manipulation.
F_DUP2FDDuplicate 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_DUPFDDuplicate a file descriptor to the lowest unused number greater than or equal to the third argument offcntl.
F_FREESPFile storage manipulation.
F_FREESP64File storage manipulation.
F_FSYNCSynchronize file data to disk.
F_FSYNC64Synchronize file data to disk.
F_GETFDReturn (as a number) the set of file descriptor flags, in which the following bits may be set:
FD_CLOEXECDuring a successfulexec call, the file descriptor will be closed automatically.
F_GETFLReturn (as a number) the set of file description status flags (O_*) as set byopen andfcntl. 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_GETLEASEIndicate the type of lease associated with the filehandle (if any) by returning one of the following flags:
F_GETLKTest for the existence of record locks on the file.
F_GETLK64Test for the existence of record locks on the file.
F_GETOWNReturn 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_SZReturn the capacity of the pipe associated with the filehandle.
F_GETSIGReturn the number of the signal sent when input or output becomes possible on the filehandle. A return value of0 meansSIGIO.
F_NOTIFYFile and directory change notification with signals.
F_SETFDSet the file descriptor flags. See"F_GETFD" for the list of available flags.
F_SETFLSet the file description status flags (O_*). Only some flags can be changed this way.
F_SETLEASESet a file lease as specified by the thirdfnctl argument, which must be one of the following:
F_SETLKAcquire a record lock.
F_SETLK64Acquire a record lock.
F_SETLKWAcquire a record lock and wait for conflicting locks to be released.
F_SETLKW64Acquire a record lock and wait for conflicting locks to be released.
F_SETOWNSet 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_SZSet the capacity of the pipe associated with the filehandle. Return the actual capacity reserved for the pipe, which may be higher than requested.
F_SETSIGSet the number of the signal sent when input or output becomes possible on the filehandle. An argument of0 meansSIGIO.
F_SHARESet share reservation.
F_UNSHARERemove share reservation.
F_COMPATF_EXLCKF_NODNYF_POSIXF_RDACCF_RDDNYF_RWACCF_RWDNYF_SHLCKF_WRACCF_WRDNYflockLOCK_EXRequest an exclusive lock.
LOCK_MANDRequest a mandatory lock.
LOCK_NBMake lock request non-blocking (can be combined with other LOCK_* flags using bitwise OR).
LOCK_READWithLOCK_MAND: Allow concurrent reads.
LOCK_RWWithLOCK_MAND: Allow concurrent reads and writes.
LOCK_SHRequest a shared lock.
LOCK_UNRelease a held lock.
LOCK_WRITEWithLOCK_MAND: Allow concurrent writes.
sysopenO_ACCMODEBit 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_APPENDOpen the file in append mode. Writes always go to the end of the file.
O_ASYNCEnable 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_CREATIf 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_DIRECTPerform direct I/O to/from user-space buffers; avoid caching at the OS level.
O_DIRECTORYFail if the filename to be opened does not refer to a directory.
O_DSYNCSynchronize file data immediately, like callingfdatasync(2) after each write.
O_EVTONLY(Mac OS) Open the file for event notifications, not reading or writing.
O_EXCLIf the file already exists, fail and set$! toEEXIST (this only makes sense in combination withO_CREAT).
O_EXLOCKWhen 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_LARGEFILEOn 32-bit platforms, allow opening files whose size exceeds 2 GiB (2,147,483,647 bytes).
O_NDELAYCompatibility symbol. UseO_NONBLOCK instead.
O_NOATIMEDon't update the access time of the file when reading from it.
O_NOCTTYIf 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_NOFOLLOWIf 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_NONBLOCKOpen 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_NOSIGPIPEIf the file to be opened is a pipe, then don't raiseSIGPIPE for write operations when the read end of the pipe is closed; make the write fail withEPIPE 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 asO_BINARY.
O_RDONLYOpen the file for reading (only).
O_RDWROpen the file for reading and writing.
O_RSRC(Mac OS) Open the resource fork of the file.
O_RSYNCExtend the effects ofO_SYNC andO_DSYNC to read operations. In particular, reading from a filehandle opened withO_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_SHLOCKWhen the file is opened, atomically obtain a shared lock.
O_SYMLINKIf the file to be opened is a symbolic link, don't follow it; open the link itself.
O_SYNCSynchronize 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) Open the file in text mode.
O_TMPFILECreate an unnamed temporary file. The filename argument specifies the directory the unnamed file should be placed in.
O_TRUNCIf the file already exists, truncate its contents to length 0.
O_TTY_INITIf the file to be opened is a terminal that is not already open in any process, initialize itstermios parameters.
O_WRONLYOpen the file for writing (only).
FAPPENDCompatibility symbol. UseO_APPEND instead.
FASYNCCompatibility symbol. UseO_ASYNC instead.
FCREATCompatibility symbol. UseO_CREAT instead.
FDEFERCompatibility symbol. UseO_DEFER instead.
FDSYNCCompatibility symbol. UseO_DSYNC instead.
FEXCLCompatibility symbol. UseO_EXCL instead.
FLARGEFILECompatibility symbol. UseO_LARGEFILE instead.
FNDELAYCompatibility symbol. UseO_NDELAY instead.
FNONBLOCKCompatibility symbol. UseO_NONBLOCK instead.
FRSYNCCompatibility symbol. UseO_RSYNC instead.
FSYNCCompatibility symbol. UseO_SYNC instead.
FTRUNCCompatibility symbol. UseO_TRUNC instead.
seek andsysseekSEEK_CURFile offsets are relative to the current position in the file.
SEEK_ENDFile offsets are relative to the end of the file (i.e. mostly negative).
SEEK_SETFile offsets are absolute (i.e. relative to the beginning of the file).
stat andchmodS_ENFMTEnforce mandatory file locks. (This symbol typically shares its value withS_ISGID.)
S_IEXECCompatibility symbol. UseS_IXUSR instead.
S_IFBLKFile type: Block device.
S_IFCHRFile type: Character device.
S_IFDIRFile type: Directory.
S_IFIFOFile type: Fifo/pipe.
S_IFLNKFile type: Symbolic link.
S_IFMTBit mask for extracting the file type bits. 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 other S_IF* constants.
_S_IFMTBit mask for extracting the file type bits. This symbol is an actual constant and cannot be used as a function; otherwise it is identical toS_IFMT.
S_IFREGFile type: Regular file.
S_IFSOCKFile type: Socket.
S_IFWHTFile type: Whiteout file (used to mark the absence/deletion of a file in overlays).
S_IMODEFunction for extracting the permission bits from a file mode.
S_IREADCompatibility symbol. UseS_IRUSR instead.
S_IRGRPPermissions: Readable by group.
S_IROTHPermissions: Readable by others.
S_IRUSRPermissions: Readable by owner.
S_IRWXGBit mask for extracting group permissions.
S_IRWXOBit mask for extracting other permissions.
S_IRWXUBit mask for extracting owner ("user") permissions.
S_ISBLKConvenience function to check for block devices:S_ISBLK($mode) is equivalent toS_IFMT($mode) == S_IFBLK.
S_ISCHRConvenience function to check for character devices:S_ISCHR($mode) is equivalent toS_IFMT($mode) == S_IFCHR.
S_ISDIRConvenience function to check for directories:S_ISDIR($mode) is equivalent toS_IFMT($mode) == S_IFDIR.
S_ISFIFOConvenience function to check for fifos:S_ISFIFO($mode) is equivalent toS_IFMT($mode) == S_IFIFO.
S_ISGIDPermissions: 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_ISLNKConvenience function to check for symbolic links:S_ISLNK($mode) is equivalent toS_IFMT($mode) == S_IFLNK.
S_ISREGConvenience function to check for regular files:S_ISREG($mode) is equivalent toS_IFMT($mode) == S_IFREG.
S_ISSOCKConvenience function to check for sockets:S_ISSOCK($mode) is equivalent toS_IFMT($mode) == S_IFSOCK.
S_ISTXTCompatibility symbol. UseS_ISVTX instead.
S_ISUIDPermissions: Set effective user ID from file (when running executables).
S_ISVTXPermissions: 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 ("sticky bit").
S_ISWHTConvenience function to check for whiteout files:S_ISWHT($mode) is equivalent toS_IFMT($mode) == S_IFWHT.
S_IWGRPPermissions: Writable by group.
S_IWOTHPermissions: Writable by others.
S_IWRITECompatibility symbol. UseS_IWUSR instead.
S_IWUSRPermissions: Writable by owner.
S_IXGRPPermissions: Executable/searchable by group.
S_IXOTHPermissions: Executable/searchable by others.
S_IXUSRPermissions: Executable/searchable by owner.
"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)
By default, if you sayuse Fcntl;, the following symbols are exported:
FD_CLOEXECF_ALLOCSPF_ALLOCSP64F_COMPATF_DUP2FDF_DUPFDF_EXLCKF_FREESPF_FREESP64F_FSYNCF_FSYNC64F_GETFDF_GETFLF_GETLKF_GETLK64F_GETOWNF_NODNYF_POSIXF_RDACCF_RDDNYF_RDLCKF_RWACCF_RWDNYF_SETFDF_SETFLF_SETLKF_SETLK64F_SETLKWF_SETLKW64F_SETOWNF_SHAREF_SHLCKF_UNLCKF_UNSHAREF_WRACCF_WRDNYF_WRLCKO_ACCMODEO_ALIASO_APPENDO_ASYNCO_BINARYO_CREATO_DEFERO_DIRECTO_DIRECTORYO_DSYNCO_EXCLO_EXLOCKO_LARGEFILEO_NDELAYO_NOCTTYO_NOFOLLOWO_NOINHERITO_NONBLOCKO_RANDOMO_RAWO_RDONLYO_RDWRO_RSRCO_RSYNCO_SEQUENTIALO_SHLOCKO_SYNCO_TEMPORARYO_TEXTO_TRUNCO_WRONLYPerldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.