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 struct chan_ops pty_ops
= {
123 .init
= pty_chan_init
,
125 .close
= generic_close
,
126 .read
= generic_read
,
127 .write
= generic_write
,
128 .console_write
= generic_console_write
,
129 .window_size
= generic_window_size
,
130 .free
= generic_free
,
134 struct chan_ops pts_ops
= {
136 .init
= pty_chan_init
,
138 .close
= generic_close
,
139 .read
= generic_read
,
140 .write
= generic_write
,
141 .console_write
= generic_console_write
,
142 .window_size
= generic_window_size
,
143 .free
= generic_free
,
148 * Overrides for Emacs so that we follow Linus's tabbing style.
149 * Emacs will notice this stuff at the end of the file and automatically
150 * adjust the settings for this buffer only. This must remain at the end
152 * ---------------------------------------------------------------------------
154 * c-file-style: "linux"