summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-02-06 12:39:10 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2016-02-06 17:17:49 -0800
commit2ca0d5755f68ea7a99c39a236ea8d02aa207d594 (patch)
tree10f3bb1b1b68c47aeecc464f8d822869293692a2 /lib
parent14f568f6830b49214e0ad020c9d30559ce8abc7d (diff)
downloadautoconf-2ca0d5755f68ea7a99c39a236ea8d02aa207d594.tar.gz
make fetch
Diffstat (limited to 'lib')
-rw-r--r--lib/Autom4te/Channels.pm2
-rw-r--r--lib/Autom4te/FileUtils.pm35
-rw-r--r--lib/Autom4te/XFile.pm15
3 files changed, 15 insertions, 37 deletions
diff --git a/lib/Autom4te/Channels.pm b/lib/Autom4te/Channels.pm
index b8ce598b..67601a0a 100644
--- a/lib/Autom4te/Channels.pm
+++ b/lib/Autom4te/Channels.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+# Copyright (C) 2002-2015 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff --git a/lib/Autom4te/FileUtils.pm b/lib/Autom4te/FileUtils.pm
index 30bbdb92..678b5983 100644
--- a/lib/Autom4te/FileUtils.pm
+++ b/lib/Autom4te/FileUtils.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2003-2012 Free Software Foundation, Inc.
+# Copyright (C) 2003-2015 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -45,40 +45,13 @@ use Autom4te::ChannelDefs;
use vars qw (@ISA @EXPORT);
@ISA = qw (Exporter);
-@EXPORT = qw (&open_quote &contents
+@EXPORT = qw (&contents
&find_file &mtime
&update_file &up_to_date_p
&xsystem &xsystem_hint &xqx
&dir_has_case_matching_file &reset_dir_cache
&set_dir_cache_file);
-
-=item C<open_quote ($file_name)>
-
-Quote C<$file_name> for open.
-
-=cut
-
-# $FILE_NAME
-# open_quote ($FILE_NAME)
-# -----------------------
-# If the string $S is a well-behaved file name, simply return it.
-# If it starts with white space, prepend './', if it ends with
-# white space, add '\0'. Return the new string.
-sub open_quote($)
-{
- my ($s) = @_;
- if ($s =~ m/^\s/)
- {
- $s = "./$s";
- }
- if ($s =~ m/\s$/)
- {
- $s = "$s\0";
- }
- return $s;
-}
-
=item C<find_file ($file_name, @include)>
Return the first path for a C<$file_name> in the C<include>s.
@@ -168,7 +141,7 @@ sub update_file ($$;$)
if ($to eq '-')
{
- my $in = new IO::File ("< " . open_quote ($from));
+ my $in = new IO::File $from, "<";
my $out = new IO::File (">-");
while ($_ = $in->getline)
{
@@ -360,7 +333,7 @@ sub contents ($)
my ($file) = @_;
verb "reading $file";
local $/; # Turn on slurp-mode.
- my $f = new Autom4te::XFile "< " . open_quote ($file);
+ my $f = new Autom4te::XFile $file, "<";
my $contents = $f->getline;
$f->close;
return $contents;
diff --git a/lib/Autom4te/XFile.pm b/lib/Autom4te/XFile.pm
index 28d5bc66..138818e8 100644
--- a/lib/Autom4te/XFile.pm
+++ b/lib/Autom4te/XFile.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001-2015 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -31,13 +31,13 @@ Autom4te::XFile - supply object methods for filehandles with error handling
use Autom4te::XFile;
$fh = new Autom4te::XFile;
- $fh->open ("< file");
+ $fh->open ("file", "<");
# No need to check $FH: we died if open failed.
print <$fh>;
$fh->close;
# No need to check the return value of close: we died if it failed.
- $fh = new Autom4te::XFile "> file";
+ $fh = new Autom4te::XFile "file", ">";
# No need to check $FH: we died if new failed.
print $fh "bar\n";
$fh->close;
@@ -130,7 +130,7 @@ Die if opening fails. Store the name of the file. Use binmode for writing.
sub open
{
my $fh = shift;
- my ($file) = @_;
+ my ($file, $mode) = @_;
# WARNING: Gross hack: $FH is a typeglob: use its hash slot to store
# the 'name' of the file we are opening. See the example with
@@ -147,7 +147,12 @@ sub open
# (This circumvents a bug in at least Cygwin bash where the shell
# parsing fails on lines ending with the continuation character '\'
# and CRLF).
- binmode $fh if $file =~ /^\s*>/;
+ # Correctly recognize usages like:
+ # - open ($file, "w")
+ # - open ($file, "+<")
+ # - open (" >$file")
+ binmode $fh
+ if (defined $mode && $mode =~ /^[+>wa]/ or $file =~ /^\s*>/);
}
=item C<$fh-E<gt>close>