2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
11 #include "chan_user.h"
13 #include "user_util.h"
14 #include "kern_util.h"
18 void (*announce)(char *dev_name, int dev);
22 char dev_name[sizeof("/dev/pts/0123456\0")];
25 static void *pty_chan_init(char *str, int device, struct chan_opts *opts)
27 struct pty_chan *data;
29 data = um_kmalloc(sizeof(*data));
30 if(data == NULL) return(NULL);
31 *data = ((struct pty_chan) { .announce = opts->announce,
37 static int pts_open(int input, int output, int primary, void *d,
40 struct pty_chan *data = d;
47 printk("open_pts : Failed to open pts\n");
51 CATCH_EINTR(err = tcgetattr(fd, &data->tt));
61 sprintf(data->dev_name, "%s", dev);
62 *dev_out = data->dev_name;
64 (*data->announce)(dev, data->dev);
68 static int getmaster(char *line)
70 char *pty, *bank, *cp;
73 pty = &line[strlen("/dev/ptyp")];
74 for (bank = "pqrs"; *bank; bank++) {
75 line[strlen("/dev/pty")] = *bank;
77 if (os_stat_file(line, NULL) < 0)
79 for (cp = "0123456789abcdef"; *cp; cp++) {
81 master = os_open_file(line, of_rdwr(OPENFLAGS()), 0);
83 char *tp = &line[strlen("/dev/")];
85 /* verify slave side is usable */
87 err = os_access(line, OS_ACC_RW_OK);
89 if(err == 0) return(master);
90 (void) os_close_file(master);
97 static int pty_open(int input, int output, int primary, void *d,
100 struct pty_chan *data = d;
102 char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
114 if(data->announce) (*data->announce)(dev, data->dev);
116 sprintf(data->dev_name, "%s", dev);
117 *dev_out = data->dev_name;
121 static int pty_console_write(int fd, const char *buf, int n, void *d)
123 struct pty_chan *data = d;
125 return(generic_console_write(fd, buf, n, &data->tt));
128 struct chan_ops pty_ops = {
130 .init = pty_chan_init,
132 .close = generic_close,
133 .read = generic_read,
134 .write = generic_write,
135 .console_write = pty_console_write,
136 .window_size = generic_window_size,
137 .free = generic_free,
141 struct chan_ops pts_ops = {
143 .init = pty_chan_init,
145 .close = generic_close,
146 .read = generic_read,
147 .write = generic_write,
148 .console_write = pty_console_write,
149 .window_size = generic_window_size,
150 .free = generic_free,
155 * Overrides for Emacs so that we follow Linus's tabbing style.
156 * Emacs will notice this stuff at the end of the file and automatically
157 * adjust the settings for this buffer only. This must remain at the end
159 * ---------------------------------------------------------------------------
161 * c-file-style: "linux"