166492cf0SYuri Pankov.\" 266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation. 466492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at 5c10c16deSRichard Lowe.\" http://www.opengroup.org/bookstore/. 666492cf0SYuri Pankov.\" 766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open 866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their 966492cf0SYuri Pankov.\" documentation. 1066492cf0SYuri Pankov.\" 1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions 1266492cf0SYuri Pankov.\" of the system documentation. 1366492cf0SYuri Pankov.\" 1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form 1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System 1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group. In the event of any discrepancy 2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group 2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee 2266492cf0SYuri Pankov.\" document. The original Standard can be obtained online at 2366492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html. 2466492cf0SYuri Pankov.\" 25c10c16deSRichard Lowe.\" This notice shall appear on any product containing this material. 2666492cf0SYuri Pankov.\" 2766492cf0SYuri Pankov.\" The contents of this file are subject to the terms of the 2866492cf0SYuri Pankov.\" Common Development and Distribution License (the "License"). 2966492cf0SYuri Pankov.\" You may not use this file except in compliance with the License. 3066492cf0SYuri Pankov.\" 3166492cf0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 3266492cf0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing. 3366492cf0SYuri Pankov.\" See the License for the specific language governing permissions 3466492cf0SYuri Pankov.\" and limitations under the License. 3566492cf0SYuri Pankov.\" 3666492cf0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each 3766492cf0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 3866492cf0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the 3966492cf0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying 4066492cf0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner] 4166492cf0SYuri Pankov.\" 4266492cf0SYuri Pankov.\" 4366492cf0SYuri Pankov.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. 4466492cf0SYuri Pankov.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved. 45*cfa8d083SRobert Mustacchi.\" Copyright 2022 Oxide Computer Company 4666492cf0SYuri Pankov.\" 47*cfa8d083SRobert Mustacchi.Dd December 1, 2022 48*cfa8d083SRobert Mustacchi.Dt ISATTY 3C 49*cfa8d083SRobert Mustacchi.Os 50*cfa8d083SRobert Mustacchi.Sh NAME 51*cfa8d083SRobert Mustacchi.Nm isatty 52*cfa8d083SRobert Mustacchi.Nd test for a terminal device 53*cfa8d083SRobert Mustacchi.Sh LIBRARY 54*cfa8d083SRobert Mustacchi.Lb libc 55*cfa8d083SRobert Mustacchi.Sh SYNOPSIS 56*cfa8d083SRobert Mustacchi.In unistd.h 57*cfa8d083SRobert Mustacchi.Ft int 58*cfa8d083SRobert Mustacchi.Fo isatty 59*cfa8d083SRobert Mustacchi.Fa "int filedes" 60*cfa8d083SRobert Mustacchi.Fc 61*cfa8d083SRobert Mustacchi.Sh DESCRIPTION 62*cfa8d083SRobert MustacchiThe 63*cfa8d083SRobert Mustacchi.Fn isatty 64*cfa8d083SRobert Mustacchifunction tests whether 65*cfa8d083SRobert Mustacchi.Fa fildes , 66*cfa8d083SRobert Mustacchian open file descriptor, is associated with a terminal device. 67*cfa8d083SRobert Mustacchi.Sh RETURN VALUES 68*cfa8d083SRobert MustacchiThe 69*cfa8d083SRobert Mustacchi.Fn isatty 70*cfa8d083SRobert Mustacchifunction returns 71*cfa8d083SRobert Mustacchi.Sy 1 72*cfa8d083SRobert Mustacchiif 73*cfa8d083SRobert Mustacchi.Fa fildes 74*cfa8d083SRobert Mustacchiis associated with a terminal; otherwise it returns 75*cfa8d083SRobert Mustacchi.Sy 0 76*cfa8d083SRobert Mustacchiand 77*cfa8d083SRobert Mustacchi.Va errno 78*cfa8d083SRobert Mustacchiis set to indicate the error. 79*cfa8d083SRobert Mustacchi.Sh ERRORS 80*cfa8d083SRobert MustacchiThe 81*cfa8d083SRobert Mustacchi.Fn isatty 82*cfa8d083SRobert Mustacchifunction may fail if: 83*cfa8d083SRobert Mustacchi.Bl -tag -width Er 84*cfa8d083SRobert Mustacchi.It Er EBADF 85*cfa8d083SRobert MustacchiThe 86*cfa8d083SRobert Mustacchi.Fa fildes 87*cfa8d083SRobert Mustacchiargument is not a valid open file descriptor. 88*cfa8d083SRobert Mustacchi.It Er ENOTTY 89*cfa8d083SRobert MustacchiThe 90*cfa8d083SRobert Mustacchi.Fa fildes 91*cfa8d083SRobert Mustacchiargument is not associated with a terminal. 92*cfa8d083SRobert Mustacchi.El 93*cfa8d083SRobert Mustacchi.Sh USAGE 94*cfa8d083SRobert MustacchiThe 95*cfa8d083SRobert Mustacchi.Fn isatty 96*cfa8d083SRobert Mustacchifunction does not necessarily indicate that a human being is available for 97*cfa8d083SRobert Mustacchiinteraction via 98*cfa8d083SRobert Mustacchi.Fa fildes . 99*cfa8d083SRobert MustacchiIt is quite possible that non-terminal devices are connected to the 100*cfa8d083SRobert Mustacchicommunications line. 101*cfa8d083SRobert Mustacchi.Pp 102*cfa8d083SRobert MustacchiThere are a few portability concerns to be aware of. 103*cfa8d083SRobert MustacchiPOSIX does not strictly require that the 104*cfa8d083SRobert Mustacchi.Fn isatty 105*cfa8d083SRobert Mustacchifunction actually set and update 106*cfa8d083SRobert Mustacchi.Va errno . 107*cfa8d083SRobert MustacchiThe only portable and reliable thing to do is to check the return value. 108*cfa8d083SRobert MustacchiOlder versions of this implementation did not set 109*cfa8d083SRobert Mustacchi.Va errno 110*cfa8d083SRobert Mustacchiand erroneously preserved 111*cfa8d083SRobert Mustacchi.Va errno 112*cfa8d083SRobert Mustacchiwhen the 113*cfa8d083SRobert Mustacchi.Fn isatty 114*cfa8d083SRobert Mustacchifunction returned 0. 115*cfa8d083SRobert MustacchiIn cases where true portability is required, one should set 116*cfa8d083SRobert Mustacchi.Va errno 117*cfa8d083SRobert Mustacchito zero before calling this function to potentially allow for and distinguish 118*cfa8d083SRobert Mustacchithis case. 119*cfa8d083SRobert Mustacchi.Sh INTERFACE STABILITY 120*cfa8d083SRobert Mustacchi.Sy Committed 121*cfa8d083SRobert Mustacchi.Sh MT-LEVEL 122*cfa8d083SRobert Mustacchi.Sy MT-Safe 123*cfa8d083SRobert Mustacchi.Sh SEE ALSO 124*cfa8d083SRobert Mustacchi.Xr ttyname 3C , 125*cfa8d083SRobert Mustacchi.Xr attributes 7 , 126*cfa8d083SRobert Mustacchi.Xr standards 7 127