Date: Thu, 27 Feb 2003 14:40:28 +0000 From: "Richard Dawe" Sender: rich AT phekda DOT freeserve DOT co DOT uk To: djgpp-workers AT delorie DOT com X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6 Subject: Use _get_dev_info & constants in isatty; add test [PATCH] Message-Id: Reply-To: djgpp-workers AT delorie DOT com Hello. I noticed the other day that isatty uses values rather than using the constants from . So I fixed that. I also made it use a _get_dev_info call, rather than duplicating that code. Using _get_dev_info means that it will detect bad file descriptors and return errno == EBADF and -1 (as required by POSIX). I also added a test program. See the patch below. OK to commit? Bye, Rich =] Index: src/libc/posix/unistd/isatty.c =================================================================== RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/isatty.c,v retrieving revision 1.1 diff -p -c -3 -r1.1 isatty.c *** src/libc/posix/unistd/isatty.c 10 May 1995 04:03:22 -0000 1.1 --- src/libc/posix/unistd/isatty.c 27 Feb 2003 14:34:42 -0000 *************** *** 1,16 **** /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include ! #include int isatty(int fd) { ! __dpmi_regs r; ! r.x.ax = 0x4400; ! r.x.bx = fd; ! __dpmi_int(0x21, &r); ! if ((r.x.ax & 0x83) == 0x83) return 1; return 0; } --- 1,21 ---- + /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include ! #include ! #include ! ! #define ISATTY_BITS (_DEV_CDEV|_DEV_STDIN|_DEV_STDOUT) int isatty(int fd) { ! const int dev_info = _get_dev_info(fd); ! ! if (dev_info == -1) ! return -1; ! ! if ((dev_info & ISATTY_BITS) == ISATTY_BITS) return 1; return 0; } Index: tests/libc/posix/unistd/makefile =================================================================== RCS file: /cvs/djgpp/djgpp/tests/libc/posix/unistd/makefile,v retrieving revision 1.3 diff -p -c -3 -r1.3 makefile *** tests/libc/posix/unistd/makefile 22 May 2001 20:52:27 -0000 1.3 --- tests/libc/posix/unistd/makefile 27 Feb 2003 14:34:42 -0000 *************** SRC += getpid.c *** 8,12 **** --- 8,13 ---- SRC += sleep.c SRC += tread.c SRC += write.c + SRC += t-isatty.c include $(TOP)/../makefile.inc *** /dev/null Thu Feb 27 14:37:44 2003 --- tests/libc/posix/unistd/t-isatty.c Thu Feb 27 14:35:40 2003 *************** *** 0 **** --- 1,19 ---- + #include + #include + #include + #include + + int + main (void) + { + /* Check the standard handles */ + assert(isatty(fileno(stdin))); + assert(isatty(fileno(stdout))); + assert(!isatty(fileno(stdprn))); + + /* Check an invalid file descriptor. */ + assert(isatty(99) < 0); + + puts("PASS"); + return(EXIT_SUCCESS); + }