diff --git a/fs/Makefile b/fs/Makefile index b3f929f..8e3fd78 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -4,7 +4,7 @@ obj-y += devfs-core.o obj-$(CONFIG_FS_DEVFS) += devfs.o obj-$(CONFIG_FS_FAT) += fat/ -obj-y += fs.o parseopt.o +obj-y += fs.o obj-$(CONFIG_FS_UBIFS) += ubifs/ obj-$(CONFIG_FS_TFTP) += tftp.o obj-$(CONFIG_FS_OMAP4_USBBOOT) += omap4_usbbootfs.o diff --git a/fs/fs.c b/fs/fs.c index f61ee09..ccb4943 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -35,8 +35,7 @@ #include #include #include - -#include "parseopt.h" +#include char *mkmodestr(unsigned long mode, char *str) { diff --git a/fs/nfs.c b/fs/nfs.c index 97f01cf..75cd127 100644 --- a/fs/nfs.c +++ b/fs/nfs.c @@ -36,8 +36,7 @@ #include #include #include - -#include "parseopt.h" +#include #define SUNRPC_PORT 111 diff --git a/fs/parseopt.c b/fs/parseopt.c deleted file mode 100644 index 8ff8301..0000000 --- a/fs/parseopt.c +++ /dev/null @@ -1,60 +0,0 @@ -#include - -#include "parseopt.h" - -void parseopt_b(const char *options, const char *opt, bool *val) -{ - const char *start; - size_t optlen = strlen(opt); - -again: - start = strstr(options, opt); - - if (!start) { - *val = false; - return; - } - - if (start > options && start[-1] != ',') { - options = start; - goto again; - } - - if (start[optlen] != ',' && start[optlen] != '\0') { - options = start; - goto again; - } - - *val = true; -} - -void parseopt_hu(const char *options, const char *opt, unsigned short *val) -{ - const char *start; - size_t optlen = strlen(opt); - ulong v; - char *endp; - -again: - start = strstr(options, opt); - - if (!start) - return; - - if (start > options && start[-1] != ',') { - options = start; - goto again; - } - - if (start[optlen] != '=') { - options = start; - goto again; - } - - v = simple_strtoul(start + optlen + 1, &endp, 0); - if (v > USHRT_MAX) - return; - - if (*endp == ',' || *endp == '\0') - *val = v; -} diff --git a/fs/parseopt.h b/fs/parseopt.h deleted file mode 100644 index abf3be3..0000000 --- a/fs/parseopt.h +++ /dev/null @@ -1,2 +0,0 @@ -void parseopt_b(const char *options, const char *opt, bool *val); -void parseopt_hu(const char *options, const char *opt, unsigned short *val); diff --git a/include/parseopt.h b/include/parseopt.h new file mode 100644 index 0000000..abf3be3 --- /dev/null +++ b/include/parseopt.h @@ -0,0 +1,2 @@ +void parseopt_b(const char *options, const char *opt, bool *val); +void parseopt_hu(const char *options, const char *opt, unsigned short *val); diff --git a/lib/Makefile b/lib/Makefile index 1be1742..8f7ef4e 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -59,3 +59,4 @@ obj-$(CONFIG_RATP) += ratp.o obj-y += list_sort.o obj-y += int_sqrt.o +obj-y += parseopt.o diff --git a/lib/parseopt.c b/lib/parseopt.c new file mode 100644 index 0000000..8ff8301 --- /dev/null +++ b/lib/parseopt.c @@ -0,0 +1,60 @@ +#include + +#include "parseopt.h" + +void parseopt_b(const char *options, const char *opt, bool *val) +{ + const char *start; + size_t optlen = strlen(opt); + +again: + start = strstr(options, opt); + + if (!start) { + *val = false; + return; + } + + if (start > options && start[-1] != ',') { + options = start; + goto again; + } + + if (start[optlen] != ',' && start[optlen] != '\0') { + options = start; + goto again; + } + + *val = true; +} + +void parseopt_hu(const char *options, const char *opt, unsigned short *val) +{ + const char *start; + size_t optlen = strlen(opt); + ulong v; + char *endp; + +again: + start = strstr(options, opt); + + if (!start) + return; + + if (start > options && start[-1] != ',') { + options = start; + goto again; + } + + if (start[optlen] != '=') { + options = start; + goto again; + } + + v = simple_strtoul(start + optlen + 1, &endp, 0); + if (v > USHRT_MAX) + return; + + if (*endp == ',' || *endp == '\0') + *val = v; +}