From nobody Mon Feb 9 02:24:22 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; 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 1530278641003594.1739090368607; Fri, 29 Jun 2018 06:24:01 -0700 (PDT) Received: from localhost ([::1]:42110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYtNY-000671-89 for importer@patchew.org; Fri, 29 Jun 2018 09:24:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYtKk-0004Xe-6b for qemu-devel@nongnu.org; Fri, 29 Jun 2018 09:21:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYtKg-0007jl-VA for qemu-devel@nongnu.org; Fri, 29 Jun 2018 09:21:06 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43240) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYtKg-0007ga-NO for qemu-devel@nongnu.org; Fri, 29 Jun 2018 09:21:02 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5TDIl18074707 for ; Fri, 29 Jun 2018 09:21:01 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jwn7x15qu-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 29 Jun 2018 09:21:01 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 29 Jun 2018 14:20:59 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 29 Jun 2018 14:20:56 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5TDKtKt39649516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 29 Jun 2018 13:20:55 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBBD04C050; Fri, 29 Jun 2018 14:20:42 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C272C4C044; Fri, 29 Jun 2018 14:20:42 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 Jun 2018 14:20:42 +0100 (BST) Received: from bahia.lan (icon-9-164-191-207.megacenter.de.ibm.com [9.164.191.207]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 8F8C222018B; Fri, 29 Jun 2018 15:20:54 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 29 Jun 2018 15:20:44 +0200 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180629132045.429006-1-groug@kaod.org> References: <20180629132045.429006-1-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 18062913-0028-0000-0000-000002D6649E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18062913-0029-0000-0000-0000238DD61E Message-Id: <20180629132045.429006-2-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1806290143 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 1/2] 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: Peter Maydell , Keno Fischer , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Keno Fischer 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 Reviewed-by: Markus Armbruster Signed-off-by: Greg Kurz --- configure | 18 ++++++++++++++++++ hmp.c | 8 ++++---- hw/9pfs/9p-local.c | 2 +- include/qemu/cutils.h | 8 ++++++++ monitor.c | 8 ++------ util/cutils.c | 15 +++++++++++++++ util/qemu-option.c | 6 +----- util/uri.c | 6 ++---- 8 files changed, 51 insertions(+), 20 deletions(-) diff --git a/configure b/configure index 4d12cfbe3f6a..26944a74be8c 100755 --- a/configure +++ b/configure @@ -4793,6 +4793,21 @@ if compile_prog "" "" ; then sem_timedwait=3Dyes fi =20 +########################################## +# check if we have strchrnul + +strchrnul=3Dno +cat > $TMPC << EOF +#include +int main(void); +// Use a haystack that the compiler shouldn't be able to constant fold +char *haystack =3D (char*)&main; +int main(void) { return strchrnul(haystack, 'x') !=3D &haystack[6]; } +EOF +if compile_prog "" "" ; then + strchrnul=3Dyes +fi + ########################################## # check if trace backend exists =20 @@ -6276,6 +6291,9 @@ fi if test "$sem_timedwait" =3D "yes" ; then echo "CONFIG_SEM_TIMEDWAIT=3Dy" >> $config_host_mak fi +if test "$strchrnul" =3D "yes" ; then + echo "HAVE_STRCHRNUL=3Dy" >> $config_host_mak +fi if test "$byteswap_h" =3D "yes" ; then echo "CONFIG_BYTESWAP_H=3Dy" >> $config_host_mak fi diff --git a/hmp.c b/hmp.c index 0da0b0ac33ee..933230d8a701 100644 --- a/hmp.c +++ b/hmp.c @@ -2140,12 +2140,12 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) int has_hold_time =3D qdict_haskey(qdict, "hold-time"); int hold_time =3D qdict_get_try_int(qdict, "hold-time", -1); Error *err =3D NULL; - char *separator; + const char *separator; int keyname_len; =20 while (1) { - separator =3D strchr(keys, '-'); - keyname_len =3D separator ? separator - keys : strlen(keys); + separator =3D qemu_strchrnul(keys, '-'); + keyname_len =3D separator - keys; =20 /* Be compatible with old interface, convert user inputted "<" */ if (keys[0] =3D=3D '<' && keyname_len =3D=3D 1) { @@ -2182,7 +2182,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) keylist->value->u.qcode.data =3D idx; } =20 - if (!separator) { + if (!*separator) { break; } keys =3D separator + 1; diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 5721eff1e189..828e8d6e5638 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 a663340b2386..274d419bb707 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -122,6 +122,14 @@ int qemu_strnlen(const char *s, int max_len); * Returns: the pointer originally in @input. */ char *qemu_strsep(char **input, const char *delim); +#ifdef HAVE_STRCHRNUL +static inline const char *qemu_strchrnul(const char *s, int c) +{ + return strchrnul(s, c); +} +#else +const char *qemu_strchrnul(const char *s, int c); +#endif 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 0730a271728b..80af6a9390f6 100644 --- a/monitor.c +++ b/monitor.c @@ -820,9 +820,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') @@ -3489,9 +3487,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 0de69e6db4a2..9205e0903166 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -544,6 +544,21 @@ int qemu_strtou64(const char *nptr, const char **endpt= r, int base, return check_strtox_error(nptr, ep, endptr, errno); } =20 +/** + * Searches for the first occurrence of 'c' in 's', and returns a pointer + * to the trailing null byte if none was found. + */ +#ifndef HAVE_STRCHRNUL +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; +} +#endif + /** * parse_uint: * diff --git a/util/qemu-option.c b/util/qemu-option.c index ba44a0895ca3..19761e3eaff0 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 8624a7ac23d9..8bdef841208d 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.14.4 From nobody Mon Feb 9 02:24:22 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; 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 1530278551920440.18665463065065; Fri, 29 Jun 2018 06:22:31 -0700 (PDT) Received: from localhost ([::1]:42104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYtM7-0005BC-9Q for importer@patchew.org; Fri, 29 Jun 2018 09:22:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYtKl-0004Xh-8s for qemu-devel@nongnu.org; Fri, 29 Jun 2018 09:21:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYtKh-0007lM-CF for qemu-devel@nongnu.org; Fri, 29 Jun 2018 09:21:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37116) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYtKh-0007hi-3o for qemu-devel@nongnu.org; Fri, 29 Jun 2018 09:21:03 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5TDIkSA027862 for ; Fri, 29 Jun 2018 09:21:01 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jwms2jfud-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 29 Jun 2018 09:21:01 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 29 Jun 2018 14:20:59 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 29 Jun 2018 14:20:57 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5TDKuF041812202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 29 Jun 2018 13:20:56 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 027E9AE04D; Fri, 29 Jun 2018 14:20:48 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ED909AE045; Fri, 29 Jun 2018 14:20:47 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 Jun 2018 14:20:47 +0100 (BST) Received: from bahia.lan (icon-9-164-191-207.megacenter.de.ibm.com [9.164.191.207]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 2C2C822018B; Fri, 29 Jun 2018 15:20:56 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 29 Jun 2018 15:20:45 +0200 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180629132045.429006-1-groug@kaod.org> References: <20180629132045.429006-1-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 18062913-0028-0000-0000-000002D6649F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18062913-0029-0000-0000-0000238DD620 Message-Id: <20180629132045.429006-3-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=652 adultscore=4 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1806290143 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 2/2] 9p: darwin: Explicitly cast comparisons of mode_t with -1 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: Peter Maydell , Keno Fischer , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Keno Fischer Comparisons of mode_t with -1 require an explicit cast, since mode_t is unsigned on Darwin. Signed-off-by: Keno Fischer Signed-off-by: Greg Kurz --- hw/9pfs/9p-local.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 828e8d6e5638..c30f4f26bd68 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -308,7 +308,7 @@ update_map_file: if (credp->fc_gid !=3D -1) { gid =3D credp->fc_gid; } - if (credp->fc_mode !=3D -1) { + if (credp->fc_mode !=3D (mode_t)-1) { mode =3D credp->fc_mode; } if (credp->fc_rdev !=3D -1) { @@ -414,7 +414,7 @@ static int local_set_xattrat(int dirfd, const char *pat= h, FsCred *credp) return err; } } - if (credp->fc_mode !=3D -1) { + if (credp->fc_mode !=3D (mode_t)-1) { uint32_t tmp_mode =3D cpu_to_le32(credp->fc_mode); err =3D fsetxattrat_nofollow(dirfd, path, "user.virtfs.mode", &tmp= _mode, sizeof(mode_t), 0); --=20 2.14.4