From patchwork Fri Sep 15 05:40:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 814069 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xtkpg2lPHz9sPr for ; Fri, 15 Sep 2017 15:43:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EjqFMhac"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xtkpg1cX4zDrYY for ; Fri, 15 Sep 2017 15:43:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EjqFMhac"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::241; helo=mail-pf0-x241.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EjqFMhac"; dkim-atps=neutral Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xtkmG6515zDrYY for ; Fri, 15 Sep 2017 15:41:34 +1000 (AEST) Received: by mail-pf0-x241.google.com with SMTP id i23so765848pfi.2 for ; Thu, 14 Sep 2017 22:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=k2tfN/TBnyOQNkQmnH4kLiz/8Lizjzcp6RP5A7pnaYQ=; b=EjqFMhac8R+3EHHIIOSRGMIQKF7KPdbh564AXfAcVJHC9o4VezrVxLinBPUzEBbaaQ gJ4rvVv6DRTm+lV2/e8XInss5kl/1BWaYZyYk1v1caO6YCLfvzh9F1hD2CGzDx7zHpKk GUXgVuhWiHbxC3y9TuptQCpgOBeDQ4SvUJrNdb9DuROnhExLu9LSyWVjLQGUc7cY1lIV +6EvJw3HWfSXHQpUJU7EKDKMJHJI394Mwc9V8AWLeeX0I4tn2fAJPVmVy/K3DmKnxbcD iKvTXOD9fLSa07sBUUaLjZDlZTKKKONPIPIfJNTZ1xJ3QYnyEYEFirKzQGrjDCvYpvyi yQ7w== 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; bh=k2tfN/TBnyOQNkQmnH4kLiz/8Lizjzcp6RP5A7pnaYQ=; b=t0itHBessHa5hfSrps8pUV0yPxGBtVl/dr3ztzIu450hbqgycSZhlD2H07MH4QpV/k cvNEZq6u/3htsxUH3Wbk3k/XcDnKAWweKfTPd+Nd8FDLEFORWlUKD/pffODtWEW//GXQ WSwXoLvt6c5BWbDnIKLnYxd6YVpKZ3lFCQMtfIlvSHeF13itdKwGna+nAAsWy/bYagsF zY/vD81+oznrJW1qN8WvNuKI6rwAdBjVb8vDQ2Ixm1q+KudQ49MrwXSzy6p71U3ruEkY nKiAfOnVJtGnUfsFMV/inYcMtujH8nOeIJ8dDBEXtjnxRK2ICNZYU4Tr3a1eUDnKmxtL lm/A== X-Gm-Message-State: AHPjjUgPUCmb4dhtq4RnZBExBsQ2e0igb5FnYj1KFv7bWCLWdjLuwKGR qlSSlFYLybTphxFn X-Google-Smtp-Source: ADKCNb4LShofuSK8JYrcfKwqgebILyN5ED6ZNMwesPdQdjOHjfns8KWqGBgD42ENpFR/zJKH7n6x5Q== X-Received: by 10.84.248.13 with SMTP id p13mr26450987pll.447.1505454092765; Thu, 14 Sep 2017 22:41:32 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id z8sm280581pgc.93.2017.09.14.22.41.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Sep 2017 22:41:32 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Fri, 15 Sep 2017 15:40:54 +1000 Message-Id: <20170915054059.32109-9-oohall@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170915054059.32109-1-oohall@gmail.com> References: <20170915054059.32109-1-oohall@gmail.com> Subject: [Skiboot] [PATCH 09/14] libc: add strnlen() X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Sometimes handy. Signed-off-by: Oliver O'Halloran --- libc/include/string.h | 1 + libc/string/strlen.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/libc/include/string.h b/libc/include/string.h index e4b4fac95ef9..2172bdcbf9f5 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -25,6 +25,7 @@ int strncasecmp(const char *s1, const char *s2, size_t n); char *strchr(const char *s, int c); char *strrchr(const char *s, int c); size_t strlen(const char *s); +size_t strnlen(const char *s, size_t n); char *strstr(const char *hay, const char *needle); char *strtok(char *src, const char *pattern); char *strdup(const char *src); diff --git a/libc/string/strlen.c b/libc/string/strlen.c index 95b99d25455f..5b408e7ef899 100644 --- a/libc/string/strlen.c +++ b/libc/string/strlen.c @@ -25,3 +25,16 @@ strlen(const char *s) return len; } +size_t +strnlen(const char *s, size_t n) +{ + size_t len = 0; + + while (*s != 0 && n) { + len += 1; + s += 1; + n--; + } + + return len; +}