| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-12-23 15:44:19 +0100 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-12-23 15:44:19 +0100 | 
| commit | 390576c3839ee7abb845e27b7267de45495e6b2f (patch) | |
| tree | c481c37c868ccc65a3476f60b17369b21a90b79b /src/util | |
| parent | 4355548f79375a62bb5e3bb5695190d48e4c0bc3 (diff) | |
Starting to turn relabsd into a proper daemon...
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/string.c | 36 | 
1 files changed, 36 insertions, 0 deletions
| diff --git a/src/util/string.c b/src/util/string.c new file mode 100644 index 0000000..edb5eb6 --- /dev/null +++ b/src/util/string.c @@ -0,0 +1,36 @@ +/**** POSIX *******************************************************************/ +#include <stdlib.h> + +/******************************************************************************/ +/**** LOCAL FUNCTIONS *********************************************************/ +/******************************************************************************/ + +/******************************************************************************/ +/**** EXPORTED FUNCTIONS ******************************************************/ +/******************************************************************************/ +int relabsd_util_parse_int +( +   const char string [const restrict static 1], +   const int min, +   const int max, +   int output [const restrict static 1] +) +{ +   char * invalid_char; /* may become an alias of string. */ +   long int buffer; + +   buffer = strtol(string, &invalid_char, 10); + +   if ((invalid_char[0] != '\0') || (string[0] == '\0')) +   { +      return -1; +   } + +   if ((buffer < ((long int) min)) || (buffer > ((long int) max))) +   { +      return -2; +   } + +   *output = ((int) buffer); +   return 0; +} | 


