From fb913b19be6ad0e6eef4ee828ec3f3e27d33c05d Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 24 Apr 2008 21:29:13 +0000 Subject: [PATCH] Added POSIX functions posix_openpt(), grantpt(), ptsname(), and unlockpt(), which provide a portable way of opening a pty. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25134 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/stdlib.h | 7 ++++ src/system/libroot/posix/stdlib/Jamfile | 3 +- src/system/libroot/posix/stdlib/pty.cpp | 52 +++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/system/libroot/posix/stdlib/pty.cpp diff --git a/headers/posix/stdlib.h b/headers/posix/stdlib.h index 74962b5fc1..1aecc1eed0 100644 --- a/headers/posix/stdlib.h +++ b/headers/posix/stdlib.h @@ -166,6 +166,13 @@ extern size_t wcstombs(char *string, const wchar_t *pwcs, size_t maxSize); /* crypt */ extern void setkey(const char *key); + +/* pty functions */ +extern int posix_openpt(int openFlags); +extern int grantpt(int masterFD); +extern char* ptsname(int masterFD); +extern int unlockpt(int masterFD); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/system/libroot/posix/stdlib/Jamfile b/src/system/libroot/posix/stdlib/Jamfile index 7ae28698c6..023ae69c5c 100644 --- a/src/system/libroot/posix/stdlib/Jamfile +++ b/src/system/libroot/posix/stdlib/Jamfile @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src system libroot posix stdlib ; -UsePrivateHeaders libroot ; +UsePrivateHeaders drivers libroot ; UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ; MergeObject posix_stdlib.o : @@ -15,6 +15,7 @@ MergeObject posix_stdlib.o : heapsort.c merge.c mktemp.c + pty.cpp qsort.c radixsort.c rand.c diff --git a/src/system/libroot/posix/stdlib/pty.cpp b/src/system/libroot/posix/stdlib/pty.cpp new file mode 100644 index 0000000000..2da52c50d6 --- /dev/null +++ b/src/system/libroot/posix/stdlib/pty.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include + +#include +#include + +#include + +#include + + +int +posix_openpt(int openFlags) +{ + return open("/dev/ptmx", openFlags); +} + + +int +grantpt(int masterFD) +{ + return ioctl(masterFD, B_IOCTL_GRANT_TTY); +} + + +char* +ptsname(int masterFD) +{ + int32 index; + if (ioctl(masterFD, B_IOCTL_GET_TTY_INDEX, &index, sizeof(index)) < 0) + return NULL; + + static char buffer[32]; + + char letter = 'p'; + snprintf(buffer, sizeof(buffer), "/dev/tt/%c%lx", char(letter + index / 16), + index % 16); + + return buffer; +} + + +int +unlockpt(int masterFD) +{ + // Noting to do ATM. + return 0; +}