📄 perlapio.1
字号:
to have \*(L"file\*(R" first. Arranges that next read operation will returnthe byte \fBc\fR. Despite the implied \*(L"character\*(R" in the name onlyvalues in the range 0..0xFF are defined. Returns the byte \fBc\fR onsuccess or \-1 (\f(CW\*(C`EOF\*(C'\fR) on error. The number of bytes that can be\&\*(L"pushed back\*(R" may vary, only 1 character is certain, and then only ifit is the last character that was read from the handle..IP "\fBPerlIO_getc(f)\fR" 4.IX Item "PerlIO_getc(f)"This corresponds to \fIgetc()\fR.Despite the c in the name only byte range 0..0xFF is supported.Returns the character read or \-1 (\f(CW\*(C`EOF\*(C'\fR) on error..IP "\fBPerlIO_eof(f)\fR" 4.IX Item "PerlIO_eof(f)"This corresponds to \fIfeof()\fR. Returns a true/false indication ofwhether the handle is at end of file. For terminal devices this mayor may not be \*(L"sticky\*(R" depending on the implementation. The flag iscleared by \fIPerlIO_seek()\fR, or \fIPerlIO_rewind()\fR..IP "\fBPerlIO_error(f)\fR" 4.IX Item "PerlIO_error(f)"This corresponds to \fIferror()\fR. Returns a true/false indication ofwhether there has been an \s-1IO\s0 error on the handle..IP "\fBPerlIO_fileno(f)\fR" 4.IX Item "PerlIO_fileno(f)"This corresponds to \fIfileno()\fR, note that on some platforms, the meaningof \*(L"fileno\*(R" may not match Unix. Returns \-1 if the handle has no opendescriptor associated with it..IP "\fBPerlIO_clearerr(f)\fR" 4.IX Item "PerlIO_clearerr(f)"This corresponds to \fIclearerr()\fR, i.e., clears 'error' and (usually)\&'eof' flags for the \*(L"stream\*(R". Does not return a value..IP "\fBPerlIO_flush(f)\fR" 4.IX Item "PerlIO_flush(f)"This corresponds to \fIfflush()\fR. Sends any buffered write data to theunderlying file. If called with \f(CW\*(C`NULL\*(C'\fR this may flush all openstreams (or core dump with some \s-1USE_STDIO\s0 implementations). Callingon a handle open for read only, or on which last operation was a readof some kind may lead to undefined behaviour on some \s-1USE_STDIO\s0implementations. The \s-1USE_PERLIO\s0 (layers) implementation tries tobehave better: it flushes all open streams when passed \f(CW\*(C`NULL\*(C'\fR, andattempts to retain data on read streams either in the buffer or byseeking the handle to the current logical position..IP "\fBPerlIO_seek(f,offset,whence)\fR" 4.IX Item "PerlIO_seek(f,offset,whence)"This corresponds to \fIfseek()\fR. Sends buffered write data to theunderlying file, or discards any buffered read data, then positionsthe file descriptor as specified by \fBoffset\fR and \fBwhence\fR (sic).This is the correct thing to do when switching between read and writeon the same handle (see issues with \fIPerlIO_flush()\fR above). Offset isof type \f(CW\*(C`Off_t\*(C'\fR which is a perl Configure value which may not be sameas stdio's \f(CW\*(C`off_t\*(C'\fR..IP "\fBPerlIO_tell(f)\fR" 4.IX Item "PerlIO_tell(f)"This corresponds to \fIftell()\fR. Returns the current file position, or(Off_t) \-1 on error. May just return value system \*(L"knows\*(R" withoutmaking a system call or checking the underlying file descriptor (souse on shared file descriptors is not safe without a\&\fIPerlIO_seek()\fR). Return value is of type \f(CW\*(C`Off_t\*(C'\fR which is a perlConfigure value which may not be same as stdio's \f(CW\*(C`off_t\*(C'\fR..IP "\fBPerlIO_getpos(f,p)\fR, \fBPerlIO_setpos(f,p)\fR" 4.IX Item "PerlIO_getpos(f,p), PerlIO_setpos(f,p)"These correspond (loosely) to \fIfgetpos()\fR and \fIfsetpos()\fR. Rather thanstdio's Fpos_t they expect a \*(L"Perl Scalar Value\*(R" to be passed. What isstored there should be considered opaque. The layout of the data mayvary from handle to handle. When not using stdio or if platform doesnot have the stdio calls then they are implemented in terms of\&\fIPerlIO_tell()\fR and \fIPerlIO_seek()\fR..IP "\fBPerlIO_rewind(f)\fR" 4.IX Item "PerlIO_rewind(f)"This corresponds to \fIrewind()\fR. It is usually defined as being.Sp.Vb 2\& PerlIO_seek(f,(Off_t)0L, SEEK_SET);\& PerlIO_clearerr(f);.Ve.IP "\fB\f(BIPerlIO_tmpfile()\fB\fR" 4.IX Item "PerlIO_tmpfile()"This corresponds to \fItmpfile()\fR, i.e., returns an anonymous PerlIO or\&\s-1NULL\s0 on error. The system will attempt to automatically delete thefile when closed. On Unix the file is usually \f(CW\*(C`unlink\*(C'\fR\-ed just afterit is created so it does not matter how it gets closed. On othersystems the file may only be deleted if closed via \fIPerlIO_close()\fRand/or the program exits via \f(CW\*(C`exit\*(C'\fR. Depending on the implementationthere may be \*(L"race conditions\*(R" which allow other processes access tothe file, though in general it will be safer in this regard thanad. hoc. schemes..IP "\fBPerlIO_setlinebuf(f)\fR" 4.IX Item "PerlIO_setlinebuf(f)"This corresponds to \fIsetlinebuf()\fR. Does not return a value. Whatconstitutes a \*(L"line\*(R" is implementation dependent but usually meansthat writing \*(L"\en\*(R" flushes the buffer. What happens with things like\&\*(L"this\enthat\*(R" is uncertain. (Perl core uses it \fIonly\fR when \*(L"dumping\*(R";it has nothing to do with $| auto-flush.).Sh "Co-existence with stdio".IX Subsection "Co-existence with stdio"There is outline support for co-existence of PerlIO with stdio.Obviously if PerlIO is implemented in terms of stdio there is noproblem. However in other cases then mechanisms must exist to create a\&\s-1FILE\s0 * which can be passed to library code which is going to use stdiocalls..PPThe first step is to add this line:.PP.Vb 1\& #define PERLIO_NOT_STDIO 0.Ve.PP\&\fIbefore\fR including any perl header files. (This will probably becomethe default at some point). That prevents \*(L"perlio.h\*(R" from attemptingto #define stdio functions onto PerlIO functions..PP\&\s-1XS\s0 code is probably better using \*(L"typemap\*(R" if it expects \s-1FILE\s0 *arguments. The standard typemap will be adjusted to comprehend anychanges in this area..IP "\fBPerlIO_importFILE(f,mode)\fR" 4.IX Item "PerlIO_importFILE(f,mode)"Used to get a PerlIO * from a \s-1FILE\s0 *..SpThe mode argument should be a string as would be passed tofopen/PerlIO_open. If it is \s-1NULL\s0 then \- for legacy support \- the codewill (depending upon the platform and the implementation) eitherattempt to empirically determine the mode in which \fIf\fR is open, oruse \*(L"r+\*(R" to indicate a read/write stream..SpOnce called the \s-1FILE\s0 * should \fI\s-1ONLY\s0\fR be closed by calling\&\f(CW\*(C`PerlIO_close()\*(C'\fR on the returned PerlIO *..SpThe PerlIO is set to textmode. Use PerlIO_binmode if this isnot the desired mode..SpThis is \fBnot\fR the reverse of \fIPerlIO_exportFILE()\fR..IP "\fBPerlIO_exportFILE(f,mode)\fR" 4.IX Item "PerlIO_exportFILE(f,mode)"Given a PerlIO * create a 'native' \s-1FILE\s0 * suitable for passing to codeexpecting to be compiled and linked with \s-1ANSI\s0 C \fIstdio.h\fR. The modeargument should be a string as would be passed to fopen/PerlIO_open.If it is \s-1NULL\s0 then \- for legacy support \- the \s-1FILE\s0 * is opened in samemode as the PerlIO *..SpThe fact that such a \s-1FILE\s0 * has been 'exported' is recorded, (normallyby pushing a new :stdio \*(L"layer\*(R" onto the PerlIO *), which may affectfuture PerlIO operations on the original PerlIO *. You should notcall \f(CW\*(C`fclose()\*(C'\fR on the file unless you call \f(CW\*(C`PerlIO_releaseFILE()\*(C'\fRto disassociate it from the PerlIO *. (Do not use \fIPerlIO_importFILE()\fRfor doing the disassociation.).SpCalling this function repeatedly will create a \s-1FILE\s0 * on each call(and will push an :stdio layer each time as well)..IP "\fBPerlIO_releaseFILE(p,f)\fR" 4.IX Item "PerlIO_releaseFILE(p,f)"Calling PerlIO_releaseFILE informs PerlIO that all use of \s-1FILE\s0 * iscomplete. It is removed from the list of 'exported' \s-1FILE\s0 *s, and theassociated PerlIO * should revert to its original behaviour..SpUse this to disassociate a file from a PerlIO * that was associatedusing \fIPerlIO_exportFILE()\fR..IP "\fBPerlIO_findFILE(f)\fR" 4.IX Item "PerlIO_findFILE(f)"Returns a native \s-1FILE\s0 * used by a stdio layer. If there is none, itwill create one with PerlIO_exportFILE. In either case the \s-1FILE\s0 *should be considered as belonging to PerlIO subsystem and shouldonly be closed by calling \f(CW\*(C`PerlIO_close()\*(C'\fR..ie n .Sh """Fast gets"" Functions".el .Sh "``Fast gets'' Functions".IX Subsection "Fast gets Functions"In addition to standard-like \s-1API\s0 defined so far above there is an\&\*(L"implementation\*(R" interface which allows perl to get at internals ofPerlIO. The following calls correspond to the various FILE_xxx macrosdetermined by Configure \- or their equivalent in otherimplementations. This section is really of interest to only thoseconcerned with detailed perl-core behaviour, implementing a PerlIOmapping or writing code which can make use of the \*(L"read ahead\*(R" thathas been done by the \s-1IO\s0 system in the same way perl does. Note thatany code that uses these interfaces must be prepared to do things thetraditional way if a handle does not support them..IP "\fBPerlIO_fast_gets(f)\fR" 4.IX Item "PerlIO_fast_gets(f)"Returns true if implementation has all the interfaces required toallow perl's \f(CW\*(C`sv_gets\*(C'\fR to \*(L"bypass\*(R" normal \s-1IO\s0 mechanism. This canvary from handle to handle..Sp.Vb 3\& PerlIO_fast_gets(f) = PerlIO_has_cntptr(f) && \e\& PerlIO_canset_cnt(f) && \e\& \`Can set pointer into buffer\*(Aq.Ve.IP "\fBPerlIO_has_cntptr(f)\fR" 4.IX Item "PerlIO_has_cntptr(f)"Implementation can return pointer to current position in the \*(L"buffer\*(R"and a count of bytes available in the buffer. Do not use this \- usePerlIO_fast_gets..IP "\fBPerlIO_get_cnt(f)\fR" 4.IX Item "PerlIO_get_cnt(f)"Return count of readable bytes in the buffer. Zero or negative returnmeans no more bytes available..IP "\fBPerlIO_get_ptr(f)\fR" 4.IX Item "PerlIO_get_ptr(f)"Return pointer to next readable byte in buffer, accessing via thepointer (dereferencing) is only safe if \fIPerlIO_get_cnt()\fR has returneda positive value. Only positive offsets up to value returned by\&\fIPerlIO_get_cnt()\fR are allowed..IP "\fBPerlIO_set_ptrcnt(f,p,c)\fR" 4.IX Item "PerlIO_set_ptrcnt(f,p,c)"Set pointer into buffer, and a count of bytes still in thebuffer. Should be used only to set pointer to within range implied byprevious calls to \f(CW\*(C`PerlIO_get_ptr\*(C'\fR and \f(CW\*(C`PerlIO_get_cnt\*(C'\fR. The twovalues \fImust\fR be consistent with each other (implementation may onlyuse one or the other or may require both)..IP "\fBPerlIO_canset_cnt(f)\fR" 4.IX Item "PerlIO_canset_cnt(f)"Implementation can adjust its idea of number of bytes in the buffer.Do not use this \- use PerlIO_fast_gets..IP "\fBPerlIO_set_cnt(f,c)\fR" 4.IX Item "PerlIO_set_cnt(f,c)"Obscure \- set count of bytes in the buffer. Deprecated. Only usableif \fIPerlIO_canset_cnt()\fR returns true. Currently used in only doio.c toforce count less than \-1 to \-1. Perhaps should be PerlIO_set_empty orsimilar. This call may actually do nothing if \*(L"count\*(R" is deduced frompointer and a \*(L"limit\*(R". Do not use this \- use \fIPerlIO_set_ptrcnt()\fR..IP "\fBPerlIO_has_base(f)\fR" 4.IX Item "PerlIO_has_base(f)"Returns true if implementation has a buffer, and can return pointerto whole buffer and its size. Used by perl for \fB\-T\fR / \fB\-B\fR tests.Other uses would be very obscure....IP "\fBPerlIO_get_base(f)\fR" 4.IX Item "PerlIO_get_base(f)"Return \fIstart\fR of buffer. Access only positive offsets in the bufferup to the value returned by \fIPerlIO_get_bufsiz()\fR..IP "\fBPerlIO_get_bufsiz(f)\fR" 4.IX Item "PerlIO_get_bufsiz(f)"Return the \fItotal number of bytes\fR in the buffer, this is neither thenumber that can be read, nor the amount of memory allocated to thebuffer. Rather it is what the operating system and/or implementationhappened to \f(CW\*(C`read()\*(C'\fR (or whatever) last time \s-1IO\s0 was requested..Sh "Other Functions".IX Subsection "Other Functions".IP "PerlIO_apply_layers(f,mode,layers)" 4.IX Item "PerlIO_apply_layers(f,mode,layers)"The new interface to the \s-1USE_PERLIO\s0 implementation. The layers \*(L":crlf\*(R"and \*(L":raw\*(R" are only ones allowed for other implementations and thoseare silently ignored. (As of perl5.8 \*(L":raw\*(R" is deprecated.) Use\&\fIPerlIO_binmode()\fR below for the portable case..IP "PerlIO_binmode(f,ptype,imode,layers)" 4.IX Item "PerlIO_binmode(f,ptype,imode,layers)"The hook used by perl's \f(CW\*(C`binmode\*(C'\fR operator.\&\fBptype\fR is perl's character for the kind of \s-1IO:\s0.RS 4.IP "'<' read" 8.IX Item "'<' read".PD 0.IP "'>' write" 8.IX Item "'>' write".IP "'+' read/write" 8.IX Item "'+' read/write".RE.RS 4.PD.Sp\&\fBimode\fR is \f(CW\*(C`O_BINARY\*(C'\fR or \f(CW\*(C`O_TEXT\*(C'\fR..Sp\&\fBlayers\fR is a string of layers to apply, only \*(L":crlf\*(R" makes sense inthe non \s-1USE_PERLIO\s0 case. (As of perl5.8 \*(L":raw\*(R" is deprecated in favourof passing \s-1NULL\s0.).SpPortable cases are:.Sp.Vb 3\& PerlIO_binmode(f,ptype,O_BINARY,Nullch);\&and\& PerlIO_binmode(f,ptype,O_TEXT,":crlf");.Ve.SpOn Unix these calls probably have no effect whatsoever. Elsewherethey alter \*(L"\en\*(R" to \s-1CR\s0,LF translation and possibly cause a special text\&\*(L"end of file\*(R" indicator to be written or honoured on read. The effectof making the call after doing any \s-1IO\s0 to the handle depends on theimplementation. (It may be ignored, affect any data which is alreadybuffered as well, or only apply to subsequent data.).RE.IP "PerlIO_debug(fmt,...)" 4.IX Item "PerlIO_debug(fmt,...)"PerlIO_debug is a \fIprintf()\fR\-like function which can be used fordebugging. No return value. Its main use is inside PerlIO where usingreal printf, \fIwarn()\fR etc. would recursively call PerlIO and be aproblem..SpPerlIO_debug writes to the file named by \f(CW$ENV\fR{'\s-1PERLIO_DEBUG\s0'} typicaluse might be.Sp.Vb 2\& Bourne shells (sh, ksh, bash, zsh, ash, ...):\& PERLIO_DEBUG=/dev/tty ./perl somescript some args\&\& Csh/Tcsh:\& setenv PERLIO_DEBUG /dev/tty\& ./perl somescript some args\&\& If you have the "env" utility:\& env PERLIO_DEBUG=/dev/tty ./perl somescript some args\&\& Win32:\& set PERLIO_DEBUG=CON\& perl somescript some args.Ve.SpIf \f(CW$ENV\fR{'\s-1PERLIO_DEBUG\s0'} is not set \fIPerlIO_debug()\fR is a no-op.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -