1570af302Sopenharmony_ci#include <stdlib.h> 2570af302Sopenharmony_ci#include <sys/ioctl.h> 3570af302Sopenharmony_ci#include <stdio.h> 4570af302Sopenharmony_ci#include <fcntl.h> 5570af302Sopenharmony_ci#include <errno.h> 6570af302Sopenharmony_ci#include "syscall.h" 7570af302Sopenharmony_ci#include <unsupported_api.h> 8570af302Sopenharmony_ci 9570af302Sopenharmony_ciint posix_openpt(int flags) 10570af302Sopenharmony_ci{ 11570af302Sopenharmony_ci UNSUPPORTED_API_VOID(LITEOS_A); 12570af302Sopenharmony_ci int r = open("/dev/ptmx", flags); 13570af302Sopenharmony_ci if (r < 0 && errno == ENOSPC) errno = EAGAIN; 14570af302Sopenharmony_ci return r; 15570af302Sopenharmony_ci} 16570af302Sopenharmony_ci 17570af302Sopenharmony_ciint grantpt(int fd) 18570af302Sopenharmony_ci{ 19570af302Sopenharmony_ci UNSUPPORTED_API_VOID(LITEOS_A); 20570af302Sopenharmony_ci return 0; 21570af302Sopenharmony_ci} 22570af302Sopenharmony_ci 23570af302Sopenharmony_ciint unlockpt(int fd) 24570af302Sopenharmony_ci{ 25570af302Sopenharmony_ci int unlock = 0; 26570af302Sopenharmony_ci return ioctl(fd, TIOCSPTLCK, &unlock); 27570af302Sopenharmony_ci} 28570af302Sopenharmony_ci 29570af302Sopenharmony_ciint __ptsname_r(int fd, char *buf, size_t len) 30570af302Sopenharmony_ci{ 31570af302Sopenharmony_ci int pty, err; 32570af302Sopenharmony_ci if (!buf) len = 0; 33570af302Sopenharmony_ci if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err; 34570af302Sopenharmony_ci if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE; 35570af302Sopenharmony_ci return 0; 36570af302Sopenharmony_ci} 37570af302Sopenharmony_ci 38570af302Sopenharmony_ciweak_alias(__ptsname_r, ptsname_r); 39