Author: pjd
Date: Thu Oct 21 10:38:14 2010
New Revision: 214129
URL: http://svn.freebsd.org/changeset/base/214129

Log:
  Remove code duplication by introducing static gctl_param_add() function which
  is now used by both gctl_ro_param() and gctl_rw_param().

Modified:
  head/lib/libgeom/geom_ctl.c

Modified: head/lib/libgeom/geom_ctl.c
==============================================================================
--- head/lib/libgeom/geom_ctl.c Thu Oct 21 10:36:36 2010        (r214128)
+++ head/lib/libgeom/geom_ctl.c Thu Oct 21 10:38:14 2010        (r214129)
@@ -150,8 +150,9 @@ gctl_new_arg(struct gctl_req *req)
        return (ap);
 }
 
-void
-gctl_ro_param(struct gctl_req *req, const char *name, int len, const void* 
value)
+static void
+gctl_param_add(struct gctl_req *req, const char *name, int len, void *value,
+    int flag)
 {
        struct gctl_req_arg *ap;
 
@@ -165,8 +166,8 @@ gctl_ro_param(struct gctl_req *req, cons
        if (ap->name == NULL)
                return;
        ap->nlen = strlen(ap->name) + 1;
-       ap->value = __DECONST(void *, value);
-       ap->flag = GCTL_PARAM_RD;
+       ap->value = value;
+       ap->flag = flag;
        if (len >= 0)
                ap->len = len;
        else if (len < 0) {
@@ -176,26 +177,17 @@ gctl_ro_param(struct gctl_req *req, cons
 }
 
 void
-gctl_rw_param(struct gctl_req *req, const char *name, int len, void* value)
+gctl_ro_param(struct gctl_req *req, const char *name, int len, const void* 
value)
 {
-       struct gctl_req_arg *ap;
 
-       if (req == NULL || req->error != NULL)
-               return;
-       ap = gctl_new_arg(req);
-       if (ap == NULL)
-               return;
-       ap->name = strdup(name);
-       gctl_check_alloc(req, ap->name);
-       if (ap->name == NULL)
-               return;
-       ap->nlen = strlen(ap->name) + 1;
-       ap->value = value;
-       ap->flag = GCTL_PARAM_RW;
-       if (len >= 0)
-               ap->len = len;
-       else if (len < 0)
-               ap->len = strlen(value) + 1;    
+       gctl_param_add(req, name, len, __DECONST(void *, value), GCTL_PARAM_RD);
+}
+
+void
+gctl_rw_param(struct gctl_req *req, const char *name, int len, void *value)
+{
+
+       gctl_param_add(req, name, len, value, GCTL_PARAM_RW);
 }
 
 const char *
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to