From 27770b91da2144b1709bda042df4d3a6f3205b6c Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Wed, 1 Jul 2020 12:51:00 +0200 Subject: [PATCH] fix encoding --- pandora_server/lib/PandoraFMS/Tools.pm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index eaba3f33fd..ded803bad9 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -374,17 +374,25 @@ our $THRRUN :shared = 1; ################################################################################ ## Reads a file and returns entire content or undef if error. ################################################################################ -sub read_file($$) { +sub read_file($;$) { my ($path, $enc) = @_; - if ( $enc eq '' ) { - $enc = 'utf8'; - } - my $_FILE; - if( !open($_FILE, "<:encoding($enc)", $path) ) { - # failed to open, return undef - return undef; + + if (!defined($enc)) { + 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.