1=head1 NAME
2
3perlapio - perl's IO abstraction interface.
4
5=head1 SYNOPSIS
6
7  #define PERLIO_NOT_STDIO 0    /* For co-existence with stdio only */
8  #include <perlio.h>           /* Usually via #include <perl.h> */
9
10  PerlIO *PerlIO_stdin(void);
11  PerlIO *PerlIO_stdout(void);
12  PerlIO *PerlIO_stderr(void);
13
14  PerlIO *PerlIO_open(const char *path,const char *mode);
15  PerlIO *PerlIO_fdopen(int fd, const char *mode);
16  PerlIO *PerlIO_reopen(const char *path, /* deprecated */
17          const char *mode, PerlIO *old);
18  int     PerlIO_close(PerlIO *f);
19
20  int     PerlIO_stdoutf(const char *fmt,...)
21  int     PerlIO_puts(PerlIO *f,const char *string);
22  int     PerlIO_putc(PerlIO *f,int ch);
23  SSize_t PerlIO_write(PerlIO *f,const void *buf,size_t numbytes);
24  int     PerlIO_printf(PerlIO *f, const char *fmt,...);
25  int     PerlIO_vprintf(PerlIO *f, const char *fmt, va_list args);
26  int     PerlIO_flush(PerlIO *f);
27
28  int     PerlIO_fill(PerlIO *f);
29  int     PerlIO_eof(PerlIO *f);
30  int     PerlIO_error(PerlIO *f);
31  void    PerlIO_clearerr(PerlIO *f);
32
33  int     PerlIO_getc(PerlIO *d);
34  int     PerlIO_ungetc(PerlIO *f,int ch);
35  SSize_t PerlIO_read(PerlIO *f, void *buf, size_t numbytes);
36  Size_t  PerlIO_unread(PerlIO *f,const void *vbuf, size_t count
37
38  int     PerlIO_fileno(PerlIO *f);
39
40  void    PerlIO_setlinebuf(PerlIO *f);
41
42  Off_t   PerlIO_tell(PerlIO *f);
43  int     PerlIO_seek(PerlIO *f, Off_t offset, int whence);
44  void    PerlIO_rewind(PerlIO *f);
45
46  int     PerlIO_getpos(PerlIO *f, SV *save);    /* prototype changed */
47  int     PerlIO_setpos(PerlIO *f, SV *saved);   /* prototype changed */
48
49  int     PerlIO_fast_gets(PerlIO *f);
50  int     PerlIO_has_cntptr(PerlIO *f);
51  SSize_t PerlIO_get_cnt(PerlIO *f);
52  char   *PerlIO_get_ptr(PerlIO *f);
53  void    PerlIO_set_ptrcnt(PerlIO *f, char *ptr, SSize_t count);
54
55  int     PerlIO_canset_cnt(PerlIO *f);              /* deprecated */
56  void    PerlIO_set_cnt(PerlIO *f, int count);      /* deprecated */
57
58  int     PerlIO_has_base(PerlIO *f);
59  char   *PerlIO_get_base(PerlIO *f);
60  SSize_t PerlIO_get_bufsiz(PerlIO *f);
61
62  PerlIO *PerlIO_importFILE(FILE *stdio, const char *mode);
63  FILE   *PerlIO_exportFILE(PerlIO *f, const char *mode);
64  FILE   *PerlIO_findFILE(PerlIO *f);
65  void    PerlIO_releaseFILE(PerlIO *f,FILE *stdio);
66
67  int     PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode,
68                                                    const char *layers);
69  int     PerlIO_binmode(pTHX_ PerlIO *f, int ptype, int imode,
70                                                    const char *layers);
71  void    PerlIO_debug(const char *fmt,...);
72
73=for apidoc_section $io
74
75=for apidoc    Amh|int      |PerlIO_apply_layers|PerlIO *f|const char *mode|const char *layers
76=for apidoc_item  |int      |PerlIO_binmode|PerlIO *f|int ptype|int imode|const char *layers
77=for apidoc_item T|int      |PerlIO_canset_cnt|PerlIO *f
78=for apidoc_item  |         |PerlIO_clearerr
79=for apidoc_item  |         |PerlIO_close
80=for apidoc_item T|void     |PerlIO_debug|const char *fmt|...
81=for apidoc_item  |         |PerlIO_eof
82=for apidoc_item  |         |PerlIO_error
83=for apidoc_item T|FILE *   |PerlIO_exportFILE|PerlIO *f|const char *mode
84=for apidoc_item T|int      |PerlIO_fast_gets|PerlIO *f
85=for apidoc_item T|PerlIO * |PerlIO_fdopen|int fd|const char *mode
86=for apidoc_item  |         |PerlIO_fileno
87=for apidoc_item  |         |PerlIO_fill
88=for apidoc_item T|FILE *   |PerlIO_findFILE|PerlIO *f
89=for apidoc_item  |         |PerlIO_flush
90=for apidoc_item  |         |PerlIO_get_base
91=for apidoc_item  |         |PerlIO_get_bufsiz
92=for apidoc_item  |         |PerlIO_get_cnt
93=for apidoc_item  |         |PerlIO_get_ptr
94=for apidoc_item T|int      |PerlIO_getc|PerlIO *d
95=for apidoc_item T|int      |PerlIO_getpos|PerlIO *f|SV *save
96=for apidoc_item T|int      |PerlIO_has_base|PerlIO *f
97=for apidoc_item T|int      |PerlIO_has_cntptr|PerlIO *f
98=for apidoc_item T|PerlIO * |PerlIO_importFILE|FILE *stdio|const char *mode
99=for apidoc_item T|PerlIO * |PerlIO_open|const char *path|const char *mode
100=for apidoc_item T|int      |PerlIO_printf|PerlIO *f|const char *fmt|...
101=for apidoc_item T|int      |PerlIO_putc|PerlIO *f|int ch
102=for apidoc_item T|int      |PerlIO_puts|PerlIO *f|const char *string
103=for apidoc_item  |         |PerlIO_read
104=for apidoc_item T|void     |PerlIO_releaseFILE|PerlIO *f|FILE *stdio
105=for apidoc_item T|PerlIO * |PerlIO_reopen|const char *path|const char *mode|PerlIO *old
106=for apidoc_item T|void     |PerlIO_rewind|PerlIO *f
107=for apidoc_item  |         |PerlIO_seek
108=for apidoc_item  |         |PerlIO_set_cnt
109=for apidoc_item  |         |PerlIO_set_ptrcnt
110=for apidoc_item  |         |PerlIO_setlinebuf
111=for apidoc_item T|int      |PerlIO_setpos|PerlIO *f|SV *saved
112=for apidoc_item  |         |PerlIO_stderr
113=for apidoc_item  |         |PerlIO_stdin
114=for apidoc_item  |         |PerlIO_stdout
115=for apidoc_item T|int      |PerlIO_stdoutf|const char *fmt|...
116=for apidoc_item  |         |PerlIO_tell
117=for apidoc_item T|int      |PerlIO_ungetc|PerlIO *f|int ch
118=for apidoc_item  |         |PerlIO_unread
119=for apidoc_item T|int      |PerlIO_vprintf|PerlIO *f|const char *fmt|va_list args
120=for apidoc_item  |         |PerlIO_write
121
122=head1 DESCRIPTION
123
124Perl's source code, and extensions that want maximum portability,
125should use the above functions instead of those defined in ANSI C's
126I<stdio.h>.  The perl headers (in particular "perlio.h") will
127C<#define> them to the I/O mechanism selected at Configure time.
128
129The functions are modeled on those in I<stdio.h>, but parameter order
130has been "tidied up a little".
131
132C<PerlIO *> takes the place of FILE *. Like FILE * it should be
133treated as opaque (it is probably safe to assume it is a pointer to
134something).
135
136There are currently two implementations:
137
138=over 4
139
140=item 1. USE_STDIO
141
142All above are #define'd to stdio functions or are trivial wrapper
143functions which call stdio. In this case I<only> PerlIO * is a FILE *.
144This has been the default implementation since the abstraction was
145introduced in perl5.003_02.
146
147=for apidoc Amnh||USE_STDIO
148
149=item 2. USE_PERLIO
150
151Introduced just after perl5.7.0, this is a re-implementation of the
152above abstraction which allows perl more control over how IO is done
153as it decouples IO from the way the operating system and C library
154choose to do things. For USE_PERLIO PerlIO * has an extra layer of
155indirection - it is a pointer-to-a-pointer.  This allows the PerlIO *
156to remain with a known value while swapping the implementation around
157underneath I<at run time>. In this case all the above are true (but
158very simple) functions which call the underlying implementation.
159
160This is the only implementation for which C<PerlIO_apply_layers()>
161does anything "interesting".
162
163The USE_PERLIO implementation is described in L<perliol>.
164
165=back
166
167Because "perlio.h" is a thin layer (for efficiency) the semantics of
168these functions are somewhat dependent on the underlying implementation.
169Where these variations are understood they are noted below.
170
171Unless otherwise noted, functions return 0 on success, or a negative
172value (usually C<EOF> which is usually -1) and set C<errno> on error.
173
174=over 4
175
176=item B<PerlIO_stdin()>, B<PerlIO_stdout()>, B<PerlIO_stderr()>
177
178Use these rather than C<stdin>, C<stdout>, C<stderr>. They are written
179to look like "function calls" rather than variables because this makes
180it easier to I<make them> function calls if platform cannot export data
181to loaded modules, or if (say) different "threads" might have different
182values.
183
184=item B<PerlIO_open(path, mode)>, B<PerlIO_fdopen(fd,mode)>
185
186These correspond to fopen()/fdopen() and the arguments are the same.
187Return C<NULL> and set C<errno> if there is an error.  There may be an
188implementation limit on the number of open handles, which may be lower
189than the limit on the number of open files - C<errno> may not be set
190when C<NULL> is returned if this limit is exceeded.
191
192=item B<PerlIO_reopen(path,mode,f)>
193
194While this currently exists in both implementations, perl itself
195does not use it. I<As perl does not use it, it is not well tested.>
196
197Perl prefers to C<dup> the new low-level descriptor to the descriptor
198used by the existing PerlIO. This may become the behaviour of this
199function in the future.
200
201=item B<PerlIO_printf(f,fmt,...)>, B<PerlIO_vprintf(f,fmt,a)>
202
203These are fprintf()/vfprintf() equivalents.
204
205=item B<PerlIO_stdoutf(fmt,...)>
206
207This is printf() equivalent. printf is #defined to this function,
208so it is (currently) legal to use C<printf(fmt,...)> in perl sources.
209
210=item B<PerlIO_read(f,buf,count)>, B<PerlIO_write(f,buf,count)>
211
212These correspond functionally to fread() and fwrite() but the
213arguments and return values are different.  The PerlIO_read() and
214PerlIO_write() signatures have been modeled on the more sane low level
215read() and write() functions instead: The "file" argument is passed
216first, there is only one "count", and the return value can distinguish
217between error and C<EOF>.
218
219Returns a byte count if successful (which may be zero or
220positive), returns negative value and sets C<errno> on error.
221Depending on implementation C<errno> may be C<EINTR> if operation was
222interrupted by a signal.
223
224=item B<PerlIO_fill(f)>
225
226Fills the buffer associated with C<f> with data from the layer below.
227C<PerlIO_read> calls this as part of its normal operation.  Returns 0
228upon success; -1 on failure.
229
230=item B<PerlIO_close(f)>
231
232Depending on implementation C<errno> may be C<EINTR> if operation was
233interrupted by a signal.
234
235=item B<PerlIO_puts(f,s)>, B<PerlIO_putc(f,c)>
236
237These correspond to fputs() and fputc().
238Note that arguments have been revised to have "file" first.
239
240=item B<PerlIO_ungetc(f,c)>
241
242This corresponds to ungetc().  Note that arguments have been revised
243to have "file" first.  Arranges that next read operation will return
244the byte B<c>.  Despite the implied "character" in the name only
245values in the range 0..0xFF are defined. Returns the byte B<c> on
246success or -1 (C<EOF>) on error.  The number of bytes that can be
247"pushed back" may vary, only 1 character is certain, and then only if
248it is the last character that was read from the handle.
249
250=item B<PerlIO_unread(f,buf,count)>
251
252This allows one to unget more than a single byte.
253It effectively unshifts C<count> bytes onto the beginning of the buffer 
254C<buf>, so that the next read operation(s) will return them before
255anything else that was in the buffer.
256
257Returns the number of unread bytes.
258
259=item B<PerlIO_getc(f)>
260
261This corresponds to getc().
262Despite the c in the name only byte range 0..0xFF is supported.
263Returns the character read or -1 (C<EOF>) on error.
264
265=item B<PerlIO_eof(f)>
266
267This corresponds to feof().  Returns a true/false indication of
268whether the handle is at end of file.  For terminal devices this may
269or may not be "sticky" depending on the implementation.  The flag is
270cleared by PerlIO_seek(), or PerlIO_rewind().
271
272=item B<PerlIO_error(f)>
273
274This corresponds to ferror().  Returns a true/false indication of
275whether there has been an IO error on the handle.
276
277=item B<PerlIO_fileno(f)>
278
279This corresponds to fileno(), note that on some platforms, the meaning
280of "fileno" may not match Unix. Returns -1 if the handle has no open
281descriptor associated with it.
282
283=item B<PerlIO_clearerr(f)>
284
285This corresponds to clearerr(), i.e., clears 'error' and (usually)
286'eof' flags for the "stream". Does not return a value.
287
288=item B<PerlIO_flush(f)>
289
290This corresponds to fflush().  Sends any buffered write data to the
291underlying file.  If called with C<NULL> this may flush all open
292streams (or core dump with some USE_STDIO implementations).  Calling
293on a handle open for read only, or on which last operation was a read
294of some kind may lead to undefined behaviour on some USE_STDIO
295implementations.  The USE_PERLIO (layers) implementation tries to
296behave better: it flushes all open streams when passed C<NULL>, and
297attempts to retain data on read streams either in the buffer or by
298seeking the handle to the current logical position.
299
300=item B<PerlIO_seek(f,offset,whence)>
301
302This corresponds to fseek().  Sends buffered write data to the
303underlying file, or discards any buffered read data, then positions
304the file descriptor as specified by B<offset> and B<whence> (sic).
305This is the correct thing to do when switching between read and write
306on the same handle (see issues with PerlIO_flush() above).  Offset is
307of type C<Off_t> which is a perl Configure value which may not be same
308as stdio's C<off_t>.
309
310=item B<PerlIO_tell(f)>
311
312This corresponds to ftell().  Returns the current file position, or
313(Off_t) -1 on error.  May just return value system "knows" without
314making a system call or checking the underlying file descriptor (so
315use on shared file descriptors is not safe without a
316PerlIO_seek()). Return value is of type C<Off_t> which is a perl
317Configure value which may not be same as stdio's C<off_t>.
318
319=item B<PerlIO_getpos(f,p)>, B<PerlIO_setpos(f,p)>
320
321These correspond (loosely) to fgetpos() and fsetpos(). Rather than
322stdio's Fpos_t they expect a "Perl Scalar Value" to be passed. What is
323stored there should be considered opaque. The layout of the data may
324vary from handle to handle.  When not using stdio or if platform does
325not have the stdio calls then they are implemented in terms of
326PerlIO_tell() and PerlIO_seek().
327
328=item B<PerlIO_rewind(f)>
329
330This corresponds to rewind(). It is usually defined as being
331
332    PerlIO_seek(f,(Off_t)0L, SEEK_SET);
333    PerlIO_clearerr(f);
334
335=item B<PerlIO_tmpfile()>
336
337This corresponds to tmpfile(), i.e., returns an anonymous PerlIO or
338NULL on error.  The system will attempt to automatically delete the
339file when closed.  On Unix the file is usually C<unlink>-ed just after
340it is created so it does not matter how it gets closed. On other
341systems the file may only be deleted if closed via PerlIO_close()
342and/or the program exits via C<exit>.  Depending on the implementation
343there may be "race conditions" which allow other processes access to
344the file, though in general it will be safer in this regard than
345ad. hoc. schemes.
346
347=item B<PerlIO_setlinebuf(f)>
348
349This corresponds to setlinebuf().  Does not return a value. What
350constitutes a "line" is implementation dependent but usually means
351that writing "\n" flushes the buffer.  What happens with things like
352"this\nthat" is uncertain.  (Perl core uses it I<only> when "dumping";
353it has nothing to do with $| auto-flush.)
354
355=back
356
357=head2 Co-existence with stdio
358
359There is outline support for co-existence of PerlIO with stdio.
360Obviously if PerlIO is implemented in terms of stdio there is no
361problem. However in other cases then mechanisms must exist to create a
362FILE * which can be passed to library code which is going to use stdio
363calls.
364
365The first step is to add this line:
366
367   #define PERLIO_NOT_STDIO 0
368
369=for apidoc Amnh ||PERLIO_NOT_STDIO
370
371I<before> including any perl header files. (This will probably become
372the default at some point).  That prevents "perlio.h" from attempting
373to #define stdio functions onto PerlIO functions.
374
375XS code is probably better using "typemap" if it expects FILE *
376arguments.  The standard typemap will be adjusted to comprehend any
377changes in this area.
378
379=over 4
380
381=item B<PerlIO_importFILE(f,mode)>
382
383Used to get a PerlIO * from a FILE *.
384
385The mode argument should be a string as would be passed to
386fopen/PerlIO_open.  If it is NULL then - for legacy support - the code
387will (depending upon the platform and the implementation) either
388attempt to empirically determine the mode in which I<f> is open, or
389use "r+" to indicate a read/write stream.
390
391Once called the FILE * should I<ONLY> be closed by calling
392C<PerlIO_close()> on the returned PerlIO *.
393
394The PerlIO is set to textmode. Use PerlIO_binmode if this is
395not the desired mode.
396
397This is B<not> the reverse of PerlIO_exportFILE().
398
399=item B<PerlIO_exportFILE(f,mode)>
400
401Given a PerlIO * create a 'native' FILE * suitable for passing to code
402expecting to be compiled and linked with ANSI C I<stdio.h>.  The mode
403argument should be a string as would be passed to fopen/PerlIO_open.
404If it is NULL then - for legacy support - the FILE * is opened in same
405mode as the PerlIO *.
406
407The fact that such a FILE * has been 'exported' is recorded, (normally
408by pushing a new :stdio "layer" onto the PerlIO *), which may affect
409future PerlIO operations on the original PerlIO *.  You should not
410call C<fclose()> on the file unless you call C<PerlIO_releaseFILE()>
411to disassociate it from the PerlIO *.  (Do not use PerlIO_importFILE()
412for doing the disassociation.)
413
414Calling this function repeatedly will create a FILE * on each call
415(and will push an :stdio layer each time as well).
416
417=item B<PerlIO_releaseFILE(p,f)>
418
419Calling PerlIO_releaseFILE informs PerlIO that all use of FILE * is
420complete. It is removed from the list of 'exported' FILE *s, and the
421associated PerlIO * should revert to its original behaviour.
422
423Use this to disassociate a file from a PerlIO * that was associated
424using PerlIO_exportFILE().
425
426=item B<PerlIO_findFILE(f)>
427
428Returns a native FILE * used by a stdio layer. If there is none, it
429will create one with PerlIO_exportFILE. In either case the FILE *
430should be considered as belonging to PerlIO subsystem and should
431only be closed by calling C<PerlIO_close()>.
432
433
434=back
435
436=head2 "Fast gets" Functions
437
438In addition to standard-like API defined so far above there is an
439"implementation" interface which allows perl to get at internals of
440PerlIO.  The following calls correspond to the various FILE_xxx macros
441determined by Configure - or their equivalent in other
442implementations. This section is really of interest to only those
443concerned with detailed perl-core behaviour, implementing a PerlIO
444mapping or writing code which can make use of the "read ahead" that
445has been done by the IO system in the same way perl does. Note that
446any code that uses these interfaces must be prepared to do things the
447traditional way if a handle does not support them.
448
449=over 4
450
451=item B<PerlIO_fast_gets(f)>
452
453Returns true if implementation has all the interfaces required to
454allow perl's C<sv_gets> to "bypass" normal IO mechanism.  This can
455vary from handle to handle.
456
457  PerlIO_fast_gets(f) = PerlIO_has_cntptr(f) && \
458                        PerlIO_canset_cnt(f) && \
459                        'Can set pointer into buffer'
460
461=item B<PerlIO_has_cntptr(f)>
462
463Implementation can return pointer to current position in the "buffer"
464and a count of bytes available in the buffer.  Do not use this - use
465PerlIO_fast_gets.
466
467=item B<PerlIO_get_cnt(f)>
468
469Return count of readable bytes in the buffer. Zero or negative return
470means no more bytes available.
471
472=item B<PerlIO_get_ptr(f)>
473
474Return pointer to next readable byte in buffer, accessing via the
475pointer (dereferencing) is only safe if PerlIO_get_cnt() has returned
476a positive value.  Only positive offsets up to value returned by
477PerlIO_get_cnt() are allowed.
478
479=item B<PerlIO_set_ptrcnt(f,p,c)>
480
481Set pointer into buffer, and a count of bytes still in the
482buffer. Should be used only to set pointer to within range implied by
483previous calls to C<PerlIO_get_ptr> and C<PerlIO_get_cnt>. The two
484values I<must> be consistent with each other (implementation may only
485use one or the other or may require both).
486
487=item B<PerlIO_canset_cnt(f)>
488
489Implementation can adjust its idea of number of bytes in the buffer.
490Do not use this - use PerlIO_fast_gets.
491
492=item B<PerlIO_set_cnt(f,c)>
493
494Obscure - set count of bytes in the buffer. Deprecated.  Only usable
495if PerlIO_canset_cnt() returns true.  Currently used in only doio.c to
496force count less than -1 to -1.  Perhaps should be PerlIO_set_empty or
497similar.  This call may actually do nothing if "count" is deduced from
498pointer and a "limit".  Do not use this - use PerlIO_set_ptrcnt().
499
500=item B<PerlIO_has_base(f)>
501
502Returns true if implementation has a buffer, and can return pointer
503to whole buffer and its size. Used by perl for B<-T> / B<-B> tests.
504Other uses would be very obscure...
505
506=item B<PerlIO_get_base(f)>
507
508Return I<start> of buffer. Access only positive offsets in the buffer
509up to the value returned by PerlIO_get_bufsiz().
510
511=item B<PerlIO_get_bufsiz(f)>
512
513Return the I<total number of bytes> in the buffer, this is neither the
514number that can be read, nor the amount of memory allocated to the
515buffer. Rather it is what the operating system and/or implementation
516happened to C<read()> (or whatever) last time IO was requested.
517
518=back
519
520=head2 Other Functions
521
522=over 4
523
524=item PerlIO_apply_layers(aTHX_ f,mode,layers)
525
526The new interface to the USE_PERLIO implementation. The layers ":crlf"
527and ":raw" are the only ones allowed for other implementations and those
528are silently ignored. (As of perl5.8 ":raw" is deprecated.)  Use
529PerlIO_binmode() below for the portable case.
530
531=item PerlIO_binmode(aTHX_ f,ptype,imode,layers)
532
533The hook used by perl's C<binmode> operator.
534B<ptype> is perl's character for the kind of IO:
535
536=over 8
537
538=item 'E<lt>' read
539
540=item 'E<gt>' write
541
542=item '+' read/write
543
544=back
545
546B<imode> is C<O_BINARY> or C<O_TEXT>.
547
548B<layers> is a string of layers to apply; only ":crlf" makes sense in
549the non-USE_PERLIO case. (As of perl5.8 ":raw" is deprecated in favour
550of passing NULL.)
551
552Portable cases are:
553
554    PerlIO_binmode(aTHX_ f,ptype,O_BINARY,NULL);
555and
556    PerlIO_binmode(aTHX_ f,ptype,O_TEXT,":crlf");
557
558On Unix these calls probably have no effect whatsoever.  Elsewhere
559they alter "\n" to CR,LF translation and possibly cause a special text
560"end of file" indicator to be written or honoured on read. The effect
561of making the call after doing any IO to the handle depends on the
562implementation. (It may be ignored, affect any data which is already
563buffered as well, or only apply to subsequent data.)
564
565=item PerlIO_debug(fmt,...)
566
567PerlIO_debug is a printf()-like function which can be used for
568debugging.  No return value. Its main use is inside PerlIO where using
569real printf, warn() etc. would recursively call PerlIO and be a
570problem.
571
572PerlIO_debug writes to the file named by $ENV{'PERLIO_DEBUG'} or defaults
573to stderr if the environment variable is not defined. Typical
574use might be
575
576  Bourne shells (sh, ksh, bash, zsh, ash, ...):
577   PERLIO_DEBUG=/tmp/perliodebug.log ./perl -Di somescript some args
578
579  Csh/Tcsh:
580   setenv PERLIO_DEBUG /tmp/perliodebug.log
581   ./perl -Di somescript some args
582
583  If you have the "env" utility:
584   env PERLIO_DEBUG=/tmp/perliodebug.log ./perl -Di somescript args
585
586  Win32:
587   set PERLIO_DEBUG=perliodebug.log
588   perl -Di somescript some args
589
590On a Perl built without C<-DDEBUGGING>, or when the C<-Di> command-line switch
591is not specified, or under taint, PerlIO_debug() is a no-op.
592
593=back
594