From nobody Fri Sep 8 21:23:35 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Rj8HC3wPmz4t8R0; Fri, 8 Sep 2023 21:23:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Rj8HC3CGtz3D9D; Fri, 8 Sep 2023 21:23:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694208215; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=od3o/1DP4O2Cvx+Ahfllx9OcSKaxh9+T59njlFGpRtc=; b=KLsqHEeEz279Fr5CDoMLaL4J3cJv2pgZJRWoeHH6aenMAGVM733IlOvvvevT/AiU/G/ZNi /Q7JqvGIuOT+YQBWrSmBvzYEcdXATZKm0HOqvTU3+LzhL/1g7pewWGxAh+JSFXKoxUu1Z/ 7/eQilYcn3eJAuNaI909o7QrEoehzUbTupQ5/PpWlDX7fqHDdioFLQOiEXWMfMq1+z02sA SPbIz1tO06FzGi1p7y2INHkoEBEdJNp96p5YSv+liTL+5L1Ko8eoewWXQizFdMhWVbOmi7 k55qMuHzP8aHURc0e9kOVD4d6sdIc01bd4QjBEhpZotPFH0VowC1ipCnhQ4BKw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694208215; a=rsa-sha256; cv=none; b=wH8/exXIEj5SAq4pKuBUbmygEtOm91OSseM3NviikiLTyeKc4v2ilA2J4oJ+YhpKDRh87X 7x1UtbOL4cOQf5NcA9Kt0OR9yqmp7yyShIOjqvkO7jaw72kp3V2sQjviTOrUYmrfS5mosF SP+Zd6nwdJvUAuyw7rejye9PGCCI8MpOaH3DlXqlp5x0Nkv0Pv1ALXrcM/styFJdwhZkp1 wSrkBi1x5dk96T5uAhaNcqys9rdORfYm1J5mc/WhUuTk3GbIcXv9ccwF7ys3YN2Qiiegq5 Bl2jIbiLcQNLWRahJrFc3cHAC0QXu0UeN6LEtgICRwrna0ypw8yjeX1/yKoBrQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694208215; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=od3o/1DP4O2Cvx+Ahfllx9OcSKaxh9+T59njlFGpRtc=; b=yLHIJRpWM9Uw7vPYQXXonnOESRQFOuBXfy+ocp5bLesN8IBzViNGIhtemjHTc+cpOl1Iwq b9ewEL5u13leatUNrmEuaVeylN0H/43jFQdqmKfZ8LUxcgB7oBS8iTAI2IaSyWI/B8DZ2D ezio9jfdz0YJdtLt7nT/MEIFghKw67r+SgY+G+tdUpKZRCa2s3/OyqbSE7RhzzaqQj15e0 Oxs2ARG8A1Rj9ebzHz2MWgYZBI1Z1gDYm1XLoJJUT7tnb2rqCGTi0S9cyQ52m5JdUKcbOC 8GfLeyqN+dvxJjAiDOKIT5FFMBef4lI5JiiYXj1XrkUxR4ajDRUZ1IGASuu8LA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Rj8HC2DYHzxtM; Fri, 8 Sep 2023 21:23:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 388LNZLU057582; Fri, 8 Sep 2023 21:23:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 388LNZpW057579; Fri, 8 Sep 2023 21:23:35 GMT (envelope-from git) Date: Fri, 8 Sep 2023 21:23:35 GMT Message-Id: <202309082123.388LNZpW057579@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Clausecker Subject: git: 331737281c19 - main - lib/libc/amd64/string: implement strnlen(3) trough memchr(3) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fuz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 331737281c1929c29e679e48783055351ac4fbd9 Auto-Submitted: auto-generated The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=331737281c1929c29e679e48783055351ac4fbd9 commit 331737281c1929c29e679e48783055351ac4fbd9 Author: Robert Clausecker AuthorDate: 2023-09-08 21:11:55 +0000 Commit: Robert Clausecker CommitDate: 2023-09-08 21:22:31 +0000 lib/libc/amd64/string: implement strnlen(3) trough memchr(3) Now that we have an optimised memchr(3), we can use it to implement strnlen(3) with better perofrmance. Sponsored by: The FreeBSD Foundation Approved by: mjg MFC after: 1 week MFC to: stable/14 Differential Revision: https://reviews.freebsd.org/D41598 --- lib/libc/amd64/string/Makefile.inc | 3 ++- lib/libc/amd64/string/strnlen.c | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/libc/amd64/string/Makefile.inc b/lib/libc/amd64/string/Makefile.inc index 7c6a1f429590..73973a6d69de 100644 --- a/lib/libc/amd64/string/Makefile.inc +++ b/lib/libc/amd64/string/Makefile.inc @@ -11,7 +11,8 @@ MDSRCS+= \ strcat.S \ strchrnul.S \ strcmp.S \ + strcpy.c \ strcspn.S \ strlen.S \ - strcpy.c \ + strnlen.c \ strspn.S diff --git a/lib/libc/amd64/string/strnlen.c b/lib/libc/amd64/string/strnlen.c new file mode 100644 index 000000000000..9db4ce30dfd4 --- /dev/null +++ b/lib/libc/amd64/string/strnlen.c @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2023 The FreeBSD Foundation + * + * This software was developed by Robert Clausecker + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ''AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE + */ + +#include +#include + +char *__memchr(const void *, int, size_t); + +size_t +strnlen(const char *s, size_t maxlen) +{ + const char *loc; + + loc = __memchr(s, '\0', maxlen); + + return (loc == NULL ? maxlen : (size_t)(loc - s)); +}