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.

115 lines
2.9 KiB

  1. package File::stat;
  2. use strict;
  3. use 5.005_64;
  4. our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
  5. BEGIN {
  6. use Exporter ();
  7. @EXPORT = qw(stat lstat);
  8. @EXPORT_OK = qw( $st_dev $st_ino $st_mode
  9. $st_nlink $st_uid $st_gid
  10. $st_rdev $st_size
  11. $st_atime $st_mtime $st_ctime
  12. $st_blksize $st_blocks
  13. );
  14. %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
  15. }
  16. use vars @EXPORT_OK;
  17. # Class::Struct forbids use of @ISA
  18. sub import { goto &Exporter::import }
  19. use Class::Struct qw(struct);
  20. struct 'File::stat' => [
  21. map { $_ => '$' } qw{
  22. dev ino mode nlink uid gid rdev size
  23. atime mtime ctime blksize blocks
  24. }
  25. ];
  26. sub populate (@) {
  27. return unless @_;
  28. my $stob = new();
  29. @$stob = (
  30. $st_dev, $st_ino, $st_mode, $st_nlink, $st_uid, $st_gid, $st_rdev,
  31. $st_size, $st_atime, $st_mtime, $st_ctime, $st_blksize, $st_blocks )
  32. = @_;
  33. return $stob;
  34. }
  35. sub lstat ($) { populate(CORE::lstat(shift)) }
  36. sub stat ($) {
  37. my $arg = shift;
  38. my $st = populate(CORE::stat $arg);
  39. return $st if $st;
  40. no strict 'refs';
  41. require Symbol;
  42. return populate(CORE::stat \*{Symbol::qualify($arg)});
  43. }
  44. 1;
  45. __END__
  46. =head1 NAME
  47. File::stat - by-name interface to Perl's built-in stat() functions
  48. =head1 SYNOPSIS
  49. use File::stat;
  50. $st = stat($file) or die "No $file: $!";
  51. if ( ($st->mode & 0111) && $st->nlink > 1) ) {
  52. print "$file is executable with lotsa links\n";
  53. }
  54. use File::stat qw(:FIELDS);
  55. stat($file) or die "No $file: $!";
  56. if ( ($st_mode & 0111) && $st_nlink > 1) ) {
  57. print "$file is executable with lotsa links\n";
  58. }
  59. =head1 DESCRIPTION
  60. This module's default exports override the core stat()
  61. and lstat() functions, replacing them with versions that return
  62. "File::stat" objects. This object has methods that
  63. return the similarly named structure field name from the
  64. stat(2) function; namely,
  65. dev,
  66. ino,
  67. mode,
  68. nlink,
  69. uid,
  70. gid,
  71. rdev,
  72. size,
  73. atime,
  74. mtime,
  75. ctime,
  76. blksize,
  77. and
  78. blocks.
  79. You may also import all the structure fields directly into your namespace
  80. as regular variables using the :FIELDS import tag. (Note that this still
  81. overrides your stat() and lstat() functions.) Access these fields as
  82. variables named with a preceding C<st_> in front their method names.
  83. Thus, C<$stat_obj-E<gt>dev()> corresponds to $st_dev if you import
  84. the fields.
  85. To access this functionality without the core overrides,
  86. pass the C<use> an empty import list, and then access
  87. function functions with their full qualified names.
  88. On the other hand, the built-ins are still available
  89. via the C<CORE::> pseudo-package.
  90. =head1 NOTE
  91. While this class is currently implemented using the Class::Struct
  92. module to build a struct-like class, you shouldn't rely upon this.
  93. =head1 AUTHOR
  94. Tom Christiansen