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