1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
|
#!/tmp/perl5 -w
#!/tmp/perl5
# Ramrodded by Dean Roehrich.
#
# Submissions for function descriptions are needed. Don't write a tutorial,
# and don't repeat things that can be found in the system's manpages,
# just give a quick 2-3 line note and a one-line example.
#
# Check the latest version of the Perl5 Module List for Dean's current
# email address (listed as DMR).
#
my $VERS = 951129; # yymmdd
local *main::XS;
local *main::PM;
open( XS, "<POSIX.xs" ) || die "Unable to open POSIX.xs";
open( PM, "<POSIX.pm" ) || die "Unable to open POSIX.pm";
close STDOUT;
open( STDOUT, ">POSIX.pod" ) || die "Unable to open POSIX.pod";
print <<'EOQ';
=head1 NAME
POSIX - Perl interface to IEEE Std 1003.1
=head1 SYNOPSIS
use POSIX;
use POSIX qw(setsid);
use POSIX qw(:errno_h :fcntl_h);
printf "EINTR is %d\n", EINTR;
$sess_id = POSIX::setsid();
$fd = POSIX::open($path, O_CREAT|O_EXCL|O_WRONLY, 0644);
# note: that's a filedescriptor, *NOT* a filehandle
=head1 DESCRIPTION
The POSIX module permits you to access all (or nearly all) the standard
POSIX 1003.1 identifiers. Many of these identifiers have been given Perl-ish
interfaces. Things which are C<#defines> in C, like EINTR or O_NDELAY, are
automatically exported into your namespace. All functions are only exported
if you ask for them explicitly. Most likely people will prefer to use the
fully-qualified function names.
This document gives a condensed list of the features available in the POSIX
module. Consult your operating system's manpages for general information on
most features. Consult L<perlfunc> for functions which are noted as being
identical to Perl's builtin functions.
The first section describes POSIX functions from the 1003.1 specification.
The second section describes some classes for signal objects, TTY objects,
and other miscellaneous objects. The remaining sections list various
constants and macros in an organization which roughly follows IEEE Std
1003.1b-1993.
=head1 NOTE
The POSIX module is probably the most complex Perl module supplied with
the standard distribution. It incorporates autoloading, namespace games,
and dynamic loading of code that's in Perl, C, or both. It's a great
source of wisdom.
=head1 CAVEATS
A few functions are not implemented because they are C specific. If you
attempt to call these, they will print a message telling you that they
aren't implemented, and suggest using the Perl equivalent should one
exist. For example, trying to access the setjmp() call will elicit the
message "setjmp() is C-specific: use eval {} instead".
Furthermore, some evil vendors will claim 1003.1 compliance, but in fact
are not so: they will not pass the PCTS (POSIX Compliance Test Suites).
For example, one vendor may not define EDEADLK, or the semantics of the
errno values set by open(2) might not be quite right. Perl does not
attempt to verify POSIX compliance. That means you can currently
successfully say "use POSIX", and then later in your program you find
that your vendor has been lax and there's no usable ICANON macro after
all. This could be construed to be a bug.
EOQ
use strict;
my $constants = {};
my $macros = {};
my $packages = [];
my $posixpack = Package->new( 'POSIX' );
my $descriptions = Description->new;
get_constants( 'XS', $constants, $macros );
get_functions( 'XS', $packages, $posixpack );
get_PMfunctions( 'PM', $packages, $posixpack, $descriptions );
# It is possible that the matches of setup_*() may depend on
# the matches of an earlier setup_*(). If you change the order,
# be careful that you're getting only what you want, and no more.
#
my $termios_flags = setup_termios( $constants );
my $wait_stuff = setup_wait( $constants, $macros );
my $stat = setup_file_char( $constants, $macros );
my $port = setup_pat( $constants, '^_POSIX' );
my $sc = setup_pat( $constants, '^_SC_' );
my $pc = setup_pat( $constants, '^_PC_' );
my $fcntl = setup_pat( $constants, '^([FO]_|FD_)' );
my $sigs = setup_pat( $constants, '^(SIG|SA_)' );
my $float = setup_pat( $constants, '^(L?DBL_|FLT_)' );
my $locale = setup_pat( $constants, '^LC_' );
my $stdio = setup_pat( $constants, '(^BUFSIZ$)|(^L_)|(^_IO...$)|(^EOF$)|(^FILENAME_MAX$)|(^TMP_MAX$)' );
my $stdlib = setup_pat( $constants, '(^EXIT_)|(^MB_CUR_MAX$)|(^RAND_MAX$)' );
my $limits = setup_pat( $constants, '(_MAX$)|(_MIN$)|(_BIT$)|(^MAX_)|(_BUF$)' );
my $math = setup_pat( $constants, '^HUGE_VAL$' );
my $time = setup_pat( $constants, '^CL' );
my $unistd = setup_pat( $constants, '(_FILENO$)|(^SEEK_...$)|(^._OK$)' );
my $errno = setup_pat( $constants, '^E' );
print_posix( $posixpack, $descriptions );
print_classes( $packages, $constants, $termios_flags, $descriptions );
print_misc( 'Pathname Constants', $pc );
print_misc( 'POSIX Constants', $port );
print_misc( 'System Configuration', $sc );
print_misc( 'Errno', $errno );
print_misc( 'Fcntl', $fcntl );
print_misc( 'Float', $float );
print_misc( 'Limits', $limits );
print_misc( 'Locale', $locale );
print_misc( 'Math', $math );
print_misc( 'Signal', $sigs );
print_misc( 'Stat', $stat );
print_misc( 'Stdlib', $stdlib );
print_misc( 'Stdio', $stdio );
print_misc( 'Time', $time );
print_misc( 'Unistd', $unistd );
print_misc( 'Wait', $wait_stuff );
print_vers( $VERS );
dregs( $macros, $constants );
exit(0);
Unimplemented.
sub dregs {
my $macros = shift;
my $constants = shift;
foreach (keys %$macros){
warn "Unknown macro $_ in the POSIX.xs module.\n";
}
foreach (keys %$constants){
warn "Unknown constant $_ in the POSIX.xs module.\n";
}
}
sub get_constants {
no strict 'refs';
my $fh = shift;
my $constants = shift;
my $macros = shift;
my $v;
while(<$fh>){
last if /^constant/;
}
while(<$fh>){ # }{{
last if /^}/;
if( /return\s+([^;]+)/ ){
$v = $1;
# skip non-symbols
if( $v !~ /^\d+$/ ){
# remove any C casts
$v =~ s,\(.*?\)\s*(\w),$1,;
# is it a macro?
if( $v =~ s/(\(.*?\))// ){
$macros->{$v} = $1;
}
else{
$constants->{$v} = 1;
}
}
}
}
}
Close the file. This uses file descriptors such as those obtained by calling
C<POSIX::open>.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY );
POSIX::close( $fd );
sub get_functions {
no strict 'refs';
my $fh = shift;
my $packages = shift;
my $posixpack = shift;
my $header = 0;
my $pack = '';
my $prefix = '';
my( $x, $y );
my( $curfuncs, $curpack );
my $ret;
while(<$fh>){
if( /^MODULE.*?PACKAGE\s*=\s*([^\s]+)/ ){
$pack = $1;
$prefix = '';
if( /PREFIX\s*=\s*([^\n]+)/ ){
$prefix = $1;
}
#print "package($pack) prefix($prefix)\n";
if( $pack eq 'POSIX' ){
$curpack = $posixpack;
}
else{
$curpack = Package->new( $pack );
push @$packages, $curpack;
}
$curfuncs = $curpack->curfuncs;
next;
}
chop;
# find function header
if( /^[^\s]/ && ! /^#/ ){
$ret = /^SysRet/ ? 2 : 1;
chop($x = <$fh>);
next if( $pack eq 'POSIX' and $x =~ /^constant/ );
$x =~ /^(.*?)\s*\((.*?)\)/;
($x,$y) = ($1, $2); # func,sig
$x =~ s/^$prefix//;
$curfuncs->{$x} = $ret;
++$header
}
# leave function header
else{
$header = 0;
}
}
}
sub get_PMfunctions {
no strict 'refs';
my $fh = shift;
my $packages = shift;
my $posixpack = shift;
my $desc = shift;
my $pack = '';
my( $curfuncs, $curpack );
my $y;
my $x;
my $sub = '';
# find the second package statement.
while(<$fh>){
if( /^package\s+(.*?);/ ){
$pack = $1;
last if $pack ne 'POSIX';
}
}
# Check if this package is already
# being used.
$curpack = '';
foreach (@$packages){
if( $_->name eq $pack ){
$curpack = $_;
last;
}
}
# maybe start a new package.
if( $curpack eq '' ){
$curpack = Package->new( $pack );
push @$packages, $curpack;
}
$curfuncs = $curpack->curfuncs;
# now fetch functions
while(<$fh>){
if( /^package\s+(.*?);/ ){
$pack = $1;
if( $pack eq 'POSIX' ){
$curpack = $posixpack;
}
else{
# Check if this package is already
# being used.
$curpack = '';
foreach (@$packages){
if( $_->name() eq $pack ){
$curpack = $_;
last;
}
}
# maybe start a new package.
if( $curpack eq '' ){
$curpack = Package->new( $pack );
push @$packages, $curpack;
}
}
$curfuncs = $curpack->curfuncs;
next;
}
if( /^sub\s+(.*?)\s/ ){
$sub = $1;
# special cases
if( $pack eq 'POSIX::SigAction' and
$sub eq 'new' ){
$curfuncs->{$sub} = 1;
}
elsif( $pack eq 'POSIX' and $sub eq 'perror' ){
$curfuncs->{$sub} = 1;
}
next;
}
if( /usage.*?\((.*?)\)/ ){
$y = $1;
$curfuncs->{$sub} = 1;
next;
}
if( /^\s+unimpl\s+"(.*?)"/ ){
$y = $1;
$y =~ s/, stopped//;
$desc->append( $pack, $sub, $y );
$curfuncs->{$sub} = 1;
next;
}
if( /^\s+redef\s+"(.*?)"/ ){
$x = $1;
$y = "Use method C<$x> instead";
$desc->append( $pack, $sub, $y );
$curfuncs->{$sub} = 1;
next;
}
}
}
Retrieves the value of a configurable limit on a file or directory. This
uses file descriptors such as those obtained by calling C<POSIX::open>.
The following will determine the maximum length of the longest allowable
pathname on the filesystem which holds C</tmp/foo>.
$fd = POSIX::open( "/tmp/foo", &POSIX::O_RDONLY );
$path_max = POSIX::fpathconf( $fd, &POSIX::_PC_PATH_MAX );
Return the mantissa and exponent of a floating-point number.
($mantissa, $exponent) = POSIX::frexp( 3.14 );
Get file status. This uses file descriptors such as those obtained by
calling C<POSIX::open>. The data returned is identical to the data from
Perl's builtin C<stat> function.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY );
@stats = POSIX::fstat( $fd );
sub print_posix {
my $pack = shift;
my $desc = shift;
print "=head1 FUNCTIONS\n\n";
print "=over 8\n\n";
dumpfuncs( $pack, $desc );
print "=back\n\n";
}
sub print_classes {
my $packages = shift;
my $constants = shift;
my $termios = shift;
my $desc = shift;
my $pack;
my @pkgs;
print "=head1 CLASSES\n\n";
@pkgs = sort { $main::a->name() cmp $main::b->name() } @$packages;
while( @pkgs ){
$pack = shift @pkgs;
print "=head2 ", $pack->name(), "\n\n";
print "=over 8\n\n";
dumpfuncs( $pack, $desc );
if( $pack->name() =~ /termios/i ){
dumpflags( $termios );
}
print "=back\n\n";
}
}
sub setup_termios {
my $constants = shift;
my $obj;
$obj = {
'c_iflag field' => [qw( BRKINT ICRNL IGNBRK IGNCR IGNPAR
INLCR INPCK ISTRIP IXOFF IXON
PARMRK )],
'c_oflag field' => [qw( OPOST )],
'c_cflag field' => [qw( CLOCAL CREAD CSIZE CS5 CS6 CS7 CS8
CSTOPB HUPCL PARENB PARODD )],
'c_lflag field' => [qw( ECHO ECHOE ECHOK ECHONL ICANON
IEXTEN ISIG NOFLSH TOSTOP )],
'c_cc field' => [qw( VEOF VEOL VERASE VINTR VKILL VQUIT
VSUSP VSTART VSTOP VMIN VTIME NCCS )],
'Baud rate' => [],
'Terminal interface' => [],
};
# look for baud rates in constants, add to termios
foreach (keys %$constants){
if( /^B\d+$/ ){
push @{$obj->{'Baud rate'}}, $_;
}
}
# look for TC* in constants, add to termios
foreach (keys %$constants){
if( /^TC/ ){
push @{$obj->{'Terminal interface'}}, $_;
}
}
# trim the constants
foreach (keys %$obj){
trim_hash( 'Constant', $obj->{$_}, $constants );
}
return $obj;
}
sub dumpfuncs {
my $pack = shift;
my $desc = shift;
my $curfuncs = $pack->curfuncs;
my $pname = $pack->name;
my $func;
my @funcs = sort keys %$curfuncs;
if( exists $curfuncs->{'new'} ){ # do new first
@funcs = grep( $_ ne 'new', @funcs );
unshift @funcs, 'new';
}
while( @funcs ){
$func = shift @funcs;
if( $func eq 'DESTROY' ){
next; # don't do DESTROY
}
print "=item $func\n\n";
if( $desc->print( $pname, $func, $curfuncs->{$func} ) ){
# if it was printed, note that
delete $curfuncs->{$func};
}
}
}
sub dumpflags {
my $flags = shift;
my $field;
foreach $field (sort keys %$flags){
print "=item $field values\n\n";
print join( ' ', @{$flags->{$field}} ), "\n\n";
}
}
sub setup_wait {
my $constants = shift;
my $macros = shift;
my $obj;
$obj = {
'Macros' => [qw( WIFEXITED WEXITSTATUS WIFSIGNALED
WTERMSIG WIFSTOPPED WSTOPSIG )],
'Constants' => [qw( WNOHANG WUNTRACED )],
};
trim_hash( 'Constant', $obj->{Constants}, $constants );
trim_hash( 'Macro', $obj->{Macros}, $macros );
return $obj;
}
sub setup_file_char {
my $constants = shift;
my $macros = shift;
my $obj;
$obj = {
'Macros' => [],
'Constants' => [],
};
# find S_* constants and add to object.
foreach (sort keys %$constants){
if( /^S_/ ){
push @{$obj->{'Constants'}}, $_;
}
}
# find S_* macros and add to object.
foreach (sort keys %$macros){
if( /^S_/ ){
push @{$obj->{'Macros'}}, $_;
}
}
# trim the hashes
trim_hash( 'Constant', $obj->{Constants}, $constants );
trim_hash( 'Macro', $obj->{Macros}, $macros );
return $obj;
}
sub setup_pat {
my $constants = shift;
my $pat = shift;
my $obj;
$obj = { 'Constants' => [] };
foreach (sort keys %$constants){
if( /$pat/ ){
push @{$obj->{'Constants'}}, $_;
}
}
trim_hash( 'Constant', $obj->{Constants}, $constants );
return $obj;
}
Get numeric formatting information. Returns a reference to a hash
containing the current locale formatting values.
The database for the B<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";
Move the read/write file pointer. This uses file descriptors such as
those obtained by calling C<POSIX::open>.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY );
$off_t = POSIX::lseek( $fd, 0, &POSIX::SEEK_SET );
sub print_vers {
my $vers = shift;
print "=head1 CREATION\n\n";
print "This document generated by $0 version $vers.\n\n";
}
sub print_misc {
my $hdr = shift;
my $obj = shift;
my $item;
print "=head1 ", uc($hdr), "\n\n";
print "=over 8\n\n";
foreach $item (sort keys %$obj){
print "=item $item\n\n";
print join( ' ', @{$obj->{$item}}), "\n\n";
}
print "=back\n\n";
}
sub trim_hash {
my $name = shift;
my $av = shift;
my $hv = shift;
foreach (@$av){
if( exists $hv->{$_} ){
delete $hv->{$_};
}
else{
warn "$name $_ is not in the POSIX.xs module";
}
}
}
{ package Package; ## Package package
sub new {
my $type = shift;
my $pack = shift || die;
my $self = [ $pack, {} ];
bless $self, $type;
}
sub name {
my $self = shift;
$self->[0];
}
sub curfuncs {
my $self = shift;
$self->[1];
}
sub DESTROY {
my $self = shift;
my $pack = $self->name;
foreach (keys %{$self->curfuncs}){
if( $_ eq 'DESTROY' ){
next; # don't expect much on DESTROY
}
warn "Function ". $pack . "::$_ did not have a description.\n";
}
}
}
{ package Description; ## Function description
sub new {
my $type = shift;
my $self = {};
bless $self, $type;
$self->fetch;
return $self;
}
sub fetch {
my $self = shift;
my $pack = '';
my $c;
my( $sub, $as );
while(<main::DATA>){
next if /^#/;
$sub = $as = '';
if( /^==(.*)/ ){
$pack = $1;
next;
}
if( /^=([^\+]+)\+\+/ ){
$sub = $1;
$as = $sub;
}
elsif( /^=([^\+]+)\+C/ ){
$sub = $1;
$as = 'C';
}
elsif( /^=([^\+]+)\+(\w+)/ ){
$sub = $1;
$as = $2;
}
elsif( /^=(.*)/ ){
$sub = $1;
}
if( $sub ne '' ){
$sub = $1;
$self->{$pack."::$sub"} = '';
$c = \($self->{$pack."::$sub"});
if( $as eq 'C' ){
$$c .= "This is identical to the C function C<$sub()>.\n";
}
elsif( $as ne '' ){
$$c .= "This is identical to Perl's builtin C<$as()> function.\n";
}
next;
}
$$c .= $_;
}
}
sub DESTROY {
my $self = shift;
foreach (keys %$self){
warn "Function $_ is not in the POSIX.xs module.\n";
}
}
sub append {
my $self = shift;
my $pack = shift;
my $sub = shift;
my $str = shift || die;
if( exists $self->{$pack."::$sub"} ){
$self->{$pack."::$sub"} .= "\n$str.\n";
}
else{
$self->{$pack."::$sub"} = "$str.\n";
}
}
sub print {
my $self = shift;
my $pack = shift;
my $sub = shift;
my $rtype = shift || die;
my $ret = 0;
if( exists $self->{$pack."::$sub"} ){
if( $rtype > 1 ){
$self->{$pack."::$sub"} =~ s/identical/similar/;
}
print $self->{$pack."::$sub"}, "\n";
delete $self->{$pack."::$sub"};
if( $rtype > 1 ){
print "Returns C<undef> on failure.\n\n";
}
$ret = 1;
}
$ret;
}
}
Create an interprocess channel. This returns file descriptors like those
returned by C<POSIX::open>.
($fd0, $fd1) = POSIX::pipe();
POSIX::write( $fd0, "hello", 5 );
POSIX::read( $fd1, $buf, 5 );
Read from a file. This uses file descriptors such as those obtained by
calling C<POSIX::open>. If the buffer C<$buf> is not large enough for the
read then Perl will extend it to make room for the request.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY );
$bytes = POSIX::read( $fd, $buf, 3 );
This is similar to the C function C<setpgid()>.
Detailed signal management. This uses C<POSIX::SigAction> objects for the
C<action> and C<oldaction> arguments. Consult your system's C<sigaction>
manpage for details.
Synopsis:
sigaction(sig, action, oldaction = 0)
Install a signal mask and suspend process until signal arrives. This uses
C<POSIX::SigSet> objects for the C<signal_mask> argument. Consult your
system's C<sigsuspend> manpage for details.
Synopsis:
sigsuspend(signal_mask)
This is identical to Perl's builtin C<sprintf()> function.
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 (C<mon>), weekday (C<wday>), and yearday (C<yday>) begin at zero.
I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The
year (C<year>) is given in years since 1900. I.e. The year 1995 is 95; the
year 2001 is 101. Consult your system's C<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";
String transformation. Returns the transformed string.
$dst = POSIX::strxfrm( $src );
Get name of current operating system.
($sysname, $nodename, $release, $version, $machine ) = POSIX::uname();
Returns the current file position, in bytes.
$pos = $fh->tell;
Get terminal control attributes.
Obtain the attributes for stdin.
$termios->getattr()
Obtain the attributes for stdout.
$termios->getattr( 1 )
Set terminal control attributes.
Set attributes immediately for stdout.
$termios->setattr( 1, &POSIX::TCSANOW );
__END__
##########
==POSIX::SigSet
=new
Create a new SigSet object. This object will be destroyed automatically
when it is no longer needed. Arguments may be supplied to initialize the
set.
Create an empty set.
$sigset = POSIX::SigSet->new;
Create a set with SIGUSR1.
$sigset = POSIX::SigSet->new( &POSIX::SIGUSR1 );
=addset
Add a signal to a SigSet object.
$sigset->addset( &POSIX::SIGUSR2 );
=delset
Remove a signal from the SigSet object.
$sigset->delset( &POSIX::SIGUSR2 );
=emptyset
Initialize the SigSet object to be empty.
$sigset->emptyset();
=fillset
Initialize the SigSet object to include all signals.
$sigset->fillset();
=ismember
Tests the SigSet object to see if it contains a specific signal.
if( $sigset->ismember( &POSIX::SIGUSR1 ) ){
print "contains SIGUSR1\n";
}
##########
==POSIX::Termios
=new
Create a new Termios object. This object will be destroyed automatically
when it is no longer needed.
$termios = POSIX::Termios->new;
=getiflag
Retrieve the c_iflag field of a termios object.
$c_iflag = $termios->getiflag;
=getoflag
Retrieve the c_oflag field of a termios object.
$c_oflag = $termios->getoflag;
=getcflag
Retrieve the c_cflag field of a termios object.
$c_cflag = $termios->getcflag;
=getlflag
Retrieve the c_lflag field of a termios object.
$c_lflag = $termios->getlflag;
=getcc
Retrieve a value from the c_cc field of a termios object. The c_cc field is
an array so an index must be specified.
$c_cc[1] = $termios->getcc(1);
=getospeed
Retrieve the output baud rate.
$ospeed = $termios->getospeed;
=getispeed
Retrieve the input baud rate.
$ispeed = $termios->getispeed;
=setiflag
Set the c_iflag field of a termios object.
$termios->setiflag( &POSIX::BRKINT );
=setoflag
Set the c_oflag field of a termios object.
$termios->setoflag( &POSIX::OPOST );
=setcflag
Set the c_cflag field of a termios object.
$termios->setcflag( &POSIX::CLOCAL );
=setlflag
Set the c_lflag field of a termios object.
$termios->setlflag( &POSIX::ECHO );
=setcc
Set a value in the c_cc field of a termios object. The c_cc field is an
array so an index must be specified.
$termios->setcc( 1, &POSIX::VEOF );
=setospeed
Set the output baud rate.
$termios->setospeed( &POSIX::B9600 );
=setispeed
Set the input baud rate.
$termios->setispeed( &POSIX::B9600 );
##
=setattr
=getattr
##########
==FileHandle
=new
=new_from_fd
=flush
=getc
=ungetc
=seek
=setbuf
=error
=clearerr
=tell
=getpos
=gets
=close
=new_tmpfile
=eof
=fileno
=setpos
=setvbuf
##########
==POSIX
=tolower+lc
=toupper+uc
=remove+unlink
=fabs+abs
=strstr+index
##
=closedir++
=readdir++
=rewinddir++
=fcntl++
=getgrgid++
=getgrnam++
=atan2++
=cos++
=exp++
=abs++
=log++
=sin++
=sqrt++
=getpwnam++
=getpwuid++
=kill++
=getc++
=rename++
=exit++
=system++
=chmod++
=mkdir++
=stat++
=umask++
=gmtime++
=localtime++
=time++
=alarm++
=chdir++
=chown++
=fork++
=getlogin++
=getpgrp++
=getppid++
=link++
=rmdir++
=sleep++
=unlink++
=utime++
##
=perror+C
=pause+C
=tzset+C
=difftime+C
=ctime+C
=clock+C
=asctime+C
=strcoll+C
=abort+C
=tcgetpgrp+C
=setsid+C
=_exit+C
=tanh+C
=tan+C
=sinh+C
=log10+C
=ldexp+C
=fmod+C
=floor+C
=cosh+C
=ceil+C
=atan+C
=asin+C
=acos+C
##
=isatty
Returns a boolean indicating whether the specified filehandle is connected
to a tty.
=setuid
Sets the real user id for this process.
=setgid
Sets the real group id for this process.
=getpid
Returns the process's id.
=getuid
Returns the user's id.
=getegid
Returns the effective group id.
=geteuid
Returns the effective user id.
=getgid
Returns the user's real group id.
=getgroups
Returns the ids of the user's supplementary groups.
=getcwd
Returns the name of the current working directory.
=strerror
Returns the error string for the specified errno.
=getenv
Returns the value of the specified enironment variable.
=getchar
Returns one character from STDIN.
=raise
Sends the specified signal to the current process.
=gets
Returns one line from STDIN.
=printf
Prints the specified arguments to STDOUT.
=rewind
Seeks to the beginning of the file.
##
=tmpnam
Returns a name for a temporary file.
$tmpfile = POSIX::tmpnam();
=cuserid
Get the character login name of the user.
$name = POSIX::cuserid();
=ctermid
Generates the path name for controlling terminal.
$path = POSIX::ctermid();
=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 C<times()> function returns four values, measured in
seconds.
=pow
Computes $x raised to the power $exponent.
$ret = POSIX::pow( $x, $exponent );
=errno
Returns the value of errno.
$errno = POSIX::errno();
=sysconf
Retrieves values of system configurable variables.
The following will get the machine's clock speed.
$clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK );
=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 C</tmp>.
$path_max = POSIX::pathconf( "/tmp", &POSIX::_PC_PATH_MAX );
=access
Determines the accessibility of a file.
if( POSIX::access( "/", &POSIX::R_OK ) ){
print "have read permission\n";
}
=setlocale
Modifies and queries program's locale.
The following will set the traditional UNIX system locale behavior.
This document generated by ./mkposixman.PL version 19951212.
##
=waitpid
=wait
=fstat
=sprintf
=opendir
=creat
=ttyname
=tzname
=fpathconf
=mktime
=tcsendbreak
=tcflush
=tcflow
=tcdrain
=tcsetpgrp
=mkfifo
=strxfrm
=wctomb
=wcstombs
=mbtowc
=mbstowcs
=mblen
=write
=uname
=setpgid
=read
=pipe
=nice
=lseek
=dup2
=dup
=close
=sigsuspend
=sigprocmask
=sigpending
=sigaction
=modf
=frexp
=localeconv
=open
=isxdigit
=isupper
=isspace
=ispunct
=isprint
=isgraph
=isdigit
=iscntrl
=isalpha
=isalnum
=islower
=assert
=strftime
##########
==POSIX::SigAction
=new
Creates a new SigAction object. This object will be destroyed automatically
when it is no longer needed.
|