From 2563b926ad91bfd2deda877a53eb09ad5c1775e5 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 19 Nov 2016 20:45:53 +0100 Subject: [PATCH] Add posix_openpt(3). --- libc/Makefile | 1 + libc/include/stdlib.h | 7 +++++-- libc/stdlib/posix_openpt.c | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 libc/stdlib/posix_openpt.c diff --git a/libc/Makefile b/libc/Makefile index 9354b55d..90208253 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -535,6 +535,7 @@ stdlib/mkostemps.o \ stdlib/mkstemp.o \ stdlib/mkstemps.o \ stdlib/on_exit.o \ +stdlib/posix_openpt.o \ stdlib/rand.o \ stdlib/realpath.o \ stdlib/setenv.o \ diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index d8f4f02f..e5b542c5 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -159,7 +159,6 @@ long lrand48(void); long mrand48(void); long nrand48(unsigned short[3]); int posix_memalign(void**, size_t, size_t); -int posix_openpt(int); char* ptsname(int); long random(void); int rand_r(unsigned *); @@ -171,6 +170,10 @@ void srandom(unsigned); int unlockpt(int); #endif +#if __USE_SORTIX || 600 <= __USE_XOPEN +int posix_openpt(int); +#endif + /* Functions copied from elsewhere. */ #if __USE_SORTIX uint32_t arc4random(void); diff --git a/libc/stdlib/posix_openpt.c b/libc/stdlib/posix_openpt.c new file mode 100644 index 00000000..c20abdb6 --- /dev/null +++ b/libc/stdlib/posix_openpt.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016 Jonas 'Sortie' Termansen. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * stdlib/posix_openpt.c + * Open a pseudoterminal master. + */ + +#include +#include + +int posix_openpt(int flags) +{ + return open("/dev/ptmx", flags); +}