[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + sug
From: |
Heinrich Schuchardt |
Subject: |
Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch |
Date: |
Sun, 29 Jan 2017 20:29:45 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 |
On 01/29/2017 06:22 PM, Andrew Makhorin wrote:
> Hi Chris,
>
>>> Not sure, but gmtime_s looks like a MSVC function. Could you point me
>>> out where gmtime_s is standardized? Thanks.
>>
>> gmtime_s is included in the (optional) annex K of C11. However, the
>> parameters are reversed compared to the MSVC version and the standard
>> one returns struct tm * while the MSVC one returns errno_t.
>>
>> Moreover, some searching shows that gmtime_s is documented starting
>> with VS 2010 (and _gmtime_s in VS 2005 and VS 2008). However, since VS
>> 2005 gmtime returns a different pointer per thread [1], so there is no
>> reason to use gmtime_s here - gmtime_s offers additional error
>> checking for null pointers, which is not an issue in this code.
>>
>
> Thank you for information.
>
> As Heinrich noticed, gmtime, strerror, and strtok are non-thread-safe
> (for example, in most recent version of glibc strtok just uses a static
> pointer without a tls specifier), so in a multi-threaded environment
> thread-safe versions of these functions should be used. The problem I
> encountered is that gcc (Debian 4.7.2-5) 4.7.2 installed on my Linux
> machine doesn't have gmtime_s, strerror_s, and strtok_s. It is unclear
> what to do if no thread-safe version of these functions are available.
>
glibc (and POSIX 2008) has these functions:
struct tm *gmtime_r(const time_t *timep, struct tm *result);
int strerror_r(int errnum, char *buf, size_t buflen);
char *strtok_r(char *str, const char *delim, char **saveptr);
Windows (and C11) supply
errno_t gmtime_s(struct tm* _tm, const __time_t* time);
errno_t strerror_s(char *buffer, size_t numberOfElements, int errnum);
char *strtok_s(char *strToken, const char *strDelimit, char **context);
We can use __WOE__ to decide which function to use.
Best regards
Heinrich Schuchardt
- [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, David Monniaux, 2017/01/28
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, Heinrich Schuchardt, 2017/01/28
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, Andrew Makhorin, 2017/01/28
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, Heinrich Schuchardt, 2017/01/28
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, Andrew Makhorin, 2017/01/28
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, Chris Matrakidis, 2017/01/28
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, Andrew Makhorin, 2017/01/29
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch,
Heinrich Schuchardt <=
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, Chris Matrakidis, 2017/01/29
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, Andrew Makhorin, 2017/01/30
- Re: [Help-glpk] things I don't understand in src/env/time.c + bugs + suggested patch, David Monniaux, 2017/01/28