delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/07/14/23:49:48

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <42D73254.70109@byu.net>
Date: Thu, 14 Jul 2005 21:49:40 -0600
From: Eric Blake <ebb9 AT byu DOT net>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: bug in freopen
References: <071420052313 DOT 28844 DOT 42D6F19F0007DD6E000070AC22007340760A050E040D0C079D0A AT comcast DOT net> <20050714233230 DOT GE26336 AT trixie DOT casa DOT cgf DOT cx>
In-Reply-To: <20050714233230.GE26336@trixie.casa.cgf.cx>
X-IsSubscribed: yes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Christopher Faylor on 7/14/2005 5:32 PM:
>>#include <stdio.h>
>>#include <errno.h>
>>int main(void)
>>{
>>  FILE* f = freopen (NULL, "rb", stdin); /* Ensure that stdin is binary */
>>  printf ("file is %s, errno %d:%s\n", f ? "good" : "null", errno,
>>          strerror(errno));
>>  return 0;
>>}
>>
> 
> Hmm.  It should be pretty simple to just make this always fail with
> EBADF.  That seems to be a valid thing to do as far as SUSv3 is
> concerned.

Just because SUSv3 permits EBADF doesn't make it a very good QofI choice.
 I don't think it would be too hard to add code that at least gives an
attempt to do the right thing using setmode()/fcntl(F_SETFL).

> 
> I am curious, though, as to the rationale behind this change.  I just
> tried this with -mno-cygwin and it dies with a ENOENT.  So, they
> apparently removed windows-specific code and replaced it with code
> that doesn't work on windows...

The rationale was that the main body of code should be as portable as
possible by sticking to standards, and that platforms that don't meet the
standards then use wrappers from gnulib.  If newlib's freopen is not
patched, then coreutils will probably have to add an autoconf test to
detect that, then add something like this to gnulib:

[freopen.h]
#if FREOPEN_NULL_BROKEN
# include <stdio.h>
# define freopen rpl_freopen
#endif

[freopen.c]
FILE*
rpl_freopen (const char *name, const char *mode, FILE* f)
{
  if (name)
    return freopen (name, mode, f);
  /* Some combination of setmode()/fcntl(fileno(f),F_SETFL,...) */
}

The other part of the rationale is that if cygwin implements this part of
freopen, it can choose to change the modes on regular files but be a no-op
on ttys.  In other words, it would replace code that looks like:
int fd = fileno (f);
if (! isatty (fd))
  setmode (fd, O_BINARY);

with the easier to read
freopen (NULL, "wb", f);

- --
Life is short - so eat dessert first!

Eric Blake             ebb9 AT byu DOT net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC1zJU84KuGfSFAYARAtinAJ9uep5VI7eg56YvNSg6EeirY1tttwCcCv2s
mrKruO0cE0QyiTlbrsyHjVk=
=3qVU
-----END PGP SIGNATURE-----

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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