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.