delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/08/25/17:34:44

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-T2-Posting-ID: dCnToGxhL58ot4EWY8b+QGwMembwLoz1X2yB7MdtIiA=
Date: Thu, 25 Aug 2005 23:34:22 +0200
From: Samuel Thibault <samuel DOT thibault AT ens-lyon DOT org>
To: cygwin AT cygwin DOT com
Cc: dave AT mielke DOT cc
Subject: strerror(), errno and syslog()
Message-ID: <20050825213422.GQ7662@bouh.ens-lyon.fr>
Mail-Followup-To: Samuel Thibault <samuel DOT thibault AT ens-lyon DOT org>, cygwin AT cygwin DOT com, dave AT mielke DOT cc
Mime-Version: 1.0
User-Agent: Mutt/1.5.9i-nntp

Hi,

This crashes (yes it's odd code, but it shouldn't crash):

#include <syslog.h>
#include <errno.h>

int main(void) {
	errno = -1;
	syslog(LOG_ERR,"foo");
}

Indeed, one of the first things that vsyslog does is

	char *errtext = strerror (get_errno ());
	int errlen = strlen (errtext);

And it happens that the current implementation of strerror() returns
NULL on invalid errno. This is not posix compliant: posix says that
"strerror() shall map any value of type int to a message". GNU libc uses
something like snprintf("Unknown error %d",errnoval); for instance.
Furthermore, "Since no return value is reserved to indicate an error, an
application wishing to check for error situations should set errno to 0,
then call strerror(), then check errno.". So on error, strerror() should
just set errno to whatever EFOO is suited, and return a message similar
to GNU libc's.

Regards,
Samuel

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019