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

Side by Side Diff: fusl/src/misc/openpty.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 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
OLDNEW
1 #include <stdlib.h> 1 #include <stdlib.h>
2 #include <fcntl.h> 2 #include <fcntl.h>
3 #include <unistd.h> 3 #include <unistd.h>
4 #include <pty.h> 4 #include <pty.h>
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <pthread.h> 6 #include <pthread.h>
7 7
8 /* Nonstandard, but vastly superior to the standard functions */ 8 /* Nonstandard, but vastly superior to the standard functions */
9 9
10 int openpty(int *pm, int *ps, char *name, const struct termios *tio, const struc t winsize *ws) 10 int openpty(int* pm,
11 { 11 int* ps,
12 » int m, s, n=0, cs; 12 char* name,
13 » char buf[20]; 13 const struct termios* tio,
14 const struct winsize* ws) {
15 int m, s, n = 0, cs;
16 char buf[20];
14 17
15 » m = open("/dev/ptmx", O_RDWR|O_NOCTTY); 18 m = open("/dev/ptmx", O_RDWR | O_NOCTTY);
16 » if (m < 0) return -1; 19 if (m < 0)
20 return -1;
17 21
18 » pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); 22 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
19 23
20 » if (ioctl(m, TIOCSPTLCK, &n) || ioctl (m, TIOCGPTN, &n)) 24 if (ioctl(m, TIOCSPTLCK, &n) || ioctl(m, TIOCGPTN, &n))
21 » » goto fail; 25 goto fail;
22 26
23 » if (!name) name = buf; 27 if (!name)
24 » snprintf(name, sizeof buf, "/dev/pts/%d", n); 28 name = buf;
25 » if ((s = open(name, O_RDWR|O_NOCTTY)) < 0) 29 snprintf(name, sizeof buf, "/dev/pts/%d", n);
26 » » goto fail; 30 if ((s = open(name, O_RDWR | O_NOCTTY)) < 0)
31 goto fail;
27 32
28 » if (tio) tcsetattr(s, TCSANOW, tio); 33 if (tio)
29 » if (ws) ioctl(s, TIOCSWINSZ, ws); 34 tcsetattr(s, TCSANOW, tio);
35 if (ws)
36 ioctl(s, TIOCSWINSZ, ws);
30 37
31 » *pm = m; 38 *pm = m;
32 » *ps = s; 39 *ps = s;
33 40
34 » pthread_setcancelstate(cs, 0); 41 pthread_setcancelstate(cs, 0);
35 » return 0; 42 return 0;
36 fail: 43 fail:
37 » close(m); 44 close(m);
38 » pthread_setcancelstate(cs, 0); 45 pthread_setcancelstate(cs, 0);
39 » return -1; 46 return -1;
40 } 47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698