aboutsummaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index 418fb98..e0e335b 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1,5 +1,7 @@
#include "common.hh"
+#include <sys/stat.h>
+
static void (*ErrorFunction)(const char *Text) = NULL;
static void (*PrintFunction)(int Level, const char *Text) = NULL;
@@ -41,6 +43,27 @@ void print(int Level, const char *Text, ...){
}
}
+int random(int Min, int Max){
+ int Range = (Max - Min) + 1;
+ int Result = Min;
+ if(Range > 0){
+ Result += rand() % Range;
+ }
+ return Result;
+}
+
+bool FileExists(const char *FileName){
+ struct stat Buffer;
+ bool Result = true;
+ if(stat(FileName, &Buffer) != 0){
+ if(errno != ENOENT){
+ error("FileExists: Unerwarteter Fehlercode %d.\n", errno);
+ }
+ Result = false;
+ }
+ return Result;
+}
+
// String Utility
// =============================================================================
bool isSpace(int c){