From patchwork Mon Mar 31 15:04:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 335420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BC3371400AD for ; Tue, 1 Apr 2014 02:04:33 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=us9pd2I3p7V5bjwSOeVa3fhRDErBwe1e/HZ6CbnKaPOLQNDLblabF 9y2fUv/5pScCwslr4RL9jJGj1WO2/TcZQxxZhM7cfvR5Hj5fPXFm1/wZGoKeNCt3 1WMY4EqqVQPhPFC0j+BExMOQdD4aTm5MSB0sj41aTs9tHke2nw2h+8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=hzes0E0I3BiYKwbpZ4yJaD7zuMU=; b=nX1VC9T+3LH8Vrv821Z6ZHMfsGru 4hFIIeSPj4HPfcOP5LTw+P85OqwhgHb2JAPIeS6F+8pDGxF3lEGMJR1DyjY60Cbv Vm3OEZDA4hPI6OoO8UW9uGB2Xtid56oK8FuMARz0Bj3TrERPNA5UWwozqL2dpLol VQODWZidaHAMcBg= Received: (qmail 25093 invoked by alias); 31 Mar 2014 15:04:28 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 25075 invoked by uid 89); 31 Mar 2014 15:04:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-we0-f173.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=VcQS+b55CRyShR/A+IdZVcg0D+Ox0QHhv/NhJexDDRM=; b=YkCAuG17y5M15/aPbcSDFQqjZ+E+vq4Xk++mAh1Mgo9RnKIdgY0R2Rl90s3azofqv7 HXOEm0Pm7fuLYLmwpmf7tiW34pP4urg/AqxKVqzI+ga4FTOcZePAdwrJ8Yy3rpRbh7iT XWV22kX1CbJuxxPI6WoPJDyFojm9sqThkrNqXDrEq/H/PPpnQQ7hPv+K8AVSZdmzvckm VUM05GO51GS9wZ8HxgVwu3YoAs5JCjE97oWybIQEMvl1IuSUxEFYd2wx1ybUnTie36Mo 2aDIW0bqPWymPkl19Q7msULIVZ05UJPkOz+xwZ1WlDpxyKBDs/vm0ZDxWW+wkAN/iiJx 5/ig== X-Gm-Message-State: ALoCoQl+pRrxsGvDXElViKfooiSzoGV2TxtNjGMLXLZkbvQO6/rnPZ3LLCdue9FgIsBQm+yvQWXp X-Received: by 10.194.19.161 with SMTP id g1mr15063185wje.20.1396278262671; Mon, 31 Mar 2014 08:04:22 -0700 (PDT) From: Will Newton To: libc-alpha@sourceware.org Subject: [PATCH] string: Cosmetic cleanup of string functions Date: Mon, 31 Mar 2014 16:04:17 +0100 Message-Id: <1396278257-24507-1-git-send-email-will.newton@linaro.org> Clean up string functions that do not have a version in gnulib on the assumption that glibc is the canonical upstream copy of this code. basename has a copy in gnulib but it is largely written to handle Windows paths so merging it is not really viable. The changes mostly consist of switching to ANSI function prototypes and removing unused includes. As many of these functions do not get built in a typical build due to architecture optimized versions being used instead I built these by hand to verify there were no build warnings and the code was identical. 2014-03-31 Will Newton * string/basename.c [HAVE_CONFIG_H]: Remove #ifdef and and contents. [!_LIBC] Remove #ifndef and contents. (basename): Use ANSI prototype. [_LIBC] Remove #idef. * string/memccpy.c (__memccpy): Use ANSI prototype. * string/memfrob.c (memfrob): Likewise. * string/strcoll.c (STRCOLL): Likewise. * string/strlen.c (strlen): Likewise. * string/strtok.c (STRTOK): Likewise. * string/strcat.c: Remove unused #include of memcopy.h. (strcat): Use ANSI prototype. * string/strchr.c: Remove unused #include of memcopy.h. (strchr): Use ANSI prototype. * string/strcmp.c: Remove unused #include of memcopy.h. (strcmp): Use ANSI prototype. * string/strcpy.c: Remove unused #include of memcopy.h. (strcpy): Use ANSI prototype. --- string/basename.c | 16 +--------------- string/memccpy.c | 6 +----- string/memfrob.c | 4 +--- string/strcat.c | 5 +---- string/strchr.c | 5 +---- string/strcmp.c | 5 +---- string/strcoll.c | 4 +--- string/strcpy.c | 5 +---- string/strlen.c | 3 +-- string/strtok.c | 4 +--- 10 files changed, 10 insertions(+), 47 deletions(-) diff --git a/string/basename.c b/string/basename.c index 29b84ee..98bf96c 100644 --- a/string/basename.c +++ b/string/basename.c @@ -16,26 +16,12 @@ License along with the GNU C Library; if not, see . */ -#ifdef HAVE_CONFIG_H -# include -#endif - #include -#ifndef _LIBC -/* We cannot generally use the name `basename' since XPG defines an unusable - variant of the function but we cannot use it. */ -# define basename gnu_basename -#endif - - char * -basename (filename) - const char *filename; +basename (const char *filename) { char *p = strrchr (filename, '/'); return p ? p + 1 : (char *) filename; } -#ifdef _LIBC libc_hidden_def (basename) -#endif diff --git a/string/memccpy.c b/string/memccpy.c index 793f68e..70ee2ae 100644 --- a/string/memccpy.c +++ b/string/memccpy.c @@ -24,11 +24,7 @@ Return the position in DEST one byte past where C was copied, or NULL if C was not found in the first N bytes of SRC. */ void * -__memccpy (dest, src, c, n) - void *dest; - const void *src; - int c; - size_t n; +__memccpy (void *dest, const void *src, int c, size_t n) { const char *s = src; char *d = dest; diff --git a/string/memfrob.c b/string/memfrob.c index 4841309..68339f7 100644 --- a/string/memfrob.c +++ b/string/memfrob.c @@ -18,9 +18,7 @@ #include void * -memfrob (s, n) - void *s; - size_t n; +memfrob (void *s, size_t n) { char *p = (char *) s; diff --git a/string/strcat.c b/string/strcat.c index bb7c0a9..2cbe8b3 100644 --- a/string/strcat.c +++ b/string/strcat.c @@ -16,15 +16,12 @@ . */ #include -#include #undef strcat /* Append SRC on the end of DEST. */ char * -strcat (dest, src) - char *dest; - const char *src; +strcat (char *dest, const char *src) { char *s1 = dest; const char *s2 = src; diff --git a/string/strchr.c b/string/strchr.c index da69ed2..6bea03e 100644 --- a/string/strchr.c +++ b/string/strchr.c @@ -21,16 +21,13 @@ . */ #include -#include #include #undef strchr /* Find the first occurrence of C in S. */ char * -strchr (s, c_in) - const char *s; - int c_in; +strchr (const char *s, int c_in) { const unsigned char *char_ptr; const unsigned long int *longword_ptr; diff --git a/string/strcmp.c b/string/strcmp.c index 212f20c..85b0170 100644 --- a/string/strcmp.c +++ b/string/strcmp.c @@ -16,7 +16,6 @@ . */ #include -#include #undef strcmp @@ -24,9 +23,7 @@ greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ int -strcmp (p1, p2) - const char *p1; - const char *p2; +strcmp (const char *p1, const char *p2) { const unsigned char *s1 = (const unsigned char *) p1; const unsigned char *s2 = (const unsigned char *) p2; diff --git a/string/strcoll.c b/string/strcoll.c index 779ba13..367ab2e 100644 --- a/string/strcoll.c +++ b/string/strcoll.c @@ -29,9 +29,7 @@ int -STRCOLL (s1, s2) - const STRING_TYPE *s1; - const STRING_TYPE *s2; +STRCOLL (const STRING_TYPE *s1, const STRING_TYPE *s2) { return STRCOLL_L (s1, s2, _NL_CURRENT_LOCALE); } diff --git a/string/strcpy.c b/string/strcpy.c index f136916..caa234a 100644 --- a/string/strcpy.c +++ b/string/strcpy.c @@ -17,15 +17,12 @@ #include #include -#include #undef strcpy /* Copy SRC to DEST. */ char * -strcpy (dest, src) - char *dest; - const char *src; +strcpy (char *dest, const char *src) { char c; char *s = (char *) src; diff --git a/string/strlen.c b/string/strlen.c index 342c4a2..19d2b2b 100644 --- a/string/strlen.c +++ b/string/strlen.c @@ -26,8 +26,7 @@ /* Return the length of the null-terminated string STR. Scan for the null terminator quickly by testing four bytes at a time. */ size_t -strlen (str) - const char *str; +strlen (const char *str) { const char *char_ptr; const unsigned long int *longword_ptr; diff --git a/string/strtok.c b/string/strtok.c index 2253440..924313e 100644 --- a/string/strtok.c +++ b/string/strtok.c @@ -36,9 +36,7 @@ static char *olds; // s = "abc\0=-def\0" */ char * -STRTOK (s, delim) - char *s; - const char *delim; +STRTOK (char *s, const char *delim) { char *token;