1 #define _GNU_SOURCE 2 #include <stdio.h> 3 #include <unistd.h> 4 #include <unsupported_api.h> 5 6 static const char defshells[] = "/bin/sh\n/bin/csh\n"; 7 8 static char *line; 9 static size_t linesize; 10 static FILE *f; 11 endusershell(void)12void endusershell(void) 13 { 14 unsupported_api(__FUNCTION__); 15 if (f) fclose(f); 16 f = 0; 17 } 18 setusershell(void)19void setusershell(void) 20 { 21 if (!f) f = fopen("/etc/shells", "rbe"); 22 if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb"); 23 } 24 getusershell(void)25char *getusershell(void) 26 { 27 ssize_t l; 28 if (!f) setusershell(); 29 if (!f) return 0; 30 l = getline(&line, &linesize, f); 31 if (l <= 0) return 0; 32 if (line[l-1]=='\n') line[l-1]=0; 33 return line; 34 } 35