• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdlib.h>
2 #include <sys/ioctl.h>
3 #include <stdio.h>
4 #include <fcntl.h>
5 #include <errno.h>
6 #include "syscall.h"
7 #include <unsupported_api.h>
8 
posix_openpt(int flags)9 int posix_openpt(int flags)
10 {
11 	UNSUPPORTED_API_VOID(LITEOS_A);
12 	int r = open("/dev/ptmx", flags);
13 	if (r < 0 && errno == ENOSPC) errno = EAGAIN;
14 	return r;
15 }
16 
grantpt(int fd)17 int grantpt(int fd)
18 {
19 	UNSUPPORTED_API_VOID(LITEOS_A);
20 	return 0;
21 }
22 
unlockpt(int fd)23 int unlockpt(int fd)
24 {
25 	int unlock = 0;
26 	return ioctl(fd, TIOCSPTLCK, &unlock);
27 }
28 
__ptsname_r(int fd,char * buf,size_t len)29 int __ptsname_r(int fd, char *buf, size_t len)
30 {
31 	int pty, err;
32 	if (!buf) len = 0;
33 	if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err;
34 	if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE;
35 	return 0;
36 }
37 
38 weak_alias(__ptsname_r, ptsname_r);
39