From: Stefan Schantl Date: Fri, 24 Aug 2018 05:37:10 +0000 (+0200) Subject: ids-functions.pl: Add function to create empty files X-Git-Tag: v2.23-core131~117^2~172 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=308ba5e74c27e50e9fda4278749256d3ff541d5e ids-functions.pl: Add function to create empty files This generic function can be used to create any kind of emtpy files - it just requires the full path and filename to work. If the specified file exists at calltime, the function will abort to prevent from overwriting existing files and content. Signed-off-by: Stefan Schantl --- diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index cb16e1b493..6f7f3ee7ef 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -355,4 +355,26 @@ sub call_suricatactrl ($) { return; } +# +## Function to create a new empty file. +# +sub create_empty_file($) { + my ($file) = @_; + + # Check if the given file exists. + if(-e $file) { + # Do nothing to prevent from overwriting existing files. + return; + } + + # Open the file for writing. + open(FILE, ">$file") or die "Could not write to $file. $!\n"; + + # Close file handle. + close(FILE); + + # Return true. + return 1; +} + 1;