MCPcopy Create free account
hub / github.com/F-Stack/f-stack / openpty

Function openpty

tools/libutil/pty.c:49–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47#include <unistd.h>
48
49int
50openpty(int *amaster, int *aslave, char *name, struct termios *termp,
51 struct winsize *winp)
52{
53 const char *slavename;
54 int master, slave;
55
56 master = posix_openpt(O_RDWR|O_NOCTTY);
57 if (master == -1)
58 return (-1);
59
60 if (grantpt(master) == -1)
61 goto bad;
62
63 if (unlockpt(master) == -1)
64 goto bad;
65
66 slavename = ptsname(master);
67 if (slavename == NULL)
68 goto bad;
69
70 slave = open(slavename, O_RDWR);
71 if (slave == -1)
72 goto bad;
73
74 *amaster = master;
75 *aslave = slave;
76
77 if (name)
78 strcpy(name, slavename);
79 if (termp)
80 tcsetattr(slave, TCSAFLUSH, termp);
81 if (winp)
82 ioctl(slave, TIOCSWINSZ, (char *)winp);
83
84 return (0);
85
86bad: close(master);
87 return (-1);
88}
89
90int
91forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp)

Callers 1

forkptyFunction · 0.85

Calls 2

ioctlFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected