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