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

Side by Side Diff: fusl/src/misc/openpty.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/misc/nftw.c ('k') | fusl/src/misc/ptsname.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 #include <stdlib.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include <pty.h>
5 #include <stdio.h>
6 #include <pthread.h>
7
8 /* Nonstandard, but vastly superior to the standard functions */
9
10 int openpty(int *pm, int *ps, char *name, const struct termios *tio, const struc t winsize *ws)
11 {
12 int m, s, n=0, cs;
13 char buf[20];
14
15 m = open("/dev/ptmx", O_RDWR|O_NOCTTY);
16 if (m < 0) return -1;
17
18 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
19
20 if (ioctl(m, TIOCSPTLCK, &n) || ioctl (m, TIOCGPTN, &n))
21 goto fail;
22
23 if (!name) name = buf;
24 snprintf(name, sizeof buf, "/dev/pts/%d", n);
25 if ((s = open(name, O_RDWR|O_NOCTTY)) < 0)
26 goto fail;
27
28 if (tio) tcsetattr(s, TCSANOW, tio);
29 if (ws) ioctl(s, TIOCSWINSZ, ws);
30
31 *pm = m;
32 *ps = s;
33
34 pthread_setcancelstate(cs, 0);
35 return 0;
36 fail:
37 close(m);
38 pthread_setcancelstate(cs, 0);
39 return -1;
40 }
OLDNEW
« no previous file with comments | « fusl/src/misc/nftw.c ('k') | fusl/src/misc/ptsname.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698