From nobody Mon Feb 9 06:26:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527816589773244.87019183171947; Thu, 31 May 2018 18:29:49 -0700 (PDT) Received: from localhost ([::1]:46891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOYsy-00048u-RR for importer@patchew.org; Thu, 31 May 2018 21:29:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOYqs-0002wc-DH for qemu-devel@nongnu.org; Thu, 31 May 2018 21:27:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOYqn-0002oi-LQ for qemu-devel@nongnu.org; Thu, 31 May 2018 21:27:34 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:40623) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fOYqn-0002oF-Fg for qemu-devel@nongnu.org; Thu, 31 May 2018 21:27:29 -0400 Received: by mail-qt0-x241.google.com with SMTP id h2-v6so30291358qtp.7 for ; Thu, 31 May 2018 18:27:29 -0700 (PDT) Received: from localhost.localdomain (96-86-104-61-static.hfc.comcastbusiness.net. [96.86.104.61]) by smtp.gmail.com with ESMTPSA id o68-v6sm2003842qkc.19.2018.05.31.18.27.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 May 2018 18:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=WYR4twGVelsi4IuqZWK9UvlDJY+hHMIUVvjMzSo2niQ=; b=iUkg2BMKHqojNDridP/lOTrG4EH2w2hBcAAewnn8f+KXasvAWkYNP4oDoer1xDuhiv Qe6v2MbCGOalGG6d312tMaHxtGEJUHcbGYbogSRlAj12eXYEVH3GXSHoyChAB8gwQO/e L6a7JTH/mXCRV6QjfizVacrIcuUFrYV5ZusOnYBLjWUJWusqqi4TauGhmOgA2DfdmaUS hRLgmRWCvvyqIfwvnp8q+0dXP/CNBRGtg/fXV3kSCxEENh7VO4edPqCvUI4KTi1pP1o3 DyzPsJQ4UZto5Om0ngUdkw9IOXumItASfaR2z0FkjLcBbu/m50OH6w2p0znRFXCMF3Xc Esog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=WYR4twGVelsi4IuqZWK9UvlDJY+hHMIUVvjMzSo2niQ=; b=OadLyAkdw32zUEcBsrY7aBOyb3UMsh+CbxGJeDEVOvgm+XkTcnPVfpu0IFncqFaIga cmEz1tRKCFVjONI6F3L8jryUPLMGe8c6OEUkvTcOff/ArV2nsQZYFFSIt8xe7dCd1xQv +C0lG17jrN49Lh45RTLgNWZAdJdNgxIMnhTCOqGF7EJMCz/GNf5Y+TmvBFNRo7XdvKpS Ed/vPCk2VJo90uET6evh33z3ycZtZ8044pgzP1GDYhwPMgOZzPxvt5+UyMUZwXk1qBun lLFyDE/OTRCnfl3837A2c8x5JhumeiKivyDBM8twTlPHDNWFrvdzMhtECv10LUOFsl6U 9RAg== X-Gm-Message-State: APt69E2VjimBVHSNlMN5VPHWBfrHxa5MAo1COtstxq0Y8TR9K4PNHlBd WoTgOqwFS+NpGuYbFFEDumECwKc99s0= X-Google-Smtp-Source: ADUXVKKUEZPIPgTCZFClBAvhkubxeCO4XnSo1gA2Jjq1f6QGR/S4lpN1/7c/0Vd6gjFhz54AAyhwbA== X-Received: by 2002:aed:30c3:: with SMTP id 61-v6mr9082876qtf.172.1527816448464; Thu, 31 May 2018 18:27:28 -0700 (PDT) From: Keno Fischer To: qemu-devel@nongnu.org Date: Thu, 31 May 2018 21:25:56 -0400 Message-Id: <1f6bc60305b8c1cd00f5e2a361a05d7b4bc56338.1527814874.git.keno@juliacomputing.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH v2 01/20] cutils: Provide strchrnul X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Keno Fischer , groug@kaod.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" strchrnul is a GNU extension and thus unavailable on a number of targets. In the review for a commit removing strchrnul from 9p, I was asked to create a qemu_strchrnul helper to factor out this functionality. Do so, and use it in a number of other places in the code base that inlined the replacement pattern in a place where strchrnul could be used. Signed-off-by: Keno Fischer Acked-by: Greg Kurz --- Changes since v1: New patch hw/9pfs/9p-local.c | 2 +- include/qemu/cutils.h | 1 + monitor.c | 8 ++------ util/cutils.c | 13 +++++++++++++ util/qemu-option.c | 6 +----- util/uri.c | 6 ++---- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index b37b1db..bcf2798 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -65,7 +65,7 @@ int local_open_nofollow(FsContext *fs_ctx, const char *pa= th, int flags, assert(*path !=3D '/'); =20 head =3D g_strdup(path); - c =3D strchrnul(path, '/'); + c =3D qemu_strchrnul(path, '/'); if (*c) { /* Intermediate path element */ head[c - path] =3D 0; diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index a663340..bc40c30 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -122,6 +122,7 @@ int qemu_strnlen(const char *s, int max_len); * Returns: the pointer originally in @input. */ char *qemu_strsep(char **input, const char *delim); +const char *qemu_strchrnul(const char *s, int c); time_t mktimegm(struct tm *tm); int qemu_fdatasync(int fd); int fcntl_setfl(int fd, int flag); diff --git a/monitor.c b/monitor.c index 922cfc0..e1f01c4 100644 --- a/monitor.c +++ b/monitor.c @@ -798,9 +798,7 @@ static int compare_cmd(const char *name, const char *li= st) p =3D list; for(;;) { pstart =3D p; - p =3D strchr(p, '|'); - if (!p) - p =3D pstart + strlen(pstart); + p =3D qemu_strchrnul(p, '|'); if ((p - pstart) =3D=3D len && !memcmp(pstart, name, len)) return 1; if (*p =3D=3D '\0') @@ -3401,9 +3399,7 @@ static void cmd_completion(Monitor *mon, const char *= name, const char *list) p =3D list; for(;;) { pstart =3D p; - p =3D strchr(p, '|'); - if (!p) - p =3D pstart + strlen(pstart); + p =3D qemu_strchrnul(p, '|'); len =3D p - pstart; if (len > sizeof(cmd) - 2) len =3D sizeof(cmd) - 2; diff --git a/util/cutils.c b/util/cutils.c index 0de69e6..6e078b0 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -545,6 +545,19 @@ int qemu_strtou64(const char *nptr, const char **endpt= r, int base, } =20 /** + * Searches for the first occurrence of 'c' in 's', and returns a pointer + * to the trailing null byte if none was found. + */ +const char *qemu_strchrnul(const char *s, int c) +{ + const char *e =3D strchr(s, c); + if (!e) { + e =3D s + strlen(s); + } + return e; +} + +/** * parse_uint: * * @s: String to parse diff --git a/util/qemu-option.c b/util/qemu-option.c index 58d1c23..54eca12 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -77,11 +77,7 @@ const char *get_opt_value(const char *p, char **value) =20 *value =3D NULL; while (1) { - offset =3D strchr(p, ','); - if (!offset) { - offset =3D p + strlen(p); - } - + offset =3D qemu_strchrnul(p, ','); length =3D offset - p; if (*offset !=3D '\0' && *(offset + 1) =3D=3D ',') { length++; diff --git a/util/uri.c b/util/uri.c index 8624a7a..8bdef84 100644 --- a/util/uri.c +++ b/util/uri.c @@ -52,6 +52,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/cutils.h" =20 #include "qemu/uri.h" =20 @@ -2266,10 +2267,7 @@ struct QueryParams *query_params_parse(const char *q= uery) /* Find the next separator, or end of the string. */ end =3D strchr(query, '&'); if (!end) { - end =3D strchr(query, ';'); - } - if (!end) { - end =3D query + strlen(query); + end =3D qemu_strchrnul(query, ';'); } =20 /* Find the first '=3D' character between here and end. */ --=20 2.8.1