fix encoding

This commit is contained in:
alejandro-campos 2020-06-24 17:54:41 +02:00
parent a81e4acbb7
commit 3a042c67f3
1 changed files with 11 additions and 6 deletions

View File

@ -378,15 +378,20 @@ our $THRRUN :shared = 1;
sub read_file($$) { sub read_file($$) {
my ($path, $enc) = @_; my ($path, $enc) = @_;
if ( $enc eq '' ) {
$enc = 'utf8';
}
my $_FILE; my $_FILE;
if ( $enc eq '' ) {
if( !open($_FILE, "<", $path) ) {
# failed to open, return undef
return undef;
}
} else {
if( !open($_FILE, "<:encoding($enc)", $path) ) { if( !open($_FILE, "<:encoding($enc)", $path) ) {
# failed to open, return undef # failed to open, return undef
return undef; return undef;
} }
}
# Slurp configuration file content. # Slurp configuration file content.
my $content = do { local $/; <$_FILE> }; my $content = do { local $/; <$_FILE> };