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"
16 #include "um_malloc.h"
19 void (*announce
)(char *dev_name
, int dev
);
23 char dev_name
[sizeof("/dev/pts/0123456\0")];
26 static void *pty_chan_init(char *str
, int device
, const struct chan_opts
*opts
)
28 struct pty_chan
*data
;
30 data
= um_kmalloc(sizeof(*data
));
31 if(data
== NULL
) return(NULL
);
32 *data
= ((struct pty_chan
) { .announce
= opts
->announce
,
38 static int pts_open(int input
, int output
, int primary
, void *d
,
41 struct pty_chan
*data
= d
;
48 printk("open_pts : Failed to open pts\n");
52 CATCH_EINTR(err
= tcgetattr(fd
, &data
->tt
));
62 sprintf(data
->dev_name
, "%s", dev
);
63 *dev_out
= data
->dev_name
;
65 (*data
->announce
)(dev
, data
->dev
);
69 static int getmaster(char *line
)
71 char *pty
, *bank
, *cp
;
74 pty
= &line
[strlen("/dev/ptyp")];
75 for (bank
= "pqrs"; *bank
; bank
++) {
76 line
[strlen("/dev/pty")] = *bank
;
78 if (os_stat_file(line
, NULL
) < 0)
80 for (cp
= "0123456789abcdef"; *cp
; cp
++) {
82 master
= os_open_file(line
, of_rdwr(OPENFLAGS()), 0);
84 char *tp
= &line
[strlen("/dev/")];
86 /* verify slave side is usable */
88 err
= os_access(line
, OS_ACC_RW_OK
);
90 if(err
== 0) return(master
);
91 (void) os_close_file(master
);
98 static int pty_open(int input
, int output
, int primary
, void *d
,
101 struct pty_chan
*data
= d
;
103 char dev
[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
115 if(data
->announce
) (*data
->announce
)(dev
, data
->dev
);
117 sprintf(data
->dev_name
, "%s", dev
);
118 *dev_out
= data
->dev_name
;
122 const struct chan_ops pty_ops
= {
124 .init
= pty_chan_init
,
126 .close
= generic_close
,
127 .read
= generic_read
,
128 .write
= generic_write
,
129 .console_write
= generic_console_write
,
130 .window_size
= generic_window_size
,
131 .free
= generic_free
,
135 const struct chan_ops pts_ops
= {
137 .init
= pty_chan_init
,
139 .close
= generic_close
,
140 .read
= generic_read
,
141 .write
= generic_write
,
142 .console_write
= generic_console_write
,
143 .window_size
= generic_window_size
,
144 .free
= generic_free
,
149 * Overrides for Emacs so that we follow Linus's tabbing style.
150 * Emacs will notice this stuff at the end of the file and automatically
151 * adjust the settings for this buffer only. This must remain at the end
153 * ---------------------------------------------------------------------------
155 * c-file-style: "linux"