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"
18 void (*announce)(char *dev_name, int dev);
22 char dev_name[sizeof("/dev/pts/0123456\0")];
25 void *pty_chan_init(char *str, int device, struct chan_opts *opts)
27 struct pty_chan *data;
29 if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL);
30 *data = ((struct pty_chan) { .announce = opts->announce,
36 int pts_open(int input, int output, int primary, void *d, char **dev_out)
38 struct pty_chan *data = d;
42 if((fd = get_pty()) < 0){
43 printk("open_pts : Failed to open pts\n");
47 tcgetattr(fd, &data->tt);
52 sprintf(data->dev_name, "%s", dev);
53 *dev_out = data->dev_name;
54 if(data->announce) (*data->announce)(dev, data->dev);
58 int getmaster(char *line)
61 char *pty, *bank, *cp;
64 pty = &line[strlen("/dev/ptyp")];
65 for (bank = "pqrs"; *bank; bank++) {
66 line[strlen("/dev/pty")] = *bank;
68 if (stat(line, &stb) < 0)
70 for (cp = "0123456789abcdef"; *cp; cp++) {
72 master = open(line, O_RDWR);
74 char *tp = &line[strlen("/dev/")];
77 /* verify slave side is usable */
79 ok = access(line, R_OK|W_OK) == 0;
81 if (ok) return(master);
89 int pty_open(int input, int output, int primary, void *d, char **dev_out)
91 struct pty_chan *data = d;
93 char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
96 if(fd < 0) return(-errno);
98 if(data->raw) raw(fd, 0);
99 if(data->announce) (*data->announce)(dev, data->dev);
101 sprintf(data->dev_name, "%s", dev);
102 *dev_out = data->dev_name;
106 int pty_console_write(int fd, const char *buf, int n, void *d)
108 struct pty_chan *data = d;
110 return(generic_console_write(fd, buf, n, &data->tt));
113 struct chan_ops pty_ops = {
115 .init = pty_chan_init,
117 .close = generic_close,
118 .read = generic_read,
119 .write = generic_write,
120 .console_write = pty_console_write,
121 .window_size = generic_window_size,
122 .free = generic_free,
126 struct chan_ops pts_ops = {
128 .init = pty_chan_init,
130 .close = generic_close,
131 .read = generic_read,
132 .write = generic_write,
133 .console_write = pty_console_write,
134 .window_size = generic_window_size,
135 .free = generic_free,
140 * Overrides for Emacs so that we follow Linus's tabbing style.
141 * Emacs will notice this stuff at the end of the file and automatically
142 * adjust the settings for this buffer only. This must remain at the end
144 * ---------------------------------------------------------------------------
146 * c-file-style: "linux"