/[autoconf]/autoconf/lib/Autom4te/XFile.pm
ViewVC logotype

Diff of /autoconf/lib/Autom4te/XFile.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by adl, Wed May 7 06:51:25 2003 UTC revision 1.8 by adl, Sat Sep 13 22:00:36 2003 UTC
# Line 18  Line 18 
18  # Written by Akim Demaille <akim@freefriends.org>.  # Written by Akim Demaille <akim@freefriends.org>.
19    
20  ###############################################################  ###############################################################
21  # The main copy of this file is in Autoconf's CVS repository. #  # The main copy of this file is in Automake's CVS repository. #
22  # Updates should be sent to autoconf-patches@gnu.org.         #  # Updates should be sent to automake-patches@gnu.org.         #
23  ###############################################################  ###############################################################
24    
25  package Autom4te::XFile;  package Autom4te::XFile;
# Line 33  Autom4te::XFile - supply object methods Line 33  Autom4te::XFile - supply object methods
33      use Autom4te::XFile;      use Autom4te::XFile;
34    
35      $fh = new Autom4te::XFile;      $fh = new Autom4te::XFile;
36      $fh->open("< file"))      $fh->open ("< file");
37      # No need to check $FH: we died if open failed.      # No need to check $FH: we died if open failed.
38      print <$fh>;      print <$fh>;
39      $fh->close;      $fh->close;
# Line 50  Autom4te::XFile - supply object methods Line 50  Autom4te::XFile - supply object methods
50      print <$fh>;      print <$fh>;
51      undef $fh;   # automatically closes the file and checks for errors.      undef $fh;   # automatically closes the file and checks for errors.
52    
53      $fh = new Autom4te::XFile "file", O_WRONLY|O_APPEND;      $fh = new Autom4te::XFile "file", O_WRONLY | O_APPEND;
54      # No need to check $FH: we died if new failed.      # No need to check $FH: we died if new failed.
55      print $fh "corge\n";      print $fh "corge\n";
56    
57      $pos = $fh->getpos;      $pos = $fh->getpos;
58      $fh->setpos($pos);      $fh->setpos ($pos);
59    
60      undef $fh;   # automatically closes the file and checks for errors.      undef $fh;   # automatically closes the file and checks for errors.
61    
# Line 89  use vars qw($VERSION @EXPORT @EXPORT_OK Line 89  use vars qw($VERSION @EXPORT @EXPORT_OK
89  use Carp;  use Carp;
90  use IO::File;  use IO::File;
91  use File::Basename;  use File::Basename;
92    use Autom4te::ChannelDefs;
93    use Autom4te::FileUtils;
94    
95  require Exporter;  require Exporter;
96  require DynaLoader;  require DynaLoader;
# Line 117  my $me = basename ($0); Line 119  my $me = basename ($0);
119  sub new  sub new
120  {  {
121    my $type = shift;    my $type = shift;
122    my $class = ref($type) || $type || "Autom4te::XFile";    my $class = ref $type || $type || "Autom4te::XFile";
123    my $fh = $class->SUPER::new ();    my $fh = $class->SUPER::new ();
124    if (@_)    if (@_)
125      {      {
# Line 132  sub new Line 134  sub new
134    
135  sub open  sub open
136  {  {
137    my ($fh) = shift;    my $fh = shift;
138    my ($file) = @_;    my ($file) = @_;
139    
140    # WARNING: Gross hack: $FH is a typeglob: use its hash slot to store    # WARNING: Gross hack: $FH is a typeglob: use its hash slot to store
# Line 143  sub open Line 145  sub open
145    
146    if (!$fh->SUPER::open (@_))    if (!$fh->SUPER::open (@_))
147      {      {
148        croak "$me: cannot open $file: $!\n";        fatal "cannot open $file: $!";
149      }      }
150    
151    # In case we're running under MSWindows, don't write with CRLF.    # In case we're running under MSWindows, don't write with CRLF.
# Line 159  sub open Line 161  sub open
161    
162  sub close  sub close
163  {  {
164    my ($fh) = shift;    my $fh = shift;
165    if (!$fh->SUPER::close (@_))    if (!$fh->SUPER::close (@_))
166      {      {
167        my $file = $fh->name;        my $file = $fh->name;
168        croak "$me: cannot close $file: $!\n";        Autom4te::FileUtils::handle_exec_errors $file
169            unless $!;
170          fatal "cannot close $file: $!";
171      }      }
172  }  }
173    
# Line 200  sub getlines Line 204  sub getlines
204    
205  sub name  sub name
206  {  {
207    my ($fh) = shift;    my $fh = shift;
208    return ${*$fh}{'autom4te_xfile_file'};    return ${*$fh}{'autom4te_xfile_file'};
209  }  }
210    
# Line 215  sub lock Line 219  sub lock
219    if (!flock ($fh, $mode))    if (!flock ($fh, $mode))
220      {      {
221        my $file = $fh->name;        my $file = $fh->name;
222        croak "$me: cannot lock $file with mode $mode: $!\n";        fatal "cannot lock $file with mode $mode: $!";
223      }      }
224  }  }
225    
# Line 225  sub lock Line 229  sub lock
229    
230  sub seek  sub seek
231  {  {
232    my ($fh) = shift;    my $fh = shift;
233    # Cannot use @_ here.    # Cannot use @_ here.
234    if (!seek ($fh, $_[0], $_[1]))    if (!seek ($fh, $_[0], $_[1]))
235      {      {
236        my $file = $fh->name;        my $file = $fh->name;
237        croak "$me: cannot rewind $file with @_: $!\n";        fatal "$me: cannot rewind $file with @_: $!";
238      }      }
239  }  }
240    
# Line 244  sub truncate Line 248  sub truncate
248    if (!truncate ($fh, $len))    if (!truncate ($fh, $len))
249      {      {
250        my $file = $fh->name;        my $file = $fh->name;
251        croak "$me: cannot truncate $file at $len: $!\n";        fatal "cannot truncate $file at $len: $!";
252      }      }
253  }  }
254    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26