[PATCH] Add simple versions of random() and srandom()
Craig Howland
howland@LGSInnovations.com
Wed Mar 23 19:41:00 GMT 2016
On 03/23/2016 03:36 PM, Yaakov Selkowitz wrote:
> On 2016-03-23 13:43, Joel Sherrill wrote:
>> On 3/23/2016 12:45 PM, Yaakov Selkowitz wrote:
>>> On 2016-03-23 12:38, Joel Sherrill wrote:
>>>> --- a/newlib/libc/include/stdlib.h
>>>> +++ b/newlib/libc/include/stdlib.h
>>>> @@ -226,6 +226,12 @@ unsigned short *
>>>> _VOID _EXFUN(srand48,(long));
>>>> _VOID _EXFUN(_srand48_r,(struct _reent *, long));
>>>> #endif /* __SVID_VISIBLE || __XSI_VISIBLE */
>>>> +#if __SVID_VISIBLE || __XSI_VISIBLE >= 4 || __BSD_VISIBLE
>>>
>>> Please review my previous comment on this.
>>
>> Is this the desired guard?
>>
>> #if __MISC_VISIBLE || __XSI_VISIBLE >= 500
>
> MISC is right, but based on Craig's comment, it should be:
>
> #if __MISC_VISIBLE || __XSI_VISIBLE >= 4
>
>>>> +ANSI_SYNOPSIS
>>>> + #define _XOPEN_SOURCE 500
>>>> + #include <stdlib.h>
>>>> + long int random(void);
>>>> + void srandom(unsigned int <[seed]>);
>>>
>>> This doesn't match the header guard, nor does it account for the
>>> multiple options.
>>
>> So how is the || documented in this format?
>
> That hasn't been determined yet, but what about e.g.:
>
> /* See PORTABILITY for feature test macros */
> #include <stdlib.h>
> long int random(void);
> void srandom(unsigned int <[seed]>);
>
> Then mention the possibilities in PORTABILITY?
>
Two other possibilities for consideration (considering in PORTABILITY as #1, and
only showing an abbreviated example without getting into the POSIX 4 extension
complication, which would just add a line or 2):
2) the way Linux man pages do it. From Linux random(3):
"Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
random(), srandom(), initstate(), setstate(): _SVID_SOURCE ||
_BSD_SOURCE || _XOPEN_SOURCE >= 500"
3) Or perhaps something like:
#define _BSD_SOURCE // one (or more) of these #defines is needed before the
#include
#define _SVID_SOURCE
#define _XOPEN_SOURCE 500
#include <stdlib.h>
The Linux 'A || B' formula could be used under PORTABILITY.
More information about the Newlib
mailing list