diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 10 | ||||
-rw-r--r-- | lib/lib.h | 1 | ||||
-rw-r--r-- | lib/pending.c | 18 | ||||
-rw-r--r-- | lib/pending.h | 6 |
4 files changed, 11 insertions, 24 deletions
@@ -203,6 +203,16 @@ long atolx(char *numstr) return val; } +long atolx_range(char *numstr, long low, long high) +{ + long val = atolx(numstr); + + if (val < low) error_exit("%ld < %ld", val, low); + if (val > high) error_exit("%ld > %ld", val, high); + + return val; +} + int numlen(long l) { int len = 0; @@ -134,6 +134,7 @@ int64_t peek(void *ptr, int size); void poke(void *ptr, uint64_t val, int size); struct string_list *find_in_path(char *path, char *filename); long atolx(char *c); +long atolx_range(char *numstr, long low, long high); int numlen(long l); int stridx(char *haystack, char needle); off_t fdlength(int fd); diff --git a/lib/pending.c b/lib/pending.c index a804d5b8..df3207ef 100644 --- a/lib/pending.c +++ b/lib/pending.c @@ -30,24 +30,6 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name)) closedir(dp); } -/* - * used to get the interger value. - */ -unsigned long get_int_value(const char *numstr, unsigned long lowrange, unsigned long highrange) -{ - unsigned long rvalue = 0; - char *ptr; - - if (!isdigit(*numstr)) perror_exit("bad number '%s'", numstr); - errno = 0; - rvalue = strtoul(numstr, &ptr, 10); - - if (errno || numstr == ptr || *ptr || rvalue < lowrange || rvalue > highrange) - perror_exit("bad number '%s'", numstr); - - return rvalue; -} - void daemonize(void) { int fd = open("/dev/null", O_RDWR); diff --git a/lib/pending.h b/lib/pending.h index fbd72c46..43885719 100644 --- a/lib/pending.h +++ b/lib/pending.h @@ -23,11 +23,5 @@ int read_password(char * buff, int buflen, char* mesg); int update_password(char *filename, char* username, char* encrypted); // cut helper functions -unsigned long get_int_value(const char *numstr, unsigned long lowrange, unsigned long highrange); - -// grep helper functions -char *astrcat (char *, char *); -char *xastrcat (char *, char *); - void daemonize(void); char *human_readable(unsigned long long size); |