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

Side by Side Diff: fusl/src/stdio/__fdopen.c

Issue 1717003002: [fusl] Don't syscall(SYS_ioctl, ...) in stdio (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « no previous file | fusl/src/stdio/__stdout_write.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "stdio_impl.h" 1 #include "stdio_impl.h"
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <sys/ioctl.h>
4 #include <fcntl.h> 3 #include <fcntl.h>
5 #include <errno.h> 4 #include <errno.h>
6 #include <string.h> 5 #include <string.h>
6 #include <unistd.h>
7 7
8 FILE* __fdopen(int fd, const char* mode) { 8 FILE* __fdopen(int fd, const char* mode) {
9 FILE* f; 9 FILE* f;
10 struct winsize wsz;
11 10
12 /* Check for valid initial mode character */ 11 /* Check for valid initial mode character */
13 if (!strchr("rwa", *mode)) { 12 if (!strchr("rwa", *mode)) {
14 errno = EINVAL; 13 errno = EINVAL;
15 return 0; 14 return 0;
16 } 15 }
17 16
18 /* Allocate FILE+buffer or fail */ 17 /* Allocate FILE+buffer or fail */
19 if (!(f = malloc(sizeof *f + UNGET + BUFSIZ))) 18 if (!(f = malloc(sizeof *f + UNGET + BUFSIZ)))
20 return 0; 19 return 0;
(...skipping 16 matching lines...) Expand all
37 __syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND); 36 __syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND);
38 f->flags |= F_APP; 37 f->flags |= F_APP;
39 } 38 }
40 39
41 f->fd = fd; 40 f->fd = fd;
42 f->buf = (unsigned char*)f + sizeof *f + UNGET; 41 f->buf = (unsigned char*)f + sizeof *f + UNGET;
43 f->buf_size = BUFSIZ; 42 f->buf_size = BUFSIZ;
44 43
45 /* Activate line buffered mode for terminals */ 44 /* Activate line buffered mode for terminals */
46 f->lbf = EOF; 45 f->lbf = EOF;
47 if (!(f->flags & F_NOWR) && !__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz)) 46 if (!(f->flags & F_NOWR) && isatty(fd))
48 f->lbf = '\n'; 47 f->lbf = '\n';
49 48
50 /* Initialize op ptrs. No problem if some are unneeded. */ 49 /* Initialize op ptrs. No problem if some are unneeded. */
51 f->read = __stdio_read; 50 f->read = __stdio_read;
52 f->write = __stdio_write; 51 f->write = __stdio_write;
53 f->seek = __stdio_seek; 52 f->seek = __stdio_seek;
54 f->close = __stdio_close; 53 f->close = __stdio_close;
55 54
56 if (!libc.threaded) 55 if (!libc.threaded)
57 f->lock = -1; 56 f->lock = -1;
58 57
59 /* Add new FILE to open file list */ 58 /* Add new FILE to open file list */
60 return __ofl_add(f); 59 return __ofl_add(f);
61 } 60 }
62 61
63 weak_alias(__fdopen, fdopen); 62 weak_alias(__fdopen, fdopen);
OLDNEW
« no previous file with comments | « no previous file | fusl/src/stdio/__stdout_write.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698