errno

Mark Allyn allyn at sleepy.UUCP
Thu Jun 13 00:26:45 AEST 1991


I need to be able to take what is printed when you call perror
and put it into a string variable to be used in a c program.

I know that the errno variable is an external variable which points
to some internal table in the kernel called sys_errlist. 

Is there some way of getting at that table so that I can get at the 
error messages?

I tried the following logical solution after RTFM but it did not
work (it got a seg fault)

goo.c

______________________________________________________
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <sys/syslog.h>
#include <errno.h>

main()
{
extern char **sys_errlist;
FILE *fpp;
int ctr1;

fpp=fopen("/goo","w");
perror("");
printf("errno is %d\n",errno);
printf("%d\n",(int)*(sys_errlist+errno));
}

_____________________________________________________
I compiled and linkded this program with
cc -g goo.c



More information about the Comp.unix.questions mailing list