blob: 4cfdd18ea1efdd383e44405a4ddcf98642f0c43d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
12struct grantpt_info {
13 int fd;
14 int res;
15 int err;
16};
17
18static 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
26int get_pty(void)
27{
28 struct grantpt_info info;
29 int fd;
30
31 fd = os_open_file("/dev/ptmx", of_rdwr(OPENFLAGS()), 0);
32 if(fd < 0){
33 printk("get_pty : Couldn't open /dev/ptmx - err = %d\n", -fd);
34 return(fd);
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 */