From: pcanterino <> Date: Wed, 9 Feb 2005 18:21:58 +0000 (+0000) Subject: file_read() is now able to open a file in binary mode (maybe we will need it) X-Git-Tag: version_2_3_1~9 X-Git-Url: https://git.p6c8.net/devedit.git/commitdiff_plain/7897c609d415e2362b8c42c3b918a7ebcb5c4bda file_read() is now able to open a file in binary mode (maybe we will need it) --- diff --git a/modules/File/Access.pm b/modules/File/Access.pm index 4fa468d..d892ed8 100644 --- a/modules/File/Access.pm +++ b/modules/File/Access.pm @@ -7,7 +7,7 @@ package File::Access; # using only one command # # Author: Patrick Canterino -# Last modified: 2005-01-06 +# Last modified: 2005-02-09 # use strict; @@ -134,17 +134,20 @@ sub file_lock(*$) # # Read out a file completely # -# Params: File +# Params: 1. File +# 2. true => open in binary mode +# false => open in normal mode (default) # # Return: Contents of the file (Scalar Reference) -sub file_read($) +sub file_read($;$) { - my $file = shift; + my ($file,$binary) = @_; local *FILE; sysopen(FILE,$file,O_RDONLY) or return; file_lock(FILE,LOCK_SH) or do { close(FILE); return }; + binmode(FILE) if($binary); read(FILE, my $content, -s $file);