isatty.c 471 B

1234567891011121314151617181920212223242526272829
  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. int
  8. _isatty(int fd)
  9. {
  10. int t;
  11. char buf[64];
  12. if(_FD2PATH(fd, buf, sizeof buf) < 0)
  13. return 0;
  14. /* might be /mnt/term/dev/cons */
  15. return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0;
  16. }
  17. /* The FD_ISTTY flag is set via _isatty in _fdsetup or open */
  18. int
  19. isatty(fd)
  20. {
  21. if(_fdinfo[fd].flags&FD_ISTTY)
  22. return 1;
  23. else
  24. return 0;
  25. }