home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari FTP
/
ATARI_FTP_0693.zip
/
ATARI_FTP_0693
/
Mint
/
mntlib32.zoo
/
isatty.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-17
|
2KB
|
63 lines
/* from the original GCC TOS library by jrd */
/* this algorithm is due to Allan Pratt @ Atari. Thanks Allan! */
#include <errno.h>
#include <osbind.h>
#include <fcntl.h>
#include <stdio.h>
#include <ioctl.h>
#include <unistd.h>
#include <string.h>
#include <support.h>
#include "lib.h"
struct __open_file __open_stat[__NHANDLES];
int isatty(fd)
int fd;
{
int rc;
long oldloc;
int handle = __OPEN_INDEX(fd);
if (handle < __NHANDLES)
if (__open_stat[handle].status != FH_UNKNOWN)
return(__open_stat[handle].status == FH_ISATTY);
oldloc = Fseek(0L, fd, SEEK_CUR); /* save current location */
if (Fseek(1L, fd, SEEK_CUR) != 0) { /* try to seek ahead one byte */
/* got either a file position or an error (usually EBADARG indicating
a range error from trying to seek past EOF), so it is not a tty */
rc = 0;
(void) Fseek(oldloc, fd, SEEK_SET); /* seek back to original location */
}
else
rc = 1; /* yes, tty */
if (handle < __NHANDLES)
if (rc) {
__open_stat[handle].status = FH_ISATTY;
__open_stat[handle].flags = CRMOD|ECHO;
}
else
__open_stat[handle].status = FH_ISAFILE;
return (rc); /* return true, false, or error */
}
/* _isctty(): determine if a file descriptor refers to this process's
controlling tty.
*/
int
_isctty(fd)
int fd;
{
char ctty_name[L_ctermid];
char ftty_name[L_ctermid];
if (!(isatty(fd)) || !(isatty(-1)))
return 0;
if (fd == -1)
return 1;
(void) ctermid(ctty_name);
(void) strncpy(ftty_name, ttyname(fd), L_ctermid);
return !(strncmp(ctty_name, ftty_name, L_ctermid));
}