2 * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
12 #include "chan_user.h"
14 #include "um_malloc.h"
20 char str[sizeof("1234567890\0")];
23 static void *fd_init(char *str, int device, const struct chan_opts *opts)
30 printk("fd_init : channel type 'fd' must specify a file "
35 n = strtoul(str, &end, 0);
36 if((*end != '\0') || (end == str)){
37 printk("fd_init : couldn't parse file descriptor '%s'\n", str);
40 data = um_kmalloc(sizeof(*data));
41 if(data == NULL) return(NULL);
42 *data = ((struct fd_chan) { .fd = n,
47 static int fd_open(int input, int output, int primary, void *d, char **dev_out)
49 struct fd_chan *data = d;
52 if(data->raw && isatty(data->fd)){
53 CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
61 sprintf(data->str, "%d", data->fd);
66 static void fd_close(int fd, void *d)
68 struct fd_chan *data = d;
71 if(data->raw && isatty(fd)){
72 CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
74 printk("Failed to restore terminal state - "
75 "errno = %d\n", -err);
80 const struct chan_ops fd_ops = {
86 .write = generic_write,
87 .console_write = generic_console_write,
88 .window_size = generic_window_size,
94 * Overrides for Emacs so that we follow Linus's tabbing style.
95 * Emacs will notice this stuff at the end of the file and automatically
96 * adjust the settings for this buffer only. This must remain at the end
98 * ---------------------------------------------------------------------------
100 * c-file-style: "linux"