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. Things which are #defines in C, like EINTR or O_NDELAY, are automatically exported into your namespace. All functions are only exported if you ask for them explicitly. Most likely people will prefer to use the fully-qualified function names.

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 perlfunc for functions which are noted as being 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.

NOTE

The POSIX module is probably the most complex Perl module supplied with the standard distribution. It incorporates autoloading, namespace games, and dynamic loading of code that's in Perl, C, or both. It's a great source of wisdom.

CAVEATS

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 setjmp() call will elicit the message "setjmp() is C-specific: use eval {} instead".

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 EDEADLK, or the semantics of the errno values set by open(2) 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 ICANON macro after all. This could be construed to be a bug.

The month (mon), weekday (wday), and yearday (yday) begin at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The year (year) is given in years since 1900. I.e. The year 1995 is 95; the year 2001 is 101. Consult your system's mktime() manpage for details about these and the other arguments.

The following will set the traditional UNIX system locale behavior (the second argument "C").

$loc = POSIX::setlocale( &POSIX::LC_ALL, "C" );

The following will query (the missing second argument) the current LC_CTYPE category.

$loc = POSIX::setlocale( &POSIX::LC_CTYPE);

The following will set the LC_CTYPE behaviour according to the locale environment variables (the second argument ""). Please see your systems setlocale(3) documentation for the locale environment variables' meaning or consult perllocale.

$loc = POSIX::setlocale( &POSIX::LC_CTYPE, "");

The following will set the LC_COLLATE behaviour to Argentinian Spanish. NOTE: The naming and availability of locales depends on your operating system. Please consult perllocale for how to find out which locales are available in your system.

The month (mon), weekday (wday), and yearday (yday) begin at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The year (year) is given in years since 1900. I.e. The year 1995 is 95; the year 2001 is 101. Consult your system's strftime() manpage for details about these and the other arguments.

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 $! ($ERRNO) to indicate a translation error, so clear $! before calling strtod. However, non-POSIX systems may not check for overflow, and therefore will never set $!.

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 $! ($ERRNO) to indicate a translation error, so clear $! before calling strtol. However, non-POSIX systems may not check for overflow, and therefore will never set $!.

strtol should respect any POSIX setlocale() settings.

To parse a string $str as a number in some base $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 strtol 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.

String to unsigned (long) integer translation. strtoul is identical to strtol except that strtoul only parses unsigned integers. See strtol for details.

Note: Some vendors supply strtod and strtol but not strtoul. Other vendors that do suply strtoul parse "-1" as a valid value.

strxfrm

String transformation. Returns the transformed string.

$dst = POSIX::strxfrm( $src );

sysconf

Retrieves values of system configurable variables.

The following will get the machine's clock speed.

$clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK );

Returns undef on failure.

system

This is identical to Perl's builtin system() function.

tan

This is identical to the C function tan().

tanh

This is identical to the C function tanh().

tcdrain

This is similar to the C function tcdrain().

Returns undef on failure.

tcflow

This is similar to the C function tcflow().

Returns undef on failure.

tcflush

This is similar to the C function tcflush().

Returns undef on failure.

tcgetpgrp

This is identical to the C function tcgetpgrp().

tcsendbreak

This is similar to the C function tcsendbreak().

Returns undef on failure.

tcsetpgrp

This is similar to the C function tcsetpgrp().

Returns undef on failure.

time

This is identical to Perl's builtin time() function.

times

The times() function returns elapsed realtime since some point in the past (such as system startup), user and system times for this process, and user and system times used by child processes. All times are returned in clock ticks.

CLASSES

POSIX::SigAction

new

Creates a new POSIX::SigAction object which corresponds to the C struct sigaction. This object will be destroyed automatically when it is no longer needed. The first parameter is the fully-qualified name of a sub which is a signal-handler. The second parameter is a POSIX::SigSet object, it defaults to the empty set. The third parameter contains the sa_flags, it defaults to 0.