strnlen, strict ansi, newlib vs glibc
Joel Sherrill
joel.sherrill@oarcorp.com
Tue Sep 16 14:44:00 GMT 2014
How about the attached patch? Does it match what you had
suggested?
If so, OK to commit?
--joel
On 9/15/2014 1:55 PM, Joel Sherrill wrote:
> On 9/15/2014 10:12 AM, Thomas Uhle wrote:
>> On Sat, 2014-09-13 at 14:57 +0200, Luca Barbato wrote:
>>
>>> On 14/08/14 17:27, Joel Sherrill wrote:
>>>> Hi
>>>>
>>>> I have some native C++ code that I developed on CentOS and it
>>>> has no warnings. Someone moved it to Cygwin and reported warnings
>>>> for strnlen() not being prototyped. I investigated and the program did
>>>> include string.h. I tried RTEMS tools and got the same as Cygwin
>>>> since we have the same string.h from newlib.
>>>>
>>>> Investigating this, it appears that strnlen() is protected by
>>>> __STRICT_ANSI__ on newlib and __USE_XOPEN2K8 on Linux.
>>>>
>>>> Command: g++ -Wall -std=c++0x -c strtest.cc
>>>>
>>>> This program is enough to reproduce the issue:
>>>>
>>>> #include <string.h>
>>>>
>>>> // size_t strnlen( const char *, size_t );
>>>>
>>>> size_t f( const char *str )
>>>> {
>>>> return strnlen( str, 1000 );
>>>> }
>>>>
>>>>
>>>> What do you all think?
>>>>
>>> Might be nice to add the support for _DEFAULT_SOURCE with the semantic
>>> of not filter what is on by default notwithstanding the defines -std
>>> might set.
>>>
>>> It seems supported by glibc and musl so might be good to do as well.
>>>
>>> lu
>>>
>> Hello Joel and Luca,
>>
>> I think that the current guard in newlib/libc/include/string.h:119
>>
>> #if !defined(__STRICT_ANSI__) || __XSI_VISIBLE >= 500
>>
>> should be simply replaced by the amended one
>>
>> #if !defined(__STRICT_ANSI__) || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
>>
>> to fix this issue.
> If Corinna and/or Jeff is OK with this, then I have no issues as
> long as -std=c99 trips the condition based on our cdefs.h. It looks
> like it should.
>
> I won't be able to try this for a few days.
>
> Getting these guards just perfect is very tedious and error prone.
>
> Thanks.
>
>> Best regards,
>>
>> Thomas Uhle
>>
--
Joel Sherrill, Ph.D. Director of Research & Development
joel.sherrill@OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
-------------- next part --------------
2014-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
Thomas Uhle <thomas.uhle@eas.iis.fraunhofer.de>
* libc/include/string.h: Correct guard for strnlen().
Index: libc/include/string.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/string.h,v
retrieving revision 1.36
diff -u -r1.36 string.h
--- libc/include/string.h 18 Aug 2014 14:18:10 -0000 1.36
+++ libc/include/string.h 16 Sep 2014 14:40:49 -0000
@@ -116,7 +116,8 @@
#if __BSD_VISIBLE || __POSIX_VISIBLE
int _EXFUN(strncasecmp,(const char *, const char *, size_t));
#endif
-#if !defined(__STRICT_ANSI__) || __XSI_VISIBLE >= 500
+#if !defined(__STRICT_ANSI__) || __POSIX_VISIBLE >= 200809 || \
+ __XSI_VISIBLE >= 700
size_t _EXFUN(strnlen,(const char *, size_t));
#endif
#if __BSD_VISIBLE
More information about the Newlib
mailing list