Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: fusl/src/legacy/getusershell.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/legacy/getpass.c ('k') | fusl/src/legacy/isastream.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <unistd.h>
4
5 static const char defshells[] = "/bin/sh\n/bin/csh\n";
6
7 static char *line;
8 static size_t linesize;
9 static FILE *f;
10
11 void endusershell(void)
12 {
13 if (f) fclose(f);
14 f = 0;
15 }
16
17 void setusershell(void)
18 {
19 if (!f) f = fopen("/etc/shells", "rbe");
20 if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb");
21 }
22
23 char *getusershell(void)
24 {
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;
32 }
OLDNEW
« no previous file with comments | « fusl/src/legacy/getpass.c ('k') | fusl/src/legacy/isastream.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698