https://man.openbsd.org/man3/ttyname.3
I believe most standard libraries has a version.
if tty -s; then echo "Standard input is a TTY (interactive mode)." else echo "Standard input is not a TTY (e.g., piped or redirected)." fi
https://github.com/openbsd/src/blob/master/lib/libc/gen/isat...
https://man.openbsd.org/fcntl
https://github.com/openbsd/src/blob/master/sys/sys/fcntl.h
https://github.com/openbsd/src/blob/ba496e5267528b649ec87212...