@@ -44,6 +44,21 @@ u64 arg_strtou64(const char *str)
}
/*
+ * u32 version of arg_strtou*()
+ */
+u32 arg_strtou32(const char *str)
+{
+ u64 tmp;
+
+ tmp = arg_strtou64(str);
+ if (tmp >= UINT32_MAX) {
+ fprintf(stderr, "ERROR: %s is too large.\n", str);
+ exit(1);
+ }
+ return (u32)tmp;
+}
+
+/*
* For a given:
* - file or directory return the containing tree root id
* - subvolume return its own tree id
@@ -94,6 +94,7 @@ const char *pretty_size_mode(u64 size, unsigned mode);
u64 parse_size(char *s);
u64 parse_qgroupid(const char *p);
u64 arg_strtou64(const char *str);
+u32 arg_strtou32(const char *str);
int arg_copy_path(char *dest, const char *src, int destlen);
int open_file_or_dir(const char *fname, DIR **dirstream);
int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags);
This function is just calling arg_strtou64() and then do extra UINT32_MAX check. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- utils-lib.c | 15 +++++++++++++++ utils.h | 1 + 2 files changed, 16 insertions(+)