fix encoding

This commit is contained in:
alejandro-campos 2020-07-01 12:51:00 +02:00
parent 2133126182
commit 27770b91da
1 changed files with 16 additions and 8 deletions

View File

@ -374,17 +374,25 @@ our $THRRUN :shared = 1;
################################################################################ ################################################################################
## Reads a file and returns entire content or undef if error. ## Reads a file and returns entire content or undef if error.
################################################################################ ################################################################################
sub read_file($$) { sub read_file($;$) {
my ($path, $enc) = @_; my ($path, $enc) = @_;
if ( $enc eq '' ) {
$enc = 'utf8';
}
my $_FILE; my $_FILE;
if( !open($_FILE, "<:encoding($enc)", $path) ) {
# failed to open, return undef if (!defined($enc)) {
return undef; if( !open($_FILE, "<", $path) ) {
# failed to open, return undef
return undef;
}
} else {
if ( $enc eq '' ) {
$enc = 'utf8';
}
if( !open($_FILE, "<:encoding($enc)", $path) ) {
# failed to open, return undef
return undef;
}
} }
# Slurp configuration file content. # Slurp configuration file content.