Skip to contentSkip to conversation

Move filedescriptor parsing code from net.c into qemu_parse_fd()

PATCH Applied Stefan Berger 2 participants 2 messages Sep 28, 2011 – Nov 1, 2011

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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

---
 cutils.c      |   12 ++++++++++++
 net.c         |    7 +------
 qemu-common.h |    1 +
 3 files changed, 14 insertions(+), 6 deletions(-)
net.c +1 -6
Index: qemu-git.pt/net.c
===================================================================
@@ -733,12 +733,7 @@ int net_handle_fd_param(Monitor *mon, co
             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;
qemu-common.h +1 -0
Index: qemu-git.pt/qemu-common.h
===================================================================
@@ -143,6 +143,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
cutils.c +12 -0
Index: qemu-git.pt/cutils.c
===================================================================
@@ -415,3 +415,15 @@ int64_t strtosz(const char *nptr, char *
 {
     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;
+}
#1 lore raw
Quoted 8 lines · Stefan Berger

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

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 60 lines
---
  cutils.c      |   12 ++++++++++++
  net.c         |    7 +------
  qemu-common.h |    1 +
  3 files changed, 14 insertions(+), 6 deletions(-)

Index: qemu-git.pt/net.c
===================================================================

net.c +1 -6
@@ -733,12 +733,7 @@ int net_handle_fd_param(Monitor *mon, co
              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;

Index: qemu-git.pt/qemu-common.h
===================================================================

qemu-common.h +1 -0
@@ -143,6 +143,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

Index: qemu-git.pt/cutils.c
===================================================================

cutils.c +12 -0
@@ -415,3 +415,15 @@ int64_t strtosz(const char *nptr, char *
  {
      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;
+}