]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Add new function profile_get_uint() in the e2fsck sources
authorTheodore Ts'o <tytso@mit.edu>
Wed, 23 May 2007 00:51:47 +0000 (20:51 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 23 May 2007 00:51:47 +0000 (20:51 -0400)
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/ChangeLog
e2fsck/profile.c
e2fsck/profile.h

index e5809d31f78e8d10f45ef9c024aa5c8e136ce483..02dcd8a5fc90e43c00702b08af87e80dcb5fed67 100644 (file)
@@ -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
index 3352a221ab806918bc6fc04523726e21a8bf150b..5752343e693cf9f28ca6085eaed47318a49b3f18 100644 (file)
@@ -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,
index 1a175fc11fc0a4fc54341a3ae230c4a97a936ad0..cf1b055edbbc5be4d0d5f27a58a9d9c30ed3208d 100644 (file)
@@ -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,