-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptyopen.c
47 lines (40 loc) · 904 Bytes
/
ptyopen.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
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include "ourhdr.h"
extern char *ptsname(int); /* prototype not in any system header */
int
ptym_open(char *pts_name)
{
char *ptr;
int fdm;
strcpy(pts_name, "/dev/ptmx"); /* in case open fails */
if ( (fdm = open(pts_name, O_RDWR)) < 0)
return(-1);
if (grantpt(fdm) < 0) { /* grant access to slave */
close(fdm);
return(-2);
}
if (unlockpt(fdm) < 0) { /* clear slave's lock flag */
close(fdm);
return(-3);
}
if ( (ptr = ptsname(fdm)) == NULL) { /* get slave's name */
close(fdm);
return(-4);
}
strcpy(pts_name, ptr); /* return name of slave */
return(fdm); /* return fd of master */
}
int
ptys_open(int fdm, char *pts_name)
{
int fds;
/* following should allocate controlling terminal */
if ( (fds = open(pts_name, O_RDWR)) < 0) {
close(fdm);
return(-5);
}
return(fds);
}