From: Stefan Berger Date: Wed, 28 Sep 2011 10:41:32 +0000 (-0400) Subject: Move filedescriptor parsing code from net.c into qemu_parse_fd() X-Git-Tag: qemu-xen-4.3.0-rc1~2063^2~5 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=443916d1d9f1094a43d28c6b8cc60e3e7e27eb36;p=qemu-upstream-4.5-testing.git Move filedescriptor parsing code from net.c into qemu_parse_fd() Move the parsing of a filedescriptor into a common function qemu_parse_fd() so others can use it as well. Have net.c call this function. v2: - moving qemu_parse_fd into cutils.c Signed-off-by: Stefan Berger Signed-off-by: Anthony Liguori --- diff --git a/cutils.c b/cutils.c index c91f88732..5d995bc4e 100644 --- a/cutils.c +++ b/cutils.c @@ -415,3 +415,15 @@ int64_t strtosz(const char *nptr, char **end) { return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB); } + +int qemu_parse_fd(const char *param) +{ + int fd; + char *endptr = NULL; + + fd = strtol(param, &endptr, 10); + if (*endptr || (fd == 0 && param == endptr)) { + return -1; + } + return fd; +} diff --git a/net.c b/net.c index d05930c91..cb52050bf 100644 --- a/net.c +++ b/net.c @@ -733,12 +733,7 @@ int net_handle_fd_param(Monitor *mon, const char *param) return -1; } } else { - char *endptr = NULL; - - fd = strtol(param, &endptr, 10); - if (*endptr || (fd == 0 && param == endptr)) { - return -1; - } + fd = qemu_parse_fd(param); } return fd; diff --git a/qemu-common.h b/qemu-common.h index 1c15cb17a..2ce47aa12 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -129,6 +129,7 @@ time_t mktimegm(struct tm *tm); int qemu_fls(int i); int qemu_fdatasync(int fd); int fcntl_setfl(int fd, int flag); +int qemu_parse_fd(const char *param); /* * strtosz() suffixes used to specify the default treatment of an