2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
12 #include "chan_user.h"
14 #include "user_util.h"
15 #include "kern_util.h"
17 #include "um_malloc.h"
20 void (*announce)(char *dev_name, int dev);
24 char dev_name[sizeof("/dev/pts/0123456\0")];
27 static void *pty_chan_init(char *str, int device, const struct chan_opts *opts)
29 struct pty_chan *data;
31 data = um_kmalloc(sizeof(*data));
32 if(data == NULL) return(NULL);
33 *data = ((struct pty_chan) { .announce = opts->announce,
39 static int pts_open(int input, int output, int primary, void *d,
42 struct pty_chan *data = d;
49 printk("open_pts : Failed to open pts\n");
53 CATCH_EINTR(err = tcgetattr(fd, &data->tt));
63 sprintf(data->dev_name, "%s", dev);
64 *dev_out = data->dev_name;
66 (*data->announce)(dev, data->dev);
70 static int getmaster(char *line)
72 char *pty, *bank, *cp;
75 pty = &line[strlen("/dev/ptyp")];
76 for (bank = "pqrs"; *bank; bank++) {
77 line[strlen("/dev/pty")] = *bank;
79 if (os_stat_file(line, NULL) < 0)
81 for (cp = "0123456789abcdef"; *cp; cp++) {
83 master = os_open_file(line, of_rdwr(OPENFLAGS()), 0);
85 char *tp = &line[strlen("/dev/")];
87 /* verify slave side is usable */
89 err = os_access(line, OS_ACC_RW_OK);
91 if(err == 0) return(master);
92 (void) os_close_file(master);
99 static int pty_open(int input, int output, int primary, void *d,
102 struct pty_chan *data = d;
104 char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
116 if(data->announce) (*data->announce)(dev, data->dev);
118 sprintf(data->dev_name, "%s", dev);
119 *dev_out = data->dev_name;
123 const struct chan_ops pty_ops = {
125 .init = pty_chan_init,
127 .close = generic_close,
128 .read = generic_read,
129 .write = generic_write,
130 .console_write = generic_console_write,
131 .window_size = generic_window_size,
132 .free = generic_free,
136 const struct chan_ops pts_ops = {
138 .init = pty_chan_init,
140 .close = generic_close,
141 .read = generic_read,
142 .write = generic_write,
143 .console_write = generic_console_write,
144 .window_size = generic_window_size,
145 .free = generic_free,
150 * Overrides for Emacs so that we follow Linus's tabbing style.
151 * Emacs will notice this stuff at the end of the file and automatically
152 * adjust the settings for this buffer only. This must remain at the end
154 * ---------------------------------------------------------------------------
156 * c-file-style: "linux"