public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bruno at clisp dot org" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/12204] New: glibc does has no POSIX compliant strerror_r function
Date: Tue, 09 Nov 2010 23:14:00 -0000	[thread overview]
Message-ID: <bug-12204-131@http.sourceware.org/bugzilla/> (raw)

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

           Summary: glibc does has no POSIX compliant strerror_r function
           Product: glibc
           Version: 2.8
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: bruno@clisp.org


glibc has two strerror_r functions, declared in <string.h> depending on
feature macros. But none of them is POSIX compliant.

The one which is in effect when _GNU_SOURCE=1 has the declaration
char *strerror_r (int, char *, size_t). It has a different return type
and therefore a different calling convention than the POSIX function.
Test case:
=================================================
#define _GNU_SOURCE 1
#include <string.h>
#include <stdio.h>

int main()
{
  char buf[100];
  char *s = strerror_r (-2, buf, sizeof (buf));
  printf ("result: %s\n", s);
  return 0;
}
=================================================

The one which is in effect when _GNU_SOURCE is undefined and
_POSIX_C_SOURCE=200112L has the declaration
int strerror_r (int, char *, size_t), which is POSIX compatible,
but it has a different return value convention in case of failure.
POSIX:2001 and POSIX:2008 say that in case of failure the strerror_r
function should return "an error number"; this is the same wording
as for pthread_create, pthread_mutex_lock, etc. However, the glibc
function returns -1 and sets errno to the error number instead.
Test case:
========================================================================
#define _POSIX_C_SOURCE 200112L
#include <string.h>
#include <errno.h>
#include <stdio.h>

int main()
{
  char buf[100] = "______";
  int r;

  r = strerror_r (-2, buf, sizeof (buf));
  if (r == 0)
    printf ("result: success %s\n", buf);
  else if (r > 0)
    printf ("result: failure %d %s\n", r, buf);
  else
    printf ("result: non-POSIX failure %d %d %s\n", r, errno, buf);

  r = strerror_r (EACCES, buf, 3);
  if (r == 0)
    printf ("result: success %s\n", buf);
  else if (r > 0)
    printf ("result: failure %d %s\n", r, buf);
  else
    printf ("result: non-POSIX failure %d %d %s\n", r, errno, buf);

  return 0;
}
==========================================================================
Expected result:
result: failure 22 ______
result: failure 34 ______

Actual result:
result: non-POSIX failure -1 22 ______
result: non-POSIX failure -1 34 ______

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


             reply	other threads:[~2010-11-09 23:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-09 23:14 bruno at clisp dot org [this message]
2010-11-09 23:20 ` [Bug libc/12204] " bruno at clisp dot org
2010-11-09 23:20 ` bruno at clisp dot org
2010-11-10  8:14 ` drepper.fsp at gmail dot com
2010-11-10  9:10 ` schwab@linux-m68k.org
2010-11-11  9:36 ` bruno at clisp dot org
2010-12-25 19:17 ` drepper.fsp at gmail dot com
2011-05-18 23:34 ` eblake at redhat dot com
2013-02-08 19:35 ` dank at kegel dot com
2014-02-16 18:28 ` jackie.rosen at hushmail dot com
2014-05-28 19:41 ` schwab at sourceware dot org
2014-06-30  6:29 ` fweimer at redhat dot com

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=bug-12204-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).