summaryrefslogtreecommitdiffstats
path: root/etc/inc
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2006-09-27 04:17:16 +0000
committerScott Ullrich <sullrich@pfsense.org>2006-09-27 04:17:16 +0000
commitfa3c05aa6f0bae36bccd4aba4b9507c3c418b481 (patch)
treee70724c9def930ecfed266cb5f3ee2c1353611a5 /etc/inc
parentf4fc97cd88466e913f480945a6d0ab1669402f2d (diff)
downloadpfsense-fa3c05aa6f0bae36bccd4aba4b9507c3c418b481.zip
pfsense-fa3c05aa6f0bae36bccd4aba4b9507c3c418b481.tar.gz
Do not leave trailing spaces before or after the text we are adding or removing.
Diffstat (limited to 'etc/inc')
-rw-r--r--etc/inc/pfsense-utils.inc20
1 files changed, 9 insertions, 11 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index e16c2d2..089f620 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -758,11 +758,11 @@ function remove_text_from_file($file, $text) {
global $fd_log;
if($fd_log)
fwrite($fd_log, "Adding needed text items:\n");
- $filecontents = exec_command_and_return_text("cat " . $file);
+ $filecontents = file_get_contents($file);
$textTMP = str_replace($text, "", $filecontents);
- $text .= $textTMP;
+ $text = $textTMP;
if($fd_log)
- fwrite($fd_log, $text . "\n");
+ fwrite($fd_log, $text);
$fd = fopen($file, "w");
fwrite($fd, $text);
fclose($fd);
@@ -774,15 +774,13 @@ function remove_text_from_file($file, $text) {
*/
function add_text_to_file($file, $text) {
if(file_exists($file) and is_writable($file)) {
- $filecontents = file($file);
- $filecontents[] = $text;
- $tmpfile = get_tmp_file();
- $fout = fopen($tmpfile, "w");
- foreach($filecontents as $line) {
- fwrite($fout, rtrim($line) . "\n");
- }
+ $filecontents = split("\n", file_get_contents($file));
+ $fout = fopen($file, "w");
+ foreach($filecontents as $line)
+ if($line)
+ fwrite($fout, rtrim($line) . "\n");
+ fwrite($fout, rtrim($text) . "\n");
fclose($fout);
- rename($tmpfile, $file);
return true;
} else {
return false;
OpenPOWER on IntegriCloud