Re: How does one get the description of an errno value

Tiago Maluta <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Steve,

> The following code snippet should do it.  It basically sets errno
> manually and outputs the associated error message.
> 
> --- BEGIN ---
> 
> #define _ALL_SOURCE
> 
> #include <stdio.h>
> #include <errno.h> /* for _MAX_ERRNO */
> 

I've searched in headers on /usr/include for MAX_ERRNO but not found.
Where MAX_ERRNO is defined?

A *very* simple workaround was check for "Unknown" word, so I tried:

int main(void) {
	int i=0;
	extern int errno;
	char str[128];

	while (strncmp(str,"Unknown",7)) {
		sprintf(str,"%s",strerror(i));
		fprintf(stderr, "%3d", i);
		errno = i;
		perror(" ");
		i++;
	}

	return (0);
}


But there is "Unknown" between valid error messages.
I think there is a better way to do it....


Best regards,

--tm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.