ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / um / os-Linux / tty.c
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdlib.h>
7 #include <errno.h>
8 #include "os.h"
9 #include "user.h"
10 #include "kern_util.h"
11
12 struct grantpt_info {
13         int fd;
14         int res;
15         int err;
16 };
17
18 static void grantpt_cb(void *arg)
19 {
20         struct grantpt_info *info = arg;
21
22         info->res = grantpt(info->fd);
23         info->err = errno;
24 }
25
26 int get_pty(void)
27 {
28         struct grantpt_info info;
29         int fd;
30
31         if((fd = os_open_file("/dev/ptmx", of_rdwr(OPENFLAGS()), 0)) < 0){
32                 printk("get_pty : Couldn't open /dev/ptmx - errno = %d\n",
33                        errno);
34                 return(-1);
35         }
36
37         info.fd = fd;
38         initial_thread_cb(grantpt_cb, &info);
39
40         if(info.res < 0){
41                 printk("get_pty : Couldn't grant pty - errno = %d\n", 
42                        info.err);
43                 return(-1);
44         }
45         if(unlockpt(fd) < 0){
46                 printk("get_pty : Couldn't unlock pty - errno = %d\n", errno);
47                 return(-1);
48         }
49         return(fd);
50 }
51
52 /*
53  * Overrides for Emacs so that we follow Linus's tabbing style.
54  * Emacs will notice this stuff at the end of the file and automatically
55  * adjust the settings for this buffer only.  This must remain at the end
56  * of the file.
57  * ---------------------------------------------------------------------------
58  * Local variables:
59  * c-file-style: "linux"
60  * End:
61  */