From 89773c294389297cee33ae3e8a66a0d4c528b69e Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Fri, 11 Jan 2008 12:21:30 +0000 Subject: * fixed encoding problem of PXE-config file output git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1463 95ad53e4-c205-0410-b2fa-d234c58c8868 --- lib/OpenSLX/Utils.pm | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/OpenSLX/Utils.pm b/lib/OpenSLX/Utils.pm index fbfd8d4c..f3a13e48 100644 --- a/lib/OpenSLX/Utils.pm +++ b/lib/OpenSLX/Utils.pm @@ -100,13 +100,17 @@ sub slurpFile my $fileName = shift || confess 'need to pass in fileName!'; my $flags = shift || {}; - checkParams($flags, { 'failIfMissing' => '?' }); + checkParams($flags, { + 'failIfMissing' => '?', + 'io-layer' => '?', + }); my $failIfMissing = exists $flags->{failIfMissing} ? $flags->{failIfMissing} : 1; + my $ioLayer = $flags->{'io-layer'} || 'utf8'; local $/; my $fh; - if (!open($fh, '<', $fileName)) { + if (!open($fh, "<:$ioLayer", $fileName)) { return '' unless $failIfMissing; croak _tr("could not open file '%s' for reading! (%s)", $fileName, $!); } @@ -120,9 +124,15 @@ sub spitFile { my $fileName = shift || croak 'need to pass in a fileName!'; my $content = shift; + my $flags = shift || {}; + + checkParams($flags, { + 'io-layer' => '?', + }); + my $ioLayer = $flags->{'io-layer'} || 'utf8'; my $fh; - open($fh, '>', $fileName) + open($fh, ">:$ioLayer", $fileName) or croak _tr("unable to create file '%s' (%s)\n", $fileName, $!); print $fh $content or croak _tr("unable to print to file '%s' (%s)\n", $fileName, $!); @@ -135,9 +145,15 @@ sub appendFile { my $fileName = shift || croak 'need to pass in a fileName!'; my $content = shift; + my $flags = shift || {}; + + checkParams($flags, { + 'io-layer' => '?', + }); + my $ioLayer = $flags->{'io-layer'} || 'utf8'; my $fh; - open($fh, '>>', $fileName) + open($fh, ">>:$ioLayer", $fileName) or croak _tr("unable to create file '%s' (%s)\n", $fileName, $!); print $fh $content or croak _tr("unable to print to file '%s' (%s)\n", $fileName, $!); -- cgit v1.2.3-55-g7522