diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-05-25 22:59:27 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-05-25 22:59:27 -0300 |
| commit | c2f41059c71a0c7bfc0b64a7f53334d3bfd0ee76 (patch) | |
| tree | 289089acc4aa6e6228bf8bf207db50ddaf481d90 /src/util.cc | |
| parent | ad8213f35523cbb07f418ae275af448a47cc0288 (diff) | |
| download | game-c2f41059c71a0c7bfc0b64a7f53334d3bfd0ee76.tar.gz game-c2f41059c71a0c7bfc0b64a7f53334d3bfd0ee76.zip | |
impl a couple more `util.cc` functions
Diffstat (limited to 'src/util.cc')
| -rw-r--r-- | src/util.cc | 23 |
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){ |
