mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: guard bug for strerror_r
Date: Fri, 8 Feb 2013 15:01:29 -0500	[thread overview]
Message-ID: <20130208200129.GK20323@brightrain.aerifal.cx> (raw)
In-Reply-To: <1360353231.2983.382.camel@eris.loria.fr>

On Fri, Feb 08, 2013 at 08:53:51PM +0100, Jens Gustedt wrote:
> Hello
> 
> Am Freitag, den 08.02.2013, 13:59 -0500 schrieb Rich Felker:
> > > #if defined(__GLIBC__) && defined(__USE_GNU)
> 
> the __GLIBC__ thing seems to work for my case, now. strerror_r seems
> to be the only interface where they use the same name with a different
> interface, so I'll bug something around that.

Yes, that and basename are the only interfaces I'm aware of with
incompatible GNU versions. I actually opened a related bug tracker
issue:

http://sourceware.org/bugzilla/show_bug.cgi?id=15124

> > I would simply avoid _ever_ using strerror_r on GNU systems. On any
> > modern GNU or POSIX 2008 conforming system, you have the vastly
> > superior strerror_l function. It does not require you to provide a
> > buffer, and it's thread-safe (the buffer returned is either immutable
> > static or thread-local). The logic I'd recommend is:
> > 
> > #if _POSIX_VERSION >= 200809L || defined(__GLIBC__)
> > /* use strerror_l */
> > #else
> > /* use strerror_r and assume POSIX version of it */
> > #endif
> 
> Hm, I have a relatively recent system (ubuntu) and there is no trace
> of strerror_l in the documentation, even in their "POSIX" man page.

It's part of the "xlocale" set of interfaces that seem to have
originated with glibc or maybe Sun, and later made it into POSIX 2008.
It allows you to pass a locale_t argument to get the results in a
non-default locale, but you can instead just request the current
locale.

Honestly I don't know why POSIX didn't just require strerror itself to
be thread-safe, but at the time it was probably an "unacceptable
burden" to at least one implementation and then the issue was never
revisited because strerror_r already existed.

> And I actually use this in P99 to provide the C11 Annex K interface
> strerror_s, which is much closer to strerror_r than strerror_l. Well,
> we now have

Are you sure this is the best interface to provide to applications?
I'd instead provide a thread-safe interface with an interface
identical to strerror, since that's by far the easiest to use.

If on the other hand you want to provide Annex K in principle, that's
another matter, but there's a fairly large portion of it that can't be
provided portably on top of an existing libc (mainly the scanf or
printf stuff, I think).

> strerror    C, POSIX
> strerror_r  POSIX
> strerror_l  POSIX
> strerror_s  C
> 
> superbe. Again a case where a liaison between the C committee and the
> POSIX could have helped.

The problem seems to be just that C didn't have threads (and thus no
need for strerror_r or strerror_l) until C11.

Rich


  reply	other threads:[~2013-02-08 20:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-08 16:48 Jens Gustedt
2013-02-08 16:55 ` Szabolcs Nagy
2013-02-08 17:30   ` Jens Gustedt
2013-02-08 18:01     ` Isaac Dunham
2013-02-08 18:59       ` Rich Felker
2013-02-08 19:53         ` Jens Gustedt
2013-02-08 20:01           ` Rich Felker [this message]
2013-02-08 20:31             ` Jens Gustedt
2013-02-08 20:38               ` Rich Felker
2013-02-10 23:08     ` Rob Landley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130208200129.GK20323@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).