Added the BSDish openpty().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25135 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
fb913b19be
commit
cc6e7cb347
19
headers/compatibility/bsd/pty.h
Normal file
19
headers/compatibility/bsd/pty.h
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2008, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _BSD_PTY_H_
|
||||
#define _BSD_PTY_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <termios.h>
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern int openpty(int* master, int* slave, char* name,
|
||||
struct termios* termAttrs, struct winsize* windowSize);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _BSD_PTY_H_
|
@ -11,6 +11,7 @@ SharedLibrary libbsd.so :
|
||||
getpass.c
|
||||
issetugid.c
|
||||
progname.c
|
||||
pty.cpp
|
||||
signal.c
|
||||
stringlist.c
|
||||
unvis.c
|
||||
|
44
src/libs/bsd/pty.cpp
Normal file
44
src/libs/bsd/pty.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <pty.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int
|
||||
openpty(int* _master, int* _slave, char* name, struct termios* termAttrs,
|
||||
struct winsize* windowSize)
|
||||
{
|
||||
int master = posix_openpt(O_RDWR);
|
||||
if (master < 0)
|
||||
return -1;
|
||||
|
||||
int slave;
|
||||
const char *ttyName;
|
||||
if (grantpt(master) != 0 || unlockpt(master) != 0
|
||||
|| (ttyName = ptsname(master)) == NULL
|
||||
|| (slave = open(ttyName, O_RDWR | O_NOCTTY)) < 0) {
|
||||
close(master);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (termAttrs != NULL && tcsetattr(master, TCSANOW, termAttrs) != 0
|
||||
|| windowSize != NULL
|
||||
&& ioctl(master, TIOCSWINSZ, windowSize, sizeof(winsize)) != 0) {
|
||||
close(slave);
|
||||
close(master);
|
||||
}
|
||||
|
||||
*_master = master;
|
||||
*_slave = slave;
|
||||
|
||||
if (name != NULL)
|
||||
strcpy(name, ttyName);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user