qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Fergeau <cfergeau@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCHv2 4/4] libcacard: replace copy_string with strndup
Date: Mon, 27 Jun 2011 17:27:39 +0200	[thread overview]
Message-ID: <1309188459-806-5-git-send-email-cfergeau@redhat.com> (raw)
In-Reply-To: <1309188459-806-1-git-send-email-cfergeau@redhat.com>

copy_string reimplements strndup, this commit removes it and
replaces all copy_string uses with strndup.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
---
 libcacard/vcard_emul_nss.c |   23 ++++++-----------------
 1 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index 2a20bd6..de324ba 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -925,17 +925,6 @@ vcard_emul_replay_insertion_events(void)
 /*
  *  Silly little functions to help parsing our argument string
  */
-static char *
-copy_string(const char *str, int str_len)
-{
-    char *new_str;
-
-    new_str = qemu_malloc(str_len+1);
-    memcpy(new_str, str, str_len);
-    new_str[str_len] = 0;
-    return new_str;
-}
-
 static int
 count_tokens(const char *str, char token, char token_end)
 {
@@ -1054,18 +1043,18 @@ vcard_emul_options(const char *args)
             }
             opts->vreader = vreaderOpt;
             vreaderOpt = &vreaderOpt[opts->vreader_count];
-            vreaderOpt->name = copy_string(name, name_length);
-            vreaderOpt->vname = copy_string(vname, vname_length);
+            vreaderOpt->name = qemu_strndup(name, name_length);
+            vreaderOpt->vname = qemu_strndup(vname, vname_length);
             vreaderOpt->card_type = type;
             vreaderOpt->type_params =
-                copy_string(type_params, type_params_length);
+                qemu_strndup(type_params, type_params_length);
             count = count_tokens(args, ',', ')') + 1;
             vreaderOpt->cert_count = count;
             vreaderOpt->cert_name = (char **)qemu_malloc(count*sizeof(char *));
             for (i = 0; i < count; i++) {
                 const char *cert = args;
                 args = strpbrk(args, ",)");
-                vreaderOpt->cert_name[i] = copy_string(cert, args - cert);
+                vreaderOpt->cert_name[i] = qemu_strndup(cert, args - cert);
                 args = strip(args+1);
             }
             if (*args == ')') {
@@ -1092,7 +1081,7 @@ vcard_emul_options(const char *args)
             args = strip(args+10);
             params = args;
             args = find_blank(args);
-            opts->hw_type_params = copy_string(params, args-params);
+            opts->hw_type_params = qemu_strndup(params, args-params);
         /* db="/data/base/path" */
         } else if (strncmp(args, "db=", 3) == 0) {
             const char *db;
@@ -1103,7 +1092,7 @@ vcard_emul_options(const char *args)
             args++;
             db = args;
             args = strpbrk(args, "\"\n");
-            opts->nss_db = copy_string(db, args-db);
+            opts->nss_db = qemu_strndup(db, args-db);
             if (*args != 0) {
                 args++;
             }
-- 
1.7.5.4

  parent reply	other threads:[~2011-06-27 15:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-24 14:37 [Qemu-devel] [PATCH 1/2] libcacard: fix soft=... parsing in vcard_emul_options Christophe Fergeau
2011-06-24 14:37 ` [Qemu-devel] [PATCH 2/2] libcacard: replace copy_string with strndup Christophe Fergeau
2011-06-24 14:52   ` Alon Levy
2011-06-24 16:51 ` [Qemu-devel] [PATCH 1/2] libcacard: fix soft=... parsing in vcard_emul_options Alon Levy
2011-06-27 12:13   ` Christophe Fergeau
2011-06-27 15:27 ` [Qemu-devel] [PATCHv2 0/4] libcacard fixes Christophe Fergeau
2011-06-27 15:27   ` [Qemu-devel] [PATCHv2 1/4] libcacard: s/strip(args++)/strip(args+1) Christophe Fergeau
2011-06-27 15:27   ` [Qemu-devel] [PATCHv2 2/4] libcacard: fix soft=... parsing in vcard_emul_options Christophe Fergeau
2011-06-27 15:27   ` [Qemu-devel] [PATCHv2 3/4] libcacard: introduce NEXT_TOKEN macro Christophe Fergeau
2011-06-27 15:27   ` Christophe Fergeau [this message]
2011-06-27 19:57   ` [Qemu-devel] [PATCHv2 0/4] libcacard fixes Alon Levy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1309188459-806-5-git-send-email-cfergeau@redhat.com \
    --to=cfergeau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).