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 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 int pts_open(int input
, int output
, int primary
, void *d
, char **dev_out
)
39 struct pty_chan
*data
= d
;
45 printk("open_pts : Failed to open pts\n");
49 CATCH_EINTR(err
= tcgetattr(fd
, &data
->tt
));
59 sprintf(data
->dev_name
, "%s", dev
);
60 *dev_out
= data
->dev_name
;
61 if(data
->announce
) (*data
->announce
)(dev
, data
->dev
);
65 int getmaster(char *line
)
67 char *pty
, *bank
, *cp
;
70 pty
= &line
[strlen("/dev/ptyp")];
71 for (bank
= "pqrs"; *bank
; bank
++) {
72 line
[strlen("/dev/pty")] = *bank
;
74 if (os_stat_file(line
, NULL
) < 0)
76 for (cp
= "0123456789abcdef"; *cp
; cp
++) {
78 master
= os_open_file(line
, of_rdwr(OPENFLAGS()), 0);
80 char *tp
= &line
[strlen("/dev/")];
82 /* verify slave side is usable */
84 err
= os_access(line
, OS_ACC_RW_OK
);
86 if(err
== 0) return(master
);
87 (void) os_close_file(master
);
94 int pty_open(int input
, int output
, int primary
, void *d
, char **dev_out
)
96 struct pty_chan
*data
= d
;
98 char dev
[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
110 if(data
->announce
) (*data
->announce
)(dev
, data
->dev
);
112 sprintf(data
->dev_name
, "%s", dev
);
113 *dev_out
= data
->dev_name
;
117 int pty_console_write(int fd
, const char *buf
, int n
, void *d
)
119 struct pty_chan
*data
= d
;
121 return(generic_console_write(fd
, buf
, n
, &data
->tt
));
124 struct chan_ops pty_ops
= {
126 .init
= pty_chan_init
,
128 .close
= generic_close
,
129 .read
= generic_read
,
130 .write
= generic_write
,
131 .console_write
= pty_console_write
,
132 .window_size
= generic_window_size
,
133 .free
= generic_free
,
137 struct chan_ops pts_ops
= {
139 .init
= pty_chan_init
,
141 .close
= generic_close
,
142 .read
= generic_read
,
143 .write
= generic_write
,
144 .console_write
= pty_console_write
,
145 .window_size
= generic_window_size
,
146 .free
= generic_free
,
151 * Overrides for Emacs so that we follow Linus's tabbing style.
152 * Emacs will notice this stuff at the end of the file and automatically
153 * adjust the settings for this buffer only. This must remain at the end
155 * ---------------------------------------------------------------------------
157 * c-file-style: "linux"