From 05c9ae52d57f5637790274c1f9e40dc19bd4f551 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 2 Nov 2008 22:15:38 +0200 Subject: [PATCH] Bug 1004: Rewrite FSF code to avoid GPLv2 2. c) c_strcasecmp and c_strncasecmp were taken from GNU coreutils 6.9, which is copyrighted by the Free Software Foundation and licensed under GNU GPL version 2 or later. It seems the programs in coreutils do not normally read commands interactively. So, including coreutils code in an interactive program such as ELinks could trigger GPLv2 section 2. c), which would require ELinks to display a copyright notice and a warranty disclaimer each time it is started. Rewrite those functions to remove the FSF-copyrighted code and make ELinks not a work based on GNU coreutils. Avoiding FSF code has the additional benefit that we won't have to ask FSF for permission if we want to add a licence exception that allows linking ELinks with OpenSSL. So it seems a good idea even if my interpretation of GPLv2 2. c) is overly strict. I haven't checked though whether there are other FSF-copyrighted portions in ELinks. (cherry picked from commit c56f3928ecf345ec79b35ab8361397fa47092de8) --- src/util/string.c | 91 ++++++++++++----------------------------------- src/util/string.h | 2 +- 2 files changed, 23 insertions(+), 70 deletions(-) diff --git a/src/util/string.c b/src/util/string.c index 690c1195..49148599 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -243,79 +243,32 @@ elinks_strlcasecmp(const unsigned char *s1, size_t n1, } } -/* c_strcasecmp - * Taken from GNU coreutils (version 6.9) - * File name: lib/c-strcasecmp.c - * Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. - * Licensed under the GPL version 2 or any later version. - */ -int c_strcasecmp (const char *s1, const char *s2) +int +c_strcasecmp(const char *s1, const char *s2) { - register const unsigned char *p1 = (const unsigned char *) s1; - register const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - - if (p1 == p2) - return 0; - - do - { - c1 = c_tolower (*p1); - c2 = c_tolower (*p2); - - if (c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); + for (;; s1++, s2++) { + unsigned char c1 = c_tolower(*(const unsigned char *) s1); + unsigned char c2 = c_tolower(*(const unsigned char *) s2); + + if (c1 != c2) + return (c1 < c2) ? -1: +1; + if (c1 == '\0') + return 0; + } } -/* c_strncasecmp - * Taken from GNU coreutils (version 6.9) - * File name: lib/c-strncasecmp.c - * ^ (note the "n") - * Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. - * Licensed under the GPL version 2 or any later version. - */ -int c_strncasecmp (const char *s1, const char *s2, size_t n) +int c_strncasecmp(const char *s1, const char *s2, size_t n) { - register const unsigned char *p1 = (const unsigned char *) s1; - register const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - - if (p1 == p2 || n == 0) - return 0; - - do - { - c1 = c_tolower (*p1); - c2 = c_tolower (*p2); - - if (--n == 0 || c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); + for (; n > 0; n--, s1++, s2++) { + unsigned char c1 = c_tolower(*(const unsigned char *) s1); + unsigned char c2 = c_tolower(*(const unsigned char *) s2); + + if (c1 != c2) + return (c1 < c2) ? -1: +1; + if (c1 == '\0') + return 0; + } + return 0; } /* c_strcasestr - adapted from src/osdep/stub.c */ diff --git a/src/util/string.h b/src/util/string.h index 50a3c224..f1e99a9a 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -98,7 +98,7 @@ int elinks_strlcasecmp(const unsigned char *s1, size_t n1, const int locale_indep); /* strcasecmp and strncasecmp which work as if they are - * in the C locale - both taken from GNU coreutils */ + * in the C locale */ int c_strcasecmp(const char *s1, const char *s2); int c_strncasecmp(const char *s1, const char *s2, size_t n);