-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_openpty.c
executable file
·52 lines (45 loc) · 958 Bytes
/
my_openpty.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
** my_init_pty.c for in /home/locque_d//rendu/proj/my_script
**
** Made by damien locque
** Login <[email protected]>
**
** Started on Thu Feb 24 18:00:51 2011 damien locque
** Last update Sun Feb 27 13:20:50 2011 damien locque
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "my_script.h"
static void my_unlockpt(int fd)
{
int tmp;
tmp = 0;
xioctl(fd, TIOCSPTLCK, &tmp);
}
static char * my_ptsname(int fd)
{
int tmp;
char *str;
tmp = 0;
str = xmalloc(18 * sizeof(*str));
memset(str, '\0', 18);
xioctl(fd, TIOCGPTN, &tmp);
sprintf(str, "/dev/pts/%i", tmp);
return (str);
}
int my_openpty(int *fdm, int *fds)
{
(*fdm) = open("/dev/ptmx", O_RDWR);
if ((*fdm) == -1)
return (-1);
my_unlockpt(*fdm);
(*fds) = open(my_ptsname((*fdm)), O_RDWR);
if ((*fds) == -1)
return (-1);
return (0);
}