X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Flib%2Fedit.c;h=153e73c9b283aaa1af7f77549537cc81867ab1a6;hb=28b98a207e5834c4066b6565c4210220957452e4;hp=cf9b044c074cbe99dc5ea341655dd801e5359f5d;hpb=669660ef3da87f94461c1410e892fae02bd50e22;p=bacula%2Fbacula diff --git a/bacula/src/lib/edit.c b/bacula/src/lib/edit.c index cf9b044c07..153e73c9b2 100644 --- a/bacula/src/lib/edit.c +++ b/bacula/src/lib/edit.c @@ -27,6 +27,7 @@ */ #include "bacula.h" +#include /* We assume ASCII input and don't worry about overflow */ uint64_t str_to_uint64(char *str) @@ -103,8 +104,9 @@ int duration_to_utime(char *str, utime_t *value) { int i, ch, len; double val; - static int mod[] = {'*', 's', 'n', 'h', 'd', 'w', 'm', 'q', 'y', 0}; - static int mult[] = {1, 1, 60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30, + /* Default to 1 day if no modifier given */ + static int mod[] = {'*', 's', 'n', 'h', 'd', 'w', 'm', 'q', 'y', 0}; + static int mult[] = {60*60*24, 1, 60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30, 60*60*24*91, 60*60*24*365}; /* Look for modifier */ @@ -126,6 +128,7 @@ int duration_to_utime(char *str, utime_t *value) if (mod[i] == 0 || !is_a_number(str)) { return 0; } + errno = 0; val = strtod(str, NULL); if (errno != 0 || val < 0) { return 0; @@ -188,7 +191,7 @@ int size_to_uint64(char *str, int str_len, uint64_t *rtn_value) 1099511627776};/* terabyte */ #endif - Dmsg0(400, "Enter sized to uint64\n"); + Dmsg1(400, "Enter sized to uint64 str=%s\n", str); /* Look for modifier */ ch = str[str_len - 1]; @@ -208,16 +211,16 @@ int size_to_uint64(char *str, int str_len, uint64_t *rtn_value) if (mod[i] == 0 || !is_a_number(str)) { return 0; } - Dmsg3(400, "size str=:%s: %f i=%d\n", str, strtod(str, NULL), i); + Dmsg3(400, "size str=:%s: %lf i=%d\n", str, strtod(str, NULL), i); - value = (uint64_t)strtod(str, NULL); - Dmsg1(400, "Int value = %d\n", (int)value); + errno = 0; + value = strtod(str, NULL); if (errno != 0 || value < 0) { return 0; } *rtn_value = (uint64_t)(value * mult[i]); - Dmsg2(400, "Full value = %f %" lld "\n", strtod(str, NULL) * mult[i], - value *mult[i]); + Dmsg2(400, "Full value = %lf %" lld "\n", value * mult[i], + (uint64_t)(value * mult[i])); return 1; } @@ -227,13 +230,13 @@ int size_to_uint64(char *str, int str_len, uint64_t *rtn_value) */ int is_a_number(const char *n) { - int digit_seen = 0; + bool digit_seen = false; if( *n == '-' || *n == '+' ) { n++; } while (B_ISDIGIT(*n)) { - digit_seen = 1; + digit_seen = true; n++; } if (digit_seen && *n == '.') { @@ -248,6 +251,19 @@ int is_a_number(const char *n) return digit_seen && *n==0; } +/* + * Check if the specified string is an integer + */ +int is_an_integer(const char *n) +{ + bool digit_seen = false; + while (B_ISDIGIT(*n)) { + digit_seen = true; + n++; + } + return digit_seen && *n==0; +} + /* * Add commas to a string, which is presumably * a number.