lib/strutils: share parse_range()
Subsystems (2)
PATCH 1/1 lib/strutils: share parse_range()
From: Davidlohr Bueso <[email protected]>
This function is currently only being used by partx(8), but it's handy and generic enough that we can use it elsewhere as well.
Signed-off-by Davidlohr Bueso <[email protected]>
--- include/strutils.h | 2 ++ lib/strutils.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- partx/partx.c | 35 ----------------------------------- 3 files changed, 46 insertions(+), 36 deletions(-)
include/strutils.h +2 -0
@@ -45,4 +45,6 @@ extern int string_to_idarray(const char *list, int ary[], size_t arysz,extern int string_to_bitarray (const char *list,char *ary,int (*name2bit)(const char *,size_t )); +extern int parse_range (const char *str,int *lower,int *upper); +#endif
lib/strutils.c +44 -1
57 lines not on this page · raw message
partx/partx.c +0 -35
@@ -558,41 +558,6 @@ done:return rc; } -static int parse_range (const char *str,int *lower,int *upper) -{ -char *end =NULL ; - -if (!str) -return 0 ; - - *upper = *lower =0 ; - errno =0 ; - -if (*str ==':' ) {/* <:N> */ - str++; - *upper =strtol (str, &end,10 ); -if (errno || !end || *end || end == str) -return -1 ; - }else { - *upper = *lower =strtol (str, &end,10 ); -if (errno || !end || end == str) -return -1 ; - -if (*end ==':' && !*(end +1 ))/* <M:> */ - *upper =0 ; -else if (*end =='-' || *end ==':' ) {/* <M:N> <M-N> */ - str = end +1 ; - end =NULL ; - errno =0 ; - *upper =strtol (str, &end,10 ); - -if (errno || !end || *end || end == str) -return -1 ; - } - } -return 0 ; -} -static blkid_partlist get_partlist (blkid_probe pr,const char *device,char *type) {
Signature · 1 line
1.7.7