+char *ttyname(int fd)
+{
+ static char ttyname_buf[32];
+ errno = ttyname_r(fd, ttyname_buf, sizeof(ttyname_buf));
+ if(errno) return NULL;
+
+ return ttyname_buf;
+}
+int ttyname_r(int fd, char *buf, size_t buflen)
+{
+ int type = _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL);
+ if( type == -1 )
+ return errno;
+ if( type != DRV_TYPE_TERMINAL )
+ return ENOTTY;
+
+ _SysIOCtl(fd, PTY_IOCTL_GETID, NULL);
+
+ _SysDebug("TODO: ttyname_r");
+
+ return ENOTIMPL;
+}
+
+int isatty(int fd)
+{
+ if( fd < 0 ) {
+ errno = EBADF;
+ return 0;
+ }
+
+ int type = _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL);
+ if( type == -1 )
+ return 0;
+ if( type != DRV_TYPE_TERMINAL ) {
+ errno = ENOTTY;
+ // NOTE: Pre POSIX 2001, EINVAL was returned
+ return 0;
+ }
+ return 1;
+}