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.

127 lines
3.0 KiB

  1. #
  2. package IO::Seekable;
  3. =head1 NAME
  4. IO::Seekable - supply seek based methods for I/O objects
  5. =head1 SYNOPSIS
  6. use IO::Seekable;
  7. package IO::Something;
  8. @ISA = qw(IO::Seekable);
  9. =head1 DESCRIPTION
  10. C<IO::Seekable> does not have a constructor of its own as it is intended to
  11. be inherited by other C<IO::Handle> based objects. It provides methods
  12. which allow seeking of the file descriptors.
  13. =over 4
  14. =item $io->getpos
  15. Returns an opaque value that represents the current position of the
  16. IO::File, or C<undef> if this is not possible (eg an unseekable stream such
  17. as a terminal, pipe or socket). If the fgetpos() function is available in
  18. your C library it is used to implements getpos, else perl emulates getpos
  19. using C's ftell() function.
  20. =item $io->setpos
  21. Uses the value of a previous getpos call to return to a previously visited
  22. position. Returns "0 but true" on success, C<undef> on failure.
  23. =back
  24. See L<perlfunc> for complete descriptions of each of the following
  25. supported C<IO::Seekable> methods, which are just front ends for the
  26. corresponding built-in functions:
  27. =over 4
  28. =item $io->setpos ( POS, WHENCE )
  29. Seek the IO::File to position POS, relative to WHENCE:
  30. =over 8
  31. =item WHENCE=0 (SEEK_SET)
  32. POS is absolute position. (Seek relative to the start of the file)
  33. =item WHENCE=1 (SEEK_CUR)
  34. POS is an offset from the current position. (Seek relative to current)
  35. =item WHENCE=2 (SEEK_END)
  36. POS is an offset from the end of the file. (Seek relative to end)
  37. =back
  38. The SEEK_* constants can be imported from the C<Fcntl> module if you
  39. don't wish to use the numbers C<0> C<1> or C<2> in your code.
  40. Returns C<1> upon success, C<0> otherwise.
  41. =item $io->sysseek( POS, WHENCE )
  42. Similar to $io->seek, but sets the IO::File's position using the system
  43. call lseek(2) directly, so will confuse most perl IO operators except
  44. sysread and syswrite (see L<perlfunc> for full details)
  45. Returns the new position, or C<undef> on failure. A position
  46. of zero is returned as the string C<"0 but true">
  47. =item $io->tell
  48. Returns the IO::File's current position, or -1 on error.
  49. =back
  50. =head1 SEE ALSO
  51. L<perlfunc>,
  52. L<perlop/"I/O Operators">,
  53. L<IO::Handle>
  54. L<IO::File>
  55. =head1 HISTORY
  56. Derived from FileHandle.pm by Graham Barr E<lt>gbarr@pobox.comE<gt>
  57. =cut
  58. require 5.005_64;
  59. use Carp;
  60. use strict;
  61. our($VERSION, @EXPORT, @ISA);
  62. use IO::Handle ();
  63. # XXX we can't get these from IO::Handle or we'll get prototype
  64. # mismatch warnings on C<use POSIX; use IO::File;> :-(
  65. use Fcntl qw(SEEK_SET SEEK_CUR SEEK_END);
  66. require Exporter;
  67. @EXPORT = qw(SEEK_SET SEEK_CUR SEEK_END);
  68. @ISA = qw(Exporter);
  69. $VERSION = "1.08";
  70. sub seek {
  71. @_ == 3 or croak 'usage: $io->seek(POS, WHENCE)';
  72. seek($_[0], $_[1], $_[2]);
  73. }
  74. sub sysseek {
  75. @_ == 3 or croak 'usage: $io->sysseek(POS, WHENCE)';
  76. sysseek($_[0], $_[1], $_[2]);
  77. }
  78. sub tell {
  79. @_ == 1 or croak 'usage: $io->tell()';
  80. tell($_[0]);
  81. }
  82. 1;