delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/08/11/22:48:48

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
From: Chris Faylor <cgf AT cygnus DOT com>
Date: Fri, 11 Aug 2000 22:47:36 -0400
To: cygwin AT sources DOT redhat DOT com
Subject: Re: fwrite inconsistency
Message-ID: <20000811224736.B22901@cygnus.com>
Reply-To: cygwin AT sources DOT redhat DOT com
Mail-Followup-To: cygwin AT sources DOT redhat DOT com
References: <B9906C3F4BB3D311A60F009027463EE9B64EE7 AT mgmgrand DOT adtech-inc DOT com> <200008120242 DOT TAA12840 AT aleph DOT ssd DOT hal DOT com>
Mime-Version: 1.0
User-Agent: Mutt/1.3.6i
In-Reply-To: <200008120242.TAA12840@aleph.ssd.hal.com>; from jjf@bcs.org.uk on Fri, Aug 11, 2000 at 07:42:58PM -0700

On Fri, Aug 11, 2000 at 07:42:58PM -0700, J. J. Farrell wrote:
>> From: "Jimen.Ching" <JChing AT adtech-inc DOT com>
>> 
>> The problem below produces "0 0" as output on HPUX and Solaris 2.5 with gcc
>> 2.8.x.  But using gcc 2.95.x on cygwin, I get "0 1".  I also tried using
>> Borland BCC, and I also got "0 1".  Is GCC trying to behave like MS
>> compilers under cygwin?
>> 
>> Is it correct for size2 to contain 1?  What does ANSI/ISO say about this?
>> 
>> -----------------------------------------------------
>> #include <stdio.h>
>> 
>> int
>> main(int argc, char *argv[])
>> 	{
>> 	int size1, size2;
>> 	FILE *fp;
>> 
>> 	fp = fopen("tst.log", "w");
>> 	size1 = fwrite(0, 1, 0, fp);
>> 	size2 = fwrite(0, 0, 1, fp);
>> 	printf("%d %d\n", size1, size2);
>> 
>> 	return 0;
>> 	}
>
>Standard C says that your program produces undefined behaviour
>because of the first parameter you give to the fwrite() calls.
>The rest of this discussion assumes that your program gives the
>same results with a valid first parameter.
>
>Standard C doesn't comment on the effect of giving 0 for "size"
>or "nmemb". It's clear from the definition that the first case
>should always return 0. The value returned in the second case
>depends on the implementor's view of whether or not a zero-length
>write succeeds.
>
>XPG3 and the Standard Unix Specification explicitly say
>
>    If size or nitems is 0, fwrite() returns 0
>
>I haven't checked, but it's very likely that POSIX says the same.
>
>This looks like a bug in cygwin's fwrite().

Cygwin uses newlib's fwrite.  If you send this bug report to
newlib AT sources DOT redhat DOT com you'll probably have better luck getting
it fixed.

cgf

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


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