diff options
author | Theodore Ts'o <tytso@mit.edu> | 2007-05-22 20:51:47 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2007-05-22 20:51:47 -0400 |
commit | 32460c1e4c7259b532bdd1e74583c80f573b467a (patch) | |
tree | 676b61778353fc88c84c385203cc9efa3ccd519b /e2fsck | |
parent | 54833579eeb458273085b4f2c224fe12a4473c73 (diff) | |
download | e2fsprogs-32460c1e4c7259b532bdd1e74583c80f573b467a.tar.gz |
Add new function profile_get_uint() in the e2fsck sources
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'e2fsck')
-rw-r--r-- | e2fsck/ChangeLog | 5 | ||||
-rw-r--r-- | e2fsck/profile.c | 41 | ||||
-rw-r--r-- | e2fsck/profile.h | 5 |
3 files changed, 51 insertions, 0 deletions
diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index e5809d31..02dcd8a5 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,8 @@ +2007-05-22 Theodore Tso <tytso@mit.edu> + + * profile.h, profile.c (profile_get_uint): New function which + returns an unsigned integer. + 2007-05-08 Kalpak Shah <kalpak@clusterfs.com> * pass1.c (check_ea_in_inode): Remove check that requires in-inode diff --git a/e2fsck/profile.c b/e2fsck/profile.c index 3352a221..5752343e 100644 --- a/e2fsck/profile.c +++ b/e2fsck/profile.c @@ -1478,6 +1478,47 @@ profile_get_integer(profile_t profile, const char *name, const char *subname, return 0; } +errcode_t +profile_get_uint(profile_t profile, const char *name, const char *subname, + const char *subsubname, unsigned int def_val, + unsigned int *ret_int) +{ + const char *value; + errcode_t retval; + char *end_value; + unsigned long ret_long; + + *ret_int = def_val; + if (profile == 0) + return 0; + + retval = profile_get_value(profile, name, subname, subsubname, &value); + if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) { + *ret_int = def_val; + return 0; + } else if (retval) + return retval; + + if (value[0] == 0) + /* Empty string is no good. */ + return PROF_BAD_INTEGER; + errno = 0; + ret_long = strtoul (value, &end_value, 10); + + /* Overflow or underflow. */ + if ((ret_long == ULONG_MAX) && errno != 0) + return PROF_BAD_INTEGER; + /* Value outside "int" range. */ + if ((unsigned long) (unsigned int) ret_long != ret_long) + return PROF_BAD_INTEGER; + /* Garbage in string. */ + if (end_value != value + strlen (value)) + return PROF_BAD_INTEGER; + + *ret_int = ret_long; + return 0; +} + static const char *const conf_yes[] = { "y", "yes", "true", "t", "1", "on", 0, diff --git a/e2fsck/profile.h b/e2fsck/profile.h index 1a175fc1..cf1b055e 100644 --- a/e2fsck/profile.h +++ b/e2fsck/profile.h @@ -70,6 +70,11 @@ long profile_get_integer const char *subsubname, int def_val, int *ret_default); +long profile_get_uint + (profile_t profile, const char *name, const char *subname, + const char *subsubname, unsigned int def_val, + unsigned int *ret_int); + long profile_get_boolean (profile_t profile, const char *name, const char *subname, const char *subsubname, int def_val, |