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 the perlfunc manpage
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.
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.
-
_exit
-
This is identical to the C function
_exit()
.
-
abort
-
This is identical to the C function
abort()
.
-
abs
-
This is identical to Perl's builtin
abs()
function.
-
access
-
Determines the accessibility of a file.
if( POSIX::access( "/", &POSIX::R_OK ) ){
print "have read permission\n";
}
Returns undef
on failure.
-
acos
-
This is identical to the C function
acos()
.
-
alarm
-
This is identical to Perl's builtin
alarm()
function.
-
asctime
-
This is identical to the C function
asctime()
.
-
asin
-
This is identical to the C function
asin()
.
-
assert
-
Unimplemented.
-
atan
-
This is identical to the C function
atan()
.
-
atan2
-
This is identical to Perl's builtin
atan2()
function.
-
atexit
-
atexit()
is C-specific: use END {} instead.
-
atof
-
atof()
is C-specific.
-
atoi
-
atoi()
is C-specific.
-
atol
-
atol()
is C-specific.
-
bsearch
-
bsearch()
not supplied.
-
calloc
-
calloc()
is C-specific.
-
ceil
-
This is identical to the C function
ceil()
.
-
chdir
-
This is identical to Perl's builtin
chdir()
function.
-
chmod
-
This is identical to Perl's builtin
chmod()
function.
-
chown
-
This is identical to Perl's builtin
chown()
function.
-
clearerr
-
Use method
FileHandle::
clearerr()
instead.
-
clock
-
This is identical to the C function
clock()
.
-
close
-
Close the file. This uses file descriptors such as those obtained by calling
POSIX::open
.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY );
POSIX::close( $fd );
Returns undef
on failure.
-
closedir
-
This is identical to Perl's builtin
closedir()
function.
-
cos
-
This is identical to Perl's builtin
cos()
function.
-
cosh
-
This is identical to the C function
cosh()
.
-
creat
-
Create a new file. This returns a file descriptor like the ones returned by
POSIX::open
. Use POSIX::close
to close the file.
$fd = POSIX::creat( "foo", 0611 );
POSIX::close( $fd );
-
ctermid
-
Generates the path name for the controlling terminal.
$path = POSIX::ctermid();
-
ctime
-
This is identical to the C function
ctime()
.
-
cuserid
-
Get the character login name of the user.
$name = POSIX::cuserid();
-
difftime
-
This is identical to the C function
difftime()
.
-
div
-
div()
is C-specific.
-
dup
-
This is similar to the C function
dup()
.
This uses file descriptors such as those obtained by calling
POSIX::open
.
Returns undef
on failure.
-
dup2
-
This is similar to the C function
dup2()
.
This uses file descriptors such as those obtained by calling
POSIX::open
.
Returns undef
on failure.
-
errno
-
Returns the value of errno.
$errno = POSIX::errno();
-
execl
-
execl()
is C-specific.
-
execle
-
execle()
is C-specific.
-
execlp
-
execlp()
is C-specific.
-
execv
-
execv()
is C-specific.
-
execve
-
execve()
is C-specific.
-
execvp
-
execvp()
is C-specific.
-
exit
-
This is identical to Perl's builtin
exit()
function.
-
exp
-
This is identical to Perl's builtin
exp()
function.
-
fabs
-
This is identical to Perl's builtin
abs()
function.
-
fclose
-
Use method
FileHandle::
close()
instead.
-
fcntl
-
This is identical to Perl's builtin
fcntl()
function.
-
fdopen
-
Use method
FileHandle::
new_from_fd()
instead.
-
feof
-
Use method
FileHandle::
eof()
instead.
-
ferror
-
Use method
FileHandle::
error()
instead.
-
fflush
-
Use method
FileHandle::
flush()
instead.
-
fgetc
-
Use method
FileHandle::
getc()
instead.
-
fgetpos
-
Use method
FileHandle::
getpos()
instead.
-
fgets
-
Use method
FileHandle::
gets()
instead.
-
fileno
-
Use method
FileHandle::
fileno()
instead.
-
floor
-
This is identical to the C function
floor()
.
-
fmod
-
This is identical to the C function
fmod()
.
-
fopen
-
Use method
FileHandle::
open()
instead.
-
fork
-
This is identical to Perl's builtin
fork()
function.
-
fpathconf
-
Retrieves the value of a configurable limit on a file or directory. This
uses file descriptors such as those obtained by calling
POSIX::open
.
The following will determine the maximum length of the longest allowable
pathname on the filesystem which holds /tmp/foo
.
$fd = POSIX::open( "/tmp/foo", &POSIX::O_RDONLY );
$path_max = POSIX::fpathconf( $fd, &POSIX::_PC_PATH_MAX );
Returns undef
on failure.
-
fprintf
-
fprintf()
is C-specific--use printf instead.
-
fputc
-
fputc()
is C-specific--use print instead.
-
fputs
-
fputs()
is C-specific--use print instead.
-
fread
-
fread()
is C-specific--use read instead.
-
free
-
free()
is C-specific.
-
freopen
-
freopen()
is C-specific--use open instead.
-
frexp
-
Return the mantissa and exponent of a floating-point number.
($mantissa, $exponent) = POSIX::frexp( 3.14 );
-
fscanf
-
fscanf()
is C-specific--use <> and regular expressions instead.
-
fseek
-
Use method
FileHandle::
seek()
instead.
-
fsetpos
-
Use method
FileHandle::
setpos()
instead.
-
fstat
-
Get file status. This uses file descriptors such as those obtained by
calling
POSIX::open
. The data returned is identical to the data from
Perl's builtin
stat
function.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY );
@stats = POSIX::fstat( $fd );
-
ftell
-
Use method
FileHandle::
tell()
instead.
-
fwrite
-
fwrite()
is C-specific--use print instead.
-
getc
-
This is identical to Perl's builtin
getc()
function.
-
getchar
-
Returns one character from STDIN.
-
getcwd
-
Returns the name of the current working directory.
-
getegid
-
Returns the effective group id.
-
getenv
-
Returns the value of the specified enironment variable.
-
geteuid
-
Returns the effective user id.
-
getgid
-
Returns the user's real group id.
-
getgrgid
-
This is identical to Perl's builtin
getgrgid()
function.
-
getgrnam
-
This is identical to Perl's builtin
getgrnam()
function.
-
getgroups
-
Returns the ids of the user's supplementary groups.
-
getlogin
-
This is identical to Perl's builtin
getlogin()
function.
-
getpgrp
-
This is identical to Perl's builtin
getpgrp()
function.
-
getpid
-
Returns the process's id.
-
getppid
-
This is identical to Perl's builtin
getppid()
function.
-
getpwnam
-
This is identical to Perl's builtin
getpwnam()
function.
-
getpwuid
-
This is identical to Perl's builtin
getpwuid()
function.
-
gets
-
Returns one line from STDIN.
-
getuid
-
Returns the user's id.
-
gmtime
-
This is identical to Perl's builtin
gmtime()
function.
-
isalnum
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
isalpha
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
isatty
-
Returns a boolean indicating whether the specified filehandle is connected
to a tty.
-
iscntrl
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
isdigit
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
isgraph
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
islower
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
isprint
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
ispunct
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
isspace
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
isupper
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
isxdigit
-
This is identical to the C function, except that it can apply to a single
character or to a whole string.
-
kill
-
This is identical to Perl's builtin
kill()
function.
-
labs
-
labs()
is C-specific, use abs instead.
-
ldexp
-
This is identical to the C function
ldexp()
.
-
ldiv
-
ldiv()
is C-specific, use / and int instead.
-
link
-
This is identical to Perl's builtin
link()
function.
-
localeconv
-
Get numeric formatting information. Returns a reference to a hash
containing the current locale formatting values.
The database for the de (Deutsch or German) locale.
$loc = POSIX::setlocale( &POSIX::LC_ALL, "de" );
print "Locale = $loc\n";
$lconv = POSIX::localeconv();
print "decimal_point = ", $lconv->{decimal_point}, "\n";
print "thousands_sep = ", $lconv->{thousands_sep}, "\n";
print "grouping = ", $lconv->{grouping}, "\n";
print "int_curr_symbol = ", $lconv->{int_curr_symbol}, "\n";
print "currency_symbol = ", $lconv->{currency_symbol}, "\n";
print "mon_decimal_point = ", $lconv->{mon_decimal_point}, "\n";
print "mon_thousands_sep = ", $lconv->{mon_thousands_sep}, "\n";
print "mon_grouping = ", $lconv->{mon_grouping}, "\n";
print "positive_sign = ", $lconv->{positive_sign}, "\n";
print "negative_sign = ", $lconv->{negative_sign}, "\n";
print "int_frac_digits = ", $lconv->{int_frac_digits}, "\n";
print "frac_digits = ", $lconv->{frac_digits}, "\n";
print "p_cs_precedes = ", $lconv->{p_cs_precedes}, "\n";
print "p_sep_by_space = ", $lconv->{p_sep_by_space}, "\n";
print "n_cs_precedes = ", $lconv->{n_cs_precedes}, "\n";
print "n_sep_by_space = ", $lconv->{n_sep_by_space}, "\n";
print "p_sign_posn = ", $lconv->{p_sign_posn}, "\n";
print "n_sign_posn = ", $lconv->{n_sign_posn}, "\n";
-
localtime
-
This is identical to Perl's builtin
localtime()
function.
-
log
-
This is identical to Perl's builtin
log()
function.
-
log10
-
This is identical to the C function
log10()
.
-
longjmp
-
longjmp()
is C-specific: use die instead.
-
lseek
-
Move the read/write file pointer. This uses file descriptors such as
those obtained by calling
POSIX::open
.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY );
$off_t = POSIX::lseek( $fd, 0, &POSIX::SEEK_SET );
Returns undef
on failure.
-
malloc
-
malloc()
is C-specific.
-
mblen
-
This is identical to the C function
mblen()
.
-
mbstowcs
-
This is identical to the C function
mbstowcs()
.
-
mbtowc
-
This is identical to the C function
mbtowc()
.
-
memchr
-
memchr()
is C-specific, use index() instead.
-
memcmp
-
memcmp()
is C-specific, use eq instead.
-
memcpy
-
memcpy()
is C-specific, use = instead.
-
memmove
-
memmove()
is C-specific, use = instead.
-
memset
-
memset()
is C-specific, use x instead.
-
mkdir
-
This is identical to Perl's builtin
mkdir()
function.
-
mkfifo
-
This is similar to the C function
mkfifo()
.
Returns undef
on failure.
-
mktime
-
Convert date/time info to a calendar time.
Synopsis:
mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
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.
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 undef
on failure.
-
modf
-
Return the integral and fractional parts of a floating-point number.
($fractional, $integral) = POSIX::modf( 3.14 );
-
nice
-
This is similar to the C function
nice()
.
Returns undef
on failure.
-
offsetof
-
offsetof()
is C-specific.
-
open
-
Open a file for reading for writing. This returns file descriptors, not
Perl filehandles. Use
POSIX::close
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 undef
on failure.
-
opendir
-
Open a directory for reading.
$dir = POSIX::opendir( "/tmp" );
@files = POSIX::readdir( $dir );
POSIX::closedir( $dir );
Returns undef
on failure.
-
pathconf
-
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 /tmp
.
$path_max = POSIX::pathconf( "/tmp", &POSIX::_PC_PATH_MAX );
Returns undef
on failure.
-
pause
-
This is similar to the C function
pause()
.
Returns undef
on failure.
-
perror
-
This is identical to the C function
perror()
.
-
pipe
-
Create an interprocess channel. This returns file descriptors like those
returned by
POSIX::open
.
($fd0, $fd1) = POSIX::pipe();
POSIX::write( $fd0, "hello", 5 );
POSIX::read( $fd1, $buf, 5 );
-
pow
-
Computes $x raised to the power $exponent.
$ret = POSIX::pow( $x, $exponent );
-
printf
-
Prints the specified arguments to STDOUT.
-
putc
-
putc()
is C-specific--use print instead.
-
putchar
-
putchar()
is C-specific--use print instead.
-
puts
-
puts()
is C-specific--use print instead.
-
qsort
-
qsort()
is C-specific, use sort instead.
-
raise
-
Sends the specified signal to the current process.
-
rand
-
rand()
is non-portable, use Perl's rand instead.
-
read
-
Read from a file. This uses file descriptors such as those obtained by
calling
POSIX::open
. If the buffer $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 undef
on failure.
-
readdir
-
This is identical to Perl's builtin
readdir()
function.
-
realloc
-
realloc()
is C-specific.
-
remove
-
This is identical to Perl's builtin
unlink()
function.
-
rename
-
This is identical to Perl's builtin
rename()
function.
-
rewind
-
Seeks to the beginning of the file.
-
rewinddir
-
This is identical to Perl's builtin
rewinddir()
function.
-
rmdir
-
This is identical to Perl's builtin
rmdir()
function.
-
scanf
-
scanf()
is C-specific--use <> and regular expressions instead.
-
setgid
-
Sets the real group id for this process.
-
setjmp
-
setjmp()
is C-specific: use eval {} instead.
-
setlocale
-
Modifies and queries program's locale.
The following will set the traditional UNIX system locale behavior.
$loc = POSIX::setlocale( &POSIX::LC_ALL, "C" );
-
setpgid
-
This is similar to the C function
setpgid()
.
Returns undef
on failure.
-
setsid
-
This is identical to the C function
setsid()
.
-
setuid
-
Sets the real user id for this process.
-
sigaction
-
Detailed signal management. This uses
POSIX::SigAction
objects for the
action
and oldaction
arguments. Consult your system's
sigaction
manpage for details.
Synopsis:
sigaction(sig, action, oldaction = 0)
Returns undef
on failure.
-
siglongjmp
-
siglongjmp()
is C-specific: use die instead.
-
sigpending
-
Examine signals that are blocked and pending. This uses
POSIX::SigSet
objects for the
sigset
argument. Consult your system's
sigpending
manpage for details.
Synopsis:
sigpending(sigset)
Returns undef
on failure.
-
sigprocmask
-
Change and/or examine calling process's signal mask. This uses
POSIX::SigSet
objects for the
sigset
and oldsigset
arguments.
Consult your system's
sigprocmask
manpage for details.
Synopsis:
sigprocmask(how, sigset, oldsigset = 0)
Returns undef
on failure.
-
sigsetjmp
-
sigsetjmp()
is C-specific: use eval {} instead.
-
sigsuspend
-
Install a signal mask and suspend process until signal arrives. This uses
POSIX::SigSet
objects for the
signal_mask
argument. Consult your
system's
sigsuspend
manpage for details.
Synopsis:
sigsuspend(signal_mask)
Returns undef
on failure.
-
sin
-
This is identical to Perl's builtin
sin()
function.
-
sinh
-
This is identical to the C function
sinh()
.
-
sleep
-
This is identical to Perl's builtin
sleep()
function.
-
sprintf
-
This is identical to Perl's builtin
sprintf()
function.
-
sqrt
-
This is identical to Perl's builtin
sqrt()
function.
-
srand
-
srand()
.
-
sscanf
-
sscanf()
is C-specific--use regular expressions instead.
-
stat
-
This is identical to Perl's builtin
stat()
function.
-
strcat
-
strcat()
is C-specific, use .= instead.
-
strchr
-
strchr()
is C-specific, use index() instead.
-
strcmp
-
strcmp()
is C-specific, use eq instead.
-
strcoll
-
This is identical to the C function
strcoll()
.
-
strcpy
-
strcpy()
is C-specific, use = instead.
-
strcspn
-
strcspn()
is C-specific, use regular expressions instead.
-
strerror
-
Returns the error string for the specified errno.
-
strftime
-
Convert date and time information to string. Returns the string.
Synopsis:
strftime(fmt, sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
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.
The string for Tuesday, December 12, 1995.
$str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0, 12, 11, 95, 2 );
print "$str\n";
-
strlen
-
strlen()
is C-specific, use length instead.
-
strncat
-
strncat()
is C-specific, use .= instead.
-
strncmp
-
strncmp()
is C-specific, use eq instead.
-
strncpy
-
strncpy()
is C-specific, use = instead.
-
stroul
-
stroul()
is C-specific.
-
strpbrk
-
strpbrk()
is C-specific.
-
strrchr
-
strrchr()
is C-specific, use rindex() instead.
-
strspn
-
strspn()
is C-specific.
-
strstr
-
This is identical to Perl's builtin
index()
function.
-
strtod
-
strtod()
is C-specific.
-
strtok
-
strtok()
is C-specific.
-
strtol
-
strtol()
is C-specific.
-
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.
($realtime, $user, $system, $cuser, $csystem) = POSIX::times();
Note: Perl's builtin
times()
function returns four values, measured in
seconds.
-
tmpfile
-
Use method
FileHandle::
new_tmpfile()
instead.
-
tmpnam
-
Returns a name for a temporary file.
$tmpfile = POSIX::tmpnam();
-
tolower
-
This is identical to Perl's builtin
lc()
function.
-
toupper
-
This is identical to Perl's builtin
uc()
function.
-
ttyname
-
This is identical to the C function
ttyname()
.
-
tzname
-
Retrieves the time conversion information from the
tzname
variable.
POSIX::tzset();
($std, $dst) = POSIX::tzname();
-
tzset
-
This is identical to the C function
tzset()
.
-
umask
-
This is identical to Perl's builtin
umask()
function.
-
uname
-
Get name of current operating system.
($sysname, $nodename, $release, $version, $machine ) = POSIX::uname();
-
ungetc
-
Use method
FileHandle::
ungetc()
instead.
-
unlink
-
This is identical to Perl's builtin
unlink()
function.
-
utime
-
This is identical to Perl's builtin
utime()
function.
-
vfprintf
-
vfprintf()
is C-specific.
-
vprintf
-
vprintf()
is C-specific.
-
vsprintf
-
vsprintf()
is C-specific.
-
wait
-
This is identical to Perl's builtin
wait()
function.
-
waitpid
-
Wait for a child process to change state. This is identical to Perl's
builtin
waitpid()
function.
$pid = POSIX::waitpid( -1, &POSIX::WNOHANG );
print "status = ", ($? / 256), "\n";
-
wcstombs
-
This is identical to the C function
wcstombs()
.
-
wctomb
-
This is identical to the C function
wctomb()
.
-
write
-
Write to a file. This uses file descriptors such as those obtained by
calling
POSIX::open
.
$fd = POSIX::open( "foo", &POSIX::O_WRONLY );
$buf = "hello";
$bytes = POSIX::write( $b, $buf, 5 );
Returns undef
on failure.