/* check for offset option in @fs */
optstr = (char *) mnt_fs_get_user_options(fs);
- if (optstr && !mnt_optstr_get_option(optstr, "offset=", &val, &valsz)) {
- int rc;
-
- val = strndup(val, valsz);
- if (!val)
- return 0;
- rc = strtosize(val, &offset);
- free(val);
- if (rc)
- return 0;
- }
+
+ if (optstr &&
+ mnt_optstr_get_option(optstr, "offset", &val, &valsz) == 0 &&
+ mnt_parse_offset(val, valsz, &offset) != 0)
+ return 0;
/* TODO:
* if (mnt_loopdev_associated_file(devname, src, offset))
extern int endswith(const char *s, const char *sx);
extern int startswith(const char *s, const char *sx);
+extern int mnt_parse_offset(const char *str, size_t len, uintmax_t *res);
+
extern int mnt_chdir_to_parent(const char *target, char **filename);
extern char *mnt_get_username(const uid_t uid);
extern int mnt_get_uid(const char *username, uid_t *uid);
return !strncmp(s, sx, off);
}
+int mnt_parse_offset(const char *str, size_t len, uintmax_t *res)
+{
+ char *p;
+ int rc = 0;
+
+ if (!str && !*str)
+ return -EINVAL;
+
+ p = strndup(str, len);
+ if (!p)
+ return -errno;
+
+ if (strtosize(p, res))
+ rc = -EINVAL;
+ free(p);
+ return rc;
+}
+
/* returns basename and keeps dirname in the @path, if @path is "/" (root)
* then returns empty string */
static char *stripoff_last_component(char *path)