delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/03/01/15:00:12

Date: Sat, 01 Mar 2003 17:55:46 +0000
From: "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
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: Some tidy-ups after the changes to isatty [PATCH]
Message-Id: <E18pBAO-0000nu-00@phekda.freeserve.co.uk>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Below is a patch, to tidy up after the changes to isatty. Changes:

* Document the new behaviour on the isatty info page.

* Some code assumed isatty(fd) != 0 indicated that fd was a terminal.
  Fix these cases.

One question: Should I have added a DJ-style copyright comment
to src/libc/go32/dpmiexcp.c?

OK to commit?

Bye, Rich =]

Index: src/libc/posix/unistd/isatty.txh
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/isatty.txh,v
retrieving revision 1.3
diff -p -c -3 -r1.3 isatty.txh
*** src/libc/posix/unistd/isatty.txh	29 Jan 2003 12:51:41 -0000	1.3
--- src/libc/posix/unistd/isatty.txh	1 Mar 2003 17:46:12 -0000
*************** Tells if the file descriptor refers to a
*** 14,20 ****
  
  @subheading Return Value
  
! Nonzero if @var{fd} is a terminal device, zero  otherwise.
  
  @subheading Portability
  
--- 14,21 ----
  
  @subheading Return Value
  
! -1 and @code{errno} set to @code{EBADF} if @var{fd} is an invalid
! file descriptor; 1 if @var{fd} is a terminal device; otherwise zero.
  
  @subheading Portability
  
Index: src/libc/posix/termios/tcsetpgr.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/termios/tcsetpgr.c,v
retrieving revision 1.1
diff -p -c -3 -r1.1 tcsetpgr.c
*** src/libc/posix/termios/tcsetpgr.c	18 Aug 1999 16:09:37 -0000	1.1
--- src/libc/posix/termios/tcsetpgr.c	1 Mar 2003 17:46:12 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  
  #include <libc/stubs.h>
*************** tcsetpgrp (int fd, pid_t pgid)
*** 10,16 ****
    int e = errno;
    pid_t pgrp =  getpgrp ();
  
!   if (isatty (fd) && pgid == pgrp)
      {
        errno = e;
        return 0;
--- 11,17 ----
    int e = errno;
    pid_t pgrp =  getpgrp ();
  
!   if ((isatty (fd) > 0) && pgid == pgrp)
      {
        errno = e;
        return 0;
Index: src/libc/posix/termios/tcgetpgr.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/termios/tcgetpgr.c,v
retrieving revision 1.1
diff -p -c -3 -r1.1 tcgetpgr.c
*** src/libc/posix/termios/tcgetpgr.c	18 Aug 1999 16:09:37 -0000	1.1
--- src/libc/posix/termios/tcgetpgr.c	1 Mar 2003 17:46:17 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  
  #include <libc/stubs.h>
*************** tcgetpgrp (int fd)
*** 9,15 ****
  {
    int e = errno;
  
!   if (isatty (fd))
      {
        errno = e;
        return getpgrp ();
--- 10,16 ----
  {
    int e = errno;
  
!   if (isatty (fd) > 0)
      {
        errno = e;
        return getpgrp ();
Index: src/libc/pc_hw/co80/conio.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/pc_hw/co80/conio.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 conio.c
*** src/libc/pc_hw/co80/conio.c	14 Jun 2002 14:20:14 -0000	1.8
--- src/libc/pc_hw/co80/conio.c	1 Mar 2003 17:46:20 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
*************** getch(void)
*** 404,414 ****
  
    /* Flush any buffered output, otherwise they might get confusing
       out-of-order execution (and we get to answer FAQs).  */
!   if (isatty(0))
    {
!     if ((stdout->_flag&_IOLBF) && isatty(fileno(stdout)))
        fflush(stdout);
!     if ((stderr->_flag&_IOLBF) && isatty(fileno(stderr)))
        fflush(stderr);
    }
    if (char_avail)
--- 405,415 ----
  
    /* Flush any buffered output, otherwise they might get confusing
       out-of-order execution (and we get to answer FAQs).  */
!   if (isatty(0) > 0)
    {
!     if ((stdout->_flag&_IOLBF) && (isatty(fileno(stdout)) > 0))
        fflush(stdout);
!     if ((stderr->_flag&_IOLBF) && (isatty(fileno(stderr)) > 0))
        fflush(stderr);
    }
    if (char_avail)
Index: src/libc/go32/dpmiexcp.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/go32/dpmiexcp.c,v
retrieving revision 1.16
diff -p -c -3 -r1.16 dpmiexcp.c
*** src/libc/go32/dpmiexcp.c	21 Dec 2002 20:33:10 -0000	1.16
--- src/libc/go32/dpmiexcp.c	1 Mar 2003 17:46:28 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1994, 1995 Charles Sandmann (sandmann AT clio DOT rice DOT edu)
     Exception handling and basis for signal support for DJGPP V2.0
     This software may be freely distributed, no warranty. */
*************** show_call_frame(void)
*** 105,111 ****
    unsigned veip;
    int max;
  
!   if (isatty(STDERR_FILENO))
    {
      max =_farpeekb(_dos_ds, 0x484) + 1;	/* number of screen lines */
      if (max < 10 || max > 75)	/* sanity check */
--- 106,112 ----
    unsigned veip;
    int max;
  
!   if (isatty(STDERR_FILENO) > 0)
    {
      max =_farpeekb(_dos_ds, 0x484) + 1;	/* number of screen lines */
      if (max < 10 || max > 75)	/* sanity check */
Index: src/libc/ansi/stdio/fwrite.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fwrite.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 fwrite.c
*** src/libc/ansi/stdio/fwrite.c	17 Oct 2002 23:00:24 -0000	1.8
--- src/libc/ansi/stdio/fwrite.c	1 Mar 2003 17:46:28 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
*************** fwrite(const void *vptr, size_t size, si
*** 19,25 ****
        && (f->_flag & (_IOTERM | _IONTERM)) == 0)
    {
      /* first time we see this handle--see if termios hooked it */
!     if (isatty(f->_file))
        f->_flag |= _IOTERM;
      else
        f->_flag |= _IONTERM;
--- 20,26 ----
        && (f->_flag & (_IOTERM | _IONTERM)) == 0)
    {
      /* first time we see this handle--see if termios hooked it */
!     if (isatty(f->_file) > 0)
        f->_flag |= _IOTERM;
      else
        f->_flag |= _IONTERM;
Index: src/libc/ansi/stdio/fread.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fread.c,v
retrieving revision 1.7
diff -p -c -3 -r1.7 fread.c
*** src/libc/ansi/stdio/fread.c	17 Oct 2002 23:00:24 -0000	1.7
--- src/libc/ansi/stdio/fread.c	1 Mar 2003 17:46:33 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
*************** fread(void *vptr, size_t size, size_t co
*** 32,38 ****
        && (iop->_flag & (_IOTERM | _IONTERM)) == 0)
    {
      /* first time we see this handle--see if termios hooked it */
!     if (isatty(iop->_file))
        iop->_flag |= _IOTERM;
      else
        iop->_flag |= _IONTERM;
--- 33,39 ----
        && (iop->_flag & (_IOTERM | _IONTERM)) == 0)
    {
      /* first time we see this handle--see if termios hooked it */
!     if (isatty(iop->_file) > 0)
        iop->_flag |= _IOTERM;
      else
        iop->_flag |= _IONTERM;
Index: src/libc/ansi/stdio/flsbuf.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/flsbuf.c,v
retrieving revision 1.11
diff -p -c -3 -r1.11 flsbuf.c
*** src/libc/ansi/stdio/flsbuf.c	29 Jan 2003 01:28:34 -0000	1.11
--- src/libc/ansi/stdio/flsbuf.c	1 Mar 2003 17:46:34 -0000
*************** _flsbuf(int c, FILE *f)
*** 51,57 ****
        f->_cnt = f->_bufsiz = size;
        f->_ptr = base;
        rn = 0;
!       if (f == stdout && isatty (fileno (stdout)))
  	f->_flag |= _IOLBF;
      }
    }
--- 51,57 ----
        f->_cnt = f->_bufsiz = size;
        f->_ptr = base;
        rn = 0;
!       if (f == stdout && isatty (fileno (stdout)) > 0)
  	f->_flag |= _IOLBF;
      }
    }
Index: src/utils/djtar/djtar.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/utils/djtar/djtar.c,v
retrieving revision 1.10
diff -p -c -3 -r1.10 djtar.c
*** src/utils/djtar/djtar.c	17 Oct 2002 23:00:26 -0000	1.10
--- src/utils/djtar/djtar.c	1 Mar 2003 17:46:40 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
*************** main(int argc, char **argv)
*** 617,623 ****
          break;
        case 'p':
          to_stdout = 1;
!         to_tty = isatty(fileno(stdout));
          log_out = stderr;
          text_dos = 1;
          break;
--- 618,624 ----
          break;
        case 'p':
          to_stdout = 1;
!         to_tty = (isatty(fileno(stdout)) > 0);
          log_out = stderr;
          text_dos = 1;
          break;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019