If I compile a program with
gcc ..... -lpthreads
(i need threads-support) I wont be able to use getpwuid any more. Each call
of getpwuid will result in a segmentation fault.
Has anybody an idea why?
example:
(here are no threads, but its just an exemple which will result in a
segmantation fault when beeing compiled with gcc -oa.out
example.c -lpthreads)
#include<pwd.h>
#include<unistd.h>
char *a;
char *getuser(void){
char *username;
struct passwd *info;
info= getpwuid(getuid());
username=info->pw_name;
return(username);
}
main()
{
a=getuser();
printf(a);
printf("\n");
}
Your example above does not test the return value
from getpwuid. According to the man page, an unsuccessful
return is NULL. If you try to dereference NULL you will
get a SIGSEGV.
--
Fletcher Glenn
email f-g-l...@quest.com (remove the dashes)