Debian Codegraph @

upstream/mageia-cauldron/man1/perlapio.1

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