perlapio.pod
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 527 行 · 第 1/2 页
POD
527 行
=head1 NAMEperlapio - perl's IO abstraction interface.=head1 SYNOPSIS #define PERLIO_NOT_STDIO 0 /* For co-existence with stdio only */ #include <perlio.h> /* Usually via #include <perl.h> */ PerlIO *PerlIO_stdin(void); PerlIO *PerlIO_stdout(void); PerlIO *PerlIO_stderr(void); PerlIO *PerlIO_open(const char *path,const char *mode); PerlIO *PerlIO_fdopen(int fd, const char *mode); PerlIO *PerlIO_reopen(const char *path, const char *mode, PerlIO *old); /* deprecated */ int PerlIO_close(PerlIO *f); int PerlIO_stdoutf(const char *fmt,...) int PerlIO_puts(PerlIO *f,const char *string); int PerlIO_putc(PerlIO *f,int ch); int PerlIO_write(PerlIO *f,const void *buf,size_t numbytes); int PerlIO_printf(PerlIO *f, const char *fmt,...); int PerlIO_vprintf(PerlIO *f, const char *fmt, va_list args); int PerlIO_flush(PerlIO *f); int PerlIO_eof(PerlIO *f); int PerlIO_error(PerlIO *f); void PerlIO_clearerr(PerlIO *f); int PerlIO_getc(PerlIO *d); int PerlIO_ungetc(PerlIO *f,int ch); int PerlIO_read(PerlIO *f, void *buf, size_t numbytes); int PerlIO_fileno(PerlIO *f); void PerlIO_setlinebuf(PerlIO *f); Off_t PerlIO_tell(PerlIO *f); int PerlIO_seek(PerlIO *f, Off_t offset, int whence); void PerlIO_rewind(PerlIO *f); int PerlIO_getpos(PerlIO *f, SV *save); /* prototype changed */ int PerlIO_setpos(PerlIO *f, SV *saved); /* prototype changed */ int PerlIO_fast_gets(PerlIO *f); int PerlIO_has_cntptr(PerlIO *f); int PerlIO_get_cnt(PerlIO *f); char *PerlIO_get_ptr(PerlIO *f); void PerlIO_set_ptrcnt(PerlIO *f, char *ptr, int count); int PerlIO_canset_cnt(PerlIO *f); /* deprecated */ void PerlIO_set_cnt(PerlIO *f, int count); /* deprecated */ int PerlIO_has_base(PerlIO *f); char *PerlIO_get_base(PerlIO *f); int PerlIO_get_bufsiz(PerlIO *f); PerlIO *PerlIO_importFILE(FILE *stdio, const char *mode); FILE *PerlIO_exportFILE(PerlIO *f, int flags); FILE *PerlIO_findFILE(PerlIO *f); void PerlIO_releaseFILE(PerlIO *f,FILE *stdio); int PerlIO_apply_layers(PerlIO *f, const char *mode, const char *layers); int PerlIO_binmode(PerlIO *f, int ptype, int imode, const char *layers); void PerlIO_debug(const char *fmt,...)=head1 DESCRIPTIONPerl's source code, and extensions that want maximum portability,should use the above functions instead of those defined in ANSI C'sI<stdio.h>. The perl headers (in particular "perlio.h") willC<#define> them to the I/O mechanism selected at Configure time.The functions are modeled on those in I<stdio.h>, but parameter orderhas been "tidied up a little".C<PerlIO *> takes the place of FILE *. Like FILE * it should betreated as opaque (it is probably safe to assume it is a pointer tosomething).There are currently three implementations:=over 4=item 1. USE_STDIOAll above are #define'd to stdio functions or are trivial wrapperfunctions which call stdio. In this case I<only> PerlIO * is a FILE *.This has been the default implementation since the abstraction wasintroduced in perl5.003_02.=item 2. USE_SFIOA "legacy" implementation in terms of the "sfio" library. Used forsome specialist applications on Unix machines ("sfio" is not widelyported away from Unix). Most of above are #define'd to the sfiofunctions. PerlIO * is in this case Sfio_t *.=item 3. USE_PERLIOIntroduced just after perl5.7.0, this is a re-implementation of theabove abstraction which allows perl more control over how IO is doneas it decouples IO from the way the operating system and C librarychoose to do things. For USE_PERLIO PerlIO * has an extra layer ofindirection - it is a pointer-to-a-pointer. This allows the PerlIO *to remain with a known value while swapping the implementation aroundunderneath I<at run time>. In this case all the above are true (butvery simple) functions which call the underlying implementation.This is the only implementation for which C<PerlIO_apply_layers()>does anything "interesting".The USE_PERLIO implementation is described in L<perliol>.=backBecause "perlio.h" is a thin layer (for efficiency) the semantics ofthese functions are somewhat dependent on the underlying implementation.Where these variations are understood they are noted below.Unless otherwise noted, functions return 0 on success, or a negativevalue (usually C<EOF> which is usually -1) and set C<errno> on error.=over 4=item B<PerlIO_stdin()>, B<PerlIO_stdout()>, B<PerlIO_stderr()>Use these rather than C<stdin>, C<stdout>, C<stderr>. They are writtento look like "function calls" rather than variables because this makesit easier to I<make them> function calls if platform cannot export datato loaded modules, or if (say) different "threads" might have differentvalues.=item B<PerlIO_open(path, mode)>, B<PerlIO_fdopen(fd,mode)>These correspond to fopen()/fdopen() and the arguments are the same.Return C<NULL> and set C<errno> if there is an error. There may be animplementation limit on the number of open handles, which may be lowerthan the limit on the number of open files - C<errno> may not be setwhen C<NULL> is returned if this limit is exceeded.=item B<PerlIO_reopen(path,mode,f)>While this currently exists in all three implementations perl itselfdoes not use it. I<As perl does not use it, it is not well tested.>Perl prefers to C<dup> the new low-level descriptor to the descriptorused by the existing PerlIO. This may become the behaviour of thisfunction in the future.=item B<PerlIO_printf(f,fmt,...)>, B<PerlIO_vprintf(f,fmt,a)>These are fprintf()/vfprintf() equivalents.=item B<PerlIO_stdoutf(fmt,...)>This is printf() equivalent. printf is #defined to this function,so it is (currently) legal to use C<printf(fmt,...)> in perl sources.=item B<PerlIO_read(f,buf,count)>, B<PerlIO_write(f,buf,count)>These correspond functionally to fread() and fwrite() but thearguments and return values are different. The PerlIO_read() andPerlIO_write() signatures have been modeled on the more sane low levelread() and write() functions instead: The "file" argument is passedfirst, there is only one "count", and the return value can distinguishbetween error and C<EOF>.Returns a byte count if successful (which may be zero orpositive), returns negative value and sets C<errno> on error.Depending on implementation C<errno> may be C<EINTR> if operation wasinterrupted by a signal.=item B<PerlIO_close(f)>Depending on implementation C<errno> may be C<EINTR> if operation wasinterrupted by a signal.=item B<PerlIO_puts(f,s)>, B<PerlIO_putc(f,c)>These correspond to fputs() and fputc().Note that arguments have been revised to have "file" first.=item B<PerlIO_ungetc(f,c)>This corresponds to ungetc(). Note that arguments have been revisedto have "file" first. Arranges that next read operation will returnthe byte B<c>. Despite the implied "character" in the name onlyvalues in the range 0..0xFF are defined. Returns the byte B<c> onsuccess or -1 (C<EOF>) on error. The number of bytes that can be"pushed back" may vary, only 1 character is certain, and then only ifit is the last character that was read from the handle.=item B<PerlIO_getc(f)>This corresponds to getc().Despite the c in the name only byte range 0..0xFF is supported.Returns the character read or -1 (C<EOF>) on error.=item B<PerlIO_eof(f)>This corresponds to feof(). Returns a true/false indication ofwhether the handle is at end of file. For terminal devices this mayor may not be "sticky" depending on the implementation. The flag iscleared by PerlIO_seek(), or PerlIO_rewind().=item B<PerlIO_error(f)>This corresponds to ferror(). Returns a true/false indication ofwhether there has been an IO error on the handle.=item B<PerlIO_fileno(f)>This corresponds to fileno(), note that on some platforms, the meaningof "fileno" may not match Unix. Returns -1 if the handle has no opendescriptor associated with it.=item B<PerlIO_clearerr(f)>This corresponds to clearerr(), i.e., clears 'error' and (usually)'eof' flags for the "stream". Does not return a value.=item B<PerlIO_flush(f)>This corresponds to fflush(). Sends any buffered write data to theunderlying file. If called with C<NULL> this may flush all openstreams (or core dump with some USE_STDIO 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 USE_STDIOimplementations. The USE_PERLIO (layers) implementation tries tobehave better: it flushes all open streams when passed C<NULL>, andattempts to retain data on read streams either in the buffer or byseeking the handle to the current logical position.=item B<PerlIO_seek(f,offset,whence)>This corresponds to fseek(). Sends buffered write data to theunderlying file, or discards any buffered read data, then positionsthe file descriptor as specified by B<offset> and B<whence> (sic).This is the correct thing to do when switching between read and writeon the same handle (see issues with PerlIO_flush() above). Offset isof type C<Off_t> which is a perl Configure value which may not be sameas stdio's C<off_t>.=item B<PerlIO_tell(f)>This corresponds to ftell(). Returns the current file position, or(Off_t) -1 on error. May just return value system "knows" withoutmaking a system call or checking the underlying file descriptor (souse on shared file descriptors is not safe without aPerlIO_seek()). Return value is of type C<Off_t> which is a perlConfigure value which may not be same as stdio's C<off_t>.=item B<PerlIO_getpos(f,p)>, B<PerlIO_setpos(f,p)>These correspond (loosely) to fgetpos() and fsetpos(). Rather thanstdio's Fpos_t they expect a "Perl Scalar Value" 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 ofPerlIO_tell() and PerlIO_seek().=item B<PerlIO_rewind(f)>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?