From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30018 invoked by alias); 9 Nov 2010 23:14:48 -0000 Received: (qmail 30005 invoked by uid 22791); 9 Nov 2010 23:14:46 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO sourceware.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 09 Nov 2010 23:14:41 +0000 From: "bruno at clisp dot org" To: glibc-bugs@sources.redhat.com Subject: [Bug libc/12204] New: glibc does has no POSIX compliant strerror_r function X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bruno at clisp dot org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: drepper.fsp at gmail dot com X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Tue, 09 Nov 2010 23:14:00 -0000 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2010-11/txt/msg00037.txt.bz2 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 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 #include 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 #include #include 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.