2 * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
12 #include "user_util.h"
13 #include "chan_user.h"
15 #include "um_malloc.h"
21 char str
[sizeof("1234567890\0")];
24 static void *fd_init(char *str
, int device
, const struct chan_opts
*opts
)
31 printk("fd_init : channel type 'fd' must specify a file "
36 n
= strtoul(str
, &end
, 0);
37 if((*end
!= '\0') || (end
== str
)){
38 printk("fd_init : couldn't parse file descriptor '%s'\n", str
);
41 data
= um_kmalloc(sizeof(*data
));
42 if(data
== NULL
) return(NULL
);
43 *data
= ((struct fd_chan
) { .fd
= n
,
48 static int fd_open(int input
, int output
, int primary
, void *d
, char **dev_out
)
50 struct fd_chan
*data
= d
;
53 if(data
->raw
&& isatty(data
->fd
)){
54 CATCH_EINTR(err
= tcgetattr(data
->fd
, &data
->tt
));
62 sprintf(data
->str
, "%d", data
->fd
);
67 static void fd_close(int fd
, void *d
)
69 struct fd_chan
*data
= d
;
72 if(data
->raw
&& isatty(fd
)){
73 CATCH_EINTR(err
= tcsetattr(fd
, TCSAFLUSH
, &data
->tt
));
75 printk("Failed to restore terminal state - "
76 "errno = %d\n", -err
);
81 const struct chan_ops fd_ops
= {
87 .write
= generic_write
,
88 .console_write
= generic_console_write
,
89 .window_size
= generic_window_size
,
95 * Overrides for Emacs so that we follow Linus's tabbing style.
96 * Emacs will notice this stuff at the end of the file and automatically
97 * adjust the settings for this buffer only. This must remain at the end
99 * ---------------------------------------------------------------------------
101 * c-file-style: "linux"