powerpc-sf longjmp clobbering of val argument
[musl.git] / src / legacy / getusershell.c
blob5fecdec2e44196f19a53dc4fd15018abc47bbb8c
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <unistd.h>
5 static const char defshells[] = "/bin/sh\n/bin/csh\n";
7 static char *line;
8 static size_t linesize;
9 static FILE *f;
11 void endusershell(void)
13 if (f) fclose(f);
14 f = 0;
17 void setusershell(void)
19 if (!f) f = fopen("/etc/shells", "rbe");
20 if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb");
23 char *getusershell(void)
25 ssize_t l;
26 if (!f) setusershell();
27 if (!f) return 0;
28 l = getline(&line, &linesize, f);
29 if (l <= 0) return 0;
30 if (line[l-1]=='\n') line[l-1]=0;
31 return line;