Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
7.8 KiB

  1. =head1 NAME
  2. perlapio - perl's IO abstraction interface.
  3. =head1 SYNOPSIS
  4. PerlIO *PerlIO_stdin(void);
  5. PerlIO *PerlIO_stdout(void);
  6. PerlIO *PerlIO_stderr(void);
  7. PerlIO *PerlIO_open(const char *,const char *);
  8. int PerlIO_close(PerlIO *);
  9. int PerlIO_stdoutf(const char *,...)
  10. int PerlIO_puts(PerlIO *,const char *);
  11. int PerlIO_putc(PerlIO *,int);
  12. int PerlIO_write(PerlIO *,const void *,size_t);
  13. int PerlIO_printf(PerlIO *, const char *,...);
  14. int PerlIO_vprintf(PerlIO *, const char *, va_list);
  15. int PerlIO_flush(PerlIO *);
  16. int PerlIO_eof(PerlIO *);
  17. int PerlIO_error(PerlIO *);
  18. void PerlIO_clearerr(PerlIO *);
  19. int PerlIO_getc(PerlIO *);
  20. int PerlIO_ungetc(PerlIO *,int);
  21. int PerlIO_read(PerlIO *,void *,size_t);
  22. int PerlIO_fileno(PerlIO *);
  23. PerlIO *PerlIO_fdopen(int, const char *);
  24. PerlIO *PerlIO_importFILE(FILE *, int flags);
  25. FILE *PerlIO_exportFILE(PerlIO *, int flags);
  26. FILE *PerlIO_findFILE(PerlIO *);
  27. void PerlIO_releaseFILE(PerlIO *,FILE *);
  28. void PerlIO_setlinebuf(PerlIO *);
  29. long PerlIO_tell(PerlIO *);
  30. int PerlIO_seek(PerlIO *,off_t,int);
  31. int PerlIO_getpos(PerlIO *,Fpos_t *)
  32. int PerlIO_setpos(PerlIO *,Fpos_t *)
  33. void PerlIO_rewind(PerlIO *);
  34. int PerlIO_has_base(PerlIO *);
  35. int PerlIO_has_cntptr(PerlIO *);
  36. int PerlIO_fast_gets(PerlIO *);
  37. int PerlIO_canset_cnt(PerlIO *);
  38. char *PerlIO_get_ptr(PerlIO *);
  39. int PerlIO_get_cnt(PerlIO *);
  40. void PerlIO_set_cnt(PerlIO *,int);
  41. void PerlIO_set_ptrcnt(PerlIO *,char *,int);
  42. char *PerlIO_get_base(PerlIO *);
  43. int PerlIO_get_bufsiz(PerlIO *);
  44. =head1 DESCRIPTION
  45. Perl's source code should use the above functions instead of those
  46. defined in ANSI C's I<stdio.h>. The perl headers will C<#define> them to
  47. the I/O mechanism selected at Configure time.
  48. The functions are modeled on those in I<stdio.h>, but parameter order
  49. has been "tidied up a little".
  50. =over 4
  51. =item B<PerlIO *>
  52. This takes the place of FILE *. Like FILE * it should be treated as
  53. opaque (it is probably safe to assume it is a pointer to something).
  54. =item B<PerlIO_stdin()>, B<PerlIO_stdout()>, B<PerlIO_stderr()>
  55. Use these rather than C<stdin>, C<stdout>, C<stderr>. They are written
  56. to look like "function calls" rather than variables because this makes
  57. it easier to I<make them> function calls if platform cannot export data
  58. to loaded modules, or if (say) different "threads" might have different
  59. values.
  60. =item B<PerlIO_open(path, mode)>, B<PerlIO_fdopen(fd,mode)>
  61. These correspond to fopen()/fdopen() arguments are the same.
  62. =item B<PerlIO_printf(f,fmt,...)>, B<PerlIO_vprintf(f,fmt,a)>
  63. These are fprintf()/vfprintf() equivalents.
  64. =item B<PerlIO_stdoutf(fmt,...)>
  65. This is printf() equivalent. printf is #defined to this function,
  66. so it is (currently) legal to use C<printf(fmt,...)> in perl sources.
  67. =item B<PerlIO_read(f,buf,count)>, B<PerlIO_write(f,buf,count)>
  68. These correspond to fread() and fwrite(). Note that arguments
  69. are different, there is only one "count" and order has
  70. "file" first.
  71. =item B<PerlIO_close(f)>
  72. =item B<PerlIO_puts(f,s)>, B<PerlIO_putc(f,c)>
  73. These correspond to fputs() and fputc().
  74. Note that arguments have been revised to have "file" first.
  75. =item B<PerlIO_ungetc(f,c)>
  76. This corresponds to ungetc().
  77. Note that arguments have been revised to have "file" first.
  78. =item B<PerlIO_getc(f)>
  79. This corresponds to getc().
  80. =item B<PerlIO_eof(f)>
  81. This corresponds to feof().
  82. =item B<PerlIO_error(f)>
  83. This corresponds to ferror().
  84. =item B<PerlIO_fileno(f)>
  85. This corresponds to fileno(), note that on some platforms,
  86. the meaning of "fileno" may not match Unix.
  87. =item B<PerlIO_clearerr(f)>
  88. This corresponds to clearerr(), i.e., clears 'eof' and 'error'
  89. flags for the "stream".
  90. =item B<PerlIO_flush(f)>
  91. This corresponds to fflush().
  92. =item B<PerlIO_tell(f)>
  93. This corresponds to ftell().
  94. =item B<PerlIO_seek(f,o,w)>
  95. This corresponds to fseek().
  96. =item B<PerlIO_getpos(f,p)>, B<PerlIO_setpos(f,p)>
  97. These correspond to fgetpos() and fsetpos(). If platform does not
  98. have the stdio calls then they are implemented in terms of PerlIO_tell()
  99. and PerlIO_seek().
  100. =item B<PerlIO_rewind(f)>
  101. This corresponds to rewind(). Note may be redefined
  102. in terms of PerlIO_seek() at some point.
  103. =item B<PerlIO_tmpfile()>
  104. This corresponds to tmpfile(), i.e., returns an anonymous
  105. PerlIO which will automatically be deleted when closed.
  106. =back
  107. =head2 Co-existence with stdio
  108. There is outline support for co-existence of PerlIO with stdio.
  109. Obviously if PerlIO is implemented in terms of stdio there is
  110. no problem. However if perlio is implemented on top of (say) sfio
  111. then mechanisms must exist to create a FILE * which can be passed
  112. to library code which is going to use stdio calls.
  113. =over 4
  114. =item B<PerlIO_importFILE(f,flags)>
  115. Used to get a PerlIO * from a FILE *.
  116. May need additional arguments, interface under review.
  117. =item B<PerlIO_exportFILE(f,flags)>
  118. Given an PerlIO * return a 'native' FILE * suitable for
  119. passing to code expecting to be compiled and linked with
  120. ANSI C I<stdio.h>.
  121. The fact that such a FILE * has been 'exported' is recorded,
  122. and may affect future PerlIO operations on the original
  123. PerlIO *.
  124. =item B<PerlIO_findFILE(f)>
  125. Returns previously 'exported' FILE * (if any).
  126. Place holder until interface is fully defined.
  127. =item B<PerlIO_releaseFILE(p,f)>
  128. Calling PerlIO_releaseFILE informs PerlIO that all use
  129. of FILE * is complete. It is removed from list of 'exported'
  130. FILE *s, and associated PerlIO * should revert to original
  131. behaviour.
  132. =item B<PerlIO_setlinebuf(f)>
  133. This corresponds to setlinebuf(). Use is deprecated pending
  134. further discussion. (Perl core uses it I<only> when "dumping";
  135. it has nothing to do with $| auto-flush.)
  136. =back
  137. In addition to user API above there is an "implementation" interface
  138. which allows perl to get at internals of PerlIO.
  139. The following calls correspond to the various FILE_xxx macros determined
  140. by Configure. This section is really of interest to only those
  141. concerned with detailed perl-core behaviour or implementing a
  142. PerlIO mapping.
  143. =over 4
  144. =item B<PerlIO_has_cntptr(f)>
  145. Implementation can return pointer to current position in the "buffer" and
  146. a count of bytes available in the buffer.
  147. =item B<PerlIO_get_ptr(f)>
  148. Return pointer to next readable byte in buffer.
  149. =item B<PerlIO_get_cnt(f)>
  150. Return count of readable bytes in the buffer.
  151. =item B<PerlIO_canset_cnt(f)>
  152. Implementation can adjust its idea of number of
  153. bytes in the buffer.
  154. =item B<PerlIO_fast_gets(f)>
  155. Implementation has all the interfaces required to
  156. allow perl's fast code to handle <FILE> mechanism.
  157. PerlIO_fast_gets(f) = PerlIO_has_cntptr(f) && \
  158. PerlIO_canset_cnt(f) && \
  159. `Can set pointer into buffer'
  160. =item B<PerlIO_set_ptrcnt(f,p,c)>
  161. Set pointer into buffer, and a count of bytes still in the
  162. buffer. Should be used only to set
  163. pointer to within range implied by previous calls
  164. to C<PerlIO_get_ptr> and C<PerlIO_get_cnt>.
  165. =item B<PerlIO_set_cnt(f,c)>
  166. Obscure - set count of bytes in the buffer. Deprecated.
  167. Currently used in only doio.c to force count < -1 to -1.
  168. Perhaps should be PerlIO_set_empty or similar.
  169. This call may actually do nothing if "count" is deduced from pointer
  170. and a "limit".
  171. =item B<PerlIO_has_base(f)>
  172. Implementation has a buffer, and can return pointer
  173. to whole buffer and its size. Used by perl for B<-T> / B<-B> tests.
  174. Other uses would be very obscure...
  175. =item B<PerlIO_get_base(f)>
  176. Return I<start> of buffer.
  177. =item B<PerlIO_get_bufsiz(f)>
  178. Return I<total size> of buffer.
  179. =back