xref: /plan9-contrib/sys/src/ape/lib/ap/plan9/isatty.c (revision 781103c4074deb8af160e8a0da2742ba6b29dc2b)
1 #include "lib.h"
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include "sys9.h"
6 #include "dir.h"
7 
8 int
_isatty(int fd)9 _isatty(int fd)
10 {
11 	char buf[64];
12 
13 	if(_FD2PATH(fd, buf, sizeof buf) < 0)
14 		return 0;
15 
16 	/* might be /mnt/term/dev/cons */
17 	return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0;
18 }
19 
20 /* The FD_ISTTY flag is set via _isatty in _fdsetup or open */
21 int
isatty(int fd)22 isatty(int fd)
23 {
24 	if(_fdinfo[fd].flags&FD_ISTTY)
25 		return 1;
26 	else
27 		return 0;
28 }
29