From 8cacb84717058962131a5d2a3180c34d514f2b05 Mon Sep 17 00:00:00 2001 From: Lukas Mai Date: Mon, 22 Jan 2024 12:38:46 +0100 Subject: [PATCH] Fcntl: add module documentation --- ext/Fcntl/Fcntl.pm | 862 +++++++++++++++++++++++++++++++-- t/porting/known_pod_issues.dat | 2 + 2 files changed, 832 insertions(+), 32 deletions(-) diff --git a/ext/Fcntl/Fcntl.pm b/ext/Fcntl/Fcntl.pm index 8e015642f1b6..dd534070ae7e 100644 --- a/ext/Fcntl/Fcntl.pm +++ b/ext/Fcntl/Fcntl.pm @@ -2,56 +2,854 @@ package Fcntl; =head1 NAME -Fcntl - load the C Fcntl.h defines +Fcntl - various flag constants and helper functions from C's fcntl.h =head1 SYNOPSIS use Fcntl; use Fcntl qw(:DEFAULT :flock); + use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC); =head1 DESCRIPTION -This module is just a translation of the C F file. -Unlike the old mechanism of requiring a translated F -file, this uses the B program (see the Perl source distribution) -and your native C compiler. This means that it has a -far more likely chance of getting the numbers right. +This module provides flags and helper functions for use with L +(S_*), L (F_*), L (LOCK_*), L +(SEEK_*), L (S_*), L (O_*), and +L (SEEK_*). They correspond to the C macros defined in +F. -=head1 NOTE +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: L, L, L, +L, L, L. -Only C<#define> symbols get translated; you must still correctly -pack up your own arguments to pass as args for locking functions, etc. +(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 C, which can't be portably +constructed in pure Perl.) =head1 EXPORTED SYMBOLS -By default your system's F_* and O_* constants (eg, F_DUPFD and -O_CREAT) and the FD_CLOEXEC constant are exported into your namespace. +=head2 Default exports and export tags -You can request that the flock() constants (LOCK_SH, LOCK_EX, LOCK_NB -and LOCK_UN) be provided by using the tag C<:flock>. See L. +The full list of default exports can be found below in L. -You can request that the old constants (FAPPEND, FASYNC, FCREAT, -FDEFER, FEXCL, FNDELAY, FNONBLOCK, FSYNC, FTRUNC) be provided for -compatibility reasons by using the tag C<:Fcompat>. For new -applications the newer versions of these constants are suggested -(O_APPEND, O_ASYNC, O_CREAT, O_DEFER, O_EXCL, O_NDELAY, O_NONBLOCK, -O_SYNC, O_TRUNC). +In addition, the following export tags are available (see L for more +information on export tags): -For ease of use also the SEEK_* constants (for seek() and sysseek(), -e.g. SEEK_END) and the S_I* constants (for chmod() and stat()) are -available for import. They can be imported either separately or using -the tags C<:seek> and C<:mode>. +=over -Please refer to your native fcntl(2), open(2), fseek(3), lseek(2) -(equal to Perl's seek() and sysseek(), respectively), and chmod(2) -documentation to see what constants are implemented in your system. +=item C<:DEFAULT> -See L to learn about the uses of the O_* constants -with sysopen(). +Equivalent to the list of default export symbols (see L). -See L and L about the SEEK_* constants. +=item C<:flock> -See L about the S_I* constants. +Equivalent to all LOCK_* symbols listed below. + +=item C<:mode> + +Equivalent to all S_* symbols listed below. + +=item C<:seek> + +Equivalent to all SEEK_* symbols listed below. + +=item C<:Fcompat> + +Equivalent to C. These only exist for compatibility with old +code (if your platform defines them at all) and should not be used in new code. + +=back + +=head2 Symbols for use with C + +=over + +=item C + +File storage manipulation. + +=item C + +File storage manipulation. + +=item C + +Duplicate a file descriptor to the number specified in the third argument to +C (if it refers to an open file, it is automatically closed first). + +=item C + +Duplicate a file descriptor to the lowest unused number greater than or equal +to the third argument of C. + +=item C + +File storage manipulation. + +=item C + +File storage manipulation. + +=item C + +Synchronize file data to disk. + +=item C + +Synchronize file data to disk. + +=item C + +Return (as a number) the set of file descriptor flags, in which the following +bits may be set: + +=over + +=item C + +During a successful C call, the file descriptor will be closed +automatically. + +=back + +=item C + +Return (as a number) the set of file description status flags (O_*) as set by +C and C. To determine the file access mode, perform a bitwise AND +with L> and see whether the result is equal to C, +C, or C. + +=item C + +Indicate the type of lease associated with the filehandle (if any) by returning +one of the following flags: + +=over + +=item C + +A read lease. + +=item C + +A write lease. + +=item C + +No lease. + +=back + +=item C + +Test for the existence of record locks on the file. + +=item C + +Test for the existence of record locks on the file. + +=item C + +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. + +=item C + +Return the capacity of the pipe associated with the filehandle. + +=item C + +Return the number of the signal sent when input or output becomes possible on +the filehandle. A return value of C<0> means C. + +=item C + +File and directory change notification with signals. + +=over + +=item C + +=item C + +=item C + +=item C + +=item C + +=item C + +=item C + +=back + +Z<> + +=item C + +Set the file descriptor flags. See L> for the list of available +flags. + +=item C + +Set the file description status flags (O_*). Only some flags can be changed +this way. + +=item C + +Set a file lease as specified by the third C argument, which must be one +of the following: + +=over + +=item C + +Set a read lease. + +=item C + +Set a write lease. + +=item C + +Remove a lease. + +=back + +=item C + +Acquire a record lock. + +=item C + +Acquire a record lock. + +=item C + +Acquire a record lock and wait for conflicting locks to be released. + +=item C + +Acquire a record lock and wait for conflicting locks to be released. + +=item C + +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. + +=item C + +Set the capacity of the pipe associated with the filehandle. Return the actual +capacity reserved for the pipe, which may be higher than requested. + +=item C + +Set the number of the signal sent when input or output becomes possible on the +filehandle. An argument of C<0> means C. + +=item C + +Set share reservation. + +=item C + +Remove share reservation. + +=item C + +=item C + +=item C + +=item C + +=item C + +=item C + +=item C + +=item C + +=item C + +=item C + +=item C + +=back + +=head2 Symbols for use with C + +=over + +=item C + +Request an exclusive lock. + +=item C + +Request a mandatory lock. + +=item C + +Make lock request non-blocking (can be combined with other LOCK_* flags using bitwise OR). + +=item C + +With C: Allow concurrent reads. + +=item C + +With C: Allow concurrent reads and writes. + +=item C + +Request a shared lock. + +=item C + +Release a held lock. + +=item C + +With C: Allow concurrent writes. + +=back + +=head2 Symbols for use with C + +=over + +=item C + +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 +L>. + +=item C + +(Mac OS) Open alias file (instead of the file that the alias refers to). + +=item C + +(NetBSD) Use alternative I/O semantics. + +=item C + +Open the file in append mode. Writes always go to the end of the file. + +=item C + +Enable signal-based I/O. When the file becomes readable or writable, a signal +is sent. + +=item C + +(Windows) Open the file in binary mode. + +=item C + +If the file to be opened does not exist yet, create it. + +=item C + +(AIX) Changes to the file are kept in memory and not written to disk until the +program performs an explicit L<< C<< $fh->sync() >>|IO::Handle/$io->sync >>. + +=item C + +Perform direct I/O to/from user-space buffers; avoid caching at the OS level. + +=item C + +Fail if the filename to be opened does not refer to a directory. + +=item C + +Synchronize file data immediately, like calling L after each +write. + +=item C + +(Mac OS) Open the file for event notifications, not reading or writing. + +=item C + +If the file already exists, fail and set C<$!> to L|Errno> (this only +makes sense in combination with C). + +=item C + +When the file is opened, atomically obtain an exclusive lock. + +=item C + +(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. + +=item C + +On 32-bit platforms, allow opening files whose size exceeds 2 GiB +(2,147,483,647 bytes). + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Don't update the access time of the file when reading from it. + +=item C + +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. + +=item C + +If the final component of the filename is a symbolic link, fail and set C<$!> +to L|Errno>. + +=item C + +(Windows) Don't let child processes inherit the opened file descriptor. + +=item C + +(Hurd) If the file to be opened is a symbolic link, don't follow it; open the +link itself. + +=item C + +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.) + +=item C + +If the file to be opened is a pipe, then don't raise C for write +operations when the read end of the pipe is closed; make the write fail with +C instead. + +=item C + +(Hurd) If the file to be opened is specially translated, don't invoke the +translator; open the bare file itself. + +=item C + +(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). + +=item C + +(Windows) Same as C. + +=item C + +Open the file for reading (only). + +=item C + +Open the file for reading and writing. + +=item C + +(Mac OS) Open the resource fork of the file. + +=item C + +Extend the effects of C and C to read operations. In +particular, reading from a filehandle opened with C will wait +until the access time of the file has been modified on disk. + +=item C + +(Windows) Indicate that the program intends to access the file contents +sequentially. This is an optimization hint for the file cache. + +=item C + +When the file is opened, atomically obtain a shared lock. + +=item C + +If the file to be opened is a symbolic link, don't follow it; open the link +itself. + +=item C + +Synchronize file data and metadata immediately, like calling L after +each write. + +=item C + +(Windows) Delete the file when its last open file descriptor is closed. + +=item C + +(Windows) Open the file in text mode. + +=item C + +Create an unnamed temporary file. The filename argument specifies the directory +the unnamed file should be placed in. + +=item C + +If the file already exists, truncate its contents to length 0. + +=item C + +If the file to be opened is a terminal that is not already open in any process, +initialize its L> parameters. + +=item C + +Open the file for writing (only). + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Compatibility symbol. Use C instead. + +=back + +=head2 Symbols for use with C and C + +=over + +=item C + +File offsets are relative to the current position in the file. + +=item C + +File offsets are relative to the end of the file (i.e. mostly negative). + +=item C + +File offsets are absolute (i.e. relative to the beginning of the file). + +=back + +=head2 Symbols for use with C and C + +=over + +=item C + +Enforce mandatory file locks. (This symbol typically shares its value with +C.) + +=item C + +Compatibility symbol. Use C instead. + +=item C + +File type: Block device. + +=item C + +File type: Character device. + +=item C + +File type: Directory. + +=item C + +File type: Fifo/pipe. + +=item C + +File type: Symbolic link. + +=item C + +Bit mask for extracting the file type bits. This symbol can also be used as a +function: C acts like C<$mode & S_IFMT>. The result will be +equal to one of the other S_IF* constants. + +=item C<_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 is identical to C. + +=item C + +File type: Regular file. + +=item C + +File type: Socket. + +=item C + +File type: Whiteout file (used to mark the absence/deletion of a file in overlays). + +=item C + +Function for extracting the permission bits from a file mode. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Permissions: Readable by group. + +=item C + +Permissions: Readable by others. + +=item C + +Permissions: Readable by owner. + +=item C + +Bit mask for extracting group permissions. + +=item C + +Bit mask for extracting other permissions. + +=item C + +Bit mask for extracting owner ("user") permissions. + +=item C + +Convenience function to check for block devices: C is +equivalent to C. + +=item C + +Convenience function to check for character devices: C is +equivalent to C. + +=item C + +Convenience function to check for directories: C is +equivalent to C. + +=item C + +Broken function; do not use. (C should always return false, +anyway.) + +=item C + +Convenience function to check for fifos: C is +equivalent to C. + +=item C + +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). + +=item C + +Convenience function to check for symbolic links: C is +equivalent to C. + +=item C + +Convenience function to check for regular files: C is +equivalent to C. + +=item C + +Convenience function to check for sockets: C is +equivalent to C. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Permissions: Set effective user ID from file (when running executables). + +=item C + +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 ("sticky bit"). + +=item C + +Convenience function to check for whiteout files: C is +equivalent to C. + +=item C + +Permissions: Writable by group. + +=item C + +Permissions: Writable by others. + +=item C + +Compatibility symbol. Use C instead. + +=item C + +Permissions: Writable by owner. + +=item C + +Permissions: Executable/searchable by group. + +=item C + +Permissions: Executable/searchable by others. + +=item C + +Permissions: Executable/searchable by owner. + +=back + +=head1 SEE ALSO + +L, L, +L, L, +L, L, +L, L, +L, L, +L, L, +L, L + +=head1 APPENDIX A + +By default, if you say C, the following symbols are exported: + + 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 =cut @@ -59,7 +857,7 @@ use strict; use Exporter 'import'; require XSLoader; -our $VERSION = '1.17'; +our $VERSION = '1.18'; XSLoader::load(); @@ -78,7 +876,7 @@ our %EXPORT_TAGS = ( S_IREAD S_IWRITE S_IEXEC S_ISREG S_ISDIR S_ISLNK S_ISSOCK S_ISBLK S_ISCHR S_ISFIFO - S_ISWHT S_ISENFMT + S_ISWHT S_ISENFMT S_IFMT S_IMODE )], ); diff --git a/t/porting/known_pod_issues.dat b/t/porting/known_pod_issues.dat index 74db7af1e91e..7660f1731463 100644 --- a/t/porting/known_pod_issues.dat +++ b/t/porting/known_pod_issues.dat @@ -124,6 +124,7 @@ fchdir(2) fchmod(2) fchown(2) fcntl(2) +fdatasync(2) fdopen(3) fetch(1) FFI::Platypus @@ -144,6 +145,7 @@ fopen(3) fork(2) fread(3) fseek(3) +fsync(2) fsync(3c) Function::Parameters futimes(2)