gods

a simple blocklist for ssh
Log | Files | Refs | README | LICENSE

range.c (316B)


      1 #include <errno.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <string.h>
      5 
      6 int
      7 range(char *s, int min, int max)
      8 {
      9 	int t;
     10 
     11 	if (!*s)
     12 		return -1;
     13 
     14 	errno = 0;
     15 	t = atoi(s);
     16 	if (errno) {
     17 		fprintf(stderr, "atoi failed: %s\n", strerror(errno));
     18 		return -1;
     19 	}
     20 	if (t < min || t > max)
     21 		return -1;
     22 
     23 	return t;
     24 }