Added open-control-tty.

This commit is contained in:
shivers 1995-10-26 20:36:37 +00:00
parent 16a701b470
commit b453a05b92
2 changed files with 42 additions and 0 deletions

View File

@ -11,11 +11,24 @@
* Re-written by Olin.
*/
#include <unistd.h>
#include <termios.h>
#include <string.h>
#include <sys/types.h>
/* This #include is for the #ifdef'd code in open_ctty() below, and
** is therefor ifdef'd identically.
*/
#if defined(TIOCSCTTY) && !defined(CIBAUD)
#include <sys/ioctl.h>
#endif
#include "tty1.h" /* Make sure the .h interface agrees with the code. */
extern int errno;
/*****************************************************************************/
int scheme_tcgetattr(int fd, char *control_chars,
int *iflag_hi8, int *iflag_lo24,
int *oflag_hi8, int *oflag_lo24,
@ -40,6 +53,8 @@ int scheme_tcgetattr(int fd, char *control_chars,
}
/*****************************************************************************/
int scheme_tcsetattr(int fd, int option,
const char *control_chars,
int iflag_hi8, int iflag_lo24,
@ -75,3 +90,28 @@ int scheme_tcsetattr(int fd, int option,
return tcsetattr(fd, option, &t);
}
/*****************************************************************************/
int open_ctty(const char *ttyname, int flags)
{
int fd = open(ttyname, flags);
/* The ifdef is tricked by HP-UX, so I'll hardwire it out for now. -Olin */
#if 0
#if defined(TIOCSCTTY) && !defined(CIBAUD)
fprintf(stderr, "Doing the ioctl.\n");
/* 4.3+BSD way to acquire control tty. !CIBAUD rules out SunOS.
** This code stolen from Steven's *Advanced Prog. in the Unix Env.*
*/
if( (fd >= 0) && (ioctl(fd, TIOCSCTTY, (char *) 0) < 0) ) {
int e = errno;
close(fd);
errno = e;
return -1;
}
#endif
#endif
return fd;
}

View File

@ -15,3 +15,5 @@ int scheme_tcsetattr(int fd, int option,
int lflag_hi8, int lflag_lo24,
int ispeed, int ospeed,
int min, int time);
int open_ctty(const char *ttyname, int flags);