This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

strerror(), errno and syslog()


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]