source: for-distributions/trunk/bin/windows/perl/lib/POSIX.pod@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 54.1 KB
Line 
1=head1 NAME
2
3POSIX - Perl interface to IEEE Std 1003.1
4
5=head1 SYNOPSIS
6
7 use POSIX;
8 use POSIX qw(setsid);
9 use POSIX qw(:errno_h :fcntl_h);
10
11 printf "EINTR is %d\n", EINTR;
12
13 $sess_id = POSIX::setsid();
14
15 $fd = POSIX::open($path, O_CREAT|O_EXCL|O_WRONLY, 0644);
16 # note: that's a filedescriptor, *NOT* a filehandle
17
18=head1 DESCRIPTION
19
20The POSIX module permits you to access all (or nearly all) the standard
21POSIX 1003.1 identifiers. Many of these identifiers have been given Perl-ish
22interfaces.
23
24I<Everything is exported by default> with the exception of any POSIX
25functions with the same name as a built-in Perl function, such as
26C<abs>, C<alarm>, C<rmdir>, C<write>, etc.., which will be exported
27only if you ask for them explicitly. This is an unfortunate backwards
28compatibility feature. You can stop the exporting by saying C<use
29POSIX ()> and then use the fully qualified names (ie. C<POSIX::SEEK_END>).
30
31This document gives a condensed list of the features available in the POSIX
32module. Consult your operating system's manpages for general information on
33most features. Consult L<perlfunc> for functions which are noted as being
34identical to Perl's builtin functions.
35
36The first section describes POSIX functions from the 1003.1 specification.
37The second section describes some classes for signal objects, TTY objects,
38and other miscellaneous objects. The remaining sections list various
39constants and macros in an organization which roughly follows IEEE Std
401003.1b-1993.
41
42=head1 NOTE
43
44The POSIX module is probably the most complex Perl module supplied with
45the standard distribution. It incorporates autoloading, namespace games,
46and dynamic loading of code that's in Perl, C, or both. It's a great
47source of wisdom.
48
49=head1 CAVEATS
50
51A few functions are not implemented because they are C specific. If you
52attempt to call these, they will print a message telling you that they
53aren't implemented, and suggest using the Perl equivalent should one
54exist. For example, trying to access the setjmp() call will elicit the
55message "setjmp() is C-specific: use eval {} instead".
56
57Furthermore, some evil vendors will claim 1003.1 compliance, but in fact
58are not so: they will not pass the PCTS (POSIX Compliance Test Suites).
59For example, one vendor may not define EDEADLK, or the semantics of the
60errno values set by open(2) might not be quite right. Perl does not
61attempt to verify POSIX compliance. That means you can currently
62successfully say "use POSIX", and then later in your program you find
63that your vendor has been lax and there's no usable ICANON macro after
64all. This could be construed to be a bug.
65
66=head1 FUNCTIONS
67
68=over 8
69
70=item _exit
71
72This is identical to the C function C<_exit()>. It exits the program
73immediately which means among other things buffered I/O is B<not> flushed.
74
75Note that when using threads and in Linux this is B<not> a good way to
76exit a thread because in Linux processes and threads are kind of the
77same thing (Note: while this is the situation in early 2003 there are
78projects under way to have threads with more POSIXly semantics in Linux).
79If you want not to return from a thread, detach the thread.
80
81=item abort
82
83This is identical to the C function C<abort()>. It terminates the
84process with a C<SIGABRT> signal unless caught by a signal handler or
85if the handler does not return normally (it e.g. does a C<longjmp>).
86
87=item abs
88
89This is identical to Perl's builtin C<abs()> function, returning
90the absolute value of its numerical argument.
91
92=item access
93
94Determines the accessibility of a file.
95
96 if( POSIX::access( "/", &POSIX::R_OK ) ){
97 print "have read permission\n";
98 }
99
100Returns C<undef> on failure. Note: do not use C<access()> for
101security purposes. Between the C<access()> call and the operation
102you are preparing for the permissions might change: a classic
103I<race condition>.
104
105=item acos
106
107This is identical to the C function C<acos()>, returning
108the arcus cosine of its numerical argument. See also L<Math::Trig>.
109
110=item alarm
111
112This is identical to Perl's builtin C<alarm()> function,
113either for arming or disarming the C<SIGARLM> timer.
114
115=item asctime
116
117This is identical to the C function C<asctime()>. It returns
118a string of the form
119
120 "Fri Jun 2 18:22:13 2000\n\0"
121
122and it is called thusly
123
124 $asctime = asctime($sec, $min, $hour, $mday, $mon, $year,
125 $wday, $yday, $isdst);
126
127The C<$mon> is zero-based: January equals C<0>. The C<$year> is
1281900-based: 2001 equals C<101>. The C<$wday>, C<$yday>, and C<$isdst>
129default to zero (and the first two are usually ignored anyway).
130
131=item asin
132
133This is identical to the C function C<asin()>, returning
134the arcus sine of its numerical argument. See also L<Math::Trig>.
135
136=item assert
137
138Unimplemented, but you can use L<perlfunc/die> and the L<Carp> module
139to achieve similar things.
140
141=item atan
142
143This is identical to the C function C<atan()>, returning the
144arcus tangent of its numerical argument. See also L<Math::Trig>.
145
146=item atan2
147
148This is identical to Perl's builtin C<atan2()> function, returning
149the arcus tangent defined by its two numerical arguments, the I<y>
150coordinate and the I<x> coordinate. See also L<Math::Trig>.
151
152=item atexit
153
154atexit() is C-specific: use C<END {}> instead, see L<perlsub>.
155
156=item atof
157
158atof() is C-specific. Perl converts strings to numbers transparently.
159If you need to force a scalar to a number, add a zero to it.
160
161=item atoi
162
163atoi() is C-specific. Perl converts strings to numbers transparently.
164If you need to force a scalar to a number, add a zero to it.
165If you need to have just the integer part, see L<perlfunc/int>.
166
167=item atol
168
169atol() is C-specific. Perl converts strings to numbers transparently.
170If you need to force a scalar to a number, add a zero to it.
171If you need to have just the integer part, see L<perlfunc/int>.
172
173=item bsearch
174
175bsearch() not supplied. For doing binary search on wordlists,
176see L<Search::Dict>.
177
178=item calloc
179
180calloc() is C-specific. Perl does memory management transparently.
181
182=item ceil
183
184This is identical to the C function C<ceil()>, returning the smallest
185integer value greater than or equal to the given numerical argument.
186
187=item chdir
188
189This is identical to Perl's builtin C<chdir()> function, allowing
190one to change the working (default) directory, see L<perlfunc/chdir>.
191
192=item chmod
193
194This is identical to Perl's builtin C<chmod()> function, allowing
195one to change file and directory permissions, see L<perlfunc/chmod>.
196
197=item chown
198
199This is identical to Perl's builtin C<chown()> function, allowing one
200to change file and directory owners and groups, see L<perlfunc/chown>.
201
202=item clearerr
203
204Use the method C<IO::Handle::clearerr()> instead, to reset the error
205state (if any) and EOF state (if any) of the given stream.
206
207=item clock
208
209This is identical to the C function C<clock()>, returning the
210amount of spent processor time in microseconds.
211
212=item close
213
214Close the file. This uses file descriptors such as those obtained by calling
215C<POSIX::open>.
216
217 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
218 POSIX::close( $fd );
219
220Returns C<undef> on failure.
221
222See also L<perlfunc/close>.
223
224=item closedir
225
226This is identical to Perl's builtin C<closedir()> function for closing
227a directory handle, see L<perlfunc/closedir>.
228
229=item cos
230
231This is identical to Perl's builtin C<cos()> function, for returning
232the cosine of its numerical argument, see L<perlfunc/cos>.
233See also L<Math::Trig>.
234
235=item cosh
236
237This is identical to the C function C<cosh()>, for returning
238the hyperbolic cosine of its numeric argument. See also L<Math::Trig>.
239
240=item creat
241
242Create a new file. This returns a file descriptor like the ones returned by
243C<POSIX::open>. Use C<POSIX::close> to close the file.
244
245 $fd = POSIX::creat( "foo", 0611 );
246 POSIX::close( $fd );
247
248See also L<perlfunc/sysopen> and its C<O_CREAT> flag.
249
250=item ctermid
251
252Generates the path name for the controlling terminal.
253
254 $path = POSIX::ctermid();
255
256=item ctime
257
258This is identical to the C function C<ctime()> and equivalent
259to C<asctime(localtime(...))>, see L</asctime> and L</localtime>.
260
261=item cuserid
262
263Get the login name of the owner of the current process.
264
265 $name = POSIX::cuserid();
266
267=item difftime
268
269This is identical to the C function C<difftime()>, for returning
270the time difference (in seconds) between two times (as returned
271by C<time()>), see L</time>.
272
273=item div
274
275div() is C-specific, use L<perlfunc/int> on the usual C</> division and
276the modulus C<%>.
277
278=item dup
279
280This is similar to the C function C<dup()>, for duplicating a file
281descriptor.
282
283This uses file descriptors such as those obtained by calling
284C<POSIX::open>.
285
286Returns C<undef> on failure.
287
288=item dup2
289
290This is similar to the C function C<dup2()>, for duplicating a file
291descriptor to an another known file descriptor.
292
293This uses file descriptors such as those obtained by calling
294C<POSIX::open>.
295
296Returns C<undef> on failure.
297
298=item errno
299
300Returns the value of errno.
301
302 $errno = POSIX::errno();
303
304This identical to the numerical values of the C<$!>, see L<perlvar/$ERRNO>.
305
306=item execl
307
308execl() is C-specific, see L<perlfunc/exec>.
309
310=item execle
311
312execle() is C-specific, see L<perlfunc/exec>.
313
314=item execlp
315
316execlp() is C-specific, see L<perlfunc/exec>.
317
318=item execv
319
320execv() is C-specific, see L<perlfunc/exec>.
321
322=item execve
323
324execve() is C-specific, see L<perlfunc/exec>.
325
326=item execvp
327
328execvp() is C-specific, see L<perlfunc/exec>.
329
330=item exit
331
332This is identical to Perl's builtin C<exit()> function for exiting the
333program, see L<perlfunc/exit>.
334
335=item exp
336
337This is identical to Perl's builtin C<exp()> function for
338returning the exponent (I<e>-based) of the numerical argument,
339see L<perlfunc/exp>.
340
341=item fabs
342
343This is identical to Perl's builtin C<abs()> function for returning
344the absolute value of the numerical argument, see L<perlfunc/abs>.
345
346=item fclose
347
348Use method C<IO::Handle::close()> instead, or see L<perlfunc/close>.
349
350=item fcntl
351
352This is identical to Perl's builtin C<fcntl()> function,
353see L<perlfunc/fcntl>.
354
355=item fdopen
356
357Use method C<IO::Handle::new_from_fd()> instead, or see L<perlfunc/open>.
358
359=item feof
360
361Use method C<IO::Handle::eof()> instead, or see L<perlfunc/eof>.
362
363=item ferror
364
365Use method C<IO::Handle::error()> instead.
366
367=item fflush
368
369Use method C<IO::Handle::flush()> instead.
370See also L<perlvar/$OUTPUT_AUTOFLUSH>.
371
372=item fgetc
373
374Use method C<IO::Handle::getc()> instead, or see L<perlfunc/read>.
375
376=item fgetpos
377
378Use method C<IO::Seekable::getpos()> instead, or see L<L/seek>.
379
380=item fgets
381
382Use method C<IO::Handle::gets()> instead. Similar to E<lt>E<gt>, also known
383as L<perlfunc/readline>.
384
385=item fileno
386
387Use method C<IO::Handle::fileno()> instead, or see L<perlfunc/fileno>.
388
389=item floor
390
391This is identical to the C function C<floor()>, returning the largest
392integer value less than or equal to the numerical argument.
393
394=item fmod
395
396This is identical to the C function C<fmod()>.
397
398 $r = fmod($x, $y);
399
400It returns the remainder C<$r = $x - $n*$y>, where C<$n = trunc($x/$y)>.
401The C<$r> has the same sign as C<$x> and magnitude (absolute value)
402less than the magnitude of C<$y>.
403
404=item fopen
405
406Use method C<IO::File::open()> instead, or see L<perlfunc/open>.
407
408=item fork
409
410This is identical to Perl's builtin C<fork()> function
411for duplicating the current process, see L<perlfunc/fork>
412and L<perlfork> if you are in Windows.
413
414=item fpathconf
415
416Retrieves the value of a configurable limit on a file or directory. This
417uses file descriptors such as those obtained by calling C<POSIX::open>.
418
419The following will determine the maximum length of the longest allowable
420pathname on the filesystem which holds C</var/foo>.
421
422 $fd = POSIX::open( "/var/foo", &POSIX::O_RDONLY );
423 $path_max = POSIX::fpathconf( $fd, &POSIX::_PC_PATH_MAX );
424
425Returns C<undef> on failure.
426
427=item fprintf
428
429fprintf() is C-specific, see L<perlfunc/printf> instead.
430
431=item fputc
432
433fputc() is C-specific, see L<perlfunc/print> instead.
434
435=item fputs
436
437fputs() is C-specific, see L<perlfunc/print> instead.
438
439=item fread
440
441fread() is C-specific, see L<perlfunc/read> instead.
442
443=item free
444
445free() is C-specific. Perl does memory management transparently.
446
447=item freopen
448
449freopen() is C-specific, see L<perlfunc/open> instead.
450
451=item frexp
452
453Return the mantissa and exponent of a floating-point number.
454
455 ($mantissa, $exponent) = POSIX::frexp( 1.234e56 );
456
457=item fscanf
458
459fscanf() is C-specific, use E<lt>E<gt> and regular expressions instead.
460
461=item fseek
462
463Use method C<IO::Seekable::seek()> instead, or see L<perlfunc/seek>.
464
465=item fsetpos
466
467Use method C<IO::Seekable::setpos()> instead, or seek L<perlfunc/seek>.
468
469=item fstat
470
471Get file status. This uses file descriptors such as those obtained by
472calling C<POSIX::open>. The data returned is identical to the data from
473Perl's builtin C<stat> function.
474
475 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
476 @stats = POSIX::fstat( $fd );
477
478=item fsync
479
480Use method C<IO::Handle::sync()> instead.
481
482=item ftell
483
484Use method C<IO::Seekable::tell()> instead, or see L<perlfunc/tell>.
485
486=item fwrite
487
488fwrite() is C-specific, see L<perlfunc/print> instead.
489
490=item getc
491
492This is identical to Perl's builtin C<getc()> function,
493see L<perlfunc/getc>.
494
495=item getchar
496
497Returns one character from STDIN. Identical to Perl's C<getc()>,
498see L<perlfunc/getc>.
499
500=item getcwd
501
502Returns the name of the current working directory.
503See also L<Cwd>.
504
505=item getegid
506
507Returns the effective group identifier. Similar to Perl' s builtin
508variable C<$(>, see L<perlvar/$EGID>.
509
510=item getenv
511
512Returns the value of the specified environment variable.
513The same information is available through the C<%ENV> array.
514
515=item geteuid
516
517Returns the effective user identifier. Identical to Perl's builtin C<$E<gt>>
518variable, see L<perlvar/$EUID>.
519
520=item getgid
521
522Returns the user's real group identifier. Similar to Perl's builtin
523variable C<$)>, see L<perlvar/$GID>.
524
525=item getgrgid
526
527This is identical to Perl's builtin C<getgrgid()> function for
528returning group entries by group identifiers, see
529L<perlfunc/getgrgid>.
530
531=item getgrnam
532
533This is identical to Perl's builtin C<getgrnam()> function for
534returning group entries by group names, see L<perlfunc/getgrnam>.
535
536=item getgroups
537
538Returns the ids of the user's supplementary groups. Similar to Perl's
539builtin variable C<$)>, see L<perlvar/$GID>.
540
541=item getlogin
542
543This is identical to Perl's builtin C<getlogin()> function for
544returning the user name associated with the current session, see
545L<perlfunc/getlogin>.
546
547=item getpgrp
548
549This is identical to Perl's builtin C<getpgrp()> function for
550returning the process group identifier of the current process, see
551L<perlfunc/getpgrp>.
552
553=item getpid
554
555Returns the process identifier. Identical to Perl's builtin
556variable C<$$>, see L<perlvar/$PID>.
557
558=item getppid
559
560This is identical to Perl's builtin C<getppid()> function for
561returning the process identifier of the parent process of the current
562process , see L<perlfunc/getppid>.
563
564=item getpwnam
565
566This is identical to Perl's builtin C<getpwnam()> function for
567returning user entries by user names, see L<perlfunc/getpwnam>.
568
569=item getpwuid
570
571This is identical to Perl's builtin C<getpwuid()> function for
572returning user entries by user identifiers, see L<perlfunc/getpwuid>.
573
574=item gets
575
576Returns one line from C<STDIN>, similar to E<lt>E<gt>, also known
577as the C<readline()> function, see L<perlfunc/readline>.
578
579B<NOTE>: if you have C programs that still use C<gets()>, be very
580afraid. The C<gets()> function is a source of endless grief because
581it has no buffer overrun checks. It should B<never> be used. The
582C<fgets()> function should be preferred instead.
583
584=item getuid
585
586Returns the user's identifier. Identical to Perl's builtin C<$E<lt>> variable,
587see L<perlvar/$UID>.
588
589=item gmtime
590
591This is identical to Perl's builtin C<gmtime()> function for
592converting seconds since the epoch to a date in Greenwich Mean Time,
593see L<perlfunc/gmtime>.
594
595=item isalnum
596
597This is identical to the C function, except that it can apply to a
598single character or to a whole string. Note that locale settings may
599affect what characters are considered C<isalnum>. Does not work on
600Unicode characters code point 256 or higher. Consider using regular
601expressions and the C</[[:alnum:]]/> construct instead, or possibly
602the C</\w/> construct.
603
604=item isalpha
605
606This is identical to the C function, except that it can apply to
607a single character or to a whole string. Note that locale settings
608may affect what characters are considered C<isalpha>. Does not work
609on Unicode characters code point 256 or higher. Consider using regular
610expressions and the C</[[:alpha:]]/> construct instead.
611
612=item isatty
613
614Returns a boolean indicating whether the specified filehandle is connected
615to a tty. Similar to the C<-t> operator, see L<perlfunc/-X>.
616
617=item iscntrl
618
619This is identical to the C function, except that it can apply to
620a single character or to a whole string. Note that locale settings
621may affect what characters are considered C<iscntrl>. Does not work
622on Unicode characters code point 256 or higher. Consider using regular
623expressions and the C</[[:cntrl:]]/> construct instead.
624
625=item isdigit
626
627This is identical to the C function, except that it can apply to
628a single character or to a whole string. Note that locale settings
629may affect what characters are considered C<isdigit> (unlikely, but
630still possible). Does not work on Unicode characters code point 256
631or higher. Consider using regular expressions and the C</[[:digit:]]/>
632construct instead, or the C</\d/> construct.
633
634=item isgraph
635
636This is identical to the C function, except that it can apply to
637a single character or to a whole string. Note that locale settings
638may affect what characters are considered C<isgraph>. Does not work
639on Unicode characters code point 256 or higher. Consider using regular
640expressions and the C</[[:graph:]]/> construct instead.
641
642=item islower
643
644This is identical to the C function, except that it can apply to
645a single character or to a whole string. Note that locale settings
646may affect what characters are considered C<islower>. Does not work
647on Unicode characters code point 256 or higher. Consider using regular
648expressions and the C</[[:lower:]]/> construct instead. Do B<not> use
649C</[a-z]/>.
650
651=item isprint
652
653This is identical to the C function, except that it can apply to
654a single character or to a whole string. Note that locale settings
655may affect what characters are considered C<isprint>. Does not work
656on Unicode characters code point 256 or higher. Consider using regular
657expressions and the C</[[:print:]]/> construct instead.
658
659=item ispunct
660
661This is identical to the C function, except that it can apply to
662a single character or to a whole string. Note that locale settings
663may affect what characters are considered C<ispunct>. Does not work
664on Unicode characters code point 256 or higher. Consider using regular
665expressions and the C</[[:punct:]]/> construct instead.
666
667=item isspace
668
669This is identical to the C function, except that it can apply to
670a single character or to a whole string. Note that locale settings
671may affect what characters are considered C<isspace>. Does not work
672on Unicode characters code point 256 or higher. Consider using regular
673expressions and the C</[[:space:]]/> construct instead, or the C</\s/>
674construct. (Note that C</\s/> and C</[[:space:]]/> are slightly
675different in that C</[[:space:]]/> can normally match a vertical tab,
676while C</\s/> does not.)
677
678=item isupper
679
680This is identical to the C function, except that it can apply to
681a single character or to a whole string. Note that locale settings
682may affect what characters are considered C<isupper>. Does not work
683on Unicode characters code point 256 or higher. Consider using regular
684expressions and the C</[[:upper:]]/> construct instead. Do B<not> use
685C</[A-Z]/>.
686
687=item isxdigit
688
689This is identical to the C function, except that it can apply to a single
690character or to a whole string. Note that locale settings may affect what
691characters are considered C<isxdigit> (unlikely, but still possible).
692Does not work on Unicode characters code point 256 or higher.
693Consider using regular expressions and the C</[[:xdigit:]]/>
694construct instead, or simply C</[0-9a-f]/i>.
695
696=item kill
697
698This is identical to Perl's builtin C<kill()> function for sending
699signals to processes (often to terminate them), see L<perlfunc/kill>.
700
701=item labs
702
703(For returning absolute values of long integers.)
704labs() is C-specific, see L<perlfunc/abs> instead.
705
706=item ldexp
707
708This is identical to the C function C<ldexp()>
709for multiplying floating point numbers with powers of two.
710
711 $x_quadrupled = POSIX::ldexp($x, 2);
712
713=item ldiv
714
715(For computing dividends of long integers.)
716ldiv() is C-specific, use C</> and C<int()> instead.
717
718=item link
719
720This is identical to Perl's builtin C<link()> function
721for creating hard links into files, see L<perlfunc/link>.
722
723=item localeconv
724
725Get numeric formatting information. Returns a reference to a hash
726containing the current locale formatting values.
727
728Here is how to query the database for the B<de> (Deutsch or German) locale.
729
730 $loc = POSIX::setlocale( &POSIX::LC_ALL, "de" );
731 print "Locale = $loc\n";
732 $lconv = POSIX::localeconv();
733 print "decimal_point = ", $lconv->{decimal_point}, "\n";
734 print "thousands_sep = ", $lconv->{thousands_sep}, "\n";
735 print "grouping = ", $lconv->{grouping}, "\n";
736 print "int_curr_symbol = ", $lconv->{int_curr_symbol}, "\n";
737 print "currency_symbol = ", $lconv->{currency_symbol}, "\n";
738 print "mon_decimal_point = ", $lconv->{mon_decimal_point}, "\n";
739 print "mon_thousands_sep = ", $lconv->{mon_thousands_sep}, "\n";
740 print "mon_grouping = ", $lconv->{mon_grouping}, "\n";
741 print "positive_sign = ", $lconv->{positive_sign}, "\n";
742 print "negative_sign = ", $lconv->{negative_sign}, "\n";
743 print "int_frac_digits = ", $lconv->{int_frac_digits}, "\n";
744 print "frac_digits = ", $lconv->{frac_digits}, "\n";
745 print "p_cs_precedes = ", $lconv->{p_cs_precedes}, "\n";
746 print "p_sep_by_space = ", $lconv->{p_sep_by_space}, "\n";
747 print "n_cs_precedes = ", $lconv->{n_cs_precedes}, "\n";
748 print "n_sep_by_space = ", $lconv->{n_sep_by_space}, "\n";
749 print "p_sign_posn = ", $lconv->{p_sign_posn}, "\n";
750 print "n_sign_posn = ", $lconv->{n_sign_posn}, "\n";
751
752=item localtime
753
754This is identical to Perl's builtin C<localtime()> function for
755converting seconds since the epoch to a date see L<perlfunc/localtime>.
756
757=item log
758
759This is identical to Perl's builtin C<log()> function,
760returning the natural (I<e>-based) logarithm of the numerical argument,
761see L<perlfunc/log>.
762
763=item log10
764
765This is identical to the C function C<log10()>,
766returning the 10-base logarithm of the numerical argument.
767You can also use
768
769 sub log10 { log($_[0]) / log(10) }
770
771or
772
773 sub log10 { log($_[0]) / 2.30258509299405 }
774
775or
776
777 sub log10 { log($_[0]) * 0.434294481903252 }
778
779=item longjmp
780
781longjmp() is C-specific: use L<perlfunc/die> instead.
782
783=item lseek
784
785Move the file's read/write position. This uses file descriptors such as
786those obtained by calling C<POSIX::open>.
787
788 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
789 $off_t = POSIX::lseek( $fd, 0, &POSIX::SEEK_SET );
790
791Returns C<undef> on failure.
792
793=item malloc
794
795malloc() is C-specific. Perl does memory management transparently.
796
797=item mblen
798
799This is identical to the C function C<mblen()>.
800Perl does not have any support for the wide and multibyte
801characters of the C standards, so this might be a rather
802useless function.
803
804=item mbstowcs
805
806This is identical to the C function C<mbstowcs()>.
807Perl does not have any support for the wide and multibyte
808characters of the C standards, so this might be a rather
809useless function.
810
811=item mbtowc
812
813This is identical to the C function C<mbtowc()>.
814Perl does not have any support for the wide and multibyte
815characters of the C standards, so this might be a rather
816useless function.
817
818=item memchr
819
820memchr() is C-specific, see L<perlfunc/index> instead.
821
822=item memcmp
823
824memcmp() is C-specific, use C<eq> instead, see L<perlop>.
825
826=item memcpy
827
828memcpy() is C-specific, use C<=>, see L<perlop>, or see L<perlfunc/substr>.
829
830=item memmove
831
832memmove() is C-specific, use C<=>, see L<perlop>, or see L<perlfunc/substr>.
833
834=item memset
835
836memset() is C-specific, use C<x> instead, see L<perlop>.
837
838=item mkdir
839
840This is identical to Perl's builtin C<mkdir()> function
841for creating directories, see L<perlfunc/mkdir>.
842
843=item mkfifo
844
845This is similar to the C function C<mkfifo()> for creating
846FIFO special files.
847
848 if (mkfifo($path, $mode)) { ....
849
850Returns C<undef> on failure. The C<$mode> is similar to the
851mode of C<mkdir()>, see L<perlfunc/mkdir>.
852
853=item mktime
854
855Convert date/time info to a calendar time.
856
857Synopsis:
858
859 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
860
861The month (C<mon>), weekday (C<wday>), and yearday (C<yday>) begin at zero.
862I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The
863year (C<year>) is given in years since 1900. I.e. The year 1995 is 95; the
864year 2001 is 101. Consult your system's C<mktime()> manpage for details
865about these and the other arguments.
866
867Calendar time for December 12, 1995, at 10:30 am.
868
869 $time_t = POSIX::mktime( 0, 30, 10, 12, 11, 95 );
870 print "Date = ", POSIX::ctime($time_t);
871
872Returns C<undef> on failure.
873
874=item modf
875
876Return the integral and fractional parts of a floating-point number.
877
878 ($fractional, $integral) = POSIX::modf( 3.14 );
879
880=item nice
881
882This is similar to the C function C<nice()>, for changing
883the scheduling preference of the current process. Positive
884arguments mean more polite process, negative values more
885needy process. Normal user processes can only be more polite.
886
887Returns C<undef> on failure.
888
889=item offsetof
890
891offsetof() is C-specific, you probably want to see L<perlfunc/pack> instead.
892
893=item open
894
895Open a file for reading for writing. This returns file descriptors, not
896Perl filehandles. Use C<POSIX::close> to close the file.
897
898Open a file read-only with mode 0666.
899
900 $fd = POSIX::open( "foo" );
901
902Open a file for read and write.
903
904 $fd = POSIX::open( "foo", &POSIX::O_RDWR );
905
906Open a file for write, with truncation.
907
908 $fd = POSIX::open( "foo", &POSIX::O_WRONLY | &POSIX::O_TRUNC );
909
910Create a new file with mode 0640. Set up the file for writing.
911
912 $fd = POSIX::open( "foo", &POSIX::O_CREAT | &POSIX::O_WRONLY, 0640 );
913
914Returns C<undef> on failure.
915
916See also L<perlfunc/sysopen>.
917
918=item opendir
919
920Open a directory for reading.
921
922 $dir = POSIX::opendir( "/var" );
923 @files = POSIX::readdir( $dir );
924 POSIX::closedir( $dir );
925
926Returns C<undef> on failure.
927
928=item pathconf
929
930Retrieves the value of a configurable limit on a file or directory.
931
932The following will determine the maximum length of the longest allowable
933pathname on the filesystem which holds C</var>.
934
935 $path_max = POSIX::pathconf( "/var", &POSIX::_PC_PATH_MAX );
936
937Returns C<undef> on failure.
938
939=item pause
940
941This is similar to the C function C<pause()>, which suspends
942the execution of the current process until a signal is received.
943
944Returns C<undef> on failure.
945
946=item perror
947
948This is identical to the C function C<perror()>, which outputs to the
949standard error stream the specified message followed by ": " and the
950current error string. Use the C<warn()> function and the C<$!>
951variable instead, see L<perlfunc/warn> and L<perlvar/$ERRNO>.
952
953=item pipe
954
955Create an interprocess channel. This returns file descriptors like those
956returned by C<POSIX::open>.
957
958 my ($read, $write) = POSIX::pipe();
959 POSIX::write( $write, "hello", 5 );
960 POSIX::read( $read, $buf, 5 );
961
962See also L<perlfunc/pipe>.
963
964=item pow
965
966Computes C<$x> raised to the power C<$exponent>.
967
968 $ret = POSIX::pow( $x, $exponent );
969
970You can also use the C<**> operator, see L<perlop>.
971
972=item printf
973
974Formats and prints the specified arguments to STDOUT.
975See also L<perlfunc/printf>.
976
977=item putc
978
979putc() is C-specific, see L<perlfunc/print> instead.
980
981=item putchar
982
983putchar() is C-specific, see L<perlfunc/print> instead.
984
985=item puts
986
987puts() is C-specific, see L<perlfunc/print> instead.
988
989=item qsort
990
991qsort() is C-specific, see L<perlfunc/sort> instead.
992
993=item raise
994
995Sends the specified signal to the current process.
996See also L<perlfunc/kill> and the C<$$> in L<perlvar/$PID>.
997
998=item rand
999
1000C<rand()> is non-portable, see L<perlfunc/rand> instead.
1001
1002=item read
1003
1004Read from a file. This uses file descriptors such as those obtained by
1005calling C<POSIX::open>. If the buffer C<$buf> is not large enough for the
1006read then Perl will extend it to make room for the request.
1007
1008 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
1009 $bytes = POSIX::read( $fd, $buf, 3 );
1010
1011Returns C<undef> on failure.
1012
1013See also L<perlfunc/sysread>.
1014
1015=item readdir
1016
1017This is identical to Perl's builtin C<readdir()> function
1018for reading directory entries, see L<perlfunc/readdir>.
1019
1020=item realloc
1021
1022realloc() is C-specific. Perl does memory management transparently.
1023
1024=item remove
1025
1026This is identical to Perl's builtin C<unlink()> function
1027for removing files, see L<perlfunc/unlink>.
1028
1029=item rename
1030
1031This is identical to Perl's builtin C<rename()> function
1032for renaming files, see L<perlfunc/rename>.
1033
1034=item rewind
1035
1036Seeks to the beginning of the file.
1037
1038=item rewinddir
1039
1040This is identical to Perl's builtin C<rewinddir()> function for
1041rewinding directory entry streams, see L<perlfunc/rewinddir>.
1042
1043=item rmdir
1044
1045This is identical to Perl's builtin C<rmdir()> function
1046for removing (empty) directories, see L<perlfunc/rmdir>.
1047
1048=item scanf
1049
1050scanf() is C-specific, use E<lt>E<gt> and regular expressions instead,
1051see L<perlre>.
1052
1053=item setgid
1054
1055Sets the real group identifier and the effective group identifier for
1056this process. Similar to assigning a value to the Perl's builtin
1057C<$)> variable, see L<perlvar/$GID>, except that the latter
1058will change only the real user identifier, and that the setgid()
1059uses only a single numeric argument, as opposed to a space-separated
1060list of numbers.
1061
1062=item setjmp
1063
1064C<setjmp()> is C-specific: use C<eval {}> instead,
1065see L<perlfunc/eval>.
1066
1067=item setlocale
1068
1069Modifies and queries program's locale. The following examples assume
1070
1071 use POSIX qw(setlocale LC_ALL LC_CTYPE);
1072
1073has been issued.
1074
1075The following will set the traditional UNIX system locale behavior
1076(the second argument C<"C">).
1077
1078 $loc = setlocale( LC_ALL, "C" );
1079
1080The following will query the current LC_CTYPE category. (No second
1081argument means 'query'.)
1082
1083 $loc = setlocale( LC_CTYPE );
1084
1085The following will set the LC_CTYPE behaviour according to the locale
1086environment variables (the second argument C<"">).
1087Please see your systems C<setlocale(3)> documentation for the locale
1088environment variables' meaning or consult L<perllocale>.
1089
1090 $loc = setlocale( LC_CTYPE, "" );
1091
1092The following will set the LC_COLLATE behaviour to Argentinian
1093Spanish. B<NOTE>: The naming and availability of locales depends on
1094your operating system. Please consult L<perllocale> for how to find
1095out which locales are available in your system.
1096
1097 $loc = setlocale( LC_ALL, "es_AR.ISO8859-1" );
1098
1099=item setpgid
1100
1101This is similar to the C function C<setpgid()> for
1102setting the process group identifier of the current process.
1103
1104Returns C<undef> on failure.
1105
1106=item setsid
1107
1108This is identical to the C function C<setsid()> for
1109setting the session identifier of the current process.
1110
1111=item setuid
1112
1113Sets the real user identifier and the effective user identifier for
1114this process. Similar to assigning a value to the Perl's builtin
1115C<$E<lt>> variable, see L<perlvar/$UID>, except that the latter
1116will change only the real user identifier.
1117
1118=item sigaction
1119
1120Detailed signal management. This uses C<POSIX::SigAction> objects for the
1121C<action> and C<oldaction> arguments. Consult your system's C<sigaction>
1122manpage for details.
1123
1124Synopsis:
1125
1126 sigaction(signal, action, oldaction = 0)
1127
1128Returns C<undef> on failure. The C<signal> must be a number (like
1129SIGHUP), not a string (like "SIGHUP"), though Perl does try hard
1130to understand you.
1131
1132=item siglongjmp
1133
1134siglongjmp() is C-specific: use L<perlfunc/die> instead.
1135
1136=item sigpending
1137
1138Examine signals that are blocked and pending. This uses C<POSIX::SigSet>
1139objects for the C<sigset> argument. Consult your system's C<sigpending>
1140manpage for details.
1141
1142Synopsis:
1143
1144 sigpending(sigset)
1145
1146Returns C<undef> on failure.
1147
1148=item sigprocmask
1149
1150Change and/or examine calling process's signal mask. This uses
1151C<POSIX::SigSet> objects for the C<sigset> and C<oldsigset> arguments.
1152Consult your system's C<sigprocmask> manpage for details.
1153
1154Synopsis:
1155
1156 sigprocmask(how, sigset, oldsigset = 0)
1157
1158Returns C<undef> on failure.
1159
1160=item sigsetjmp
1161
1162C<sigsetjmp()> is C-specific: use C<eval {}> instead,
1163see L<perlfunc/eval>.
1164
1165=item sigsuspend
1166
1167Install a signal mask and suspend process until signal arrives. This uses
1168C<POSIX::SigSet> objects for the C<signal_mask> argument. Consult your
1169system's C<sigsuspend> manpage for details.
1170
1171Synopsis:
1172
1173 sigsuspend(signal_mask)
1174
1175Returns C<undef> on failure.
1176
1177=item sin
1178
1179This is identical to Perl's builtin C<sin()> function
1180for returning the sine of the numerical argument,
1181see L<perlfunc/sin>. See also L<Math::Trig>.
1182
1183=item sinh
1184
1185This is identical to the C function C<sinh()>
1186for returning the hyperbolic sine of the numerical argument.
1187See also L<Math::Trig>.
1188
1189=item sleep
1190
1191This is functionally identical to Perl's builtin C<sleep()> function
1192for suspending the execution of the current for process for certain
1193number of seconds, see L<perlfunc/sleep>. There is one significant
1194difference, however: C<POSIX::sleep()> returns the number of
1195B<unslept> seconds, while the C<CORE::sleep()> returns the
1196number of slept seconds.
1197
1198=item sprintf
1199
1200This is similar to Perl's builtin C<sprintf()> function
1201for returning a string that has the arguments formatted as requested,
1202see L<perlfunc/sprintf>.
1203
1204=item sqrt
1205
1206This is identical to Perl's builtin C<sqrt()> function.
1207for returning the square root of the numerical argument,
1208see L<perlfunc/sqrt>.
1209
1210=item srand
1211
1212Give a seed the pseudorandom number generator, see L<perlfunc/srand>.
1213
1214=item sscanf
1215
1216sscanf() is C-specific, use regular expressions instead,
1217see L<perlre>.
1218
1219=item stat
1220
1221This is identical to Perl's builtin C<stat()> function
1222for returning information about files and directories.
1223
1224=item strcat
1225
1226strcat() is C-specific, use C<.=> instead, see L<perlop>.
1227
1228=item strchr
1229
1230strchr() is C-specific, see L<perlfunc/index> instead.
1231
1232=item strcmp
1233
1234strcmp() is C-specific, use C<eq> or C<cmp> instead, see L<perlop>.
1235
1236=item strcoll
1237
1238This is identical to the C function C<strcoll()>
1239for collating (comparing) strings transformed using
1240the C<strxfrm()> function. Not really needed since
1241Perl can do this transparently, see L<perllocale>.
1242
1243=item strcpy
1244
1245strcpy() is C-specific, use C<=> instead, see L<perlop>.
1246
1247=item strcspn
1248
1249strcspn() is C-specific, use regular expressions instead,
1250see L<perlre>.
1251
1252=item strerror
1253
1254Returns the error string for the specified errno.
1255Identical to the string form of the C<$!>, see L<perlvar/$ERRNO>.
1256
1257=item strftime
1258
1259Convert date and time information to string. Returns the string.
1260
1261Synopsis:
1262
1263 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1264
1265The month (C<mon>), weekday (C<wday>), and yearday (C<yday>) begin at zero.
1266I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The
1267year (C<year>) is given in years since 1900. I.e., the year 1995 is 95; the
1268year 2001 is 101. Consult your system's C<strftime()> manpage for details
1269about these and the other arguments.
1270
1271If you want your code to be portable, your format (C<fmt>) argument
1272should use only the conversion specifiers defined by the ANSI C
1273standard (C89, to play safe). These are C<aAbBcdHIjmMpSUwWxXyYZ%>.
1274But even then, the B<results> of some of the conversion specifiers are
1275non-portable. For example, the specifiers C<aAbBcpZ> change according
1276to the locale settings of the user, and both how to set locales (the
1277locale names) and what output to expect are non-standard.
1278The specifier C<c> changes according to the timezone settings of the
1279user and the timezone computation rules of the operating system.
1280The C<Z> specifier is notoriously unportable since the names of
1281timezones are non-standard. Sticking to the numeric specifiers is the
1282safest route.
1283
1284The given arguments are made consistent as though by calling
1285C<mktime()> before calling your system's C<strftime()> function,
1286except that the C<isdst> value is not affected.
1287
1288The string for Tuesday, December 12, 1995.
1289
1290 $str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0, 12, 11, 95, 2 );
1291 print "$str\n";
1292
1293=item strlen
1294
1295strlen() is C-specific, use C<length()> instead, see L<perlfunc/length>.
1296
1297=item strncat
1298
1299strncat() is C-specific, use C<.=> instead, see L<perlop>.
1300
1301=item strncmp
1302
1303strncmp() is C-specific, use C<eq> instead, see L<perlop>.
1304
1305=item strncpy
1306
1307strncpy() is C-specific, use C<=> instead, see L<perlop>.
1308
1309=item strpbrk
1310
1311strpbrk() is C-specific, use regular expressions instead,
1312see L<perlre>.
1313
1314=item strrchr
1315
1316strrchr() is C-specific, see L<perlfunc/rindex> instead.
1317
1318=item strspn
1319
1320strspn() is C-specific, use regular expressions instead,
1321see L<perlre>.
1322
1323=item strstr
1324
1325This is identical to Perl's builtin C<index()> function,
1326see L<perlfunc/index>.
1327
1328=item strtod
1329
1330String to double translation. Returns the parsed number and the number
1331of characters in the unparsed portion of the string. Truly
1332POSIX-compliant systems set $! ($ERRNO) to indicate a translation
1333error, so clear $! before calling strtod. However, non-POSIX systems
1334may not check for overflow, and therefore will never set $!.
1335
1336strtod should respect any POSIX I<setlocale()> settings.
1337
1338To parse a string $str as a floating point number use
1339
1340 $! = 0;
1341 ($num, $n_unparsed) = POSIX::strtod($str);
1342
1343The second returned item and $! can be used to check for valid input:
1344
1345 if (($str eq '') || ($n_unparsed != 0) || $!) {
1346 die "Non-numeric input $str" . ($! ? ": $!\n" : "\n");
1347 }
1348
1349When called in a scalar context strtod returns the parsed number.
1350
1351=item strtok
1352
1353strtok() is C-specific, use regular expressions instead, see
1354L<perlre>, or L<perlfunc/split>.
1355
1356=item strtol
1357
1358String to (long) integer translation. Returns the parsed number and
1359the number of characters in the unparsed portion of the string. Truly
1360POSIX-compliant systems set $! ($ERRNO) to indicate a translation
1361error, so clear $! before calling strtol. However, non-POSIX systems
1362may not check for overflow, and therefore will never set $!.
1363
1364strtol should respect any POSIX I<setlocale()> settings.
1365
1366To parse a string $str as a number in some base $base use
1367
1368 $! = 0;
1369 ($num, $n_unparsed) = POSIX::strtol($str, $base);
1370
1371The base should be zero or between 2 and 36, inclusive. When the base
1372is zero or omitted strtol will use the string itself to determine the
1373base: a leading "0x" or "0X" means hexadecimal; a leading "0" means
1374octal; any other leading characters mean decimal. Thus, "1234" is
1375parsed as a decimal number, "01234" as an octal number, and "0x1234"
1376as a hexadecimal number.
1377
1378The second returned item and $! can be used to check for valid input:
1379
1380 if (($str eq '') || ($n_unparsed != 0) || !$!) {
1381 die "Non-numeric input $str" . $! ? ": $!\n" : "\n";
1382 }
1383
1384When called in a scalar context strtol returns the parsed number.
1385
1386=item strtoul
1387
1388String to unsigned (long) integer translation. strtoul() is identical
1389to strtol() except that strtoul() only parses unsigned integers. See
1390L</strtol> for details.
1391
1392Note: Some vendors supply strtod() and strtol() but not strtoul().
1393Other vendors that do supply strtoul() parse "-1" as a valid value.
1394
1395=item strxfrm
1396
1397String transformation. Returns the transformed string.
1398
1399 $dst = POSIX::strxfrm( $src );
1400
1401Used in conjunction with the C<strcoll()> function, see L</strcoll>.
1402
1403Not really needed since Perl can do this transparently, see
1404L<perllocale>.
1405
1406=item sysconf
1407
1408Retrieves values of system configurable variables.
1409
1410The following will get the machine's clock speed.
1411
1412 $clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK );
1413
1414Returns C<undef> on failure.
1415
1416=item system
1417
1418This is identical to Perl's builtin C<system()> function, see
1419L<perlfunc/system>.
1420
1421=item tan
1422
1423This is identical to the C function C<tan()>, returning the
1424tangent of the numerical argument. See also L<Math::Trig>.
1425
1426=item tanh
1427
1428This is identical to the C function C<tanh()>, returning the
1429hyperbolic tangent of the numerical argument. See also L<Math::Trig>.
1430
1431=item tcdrain
1432
1433This is similar to the C function C<tcdrain()> for draining
1434the output queue of its argument stream.
1435
1436Returns C<undef> on failure.
1437
1438=item tcflow
1439
1440This is similar to the C function C<tcflow()> for controlling
1441the flow of its argument stream.
1442
1443Returns C<undef> on failure.
1444
1445=item tcflush
1446
1447This is similar to the C function C<tcflush()> for flushing
1448the I/O buffers of its argument stream.
1449
1450Returns C<undef> on failure.
1451
1452=item tcgetpgrp
1453
1454This is identical to the C function C<tcgetpgrp()> for returning the
1455process group identifier of the foreground process group of the controlling
1456terminal.
1457
1458=item tcsendbreak
1459
1460This is similar to the C function C<tcsendbreak()> for sending
1461a break on its argument stream.
1462
1463Returns C<undef> on failure.
1464
1465=item tcsetpgrp
1466
1467This is similar to the C function C<tcsetpgrp()> for setting the
1468process group identifier of the foreground process group of the controlling
1469terminal.
1470
1471Returns C<undef> on failure.
1472
1473=item time
1474
1475This is identical to Perl's builtin C<time()> function
1476for returning the number of seconds since the epoch
1477(whatever it is for the system), see L<perlfunc/time>.
1478
1479=item times
1480
1481The times() function returns elapsed realtime since some point in the past
1482(such as system startup), user and system times for this process, and user
1483and system times used by child processes. All times are returned in clock
1484ticks.
1485
1486 ($realtime, $user, $system, $cuser, $csystem) = POSIX::times();
1487
1488Note: Perl's builtin C<times()> function returns four values, measured in
1489seconds.
1490
1491=item tmpfile
1492
1493Use method C<IO::File::new_tmpfile()> instead, or see L<File::Temp>.
1494
1495=item tmpnam
1496
1497Returns a name for a temporary file.
1498
1499 $tmpfile = POSIX::tmpnam();
1500
1501For security reasons, which are probably detailed in your system's
1502documentation for the C library tmpnam() function, this interface
1503should not be used; instead see L<File::Temp>.
1504
1505=item tolower
1506
1507This is identical to the C function, except that it can apply to a single
1508character or to a whole string. Consider using the C<lc()> function,
1509see L<perlfunc/lc>, or the equivalent C<\L> operator inside doublequotish
1510strings.
1511
1512=item toupper
1513
1514This is identical to the C function, except that it can apply to a single
1515character or to a whole string. Consider using the C<uc()> function,
1516see L<perlfunc/uc>, or the equivalent C<\U> operator inside doublequotish
1517strings.
1518
1519=item ttyname
1520
1521This is identical to the C function C<ttyname()> for returning the
1522name of the current terminal.
1523
1524=item tzname
1525
1526Retrieves the time conversion information from the C<tzname> variable.
1527
1528 POSIX::tzset();
1529 ($std, $dst) = POSIX::tzname();
1530
1531=item tzset
1532
1533This is identical to the C function C<tzset()> for setting
1534the current timezone based on the environment variable C<TZ>,
1535to be used by C<ctime()>, C<localtime()>, C<mktime()>, and C<strftime()>
1536functions.
1537
1538=item umask
1539
1540This is identical to Perl's builtin C<umask()> function
1541for setting (and querying) the file creation permission mask,
1542see L<perlfunc/umask>.
1543
1544=item uname
1545
1546Get name of current operating system.
1547
1548 ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
1549
1550Note that the actual meanings of the various fields are not
1551that well standardized, do not expect any great portability.
1552The C<$sysname> might be the name of the operating system,
1553the C<$nodename> might be the name of the host, the C<$release>
1554might be the (major) release number of the operating system,
1555the C<$version> might be the (minor) release number of the
1556operating system, and the C<$machine> might be a hardware identifier.
1557Maybe.
1558
1559=item ungetc
1560
1561Use method C<IO::Handle::ungetc()> instead.
1562
1563=item unlink
1564
1565This is identical to Perl's builtin C<unlink()> function
1566for removing files, see L<perlfunc/unlink>.
1567
1568=item utime
1569
1570This is identical to Perl's builtin C<utime()> function
1571for changing the time stamps of files and directories,
1572see L<perlfunc/utime>.
1573
1574=item vfprintf
1575
1576vfprintf() is C-specific, see L<perlfunc/printf> instead.
1577
1578=item vprintf
1579
1580vprintf() is C-specific, see L<perlfunc/printf> instead.
1581
1582=item vsprintf
1583
1584vsprintf() is C-specific, see L<perlfunc/sprintf> instead.
1585
1586=item wait
1587
1588This is identical to Perl's builtin C<wait()> function,
1589see L<perlfunc/wait>.
1590
1591=item waitpid
1592
1593Wait for a child process to change state. This is identical to Perl's
1594builtin C<waitpid()> function, see L<perlfunc/waitpid>.
1595
1596 $pid = POSIX::waitpid( -1, POSIX::WNOHANG );
1597 print "status = ", ($? / 256), "\n";
1598
1599=item wcstombs
1600
1601This is identical to the C function C<wcstombs()>.
1602Perl does not have any support for the wide and multibyte
1603characters of the C standards, so this might be a rather
1604useless function.
1605
1606=item wctomb
1607
1608This is identical to the C function C<wctomb()>.
1609Perl does not have any support for the wide and multibyte
1610characters of the C standards, so this might be a rather
1611useless function.
1612
1613=item write
1614
1615Write to a file. This uses file descriptors such as those obtained by
1616calling C<POSIX::open>.
1617
1618 $fd = POSIX::open( "foo", &POSIX::O_WRONLY );
1619 $buf = "hello";
1620 $bytes = POSIX::write( $b, $buf, 5 );
1621
1622Returns C<undef> on failure.
1623
1624See also L<perlfunc/syswrite>.
1625
1626=back
1627
1628=head1 CLASSES
1629
1630=head2 POSIX::SigAction
1631
1632=over 8
1633
1634=item new
1635
1636Creates a new C<POSIX::SigAction> object which corresponds to the C
1637C<struct sigaction>. This object will be destroyed automatically when it is
1638no longer needed. The first parameter is the fully-qualified name of a sub
1639which is a signal-handler. The second parameter is a C<POSIX::SigSet>
1640object, it defaults to the empty set. The third parameter contains the
1641C<sa_flags>, it defaults to 0.
1642
1643 $sigset = POSIX::SigSet->new(SIGINT, SIGQUIT);
1644 $sigaction = POSIX::SigAction->new( \&main::handler, $sigset, &POSIX::SA_NOCLDSTOP );
1645
1646This C<POSIX::SigAction> object is intended for use with the C<POSIX::sigaction()>
1647function.
1648
1649=back
1650
1651=over 8
1652
1653=item handler
1654
1655=item mask
1656
1657=item flags
1658
1659accessor functions to get/set the values of a SigAction object.
1660
1661 $sigset = $sigaction->mask;
1662 $sigaction->flags(&POSIX::SA_RESTART);
1663
1664=item safe
1665
1666accessor function for the "safe signals" flag of a SigAction object; see
1667L<perlipc> for general information on safe (a.k.a. "deferred") signals. If
1668you wish to handle a signal safely, use this accessor to set the "safe" flag
1669in the C<POSIX::SigAction> object:
1670
1671 $sigaction->safe(1);
1672
1673You may also examine the "safe" flag on the output action object which is
1674filled in when given as the third parameter to C<POSIX::sigaction()>:
1675
1676 sigaction(SIGINT, $new_action, $old_action);
1677 if ($old_action->safe) {
1678 # previous SIGINT handler used safe signals
1679 }
1680
1681=back
1682
1683=head2 POSIX::SigSet
1684
1685=over 8
1686
1687=item new
1688
1689Create a new SigSet object. This object will be destroyed automatically
1690when it is no longer needed. Arguments may be supplied to initialize the
1691set.
1692
1693Create an empty set.
1694
1695 $sigset = POSIX::SigSet->new;
1696
1697Create a set with SIGUSR1.
1698
1699 $sigset = POSIX::SigSet->new( &POSIX::SIGUSR1 );
1700
1701=item addset
1702
1703Add a signal to a SigSet object.
1704
1705 $sigset->addset( &POSIX::SIGUSR2 );
1706
1707Returns C<undef> on failure.
1708
1709=item delset
1710
1711Remove a signal from the SigSet object.
1712
1713 $sigset->delset( &POSIX::SIGUSR2 );
1714
1715Returns C<undef> on failure.
1716
1717=item emptyset
1718
1719Initialize the SigSet object to be empty.
1720
1721 $sigset->emptyset();
1722
1723Returns C<undef> on failure.
1724
1725=item fillset
1726
1727Initialize the SigSet object to include all signals.
1728
1729 $sigset->fillset();
1730
1731Returns C<undef> on failure.
1732
1733=item ismember
1734
1735Tests the SigSet object to see if it contains a specific signal.
1736
1737 if( $sigset->ismember( &POSIX::SIGUSR1 ) ){
1738 print "contains SIGUSR1\n";
1739 }
1740
1741=back
1742
1743=head2 POSIX::Termios
1744
1745=over 8
1746
1747=item new
1748
1749Create a new Termios object. This object will be destroyed automatically
1750when it is no longer needed. A Termios object corresponds to the termios
1751C struct. new() mallocs a new one, getattr() fills it from a file descriptor,
1752and setattr() sets a file descriptor's parameters to match Termios' contents.
1753
1754 $termios = POSIX::Termios->new;
1755
1756=item getattr
1757
1758Get terminal control attributes.
1759
1760Obtain the attributes for stdin.
1761
1762 $termios->getattr()
1763
1764Obtain the attributes for stdout.
1765
1766 $termios->getattr( 1 )
1767
1768Returns C<undef> on failure.
1769
1770=item getcc
1771
1772Retrieve a value from the c_cc field of a termios object. The c_cc field is
1773an array so an index must be specified.
1774
1775 $c_cc[1] = $termios->getcc(1);
1776
1777=item getcflag
1778
1779Retrieve the c_cflag field of a termios object.
1780
1781 $c_cflag = $termios->getcflag;
1782
1783=item getiflag
1784
1785Retrieve the c_iflag field of a termios object.
1786
1787 $c_iflag = $termios->getiflag;
1788
1789=item getispeed
1790
1791Retrieve the input baud rate.
1792
1793 $ispeed = $termios->getispeed;
1794
1795=item getlflag
1796
1797Retrieve the c_lflag field of a termios object.
1798
1799 $c_lflag = $termios->getlflag;
1800
1801=item getoflag
1802
1803Retrieve the c_oflag field of a termios object.
1804
1805 $c_oflag = $termios->getoflag;
1806
1807=item getospeed
1808
1809Retrieve the output baud rate.
1810
1811 $ospeed = $termios->getospeed;
1812
1813=item setattr
1814
1815Set terminal control attributes.
1816
1817Set attributes immediately for stdout.
1818
1819 $termios->setattr( 1, &POSIX::TCSANOW );
1820
1821Returns C<undef> on failure.
1822
1823=item setcc
1824
1825Set a value in the c_cc field of a termios object. The c_cc field is an
1826array so an index must be specified.
1827
1828 $termios->setcc( &POSIX::VEOF, 1 );
1829
1830=item setcflag
1831
1832Set the c_cflag field of a termios object.
1833
1834 $termios->setcflag( $c_cflag | &POSIX::CLOCAL );
1835
1836=item setiflag
1837
1838Set the c_iflag field of a termios object.
1839
1840 $termios->setiflag( $c_iflag | &POSIX::BRKINT );
1841
1842=item setispeed
1843
1844Set the input baud rate.
1845
1846 $termios->setispeed( &POSIX::B9600 );
1847
1848Returns C<undef> on failure.
1849
1850=item setlflag
1851
1852Set the c_lflag field of a termios object.
1853
1854 $termios->setlflag( $c_lflag | &POSIX::ECHO );
1855
1856=item setoflag
1857
1858Set the c_oflag field of a termios object.
1859
1860 $termios->setoflag( $c_oflag | &POSIX::OPOST );
1861
1862=item setospeed
1863
1864Set the output baud rate.
1865
1866 $termios->setospeed( &POSIX::B9600 );
1867
1868Returns C<undef> on failure.
1869
1870=item Baud rate values
1871
1872B38400 B75 B200 B134 B300 B1800 B150 B0 B19200 B1200 B9600 B600 B4800 B50 B2400 B110
1873
1874=item Terminal interface values
1875
1876TCSADRAIN TCSANOW TCOON TCIOFLUSH TCOFLUSH TCION TCIFLUSH TCSAFLUSH TCIOFF TCOOFF
1877
1878=item c_cc field values
1879
1880VEOF VEOL VERASE VINTR VKILL VQUIT VSUSP VSTART VSTOP VMIN VTIME NCCS
1881
1882=item c_cflag field values
1883
1884CLOCAL CREAD CSIZE CS5 CS6 CS7 CS8 CSTOPB HUPCL PARENB PARODD
1885
1886=item c_iflag field values
1887
1888BRKINT ICRNL IGNBRK IGNCR IGNPAR INLCR INPCK ISTRIP IXOFF IXON PARMRK
1889
1890=item c_lflag field values
1891
1892ECHO ECHOE ECHOK ECHONL ICANON IEXTEN ISIG NOFLSH TOSTOP
1893
1894=item c_oflag field values
1895
1896OPOST
1897
1898=back
1899
1900=head1 PATHNAME CONSTANTS
1901
1902=over 8
1903
1904=item Constants
1905
1906_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
1907
1908=back
1909
1910=head1 POSIX CONSTANTS
1911
1912=over 8
1913
1914=item Constants
1915
1916_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
1917
1918=back
1919
1920=head1 SYSTEM CONFIGURATION
1921
1922=over 8
1923
1924=item Constants
1925
1926_SC_ARG_MAX _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
1927
1928=back
1929
1930=head1 ERRNO
1931
1932=over 8
1933
1934=item Constants
1935
1936E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN EALREADY EBADF
1937EBUSY ECHILD ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ
1938EDOM EDQUOT EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS EINTR
1939EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK EMSGSIZE ENAMETOOLONG
1940ENETDOWN ENETRESET ENETUNREACH ENFILE ENOBUFS ENODEV ENOENT ENOEXEC
1941ENOLCK ENOMEM ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
1942ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM EPFNOSUPPORT EPIPE
1943EPROCLIM EPROTONOSUPPORT EPROTOTYPE ERANGE EREMOTE ERESTART EROFS
1944ESHUTDOWN ESOCKTNOSUPPORT ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS
1945ETXTBSY EUSERS EWOULDBLOCK EXDEV
1946
1947=back
1948
1949=head1 FCNTL
1950
1951=over 8
1952
1953=item Constants
1954
1955FD_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
1956
1957=back
1958
1959=head1 FLOAT
1960
1961=over 8
1962
1963=item Constants
1964
1965DBL_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
1966
1967=back
1968
1969=head1 LIMITS
1970
1971=over 8
1972
1973=item Constants
1974
1975ARG_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
1976
1977=back
1978
1979=head1 LOCALE
1980
1981=over 8
1982
1983=item Constants
1984
1985LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME
1986
1987=back
1988
1989=head1 MATH
1990
1991=over 8
1992
1993=item Constants
1994
1995HUGE_VAL
1996
1997=back
1998
1999=head1 SIGNAL
2000
2001=over 8
2002
2003=item Constants
2004
2005SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK SA_RESETHAND SA_RESTART
2006SA_SIGINFO SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT
2007SIGKILL SIGPIPE SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU
2008SIGUSR1 SIGUSR2 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK
2009SIG_UNBLOCK
2010
2011=back
2012
2013=head1 STAT
2014
2015=over 8
2016
2017=item Constants
2018
2019S_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
2020
2021=item Macros
2022
2023S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG
2024
2025=back
2026
2027=head1 STDLIB
2028
2029=over 8
2030
2031=item Constants
2032
2033EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX RAND_MAX
2034
2035=back
2036
2037=head1 STDIO
2038
2039=over 8
2040
2041=item Constants
2042
2043BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid L_tmpname TMP_MAX
2044
2045=back
2046
2047=head1 TIME
2048
2049=over 8
2050
2051=item Constants
2052
2053CLK_TCK CLOCKS_PER_SEC
2054
2055=back
2056
2057=head1 UNISTD
2058
2059=over 8
2060
2061=item Constants
2062
2063R_OK SEEK_CUR SEEK_END SEEK_SET STDIN_FILENO STDOUT_FILENO STDERR_FILENO W_OK X_OK
2064
2065=back
2066
2067=head1 WAIT
2068
2069=over 8
2070
2071=item Constants
2072
2073WNOHANG WUNTRACED
2074
2075=over 16
2076
2077=item WNOHANG
2078
2079Do not suspend the calling process until a child process
2080changes state but instead return immediately.
2081
2082=item WUNTRACED
2083
2084Catch stopped child processes.
2085
2086=back
2087
2088=item Macros
2089
2090WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG WIFSTOPPED WSTOPSIG
2091
2092=over 16
2093
2094=item WIFEXITED
2095
2096WIFEXITED($?) returns true if the child process exited normally
2097(C<exit()> or by falling off the end of C<main()>)
2098
2099=item WEXITSTATUS
2100
2101WEXITSTATUS($?) returns the normal exit status of the child process
2102(only meaningful if WIFEXITED($?) is true)
2103
2104=item WIFSIGNALED
2105
2106WIFSIGNALED($?) returns true if the child process terminated because
2107of a signal
2108
2109=item WTERMSIG
2110
2111WTERMSIG($?) returns the signal the child process terminated for
2112(only meaningful if WIFSIGNALED($?) is true)
2113
2114=item WIFSTOPPED
2115
2116WIFSTOPPED($?) returns true if the child process is currently stopped
2117(can happen only if you specified the WUNTRACED flag to waitpid())
2118
2119=item WSTOPSIG
2120
2121WSTOPSIG($?) returns the signal the child process was stopped for
2122(only meaningful if WIFSTOPPED($?) is true)
2123
2124=back
2125
2126=back
2127
Note: See TracBrowser for help on using the repository browser.