Re: [PATCH v8 03/12] Move lower case functions into wrapper.c
- From
Christian Couder <chriscool@tuxfamily.org>
- Date
- Mar 27, 2014, 07:47 UTC
- Message-ID
- <20140327.084745.2069840957131666658.chriscool@tuxfamily.org>
- In-Reply-To
- <xmqqppl8ftjd.fsf@gitster.dls.corp.google.com>
From: Junio C Hamano <gitster@pobox.com>
Show 42 quoted lines
>
> Christian Couder <chriscool@tuxfamily.org> writes:
>
>> diff --git a/wrapper.c b/wrapper.c
>> index 0cc5636..c46026a 100644
>> --- a/wrapper.c
>> +++ b/wrapper.c
>> @@ -455,3 +455,17 @@ struct passwd *xgetpwuid_self(void)
>> errno ? strerror(errno) : _("no such user"));
>> return pw;
>> }
>> +
>> +void lowercase(char *p)
>> +{
>> + for (; *p; p++)
>> + *p = tolower(*p);
>> +}
>> +
>> +char *xstrdup_tolower(const char *str)
>> +{
>> + char *dup = xstrdup(str);
>> + lowercase(dup);
>> + return dup;
>> +}
>> +
>
> As a pure code-movement step, this may be OK, but I am not sure if
> both of them want to be public functions in this shape.
>
> Perhaps
>
> char *downcase_copy(const char *str)
> {
> char *copy = xmalloc(strlen(str) + 1);
> int i;
> for (i = 0; str[i]; i++)
> copy[i] = tolower(str[i]);
> copy[i] = '\0';
> return copy;
> }
>
> may avoid having to copy things twice.Yeah, but it seems a bit wasteful to allocate memory for a new string, then downcase it, then compare it with strcmp() and then free it, instead of just using strcasecmp() on the original string.
> Do you need the other > function exposed?
No, with the change you suggest, I don't.
Thanks, Christian.