This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Let h2xs read multiple header files
[perl5.git] / vms / ext / Stdio / Stdio.pm
CommitLineData
0d7e20a5 1# VMS::Stdio - VMS extensions to Perl's stdio calls
748a9306
LW
2#
3# Author: Charles Bailey bailey@genetics.upenn.edu
ff0cee69 4# Version: 2.02
5# Revised: 15-Feb-1997
0d7e20a5 6
7package VMS::Stdio;
8
9require 5.002;
10use vars qw( $VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS @ISA );
11use Carp '&croak';
12use DynaLoader ();
13use Exporter ();
14
ff0cee69 15$VERSION = '2.02';
740ce14c 16@ISA = qw( Exporter DynaLoader IO::File );
0d7e20a5 17@EXPORT = qw( &O_APPEND &O_CREAT &O_EXCL &O_NDELAY &O_NOWAIT
18 &O_RDONLY &O_RDWR &O_TRUNC &O_WRONLY );
19@EXPORT_OK = qw( &flush &getname &remove &rewind &sync &tmpnam
20 &vmsopen &vmssysopen &waitfh );
21%EXPORT_TAGS = ( CONSTANTS => [ qw( &O_APPEND &O_CREAT &O_EXCL &O_NDELAY
22 &O_NOWAIT &O_RDONLY &O_RDWR &O_TRUNC
23 &O_WRONLY ) ],
24 FUNCTIONS => [ qw( &flush &getname &remove &rewind &sync
25 &tmpnam &vmsopen &vmssysopen &waitfh ) ] );
26
27bootstrap VMS::Stdio $VERSION;
28
29sub AUTOLOAD {
30 my($constname) = $AUTOLOAD;
31 $constname =~ s/.*:://;
32 if ($constname =~ /^O_/) {
33 my($val) = constant($constname);
34 defined $val or croak("Unknown VMS::Stdio constant $constname");
5f05dabc 35 *$AUTOLOAD = sub { val; }
0d7e20a5 36 }
740ce14c 37 else { # We don't know about it; hand off to IO::File
38 require IO::File;
55497cff 39
5f05dabc 40 *$AUTOLOAD = eval "sub { shift->IO::File::$constname(\@_) }";
41 croak "Error autoloading IO::File::$constname: $@" if $@;
0d7e20a5 42 }
43 goto &$AUTOLOAD;
44}
45
46sub DESTROY { close($_[0]); }
47
48
49################################################################################
50# Intercept calls to old VMS::stdio package, complain, and hand off
51# This will be removed in a future version of VMS::Stdio
52
53package VMS::stdio;
54
55sub AUTOLOAD {
56 my($func) = $AUTOLOAD;
57 $func =~ s/.*:://;
58 # Cheap trick: we know DynaLoader has required Carp.pm
59 Carp::carp("Old package VMS::stdio is now VMS::Stdio; please update your code");
60 if ($func eq 'vmsfopen') {
61 Carp::carp("Old function &vmsfopen is now &vmsopen");
62 goto &VMS::Stdio::vmsopen;
63 }
64 elsif ($func eq 'fgetname') {
65 Carp::carp("Old function &fgetname is now &getname");
66 goto &VMS::Stdio::getname;
67 }
68 else { goto &{"VMS::Stdio::$func"}; }
69}
70
71package VMS::Stdio; # in case we ever use AutoLoader
72
731;
74
75__END__
748a9306
LW
76
77=head1 NAME
78
2ceaccd7 79VMS::Stdio - standard I/O functions via VMS extensions
748a9306
LW
80
81=head1 SYNOPSIS
82
0d7e20a5 83use VMS::Stdio qw( &flush &getname &remove &rewind &sync &tmpnam
84 &vmsopen &vmssysopen &waitfh );
85$uniquename = tmpnam;
86$fh = vmsopen("my.file","rfm=var","alq=100",...) or die $!;
87$name = getname($fh);
88print $fh "Hello, world!\n";
89flush($fh);
90sync($fh);
91rewind($fh);
92$line = <$fh>;
93undef $fh; # closes file
94$fh = vmssysopen("another.file", O_RDONLY | O_NDELAY, 0, "ctx=bin");
95sysread($fh,$data,128);
96waitfh($fh);
97close($fh);
98remove("another.file");
748a9306
LW
99
100=head1 DESCRIPTION
101
2ceaccd7 102This package gives Perl scripts access via VMS extensions to several
0d7e20a5 103C stdio operations not available through Perl's CORE I/O functions.
104The specific routines are described below. These functions are
105prototyped as unary operators, with the exception of C<vmsopen>
106and C<vmssysopen>, which can take any number of arguments, and
107C<tmpnam>, which takes none.
108
109All of the routines are available for export, though none are
110exported by default. All of the constants used by C<vmssysopen>
111to specify access modes are exported by default. The routines
112are associated with the Exporter tag FUNCTIONS, and the constants
113are associated with the Exporter tag CONSTANTS, so you can more
114easily choose what you'd like to import:
115
116 # import constants, but not functions
117 use VMS::Stdio; # same as use VMS::Stdio qw( :DEFAULT );
118 # import functions, but not constants
119 use VMS::Stdio qw( !:CONSTANTS :FUNCTIONS );
120 # import both
121 use VMS::Stdio qw( :CONSTANTS :FUNCTIONS );
122 # import neither
123 use VMS::Stdio ();
124
125Of course, you can also choose to import specific functions by
126name, as usual.
127
740ce14c 128This package C<ISA> IO::File, so that you can call IO::File
0d7e20a5 129methods on the handles returned by C<vmsopen> and C<vmssysopen>.
740ce14c 130The IO::File package is not initialized, however, until you
0d7e20a5 131actually call a method that VMS::Stdio doesn't provide. This
132is doen to save startup time for users who don't wish to use
740ce14c 133the IO::File methods.
0d7e20a5 134
135B<Note:> In order to conform to naming conventions for Perl
136extensions and functions, the name of this package has been
137changed to VMS::Stdio as of Perl 5.002, and the names of some
138routines have been changed. Calls to the old VMS::stdio routines
139will generate a warning, and will be routed to the equivalent
140VMS::Stdio function. This compatibility interface will be
141removed in a future release of this extension, so please
142update your code to use the new routines.
143
2ceaccd7
LV
144=over
145
0d7e20a5 146=item flush
147
148This function causes the contents of stdio buffers for the specified
149file handle to be flushed. If C<undef> is used as the argument to
150C<flush>, all currently open file handles are flushed. Like the CRTL
151fflush() routine, it does not flush any underlying RMS buffers for the
152file, so the data may not be flushed all the way to the disk. C<flush>
153returns a true value if successful, and C<undef> if not.
154
155=item getname
156
157The C<getname> function returns the file specification associated
740ce14c 158with a Perl I/O handle. If an error occurs, it returns C<undef>.
748a9306 159
0d7e20a5 160=item remove
748a9306 161
0d7e20a5 162This function deletes the file named in its argument, returning
163a true value if successful and C<undef> if not. It differs from
164the CORE Perl function C<unlink> in that it does not try to
165reset file protection if the original protection does not give
166you delete access to the file (cf. L<perlvms>). In other words,
167C<remove> is equivalent to
168
169 unlink($file) if VMS::Filespec::candelete($file);
748a9306 170
0d7e20a5 171=item rewind
172
173C<rewind> resets the current position of the specified file handle
174to the beginning of the file. It's really just a convenience
175method equivalent in effect to C<seek($fh,0,0)>. It returns a
176true value if successful, and C<undef> if it fails.
177
178=item sync
179
180This function flushes buffered data for the specified file handle
181from stdio and RMS buffers all the way to disk. If successful, it
182returns a true value; otherwise, it returns C<undef>.
183
184=item tmpnam
748a9306
LW
185
186The C<tmpnam> function returns a unique string which can be used
187as a filename when creating temporary files. If, for some
188reason, it is unable to generate a name, it returns C<undef>.
189
0d7e20a5 190=item vmsopen
748a9306 191
0d7e20a5 192The C<vmsopen> function enables you to specify optional RMS arguments
5f05dabc 193to the VMS CRTL when opening a file. Its operation is similar to the built-in
0d7e20a5 194Perl C<open> function (see L<perlfunc> for a complete description),
5f05dabc 195but it will only open normal files; it cannot open pipes or duplicate
740ce14c 196existing I/O handles. Up to 8 optional arguments may follow the
748a9306 197file name. These arguments should be strings which specify
0d7e20a5 198optional file characteristics as allowed by the CRTL. (See the
199CRTL reference manual description of creat() and fopen() for details.)
200If successful, C<vmsopen> returns a VMS::Stdio file handle; if an
201error occurs, it returns C<undef>.
202
5f05dabc 203You can use the file handle returned by C<vmsopen> just as you
0d7e20a5 204would any other Perl file handle. The class VMS::Stdio ISA
740ce14c 205IO::File, so you can call IO::File methods using the handle
0d7e20a5 206returned by C<vmsopen>. However, C<use>ing VMS::Stdio does not
740ce14c 207automatically C<use> IO::File; you must do so explicitly in
208your program if you want to call IO::File methods. This is
209done to avoid the overhead of initializing the IO::File package
0d7e20a5 210in programs which intend to use the handle returned by C<vmsopen>
211as a normal Perl file handle only. When the scalar containing
212a VMS::Stdio file handle is overwritten, C<undef>d, or goes
213out of scope, the associated file is closed automatically.
214
215=item vmssysopen
216
217This function bears the same relationship to the CORE function
218C<sysopen> as C<vmsopen> does to C<open>. Its first three arguments
219are the name, access flags, and permissions for the file. Like
220C<vmsopen>, it takes up to 8 additional string arguments which
221specify file characteristics. Its return value is identical to
222that of C<vmsopen>.
223
224The symbolic constants for the mode argument are exported by
225VMS::Stdio by default, and are also exported by the Fcntl package.
226
227=item waitfh
228
229This function causes Perl to wait for the completion of an I/O
230operation on the file handle specified as its argument. It is
231used with handles opened for asynchronous I/O, and performs its
232task by calling the CRTL routine fwait().
748a9306
LW
233
234=head1 REVISION
235
5f05dabc 236This document was last revised on 10-Dec-1996, for Perl 5.004.
748a9306
LW
237
238=cut