From: Theodore Ts'o Date: Wed, 23 May 2007 00:51:47 +0000 (-0400) Subject: Add new function profile_get_uint() in the e2fsck sources X-Git-Tag: E2FSPROGS-1_40~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32460c1e4c7259b532bdd1e74583c80f573b467a;p=thirdparty%2Fe2fsprogs.git Add new function profile_get_uint() in the e2fsck sources Signed-off-by: "Theodore Ts'o" --- diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index e5809d31f..02dcd8a5f 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,8 @@ +2007-05-22 Theodore Tso + + * profile.h, profile.c (profile_get_uint): New function which + returns an unsigned integer. + 2007-05-08 Kalpak Shah * pass1.c (check_ea_in_inode): Remove check that requires in-inode diff --git a/e2fsck/profile.c b/e2fsck/profile.c index 3352a221a..5752343e6 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 1a175fc11..cf1b055ed 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,