From c2f41059c71a0c7bfc0b64a7f53334d3bfd0ee76 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Sun, 25 May 2025 22:59:27 -0300 Subject: impl a couple more `util.cc` functions --- src/util.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/util.cc') 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 + 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){ -- cgit v1.2.3