+ *endp = NULL;
+ ofs = strtol(str, endp, 0);
+ s = **endp;
+ /* trailing char, see if it is a size specifier */
+ if (s == 's' || s == 'S') /* sector */
+ ofs <<= 9;
+ else if (s == 'k' || s == 'K') /* kb */
+ ofs <<= 10;
+ else if (s == 'm' || s == 'M') /* Mb */
+ ofs <<= 20;
+ else if (s == 'g' || s == 'G') /* Gb */
+ ofs <<= 30;
+ else
+ return ofs; /* invalid character */
+ (*endp)++;
+ return ofs;
+}
+
+/* Convert a string to a size. The string should be a number,
+ optionally followed by S (sectors), K (K-Bytes), M (Megabytes), G
+ (Gigabytes) */
+mt_off_t str_to_off_with_end(const char *str, char **endp) {
+ char s;
+ mt_off_t siz;
+
+ *endp = NULL;
+ siz = strtol(str, endp, 0);
+ s = **endp;
+ /* trailing char, see if it is a size specifier */
+ if (s == 's' || s == 'S') /* sector */
+ siz <<= 9;
+ else if (s == 'k' || s == 'K') /* kb */
+ siz <<= 10;
+ else if (s == 'm' || s == 'M') /* Mb */
+ siz <<= 20;
+ else if (s == 'g' || s == 'G') /* Gb */
+ siz <<= 30;
+ else
+ return siz; /* invalid character */
+ (*endp)++;
+ return siz;
+}
+
+off_t str_to_offset(char *str) {
+ char *end;
+ off_t ofs = str_to_offset_with_end(str, &end);