2 * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
12 #include "user_util.h"
13 #include "chan_user.h"
19 char str[sizeof("1234567890\0")];
22 static void *fd_init(char *str, int device, struct chan_opts *opts)
29 printk("fd_init : channel type 'fd' must specify a file "
34 n = strtoul(str, &end, 0);
35 if((*end != '\0') || (end == str)){
36 printk("fd_init : couldn't parse file descriptor '%s'\n", str);
39 data = um_kmalloc(sizeof(*data));
40 if(data == NULL) return(NULL);
41 *data = ((struct fd_chan) { .fd = n,
46 static int fd_open(int input, int output, int primary, void *d, char **dev_out)
48 struct fd_chan *data = d;
51 if(data->raw && isatty(data->fd)){
52 CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
60 sprintf(data->str, "%d", data->fd);
65 static void fd_close(int fd, void *d)
67 struct fd_chan *data = d;
70 if(data->raw && isatty(fd)){
71 CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
73 printk("Failed to restore terminal state - "
74 "errno = %d\n", -err);
79 static int fd_console_write(int fd, const char *buf, int n, void *d)
81 struct fd_chan *data = d;
83 return(generic_console_write(fd, buf, n, &data->tt));
86 struct chan_ops fd_ops = {
92 .write = generic_write,
93 .console_write = fd_console_write,
94 .window_size = generic_window_size,
100 * Overrides for Emacs so that we follow Linus's tabbing style.
101 * Emacs will notice this stuff at the end of the file and automatically
102 * adjust the settings for this buffer only. This must remain at the end
104 * ---------------------------------------------------------------------------
106 * c-file-style: "linux"