From patchwork Tue Apr 1 08:46:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuo-Jung Su X-Patchwork-Id: 335704 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 9CCC3140085 for ; Tue, 1 Apr 2014 19:47:51 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 554464B7FB; Tue, 1 Apr 2014 10:47:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lTdN8KLV2tJd; Tue, 1 Apr 2014 10:47:50 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1EE764B802; Tue, 1 Apr 2014 10:47:48 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 914484B7FB for ; Tue, 1 Apr 2014 10:47:43 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z-xJqhe0MnxV for ; Tue, 1 Apr 2014 10:47:40 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) by theia.denx.de (Postfix) with ESMTPS id 4D14F4B817 for ; Tue, 1 Apr 2014 10:47:32 +0200 (CEST) Received: by mail-pb0-f44.google.com with SMTP id rp16so9566386pbb.3 for ; Tue, 01 Apr 2014 01:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=W+mHKxGhE5jl9iR5xQU9oT6XKbeM13UxN6S1qw67FJw=; b=EcKHAs4pWeKujOM/Y7Db75tnvwrOzjWmEqO/xzxGCV3OcjiBVTyrjhGmYZ1QDiQ90V RBNZWcvb6IITyJgzgqOiYzgOTYN6ApJXXdGQjZ6YB8wVgJWjrl6XsU01JGqggsjVyxN5 lBt/idj8jgY0XqJjS+76EwouQOEEdXlaG/oV5jwj7nN1i3eXanfmXMTwt+VyoqVd6Oj8 OMLgAVW/iMB4I5nXTFYjS0oe8g34Cwp7S/iBlujZltGQi4NdmtDWv/vUNsmEXBWtphZZ fOnCxmp0aVuXU7R6uud/82HMhNQF6ZWyg2Kmeu8TVObhCrd9oRhFLovptcpVc9sGm0zt 7PdQ== X-Received: by 10.68.196.168 with SMTP id in8mr11506083pbc.132.1396342050684; Tue, 01 Apr 2014 01:47:30 -0700 (PDT) Received: from localhost ([111.81.239.132]) by mx.google.com with ESMTPSA id y4sm48446934pbk.76.2014.04.01.01.47.23 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 01 Apr 2014 01:47:30 -0700 (PDT) From: Kuo-Jung Su To: u-boot@lists.denx.de Date: Tue, 1 Apr 2014 16:46:52 +0800 Message-Id: <1396342019-644-2-git-send-email-dantesu@gmail.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1396342019-644-1-git-send-email-dantesu@gmail.com> References: <1396342019-644-1-git-send-email-dantesu@gmail.com> In-Reply-To: <1364540788-13943-1-git-send-email-dantesu@gmail.com> References: <1364540788-13943-1-git-send-email-dantesu@gmail.com> Cc: Marek Vasut , Kuo-Jung Su Subject: [U-Boot] [PATCH v12 1/8] libc: move strlcpy() from ether.c to string.c X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Kuo-Jung Su It would be better to have strlcpy() moved to lib/string.c, so that it could be reused by others without enabling USB Gadget Ethernet. Signed-off-by: Kuo-Jung Su CC: Albert Aribaud CC: Wolfgang Denk Cc: Marek Vasut --- Changes for v12: - Initial commit drivers/usb/gadget/ether.c | 24 ------------------------ include/linux/string.h | 3 +++ lib/string.c | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 24 deletions(-) -- 1.7.9.5 diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index cc6cc1f..cabd81f 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -857,30 +857,6 @@ DEFINE_CACHE_ALIGN_BUFFER(u8, control_req, USB_BUFSIZ); DEFINE_CACHE_ALIGN_BUFFER(u8, status_req, STATUS_BYTECOUNT); #endif - -/** - * strlcpy - Copy a %NUL terminated string into a sized buffer - * @dest: Where to copy the string to - * @src: Where to copy the string from - * @size: size of destination buffer - * - * Compatible with *BSD: the result is always a valid - * NUL-terminated string that fits in the buffer (unless, - * of course, the buffer size is zero). It does not pad - * out the result like strncpy() does. - */ -size_t strlcpy(char *dest, const char *src, size_t size) -{ - size_t ret = strlen(src); - - if (size) { - size_t len = (ret >= size) ? size - 1 : ret; - memcpy(dest, src, len); - dest[len] = '\0'; - } - return ret; -} - /*============================================================================*/ /* diff --git a/include/linux/string.h b/include/linux/string.h index 8e44855..5c9d6c3 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -23,6 +23,9 @@ extern __kernel_size_t strspn(const char *,const char *); #ifndef __HAVE_ARCH_STRCPY extern char * strcpy(char *,const char *); #endif +#ifndef __HAVE_ARCH_STRLCPY +extern __kernel_size_t strlcpy(char *, const char *, __kernel_size_t); +#endif #ifndef __HAVE_ARCH_STRNCPY extern char * strncpy(char *,const char *, __kernel_size_t); #endif diff --git a/lib/string.c b/lib/string.c index 29c2ca7..adf718c 100644 --- a/lib/string.c +++ b/lib/string.c @@ -80,6 +80,31 @@ char * strcpy(char * dest,const char *src) } #endif +#ifndef __HAVE_ARCH_STRLCPY +/** + * strlcpy - Copy a %NUL terminated string into a sized buffer + * @dest: Where to copy the string to + * @src: Where to copy the string from + * @size: size of destination buffer + * + * Compatible with *BSD: the result is always a valid + * NUL-terminated string that fits in the buffer (unless, + * of course, the buffer size is zero). It does not pad + * out the result like strncpy() does. + */ +size_t strlcpy(char *dest, const char *src, size_t size) +{ + size_t ret = strlen(src); + + if (size) { + size_t len = (ret >= size) ? size - 1 : ret; + memcpy(dest, src, len); + dest[len] = '\0'; + } + return ret; +} +#endif + #ifndef __HAVE_ARCH_STRNCPY /** * strncpy - Copy a length-limited, %NUL-terminated string