From nobody Sat Sep 23 18:22:32 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 4RtHYP2dV9z4v38r; Sat, 23 Sep 2023 18:22:33 +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 4RtHYP16kVz4l0M; Sat, 23 Sep 2023 18:22:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695493353; 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=s5rqCN0eyu2vfBKy7zQ879kS6aP9d+gmyP9JyqNOuFM=; b=V85f1FCixM3KveCRcJBaE6iOkE1/5oIobU/yw85kVSErdZ5ptl+VNjxZaCjx1UaIHgBxjN pNIWPwPV46EaH8vk51dAlJFsyuuihYSpNiD7qIDgynJWpseCuOaTeru0LyNY0klgxm6qke whGU1Y2T1H0WIwcZpKJ9nT90CKbZar8ZkObkJ5gL9ymHLf3CjF4+kc+Z5Wx/pTZOddBNST LFcXOkp8gmfI1/Xwkdkx/zLC5JEjEZp9VtyP2JsUc5neX8UCluUIxjan5srupp+OuVN2ge pAR8ntQ3/MRONgDSAlmLsE1H7EW50psp3InmE9YBoz7ADKUTNVyF4cCKp1zv0w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695493353; a=rsa-sha256; cv=none; b=aLwptjQIO1AlBvXDxyVRs9IHKY0sF/AzEKfLfLiDqUChSnM8ZyVNPZgpxxhJi2xuTcwkAM PsdWd55iJNCcf/C+VnIY9EBUyzx/W/Feiyv4YSdjjV989Th0TnJpMIC0WWJSiQHZmB50v+ dfegC/9sWEj2ousbKjBOCD79ShILUpwHMe1H+x3A8ZWF0eFtMSqaXKcCG18F6Wafd6pdKn Rp2pdEKCry2LtaPyhGXHKO+Dgh9yZY845XRrgM1jwmMXDz7bF/mkvaYiBctF8uRZkkhPIr c+o0mNNPR8R6n7kHKijkuxq4WabqwpAjQ/zhlmfxEUT3lphIniga+T2DSF+S4w== 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=1695493353; 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=s5rqCN0eyu2vfBKy7zQ879kS6aP9d+gmyP9JyqNOuFM=; b=CZXNMUtxLhPDmINGugFQqTDTFvaE18FX/vQuaKJ2kDS6e/dGp4zqeFWxspejwgcwTQTBey JxWSeyjH4NAV55vy51aaZkqX+S1kmrR0/wHY2bVGfOvFV+b6JgbasvSjZOZpIgcAOfs+Xh H37PhLbo9rsi9MDdwkegrZ9eib98Ie60OqjBOZdBpD9Zfgok2Y7qudr/KRlIbr1hL3cCoM VuY1Zt/z3P/i8Zwmgy9m1Ri2M9MYsT5JzYp2DCZbUbeuPvsfoL1/jXNxRcaxvHflC+L7wx NdHbG8BX9+NeXJ4Z8bh3wJfvk19mlhiYTOQ6MLj/5IA6Q0ekf7oO95m9fCQJJA== 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 4RtHYN6kLNzVS; Sat, 23 Sep 2023 18:22:32 +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 38NIMWdN004111; Sat, 23 Sep 2023 18:22:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38NIMWpE004108; Sat, 23 Sep 2023 18:22:32 GMT (envelope-from git) Date: Sat, 23 Sep 2023 18:22:32 GMT Message-Id: <202309231822.38NIMWpE004108@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Robert Clausecker Subject: git: 62f73a711e22 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 62f73a711e224d06e62891c3212e063a752cedab Auto-Submitted: auto-generated The branch stable/14 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=62f73a711e224d06e62891c3212e063a752cedab commit 62f73a711e224d06e62891c3212e063a752cedab Author: Robert Clausecker AuthorDate: 2023-09-08 21:11:55 +0000 Commit: Robert Clausecker CommitDate: 2023-09-23 18:21:37 +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 (cherry picked from commit 331737281c1929c29e679e48783055351ac4fbd9) --- 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)); +}