X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Fssic.pl;h=285c20fa4bdc5d2e779ec0ab59e8283fbe4536ff;hb=4044ca6ad9ed9a23b873036b1225e2d424fa7031;hp=d678556be7716789249ad70d4c540e31f266ad71;hpb=da9d788a9059ee88240cbbcc5096abc553b1cf1f;p=ssic.git diff --git a/src/ssic.pl b/src/ssic.pl index d678556..285c20f 100644 --- a/src/ssic.pl +++ b/src/ssic.pl @@ -111,7 +111,7 @@ sub compile my $var_name; my $var_value; - if ($input eq $output) { + if ($input eq $output and $input ne "-") { error(4, "Input and output files are equal\n"); } @@ -127,8 +127,8 @@ sub compile if ($output eq "-") { $output_fh = *STDOUT; } else { - if (not open($output_fh, ">", $output)) { - error(4, "%s: %s\n", $output, $!); + if (not open($output_fh, ">", $output . "~")) { + error(4, "%s: %s\n", $output . "~", $!); } } @@ -152,6 +152,17 @@ sub compile } print($output_fh $ssi->process(<$input_fh>)); + + if ($input ne "-") { + close($input_fh); + } + if ($output ne "-") { + close($output_fh); + } + + if (not rename($output . "~", $output)) { + error(4, "%s: %s\n", $output, $!); + } } main();