Patchwork Modify strnlen() check for old OSes to check its presence directly

login
register
about
Submitter Andrey Korolyov
Date 2016-01-03 19:22:19
Message ID <1451848939-8160-1-git-send-email-andrey@xdel.ru>
Download mbox | patch
Permalink /patch/4350/
State Accepted
Headers show

Comments

Andrey Korolyov - 2016-01-03 19:22:19
Adding generic check against the function in addition to check for
a problematic compiler.

Fixes: r1878: Make strnlen() visible in old versions of glibc.

Signed-off-by: Andrey Korolyov <andrey@xdel.ru>
---
 flash.h   | 2 +-
 helpers.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Stefan Tauner - 2016-01-04 03:37:13
On Sun,  3 Jan 2016 22:22:19 +0300
Andrey Korolyov <andrey@xdel.ru> wrote:

> Adding generic check against the function in addition to check for
> a problematic compiler.

Hi Andrey,

thanks for the patch. Did you notice any breakage in the wild? I
hesitate to include your change because that could actually break some
configurations: in case HAVE_STRNLEN is not defined but strnlen is
provided nonetheless linking would fail. Actually I'd be surprised if it
would not make problems with other libc implementations.
Andrey Korolyov - 2016-01-04 10:14:03
>
> thanks for the patch. Did you notice any breakage in the wild? I
> hesitate to include your change because that could actually break some
> configurations: in case HAVE_STRNLEN is not defined but strnlen is
> provided nonetheless linking would fail. Actually I'd be surprised if it
> would not make problems with other libc implementations.
>
> --

Hi Stefan,

NetBSD before 6.0 is definitely the one which breaks here, as well as
other late adopters of srtnlen(), like FreeBSD before 8.0. Please feel
free to NAK the patch if you think that the support of ancient libcs
is not something to worry about (and old BSDs are definitely not LTS
distros with ten-year support span).
Stefan Tauner - 2016-01-23 17:12:08
On Mon, 4 Jan 2016 13:14:03 +0300
Andrey Korolyov <andrey@xdel.ru> wrote:

> >
> > thanks for the patch. Did you notice any breakage in the wild? I
> > hesitate to include your change because that could actually break some
> > configurations: in case HAVE_STRNLEN is not defined but strnlen is
> > provided nonetheless linking would fail. Actually I'd be surprised if it
> > would not make problems with other libc implementations.
>
> NetBSD before 6.0 is definitely the one which breaks here, as well as
> other late adopters of srtnlen(), like FreeBSD before 8.0. Please feel
> free to NAK the patch if you think that the support of ancient libcs
> is not something to worry about (and old BSDs are definitely not LTS
> distros with ten-year support span).

Thanks for the explanation. I have merged the respective change now in
r1917 because I could not find any problems with it on any of our
buildbot tests. Hopefully no one else will either :)

Patch

diff --git a/flash.h b/flash.h
index 24861ba..3af4c43 100644
--- a/flash.h
+++ b/flash.h
@@ -260,7 +260,7 @@  void tolower_string(char *str);
 #ifdef __MINGW32__
 char* strtok_r(char *str, const char *delim, char **nextp);
 #endif
-#if defined(__DJGPP__)
+#if defined(__DJGPP__) || ! defined(HAVE_STRNLEN)
 size_t strnlen(const char *str, size_t n);
 #endif
 
diff --git a/helpers.c b/helpers.c
index 7a146c3..cdc87e0 100644
--- a/helpers.c
+++ b/helpers.c
@@ -92,7 +92,7 @@  char* strtok_r(char *str, const char *delim, char **nextp)
 #endif
 
 /* There is no strnlen in DJGPP */
-#if defined(__DJGPP__)
+#if defined(__DJGPP__) || ! defined(HAVE_STRNLEN)
 size_t strnlen(const char *str, size_t n)
 {
 	size_t i;