feat(unistd): cwd/link/readlink/path ops

This commit is contained in:
2026-09-05 23:32:29 -04:00
parent 523045b5ae
commit 9eb32c4010
22 changed files with 2001 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <termios.h>
#include "../internal/syscall.h"
/*
* isatty: report whether fildes is associated with a terminal.
*
* The probe is the kernel's own: issue the TCGETS ioctl, which a real
* terminal answers with 0 and everything else rejects with -ENOTTY (a
* regular file, directory, pipe, socket, or a character device that is
* not a terminal such as /dev/null). A char-device fstat check is NOT
* sufficient — /dev/null is a character device but not a tty — so the
* ioctl is the correct test.
*
* The result is derived from the raw syscall return (negative -errno on
* failure), so isatty never writes errno: POSIX permits an errno set on
* a 0 return but does not require one, and skipping the write keeps the
* probe free of thread-local side effects.
*/
int
isatty(int fildes)
{
struct termios t;
return __syscall3(SYS_ioctl, fildes, 0x5401 /* TCGETS */, (long)&t) == 0 ? 1 : 0;
}