3 POSIX - Perl interface to IEEE Std 1003.1
7 The POSIX module permits you to access all (or nearly all) the standard
8 POSIX 1003.1 identifiers. Many of these identifiers have been given Perl-ish
9 interfaces. Things which are C<#defines> in C, like EINTR or O_NDELAY, are
10 automatically exported into your namespace. All functions are only exported
11 if you ask for them explicitly. Most likely people will prefer to use the
12 fully-qualified function names.
14 This document gives a condensed list of the features available in the POSIX
15 module. Consult your operating system's manpages for general information on
16 most features. Consult L<perlfunc> for functions which are noted as being
17 identical to Perl's builtin functions.
19 The first section describes POSIX functions from the 1003.1 specification.
20 The second section describes some classes for signal objects, TTY objects,
21 and other miscellaneous objects. The remaining sections list various
22 constants and macros in an organization which roughly follows IEEE Std
27 printf "EINTR is %d\n", EINTR;
29 $sess_id = POSIX::setsid();
31 $fd = POSIX::open($path, O_CREAT|O_EXCL|O_WRONLY, 0644);
32 # note: that's a filedescriptor, *NOT* a filehandle
36 The POSIX module is probably the most complex Perl module supplied with
37 the standard distribution. It incorporates autoloading, namespace games,
38 and dynamic loading of code that's in Perl, C, or both. It's a great
43 A few functions are not implemented because they are C specific. If you
44 attempt to call these, they will print a message telling you that they
45 aren't implemented, and suggest using the Perl equivalent should one
46 exist. For example, trying to access the setjmp() call will elicit the
47 message "setjmp() is C-specific: use eval {} instead".
49 Furthermore, some evil vendors will claim 1003.1 compliance, but in fact
50 are not so: they will not pass the PCTS (POSIX Compliance Test Suites).
51 For example, one vendor may not define EDEADLK, or the semantics of the
52 errno values set by open(2) might not be quite right. Perl does not
53 attempt to verify POSIX compliance. That means you can currently
54 successfully say "use POSIX", and then later in your program you find
55 that your vendor has been lax and there's no usable ICANON macro after
56 all. This could be construed to be a bug.
64 This is identical to the C function C<_exit()>.
68 This is identical to the C function C<abort()>.
72 This is identical to Perl's builtin C<abs()> function.
76 Determines the accessibility of a file.
78 if( POSIX::access( "/", &POSIX::R_OK ) ){
79 print "have read permission\n";
82 Returns C<undef> on failure.
86 This is identical to the C function C<acos()>.
90 This is identical to Perl's builtin C<alarm()> function.
94 This is identical to the C function C<asctime()>.
98 This is identical to the C function C<asin()>.
105 This is identical to the C function C<atan()>.
109 This is identical to Perl's builtin C<atan2()> function.
113 atexit() is C-specific: use END {} instead.
117 atof() is C-specific.
121 atoi() is C-specific.
125 atol() is C-specific.
129 bsearch() not supplied.
133 calloc() is C-specific.
137 This is identical to the C function C<ceil()>.
141 This is identical to Perl's builtin C<chdir()> function.
145 This is identical to Perl's builtin C<chmod()> function.
149 This is identical to Perl's builtin C<chown()> function.
153 Use method C<FileHandle::clearerr()> instead.
157 This is identical to the C function C<clock()>.
162 Returns C<undef> on failure.
166 This is identical to Perl's builtin C<closedir()> function.
170 This is identical to Perl's builtin C<cos()> function.
174 This is identical to the C function C<cosh()>.
181 Generates the path name for controlling terminal.
183 $path = POSIX::ctermid();
187 This is identical to the C function C<ctime()>.
191 Get the character login name of the user.
193 $name = POSIX::cuserid();
197 This is identical to the C function C<difftime()>.
206 Returns C<undef> on failure.
211 Returns C<undef> on failure.
215 Returns the value of errno.
217 $errno = POSIX::errno();
221 execl() is C-specific.
225 execle() is C-specific.
229 execlp() is C-specific.
233 execv() is C-specific.
237 execve() is C-specific.
241 execvp() is C-specific.
245 This is identical to Perl's builtin C<exit()> function.
249 This is identical to Perl's builtin C<exp()> function.
253 This is identical to Perl's builtin C<abs()> function.
257 Use method C<FileHandle::close()> instead.
261 This is identical to Perl's builtin C<fcntl()> function.
265 Use method C<FileHandle::new_from_fd()> instead.
269 Use method C<FileHandle::eof()> instead.
273 Use method C<FileHandle::error()> instead.
277 Use method C<FileHandle::flush()> instead.
281 Use method C<FileHandle::getc()> instead.
285 Use method C<FileHandle::getpos()> instead.
289 Use method C<FileHandle::gets()> instead.
293 Use method C<FileHandle::fileno()> instead.
297 This is identical to the C function C<floor()>.
301 This is identical to the C function C<fmod()>.
305 Use method C<FileHandle::open()> instead.
309 This is identical to Perl's builtin C<fork()> function.
314 Returns C<undef> on failure.
318 fprintf() is C-specific--use printf instead.
322 fputc() is C-specific--use print instead.
326 fputs() is C-specific--use print instead.
330 fread() is C-specific--use read instead.
334 free() is C-specific.
338 freopen() is C-specific--use open instead.
345 fscanf() is C-specific--use <> and regular expressions instead.
349 Use method C<FileHandle::seek()> instead.
353 Use method C<FileHandle::setpos()> instead.
360 Use method C<FileHandle::tell()> instead.
364 fwrite() is C-specific--use print instead.
368 This is identical to Perl's builtin C<getc()> function.
372 Returns one character from STDIN.
376 Returns the name of the current working directory.
380 Returns the effective group id.
384 Returns the value of the specified enironment variable.
388 Returns the effective user id.
392 Returns the user's real group id.
396 This is identical to Perl's builtin C<getgrgid()> function.
400 This is identical to Perl's builtin C<getgrnam()> function.
404 Returns the ids of the user's supplementary groups.
408 This is identical to Perl's builtin C<getlogin()> function.
412 This is identical to Perl's builtin C<getpgrp()> function.
416 Returns the process's id.
420 This is identical to Perl's builtin C<getppid()> function.
424 This is identical to Perl's builtin C<getpwnam()> function.
428 This is identical to Perl's builtin C<getpwuid()> function.
432 Returns one line from STDIN.
436 Returns the user's id.
440 This is identical to Perl's builtin C<gmtime()> function.
450 Returns a boolean indicating whether the specified filehandle is connected
482 This is identical to Perl's builtin C<kill()> function.
486 labs() is C-specific, use abs instead.
490 This is identical to the C function C<ldexp()>.
494 ldiv() is C-specific, use / and int instead.
498 This is identical to Perl's builtin C<link()> function.
505 This is identical to Perl's builtin C<localtime()> function.
509 This is identical to Perl's builtin C<log()> function.
513 This is identical to the C function C<log10()>.
517 longjmp() is C-specific: use die instead.
522 Returns C<undef> on failure.
526 malloc() is C-specific.
539 memchr() is C-specific, use index() instead.
543 memcmp() is C-specific, use eq instead.
547 memcpy() is C-specific, use = instead.
551 memmove() is C-specific, use = instead.
555 memset() is C-specific, use x instead.
559 This is identical to Perl's builtin C<mkdir()> function.
564 Returns C<undef> on failure.
569 Returns C<undef> on failure.
577 Returns C<undef> on failure.
581 offsetof() is C-specific.
586 Returns C<undef> on failure.
593 Retrieves the value of a configurable limit on a file or directory.
595 The following will determine the maximum length of the longest allowable
596 pathname on the filesystem which holds C</tmp>.
598 $path_max = POSIX::pathconf( "/tmp", &POSIX::_PC_PATH_MAX );
600 Returns C<undef> on failure.
604 This is similar to the C function C<pause()>.
606 Returns C<undef> on failure.
610 This is identical to the C function C<perror()>.
617 Computes $x raised to the power $exponent.
619 $ret = POSIX::pow( $x, $exponent );
623 Prints the specified arguments to STDOUT.
627 putc() is C-specific--use print instead.
631 putchar() is C-specific--use print instead.
635 puts() is C-specific--use print instead.
639 qsort() is C-specific, use sort instead.
643 Sends the specified signal to the current process.
647 rand() is non-portable, use Perl's rand instead.
652 Returns C<undef> on failure.
656 This is identical to Perl's builtin C<readdir()> function.
660 realloc() is C-specific.
664 This is identical to Perl's builtin C<unlink()> function.
668 This is identical to Perl's builtin C<rename()> function.
672 Seeks to the beginning of the file.
676 This is identical to Perl's builtin C<rewinddir()> function.
680 This is identical to Perl's builtin C<rmdir()> function.
684 scanf() is C-specific--use <> and regular expressions instead.
688 Sets the real group id for this process.
692 setjmp() is C-specific: use eval {} instead.
696 Modifies and queries program's locale.
698 The following will set the traditional UNIX system locale behavior.
700 $loc = POSIX::setlocale( &POSIX::LC_ALL, "C" );
705 Returns C<undef> on failure.
709 This is identical to the C function C<setsid()>.
713 Sets the real user id for this process.
718 Returns C<undef> on failure.
722 siglongjmp() is C-specific: use die instead.
727 Returns C<undef> on failure.
732 Returns C<undef> on failure.
736 sigsetjmp() is C-specific: use eval {} instead.
741 Returns C<undef> on failure.
745 This is identical to Perl's builtin C<sin()> function.
749 This is identical to the C function C<sinh()>.
753 This is identical to Perl's builtin C<sleep()> function.
760 This is identical to Perl's builtin C<sqrt()> function.
768 sscanf() is C-specific--use regular expressions instead.
772 This is identical to Perl's builtin C<stat()> function.
776 strcat() is C-specific, use .= instead.
780 strchr() is C-specific, use index() instead.
784 strcmp() is C-specific, use eq instead.
788 This is identical to the C function C<strcoll()>.
792 strcpy() is C-specific, use = instead.
796 strcspn() is C-specific, use regular expressions instead.
800 Returns the error string for the specified errno.
807 strlen() is C-specific, use length instead.
811 strncat() is C-specific, use .= instead.
815 strncmp() is C-specific, use eq instead.
819 strncpy() is C-specific, use = instead.
823 stroul() is C-specific.
827 strpbrk() is C-specific.
831 strrchr() is C-specific, use rindex() instead.
835 strspn() is C-specific.
839 This is identical to Perl's builtin C<index()> function.
843 strtod() is C-specific.
847 strtok() is C-specific.
851 strtol() is C-specific.
858 Retrieves values of system configurable variables.
860 The following will get the machine's clock speed.
862 $clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK );
864 Returns C<undef> on failure.
868 This is identical to Perl's builtin C<system()> function.
872 This is identical to the C function C<tan()>.
876 This is identical to the C function C<tanh()>.
881 Returns C<undef> on failure.
886 Returns C<undef> on failure.
891 Returns C<undef> on failure.
895 This is identical to the C function C<tcgetpgrp()>.
900 Returns C<undef> on failure.
905 Returns C<undef> on failure.
909 This is identical to Perl's builtin C<time()> function.
913 The times() function returns elapsed realtime since some point in the past
914 (such as system startup), user and system times for this process, and user
915 and system times used by child processes. All times are returned in clock
918 ($realtime, $user, $system, $cuser, $csystem) = POSIX::times();
920 Note: Perl's builtin C<times()> function returns four values, measured in
925 Use method C<FileHandle::new_tmpfile()> instead.
929 Returns a name for a temporary file.
931 $tmpfile = POSIX::tmpnam();
935 This is identical to Perl's builtin C<lc()> function.
939 This is identical to Perl's builtin C<uc()> function.
949 This is identical to the C function C<tzset()>.
953 This is identical to Perl's builtin C<umask()> function.
960 Use method C<FileHandle::ungetc()> instead.
964 This is identical to Perl's builtin C<unlink()> function.
968 This is identical to Perl's builtin C<utime()> function.
972 vfprintf() is C-specific.
976 vprintf() is C-specific.
980 vsprintf() is C-specific.
997 Returns C<undef> on failure.
1028 Returns C<undef> on failure.
1054 Returns C<undef> on failure.
1059 Returns C<undef> on failure.
1069 =head2 POSIX::SigAction
1075 Creates a new SigAction object. This object will be destroyed automatically
1076 when it is no longer needed.
1080 =head2 POSIX::SigSet
1086 Create a new SigSet object. This object will be destroyed automatically
1087 when it is no longer needed. Arguments may be supplied to initialize the
1090 Create an empty set.
1092 $sigset = POSIX::SigSet->new;
1094 Create a set with SIGUSR1.
1096 $sigset = POSIX::SigSet->new( &POSIX::SIGUSR1 );
1100 Add a signal to a SigSet object.
1102 $sigset->addset( &POSIX::SIGUSR2 );
1104 Returns C<undef> on failure.
1108 Remove a signal from the SigSet object.
1110 $sigset->delset( &POSIX::SIGUSR2 );
1112 Returns C<undef> on failure.
1116 Initialize the SigSet object to be empty.
1118 $sigset->emptyset();
1120 Returns C<undef> on failure.
1124 Initialize the SigSet object to include all signals.
1128 Returns C<undef> on failure.
1132 Tests the SigSet object to see if it contains a specific signal.
1134 if( $sigset->ismember( &POSIX::SIGUSR1 ) ){
1135 print "contains SIGUSR1\n";
1140 =head2 POSIX::Termios
1146 Create a new Termios object. This object will be destroyed automatically
1147 when it is no longer needed.
1149 $termios = POSIX::Termios->new;
1154 Returns C<undef> on failure.
1158 Retrieve a value from the c_cc field of a termios object. The c_cc field is
1159 an array so an index must be specified.
1161 $c_cc[1] = $termios->getcc(1);
1165 Retrieve the c_cflag field of a termios object.
1167 $c_cflag = $termios->getcflag;
1171 Retrieve the c_iflag field of a termios object.
1173 $c_iflag = $termios->getiflag;
1177 Retrieve the input baud rate.
1179 $ispeed = $termios->getispeed;
1183 Retrieve the c_lflag field of a termios object.
1185 $c_lflag = $termios->getlflag;
1189 Retrieve the c_oflag field of a termios object.
1191 $c_oflag = $termios->getoflag;
1195 Retrieve the output baud rate.
1197 $ospeed = $termios->getospeed;
1202 Returns C<undef> on failure.
1206 Set a value in the c_cc field of a termios object. The c_cc field is an
1207 array so an index must be specified.
1209 $termios->setcc( 1, &POSIX::VEOF );
1213 Set the c_cflag field of a termios object.
1215 $termios->setcflag( &POSIX::CLOCAL );
1219 Set the c_iflag field of a termios object.
1221 $termios->setiflag( &POSIX::BRKINT );
1225 Set the input baud rate.
1227 $termios->setispeed( &POSIX::B9600 );
1229 Returns C<undef> on failure.
1233 Set the c_lflag field of a termios object.
1235 $termios->setlflag( &POSIX::ECHO );
1239 Set the c_oflag field of a termios object.
1241 $termios->setoflag( &POSIX::OPOST );
1245 Set the output baud rate.
1247 $termios->setospeed( &POSIX::B9600 );
1249 Returns C<undef> on failure.
1251 =item Baud rate values
1253 B38400 B75 B200 B134 B300 B1800 B150 B0 B19200 B1200 B9600 B600 B4800 B50 B2400 B110
1255 =item Terminal interface values
1257 TCSADRAIN TCSANOW TCOON TCIOFLUSH TCOFLUSH TCION TCIFLUSH TCSAFLUSH TCIOFF TCOOFF
1259 =item c_cc field values
1261 VEOF VEOL VERASE VINTR VKILL VQUIT VSUSP VSTART VSTOP VMIN VTIME NCCS
1263 =item c_cflag field values
1265 CLOCAL CREAD CSIZE CS5 CS6 CS7 CS8 CSTOPB HUPCL PARENB PARODD
1267 =item c_iflag field values
1269 BRKINT ICRNL IGNBRK IGNCR IGNPAR INLCR INPCK ISTRIP IXOFF IXON PARMRK
1271 =item c_lflag field values
1273 ECHO ECHOE ECHOK ECHONL ICANON IEXTEN ISIG NOFLSH TOSTOP
1275 =item c_oflag field values
1281 =head1 PATHNAME CONSTANTS
1287 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX _PC_PIPE_BUF _PC_VDISABLE
1291 =head1 POSIX CONSTANTS
1297 _POSIX_ARG_MAX _POSIX_CHILD_MAX _POSIX_CHOWN_RESTRICTED _POSIX_JOB_CONTROL _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_NO_TRUNC _POSIX_OPEN_MAX _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SAVED_IDS _POSIX_SSIZE_MAX _POSIX_STREAM_MAX _POSIX_TZNAME_MAX _POSIX_VDISABLE _POSIX_VERSION
1301 =head1 SYSTEM CONFIGURATION
1307 _SC_ARG_MAX _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
1317 E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOLCK ENOMEM ENOSPC ENOSYS ENOTDIR ENOTEMPTY ENOTTY ENXIO EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV
1327 FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_OK F_RDLCK F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK O_RDONLY O_RDWR O_TRUNC O_WRONLY
1337 DBL_DIG DBL_EPSILON DBL_MANT_DIG DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP FLT_DIG FLT_EPSILON FLT_MANT_DIG FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP FLT_RADIX FLT_ROUNDS LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP
1347 ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
1357 LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME
1377 SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
1387 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU S_ISGID S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
1391 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG
1401 EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX RAND_MAX
1411 BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid L_tmpname TMP_MAX _IOFBF _IOLBF _IONBF
1421 CLK_TCK CLOCKS_PER_SEC
1431 R_OK SEEK_CUR SEEK_END SEEK_SET STDIN_FILENO STDOUT_FILENO STRERR_FILENO W_OK X_OK
1445 WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG WIFSTOPPED WSTOPSIG
1451 This document generated by mkposixman.PL version 951129.