=head1 NAME POSIX - Perl interface to IEEE Std 1003.1 =head1 SYNOPSIS use POSIX (); use POSIX qw(setsid); use POSIX qw(:errno_h :fcntl_h); printf "EINTR is %d\n", EINTR; $sess_id = POSIX::setsid(); $fd = POSIX::open($path, O_CREAT|O_EXCL|O_WRONLY, 0644); # note: that's a filedescriptor, *NOT* a filehandle =head1 DESCRIPTION The POSIX module permits you to access all (or nearly all) the standard POSIX 1003.1 identifiers. Many of these identifiers have been given Perl-ish interfaces. This document gives a condensed list of the features available in the POSIX module. Consult your operating system's manpages for general information on most features. Consult L for functions which are noted as being identical or almost identical to Perl's builtin functions. The first section describes POSIX functions from the 1003.1 specification. The second section describes some classes for signal objects, TTY objects, and other miscellaneous objects. The remaining sections list various constants and macros in an organization which roughly follows IEEE Std 1003.1b-1993. =head1 CAVEATS I (with a handful of exceptions). This is an unfortunate backwards compatibility feature and its use is B>. You should either prevent the exporting (by saying S>, as usual) and then use fully qualified names (e.g. C), or give an explicit import list. If you do neither and opt for the default (as in S>), you will import I of symbols into your namespace. A few functions are not implemented because they are C specific. If you attempt to call these, they will print a message telling you that they aren't implemented, and suggest using the Perl equivalent, should one exist. For example, trying to access the C call will elicit the message "C". Furthermore, some evil vendors will claim 1003.1 compliance, but in fact are not so: they will not pass the PCTS (POSIX Compliance Test Suites). For example, one vendor may not define C, or the semantics of the errno values set by C might not be quite right. Perl does not attempt to verify POSIX compliance. That means you can currently successfully say "use POSIX", and then later in your program you find that your vendor has been lax and there's no usable C macro after all. This could be construed to be a bug. =head1 FUNCTIONS =over 8 =item C<_exit> This is identical to the C function C<_exit()>. It exits the program immediately which means among other things buffered I/O is B flushed. Note that when using threads and in Linux this is B a good way to exit a thread because in Linux processes and threads are kind of the same thing (Note: while this is the situation in early 2003 there are projects under way to have threads with more POSIXly semantics in Linux). If you want not to return from a thread, detach the thread. =item C This is identical to the C function C. It terminates the process with a C signal unless caught by a signal handler or if the handler does not return normally (it e.g. does a C). =item C This is identical to Perl's builtin C function, returning the absolute value of its numerical argument (except that C must be provided an explicit value (rather than relying on an implicit C<$_>): $absolute_value = POSIX::abs(42); # good $absolute_value = POSIX::abs(); # throws exception =item C Determines the accessibility of a file. if( POSIX::access( "/", &POSIX::R_OK ) ){ print "have read permission\n"; } Returns C on failure. Note: do not use C for security purposes. Between the C call and the operation you are preparing for the permissions might change: a classic I. =item C This is identical to the C function C, returning the arcus cosine of its numerical argument. See also L. =item C This is identical to the C function C, returning the hyperbolic arcus cosine of its numerical argument [C99]. See also L. =item C This is identical to Perl's builtin C function, either for arming or disarming the C timer, except that C must be provided an explicit value (rather than relying on an implicit C<$_>): POSIX::alarm(3) # good POSIX::alarm() # throws exception =item C This is identical to the C function C. It returns a string of the form "Fri Jun 2 18:22:13 2000\n\0" and it is called thusly $asctime = asctime($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst); The C<$mon> is zero-based: January equals C<0>. The C<$year> is 1900-based: 2001 equals C<101>. C<$wday> and C<$yday> default to zero (and are usually ignored anyway), and C<$isdst> defaults to -1. =item C This is identical to the C function C, returning the arcus sine of its numerical argument. See also L. =item C This is identical to the C function C, returning the hyperbolic arcus sine of its numerical argument [C99]. See also L. =item C Unimplemented, but you can use L and the L module to achieve similar things. =item C This is identical to the C function C, returning the arcus tangent of its numerical argument. See also L. =item C This is identical to the C function C, returning the hyperbolic arcus tangent of its numerical argument [C99]. See also L. =item C This is identical to Perl's builtin C function, returning the arcus tangent defined by its two numerical arguments, the I coordinate and the I coordinate. See also L. =item C Not implemented. C is C-specific: use C instead, see L. =item C Not implemented. C is C-specific. Perl converts strings to numbers transparently. If you need to force a scalar to a number, add a zero to it. =item C Not implemented. C is C-specific. Perl converts strings to numbers transparently. If you need to force a scalar to a number, add a zero to it. If you need to have just the integer part, see L. =item C Not implemented. C is C-specific. Perl converts strings to numbers transparently. If you need to force a scalar to a number, add a zero to it. If you need to have just the integer part, see L. =item C C not supplied. For doing binary search on wordlists, see L. =item C Not implemented. C is C-specific. Perl does memory management transparently. =item C The cube root [C99]. =item C This is identical to the C function C, returning the smallest integer value greater than or equal to the given numerical argument. =item C This is identical to Perl's builtin C function, allowing one to change the working (default) directory -- see L -- with the exception that C must be provided an explicit value (rather than relying on an implicit C<$_>): $rv = POSIX::chdir('path/to/dir'); # good $rv = POSIX::chdir(); # throws exception =item C This is identical to Perl's builtin C function, allowing one to change file and directory permissions -- see L -- with the exception that C can only change one file at a time (rather than a list of files): $c = chmod 0664, $file1, $file2; # good $c = POSIX::chmod 0664, $file1; # throws exception $c = POSIX::chmod 0664, $file1, $file2; # throws exception As with the built-in C, C<$file> may be a filename or a file handle. =item C This is identical to Perl's builtin C function, allowing one to change file and directory owners and groups, see L. =item C Not implemented. Use the method C instead, to reset the error state (if any) and EOF state (if any) of the given stream. =item C This is identical to the C function C, returning the amount of spent processor time in microseconds. =item C Close the file. This uses file descriptors such as those obtained by calling C. $fd = POSIX::open( "foo", &POSIX::O_RDONLY ); POSIX::close( $fd ); Returns C on failure. See also L. =item C This is identical to Perl's builtin C function for closing a directory handle, see L. =item C This is identical to Perl's builtin C function, for returning the cosine of its numerical argument, see L. See also L. =item C This is identical to the C function C, for returning the hyperbolic cosine of its numeric argument. See also L. =item C Returns C but with the sign of C [C99]. $x_with_sign_of_y = POSIX::copysign($x, $y); See also L. =item C Create a new file. This returns a file descriptor like the ones returned by C. Use C to close the file. $fd = POSIX::creat( "foo", 0611 ); POSIX::close( $fd ); See also L and its C flag. =item C Generates the path name for the controlling terminal. $path = POSIX::ctermid(); =item C This is identical to the C function C and equivalent to C, see L and L. =item C [POSIX.1-1988] Get the login name of the owner of the current process. $name = POSIX::cuserid(); Note: this function has not been specified by POSIX since 1990 and is included only for backwards compatibility. New code should use L|perlfunc/getlogin> instead. =item C This is identical to the C function C, for returning the time difference (in seconds) between two times (as returned by C), see L. =item C
Not implemented. C is C-specific, use L on the usual C division and the modulus C<%>. =item C This is similar to the C function C, for duplicating a file descriptor. This uses file descriptors such as those obtained by calling C. Returns C on failure. =item C This is similar to the C function C, for duplicating a file descriptor to an another known file descriptor. This uses file descriptors such as those obtained by calling C. Returns C on failure. =item C The error function [C99]. =item C The complementary error function [C99]. =item C Returns the value of errno. $errno = POSIX::errno(); This identical to the numerical values of the C<$!>, see L. =item C Not implemented. C is C-specific, see L. =item C Not implemented. C is C-specific, see L. =item C Not implemented. C is C-specific, see L. =item C Not implemented. C is C-specific, see L. =item C Not implemented. C is C-specific, see L. =item C Not implemented. C is C-specific, see L. =item C This is identical to Perl's builtin C function for exiting the program, see L. =item C This is identical to Perl's builtin C function for returning the exponent (I-based) of the numerical argument, see L. =item C Equivalent to C, but more precise for small argument values [C99]. See also L. =item C This is identical to Perl's builtin C function for returning the absolute value of the numerical argument, see L. =item C Not implemented. Use method C instead, or see L. =item C This is identical to Perl's builtin C function, see L. =item C Not implemented. Use method C instead, or see L. =item C Not implemented. Use method C instead, or see L. =item C Not implemented. Use method C instead. =item C Not implemented. Use method C instead. See also C>. =item C Not implemented. Use method C instead, or see L. =item C Not implemented. Use method C instead, or see L. =item C Not implemented. Use method C instead. Similar to EE, also known as L. =item C Not implemented. Use method C instead, or see L. =item C This is identical to the C function C, returning the largest integer value less than or equal to the numerical argument. =item C "Positive difference", S> if S y>>, zero otherwise [C99]. =item C Returns the current floating point rounding mode, one of FE_TONEAREST FE_TOWARDZERO FE_UPWARD FE_DOWNWARD C is like L, C is like L [C99]. =item C Sets the floating point rounding mode, see L [C99]. =item C "Fused multiply-add", S>, possibly faster (and less lossy) than the explicit two operations [C99]. my $fused = POSIX::fma($x, $y, $z); =item C Maximum of C and C, except when either is C, returns the other [C99]. my $min = POSIX::fmax($x, $y); =item C Minimum of C and C, except when either is C, returns the other [C99]. my $min = POSIX::fmin($x, $y); =item C This is identical to the C function C. $r = fmod($x, $y); It returns the remainder S>, where S>. The C<$r> has the same sign as C<$x> and magnitude (absolute value) less than the magnitude of C<$y>. =item C Not implemented. Use method C instead, or see L. =item C This is identical to Perl's builtin C function for duplicating the current process, see L and L if you are in Windows. =item C Retrieves the value of a configurable limit on a file or directory. This uses file descriptors such as those obtained by calling C. The following will determine the maximum length of the longest allowable pathname on the filesystem which holds F. $fd = POSIX::open( "/var/foo", &POSIX::O_RDONLY ); $path_max = POSIX::fpathconf($fd, &POSIX::_PC_PATH_MAX); Returns C on failure. =item C Returns one of FP_NORMAL FP_ZERO FP_SUBNORMAL FP_INFINITE FP_NAN telling the class of the argument [C99]. C is positive or negative infinity, C is not-a-number. C means subnormal numbers (also known as denormals), very small numbers with low precision. C is zero. C is all the rest. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific. Perl does memory management transparently. =item C Not implemented. C is C-specific, see L instead. =item C Return the mantissa and exponent of a floating-point number. ($mantissa, $exponent) = POSIX::frexp( 1.234e56 ); =item C Not implemented. C is C-specific, use EE and regular expressions instead. =item C Not implemented. Use method C instead, or see L. =item C Not implemented. Use method C instead, or seek L. =item C Get file status. This uses file descriptors such as those obtained by calling C. The data returned is identical to the data from Perl's builtin C function. $fd = POSIX::open( "foo", &POSIX::O_RDONLY ); @stats = POSIX::fstat( $fd ); =item C Not implemented. Use method C instead. =item C Not implemented. Use method C instead, or see L. =item C Not implemented. C is C-specific, see L instead. =item C This is identical to Perl's builtin C function, see L. =item C Returns one character from STDIN. Identical to Perl's C, see L. =item C Returns the name of the current working directory. See also L. =item C Returns the effective group identifier. Similar to Perl' s builtin variable C<$(>, see L. =item C Returns the value of the specified environment variable. The same information is available through the C<%ENV> array. =item C Returns the effective user identifier. Identical to Perl's builtin C<$E> variable, see L. =item C Returns the user's real group identifier. Similar to Perl's builtin variable C<$)>, see L. =item C This is identical to Perl's builtin C function for returning group entries by group identifiers, see L. =item C This is identical to Perl's builtin C function for returning group entries by group names, see L. =item C Returns the ids of the user's supplementary groups. Similar to Perl's builtin variable C<$)>, see L. =item C This is identical to Perl's builtin C function for returning the user name associated with the current session, see L. =item C use POSIX ':nan_payload'; getpayload($var) Returns the C payload. Note the API instability warning in L. See L for more discussion about C. =item C This is identical to Perl's builtin C function for returning the process group identifier of the current process, see L. =item C Returns the process identifier. Identical to Perl's builtin variable C<$$>, see L. =item C This is identical to Perl's builtin C function for returning the process identifier of the parent process of the current process , see L. =item C This is identical to Perl's builtin C function for returning user entries by user names, see L. =item C This is identical to Perl's builtin C function for returning user entries by user identifiers, see L. =item C Returns one line from C, similar to EE, also known as the C function, see L. B: if you have C programs that still use C, be very afraid. The C function is a source of endless grief because it has no buffer overrun checks. It should B be used. The C function should be preferred instead. =item C Returns the user's identifier. Identical to Perl's builtin C<$E> variable, see L. =item C This is identical to Perl's builtin C function for converting seconds since the epoch to a date in Greenwich Mean Time, see L. =item C Equivalent to C> except more stable on very large or very small arguments [C99]. =item C Integer binary logarithm [C99] For example C is 4, as an integer. See also L. =item C The infinity as a constant: use POSIX qw(Inf); my $pos_inf = +Inf; # Or just Inf. my $neg_inf = -Inf; See also L, and L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C Returns a boolean indicating whether the specified filehandle is connected to a tty. Similar to the C<-t> operator, see L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C Returns true if the argument is a finite number (that is, not an infinity, or the not-a-number) [C99]. See also L, L, and L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C (Also C, C, C, C, C) Floating point comparisons which handle the C [C99]. =item C Returns true if the argument is an infinity (positive or negative) [C99]. See also L, L, L, and L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C Returns true if the argument is C (not-a-number) [C99]. Note that you cannot test for "C-ness" with $x == $x since the C is not equivalent to anything, B. See also L, L, L, and L. =item C Returns true if the argument is normal (that is, not a subnormal/denormal, and not an infinity, or a not-a-number) [C99]. See also L, and L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C use POSIX ':nan_payload'; issignaling($var, $payload) Return true if the argument is a I NaN. Note the API instability warning in L. See L for more discussion about C. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C This function has been removed as of v5.24. It was very similar to matching against S>, which you should convert to use instead. See L. =item C =item C =item C =item C =item C =item C The Bessel function of the first kind of the order zero. =item C This is identical to Perl's builtin C function for sending signals to processes (often to terminate them), see L. =item C Not implemented. (For returning absolute values of long integers.) C is C-specific, see L instead. =item C This is identical to the C function, except the order of arguments is consistent with Perl's builtin C with the added restriction of only one path, not a list of paths. Does the same thing as the C function but changes the owner of a symbolic link instead of the file the symbolic link points to. POSIX::lchown($uid, $gid, $file_path); =item C This is identical to the C function C for multiplying floating point numbers with powers of two. $x_quadrupled = POSIX::ldexp($x, 2); =item C Not implemented. (For computing dividends of long integers.) C is C-specific, use C and C instead. =item C The logarithm of the Gamma function [C99]. See also L. =item C Equivalent to S>, but more stable results for small argument values [C99]. =item C Logarithm base two [C99]. See also L. =item C Integer binary logarithm [C99]. For example C is 4, as a floating point number. See also L. =item C This is identical to Perl's builtin C function for creating hard links into files, see L. =item C Get numeric formatting information. Returns a reference to a hash containing the current underlying locale's formatting values. Users of this function should also read L, which provides a comprehensive discussion of Perl locale handling, including L. Prior to Perl 5.28, or when operating in a non thread-safe environment, it should not be used in a threaded application unless it's certain that the underlying locale is C or POSIX. This is because it otherwise changes the locale, which globally affects all threads simultaneously. Windows platforms starting with Visual Studio 2005 are mostly thread-safe, but use of this function in those prior to Visual Studio 2015 can interefere with a thread that has called L. Here is how to query the database for the B (Deutsch or German) locale. my $loc = POSIX::setlocale( &POSIX::LC_ALL, "de" ); print "Locale: \"$loc\"\n"; my $lconv = POSIX::localeconv(); foreach my $property (qw( decimal_point thousands_sep grouping int_curr_symbol currency_symbol mon_decimal_point mon_thousands_sep mon_grouping positive_sign negative_sign int_frac_digits frac_digits p_cs_precedes p_sep_by_space n_cs_precedes n_sep_by_space p_sign_posn n_sign_posn int_p_cs_precedes int_p_sep_by_space int_n_cs_precedes int_n_sep_by_space int_p_sign_posn int_n_sign_posn )) { printf qq(%s: "%s",\n), $property, $lconv->{$property}; } The members whose names begin with C and C were added by POSIX.1-2008 and are only available on systems that support them. =item C This is identical to Perl's builtin C function for converting seconds since the epoch to a date see L except that C must be provided an explicit value (rather than relying on an implicit C<$_>): @localtime = POSIX::localtime(time); # good @localtime = localtime(); # good @localtime = POSIX::localtime(); # throws exception =item C This is identical to Perl's builtin C function, returning the natural (I-based) logarithm of the numerical argument, see L. =item C This is identical to the C function C, returning the 10-base logarithm of the numerical argument. You can also use sub log10 { log($_[0]) / log(10) } or sub log10 { log($_[0]) / 2.30258509299405 } or sub log10 { log($_[0]) * 0.434294481903252 } =item C Not implemented. C is C-specific: use L instead. =item C Move the file's read/write position. This uses file descriptors such as those obtained by calling C. $fd = POSIX::open( "foo", &POSIX::O_RDONLY ); $off_t = POSIX::lseek( $fd, 0, &POSIX::SEEK_SET ); Returns C on failure. =item C Depending on the current floating point rounding mode, rounds the argument either toward nearest (like L), toward zero (like L), downward (toward negative infinity), or upward (toward positive infinity) [C99]. For the rounding mode, see L. =item C Like L, but as integer, as opposed to floating point [C99]. See also L, L, L. Owing to an oversight, this is not currently exported by default, or as part of the C<:math_h_c99> export tag; importing it must therefore be done by explicit name. =item C Not implemented. C is C-specific. Perl does memory management transparently. =item C This is identical to the C function C. Core Perl does not have any support for the wide and multibyte characters of the C standards, except under UTF-8 locales, so this might be a rather useless function. However, Perl supports Unicode, see L. =item C This is identical to the C function C. See L. =item C This is identical to the C function C. See L. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, use C instead, see L. =item C Not implemented. C is C-specific, use C<=>, see L, or see L. =item C Not implemented. C is C-specific, use C<=>, see L, or see L. =item C Not implemented. C is C-specific, use C instead, see L. =item C This is identical to Perl's builtin C function for creating directories, see L. =item C This is similar to the C function C for creating FIFO special files. if (mkfifo($path, $mode)) { .... Returns C on failure. The C<$mode> is similar to the mode of C, see L, though for C you B specify the C<$mode>. =item C Convert date/time info to a calendar time. Synopsis: mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1) The month (C), weekday (C), and yearday (C) begin at zero, I, January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The year (C) is given in years since 1900; I, the year 1995 is 95; the year 2001 is 101. Consult your system's C manpage for details about these and the other arguments. Calendar time for December 12, 1995, at 10:30 am. $time_t = POSIX::mktime( 0, 30, 10, 12, 11, 95 ); print "Date = ", POSIX::ctime($time_t); Returns C on failure. =item C Return the integral and fractional parts of a floating-point number. ($fractional, $integral) = POSIX::modf( 3.14 ); See also L. =item C The not-a-number as a constant: use POSIX qw(NaN); my $nan = NaN; See also L, C, and L. =item C my $nan = nan(); Returns C, not-a-number [C99]. The returned NaN is always a I NaN, as opposed to I. With an argument, can be used to generate a NaN with I. The argument is first interpreted as a floating point number, but then any fractional parts are truncated (towards zero), and the value is interpreted as an unsigned integer. The bits of this integer are stored in the unused bits of the NaN. The result has a dual nature: it is a NaN, but it also carries the integer inside it. The integer can be retrieved with L. Note, though, that the payload is not propagated, not even on copies, and definitely not in arithmetic operations. How many bits fit in the NaN depends on what kind of floating points are being used, but on the most common platforms (64-bit IEEE 754, or the x86 80-bit long doubles) there are 51 and 61 bits available, respectively. (There would be 52 and 62, but the quiet/signaling bit of NaNs takes away one.) However, because of the floating-point-to- integer-and-back conversions, please test carefully whether you get back what you put in. If your integers are only 32 bits wide, you probably should not rely on more than 32 bits of payload. Whether a "signaling" NaN is in any way different from a "quiet" NaN, depends on the platform. Also note that the payload of the default NaN (no argument to nan()) is not necessarily zero, use C to explicitly set the payload. On some platforms like the 32-bit x86, (unless using the 80-bit long doubles) the signaling bit is not supported at all. See also L, L, L and L. =item C Returns the nearest integer to the argument, according to the current rounding mode (see L) [C99]. =item C Returns the next representable floating point number after C in the direction of C [C99]. my $nextafter = POSIX::nextafter($x, $y); Like L, but potentially less accurate. =item C Returns the next representable floating point number after C in the direction of C [C99]. my $nexttoward = POSIX::nexttoward($x, $y); Like L, but potentially more accurate. =item C This is similar to the C function C, for changing the scheduling preference of the current process. Positive arguments mean a more polite process, negative values a more needy process. Normal (non-root) user processes can only change towards being more polite. Returns C on failure. =item C Not implemented. C is C-specific, you probably want to see L instead. =item C Open a file for reading for writing. This returns file descriptors, not Perl filehandles. Use C to close the file. Open a file read-only with mode 0666. $fd = POSIX::open( "foo" ); Open a file for read and write. $fd = POSIX::open( "foo", &POSIX::O_RDWR ); Open a file for write, with truncation. $fd = POSIX::open( "foo", &POSIX::O_WRONLY | &POSIX::O_TRUNC ); Create a new file with mode 0640. Set up the file for writing. $fd = POSIX::open( "foo", &POSIX::O_CREAT | &POSIX::O_WRONLY, 0640 ); Returns C on failure. See also L. =item C Open a directory for reading. $dir = POSIX::opendir( "/var" ); @files = POSIX::readdir( $dir ); POSIX::closedir( $dir ); Returns C on failure. =item C Retrieves the value of a configurable limit on a file or directory. The following will determine the maximum length of the longest allowable pathname on the filesystem which holds C. $path_max = POSIX::pathconf( "/var", &POSIX::_PC_PATH_MAX ); Returns C on failure. =item C This is similar to the C function C, which suspends the execution of the current process until a signal is received. Returns C on failure. =item C This is identical to the C function C, which outputs to the standard error stream the specified message followed by C<": "> and the current error string. Use the C function and the C<$!> variable instead, see L and L. =item C Create an interprocess channel. This returns file descriptors like those returned by C. my ($read, $write) = POSIX::pipe(); POSIX::write( $write, "hello", 5 ); POSIX::read( $read, $buf, 5 ); See also L. =item C Computes C<$x> raised to the power C<$exponent>. $ret = POSIX::pow( $x, $exponent ); You can also use the C<**> operator, see L. =item C Formats and prints the specified arguments to C. See also L. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, see L instead. =item C Sends the specified signal to the current process. See also L and the C<$$> in L. =item C Not implemented. C is non-portable, see L instead. =item C Read from a file. This uses file descriptors such as those obtained by calling C. If the buffer C<$buf> is not large enough for the read then Perl will extend it to make room for the request. $fd = POSIX::open( "foo", &POSIX::O_RDONLY ); $bytes = POSIX::read( $fd, $buf, 3 ); Returns C on failure. See also L. =item C This is identical to Perl's builtin C function for reading directory entries, see L. =item C Not implemented. C is C-specific. Perl does memory management transparently. =item C Given C and C, returns the value S>, where C is the integer closest to C/C. [C99] my $remainder = POSIX::remainder($x, $y) See also L. =item C Deletes a name from the filesystem. Calls L for files and L for directories. =item C Like L but also returns the low-order bits of the quotient (n) [C99] (This is quite esoteric interface, mainly used to implement numerical algorithms.) =item C This is identical to Perl's builtin C function for renaming files, see L. =item C Seeks to the beginning of the file. =item C This is identical to Perl's builtin C function for rewinding directory entry streams, see L. =item C Identical to L. =item C This is identical to Perl's builtin C function for removing (empty) directories, see L. =item C Returns the integer (but still as floating point) nearest to the argument [C99]. See also L, L, L, L, and L. =item C Returns S> [C99]. See also L and L. =item C Not implemented. C is C-specific, use EE and regular expressions instead, see L. =item C Sets the real group identifier and the effective group identifier for this process. Similar to assigning a value to the Perl's builtin C<$)> variable, see L, except that the latter will change only the real user identifier, and that the setgid() uses only a single numeric argument, as opposed to a space-separated list of numbers. =item C Not implemented. C is C-specific: use C instead, see L. =item C WARNING! Do NOT use this function in a L. The locale will change in all other threads at the same time, and should your thread get paused by the operating system, and another started, that thread will not have the locale it is expecting. On some platforms, there can be a race leading to segfaults if two threads call this function nearly simultaneously. Modifies and queries the program's underlying locale. Users of this function should read L, whch provides a comprehensive discussion of Perl locale handling, knowledge of which is necessary to properly use this function. It contains L. The discussion here is merely a summary reference for C. Note that Perl itself is almost entirely unaffected by the locale except within the scope of S>. (Exceptions are listed in L.) The following examples assume use POSIX qw(setlocale LC_ALL LC_CTYPE); has been issued. The following will set the traditional UNIX system locale behavior (the second argument C<"C">). $loc = setlocale( LC_ALL, "C" ); The following will query the current C category. (No second argument means 'query'.) $loc = setlocale( LC_CTYPE ); The following will set the C behaviour according to the locale environment variables (the second argument C<"">). Please see your system's C documentation for the locale environment variables' meaning or consult L. $loc = setlocale( LC_CTYPE, "" ); The following will set the C behaviour to Argentinian Spanish. B: The naming and availability of locales depends on your operating system. Please consult L for how to find out which locales are available in your system. $loc = setlocale( LC_COLLATE, "es_AR.ISO8859-1" ); =item C use POSIX ':nan_payload'; setpayload($var, $payload); Sets the C payload of var. NOTE: the NaN payload APIs are based on the latest (as of June 2015) proposed ISO C interfaces, but they are not yet a standard. Things may change. See L for more discussion about C. See also L, L, L, and L. =item C use POSIX ':nan_payload'; setpayloadsig($var, $payload); Like L but also makes the NaN I. Depending on the platform the NaN may or may not behave differently. Note the API instability warning in L. Note that because how the floating point formats work out, on the most common platforms signaling payload of zero is best avoided, since it might end up being identical to C<+Inf>. See also L, L, L, and L. =item C This is similar to the C function C for setting the process group identifier of the current process. Returns C on failure. =item C This is identical to the C function C for setting the session identifier of the current process. =item C Sets the real user identifier and the effective user identifier for this process. Similar to assigning a value to the Perl's builtin C<$E> variable, see L, except that the latter will change only the real user identifier. =item C Detailed signal management. This uses C objects for the C and C arguments (the oldaction can also be just a hash reference). Consult your system's C manpage for details, see also C. Synopsis: sigaction(signal, action, oldaction = 0) Returns C on failure. The C must be a number (like C), not a string (like C<"SIGHUP">), though Perl does try hard to understand you. If you use the C flag, the signal handler will in addition to the first argument, the signal name, also receive a second argument, a hash reference, inside which are the following keys with the following semantics, as defined by POSIX/SUSv3: signo the signal number errno the error number code if this is zero or less, the signal was sent by a user process and the uid and pid make sense, otherwise the signal was sent by the kernel The constants for specific C values can be imported individually or using the C<:signal_h_si_code> tag. The following are also defined by POSIX/SUSv3, but unfortunately not very widely implemented: pid the process id generating the signal uid the uid of the process id generating the signal status exit value or signal for SIGCHLD band band event for SIGPOLL addr address of faulting instruction or memory reference for SIGILL, SIGFPE, SIGSEGV or SIGBUS A third argument is also passed to the handler, which contains a copy of the raw binary contents of the C structure: if a system has some non-POSIX fields, this third argument is where to C them from. Note that not all C values make sense simultaneously (some are valid only for certain signals, for example), and not all values make sense from Perl perspective, you should to consult your system's C and possibly also C documentation. =item C Not implemented. C is C-specific: use L instead. =item C Returns zero for positive arguments, non-zero for negative arguments [C99]. =item C Examine signals that are blocked and pending. This uses C objects for the C argument. Consult your system's C manpage for details. Synopsis: sigpending(sigset) Returns C on failure. =item C Change and/or examine calling process's signal mask. This uses C objects for the C and C arguments. Consult your system's C manpage for details. Synopsis: sigprocmask(how, sigset, oldsigset = 0) Returns C on failure. Note that you can't reliably block or unblock a signal from its own signal handler if you're using safe signals. Other signals can be blocked or unblocked reliably. =item C Not implemented. C is C-specific: use C instead, see L. =item C Install a signal mask and suspend process until signal arrives. This uses C objects for the C argument. Consult your system's C manpage for details. Synopsis: sigsuspend(signal_mask) Returns C on failure. =item C This is identical to Perl's builtin C function for returning the sine of the numerical argument, see L. See also L. =item C This is identical to the C function C for returning the hyperbolic sine of the numerical argument. See also L. =item C This is functionally identical to Perl's builtin C function for suspending the execution of the current for process for certain number of seconds, see L. There is one significant difference, however: C returns the number of B seconds, while the C returns the number of slept seconds. =item C This is similar to Perl's builtin C function for returning a string that has the arguments formatted as requested, see L. =item C This is identical to Perl's builtin C function. for returning the square root of the numerical argument, see L. =item C Give a seed the pseudorandom number generator, see L. =item C Not implemented. C is C-specific, use regular expressions instead, see L. =item C This is identical to Perl's builtin C function for returning information about files and directories. =item C Not implemented. C is C-specific, use C<.=> instead, see L. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, use C or C instead, see L. =item C This is identical to the C function C for collating (comparing) strings transformed using the C function. Not really needed since Perl can do this transparently, see L. Beware that in a UTF-8 locale, anything you pass to this function must be in UTF-8; and when not in a UTF-8 locale, anything passed must not be UTF-8 encoded. =item C Not implemented. C is C-specific, use C<=> instead, see L. =item C Not implemented. C is C-specific, use regular expressions instead, see L. =item C Returns the error string for the specified errno. Identical to the string form of C<$!>, see L. =item C Convert date and time information to string. Returns the string. Synopsis: strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) The month (C), weekday (C), and yearday (C) begin at zero, I, January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The year (C) is given in years since 1900, I, the year 1995 is 95; the year 2001 is 101. Consult your system's C manpage for details about these and the other arguments. If you want your code to be portable, your format (C) argument should use only the conversion specifiers defined by the ANSI C standard (C89, to play safe). These are C. But even then, the B of some of the conversion specifiers are non-portable. For example, the specifiers C change according to the locale settings of the user, and both how to set locales (the locale names) and what output to expect are non-standard. The specifier C changes according to the timezone settings of the user and the timezone computation rules of the operating system. The C specifier is notoriously unportable since the names of timezones are non-standard. Sticking to the numeric specifiers is the safest route. The given arguments are made consistent as though by calling C before calling your system's C function, except that the C value is not affected. The string for Tuesday, December 12, 1995. $str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0, 12, 11, 95, 2 ); print "$str\n"; =item C Not implemented. C is C-specific, use C instead, see L. =item C Not implemented. C is C-specific, use C<.=> instead, see L. =item C Not implemented. C is C-specific, use C instead, see L. =item C Not implemented. C is C-specific, use C<=> instead, see L. =item C Not implemented. C is C-specific, use regular expressions instead, see L. =item C Not implemented. C is C-specific, see L instead. =item C Not implemented. C is C-specific, use regular expressions instead, see L. =item C This is identical to Perl's builtin C function, see L. =item C String to double translation. Returns the parsed number and the number of characters in the unparsed portion of the string. Truly POSIX-compliant systems set C<$!> (C<$ERRNO>) to indicate a translation error, so clear C<$!> before calling C. However, non-POSIX systems may not check for overflow, and therefore will never set C<$!>. C respects any POSIX C C settings, regardless of whether or not it is called from Perl code that is within the scope of S>. This means it should not be used in a threaded application unless it's certain that the underlying locale is C or POSIX. This is because it otherwise changes the locale, which globally affects all threads simultaneously. To parse a string C<$str> as a floating point number use $! = 0; ($num, $n_unparsed) = POSIX::strtod($str); The second returned item and C<$!> can be used to check for valid input: if (($str eq '') || ($n_unparsed != 0) || $!) { die "Non-numeric input $str" . ($! ? ": $!\n" : "\n"); } When called in a scalar context C returns the parsed number. =item C Not implemented. C is C-specific, use regular expressions instead, see L, or L. =item C String to (long) integer translation. Returns the parsed number and the number of characters in the unparsed portion of the string. Truly POSIX-compliant systems set C<$!> (C<$ERRNO>) to indicate a translation error, so clear C<$!> before calling C. However, non-POSIX systems may not check for overflow, and therefore will never set C<$!>. C should respect any POSIX I settings. To parse a string C<$str> as a number in some base C<$base> use $! = 0; ($num, $n_unparsed) = POSIX::strtol($str, $base); The base should be zero or between 2 and 36, inclusive. When the base is zero or omitted C will use the string itself to determine the base: a leading "0x" or "0X" means hexadecimal; a leading "0" means octal; any other leading characters mean decimal. Thus, "1234" is parsed as a decimal number, "01234" as an octal number, and "0x1234" as a hexadecimal number. The second returned item and C<$!> can be used to check for valid input: if (($str eq '') || ($n_unparsed != 0) || !$!) { die "Non-numeric input $str" . $! ? ": $!\n" : "\n"; } When called in a scalar context C returns the parsed number. =item C Like L but for long doubles. Defined only if the system supports long doubles. =item C String to unsigned (long) integer translation. C is identical to C except that C only parses unsigned integers. See L for details. Note: Some vendors supply C and C but not C. Other vendors that do supply C parse "-1" as a valid value. =item C String transformation. Returns the transformed string. $dst = POSIX::strxfrm( $src ); Used in conjunction with the C function, see L. Not really needed since Perl can do this transparently, see L. Beware that in a UTF-8 locale, anything you pass to this function must be in UTF-8; and when not in a UTF-8 locale, anything passed must not be UTF-8 encoded. =item C Retrieves values of system configurable variables. The following will get the machine's clock speed. $clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK ); Returns C on failure. =item C This is identical to Perl's builtin C function, see L. =item C This is identical to the C function C, returning the tangent of the numerical argument. See also L. =item C This is identical to the C function C, returning the hyperbolic tangent of the numerical argument. See also L. =item C This is similar to the C function C for draining the output queue of its argument stream. Returns C on failure. =item C This is similar to the C function C for controlling the flow of its argument stream. Returns C on failure. =item C This is similar to the C function C for flushing the I/O buffers of its argument stream. Returns C on failure. =item C This is identical to the C function C for returning the process group identifier of the foreground process group of the controlling terminal. =item C This is similar to the C function C for sending a break on its argument stream. Returns C on failure. =item C This is similar to the C function C for setting the process group identifier of the foreground process group of the controlling terminal. Returns C on failure. =item C The Gamma function [C99]. See also L. =item C