delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/10/21/19:00:51

From: Alain Magloire <alainm AT rcsm DOT ece DOT mcgill DOT ca>
Message-Id: <199910212239.SAA11959@mccoy2.ECE.McGill.CA>
Subject: Re: Bug in fsetpos()?
To: djgpp-workers AT delorie DOT com
Date: Thu, 21 Oct 1999 18:39:38 -0400 (EDT)
In-Reply-To: <199910212101.RAA06252@envy.delorie.com> from "DJ Delorie" at Oct 21, 99 05:01:03 pm
X-Mailer: ELM [version 2.4 PL25]
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Bonjour M. DJ Delorie

> 
> > I was looking at fseek(), fgetpos(), fsetpos() earlier and I noticed
> > that fsetpos() appears to ignore the return value of fseek(). Is
> > this intended?  If not, there's a patch below to fix it. I also
> > altered the return value to be -1, to be consistent with fseek(). If
> > this is the intended behaviour, may I ask why?
> 
> Linux says:
> 
> RETURN VALUES
>        The rewind function returns no value.  Upon successful
>        completion, fgetpos, fseek, fsetpos return 0, and ftell returns
>        the current offset.  Otherwise, -1 is returned and the global
>        variable errno is set to indicate the error.

I would consider this to be a "bug" in the Linux man pages.  I think 
linux uses GNU lib C now and more accurate informations are in the
info manuals.  Probably, in glibc on error fseek() returns EOF, which
maps to -1.

stating -1 explicitely in the man pages, has the nasty side effect of
making people do things like :

if (fsetpos(stream, pos) == -1 /* or < 0 */) { ...} 

which may lead to trouble when porting to other operationg systems.
I would advocate for testing != 0.

BTW, if my point did not come across, I'm not saying that fsetpos()
returning -1 is a bug, but applications testing for negative return value
for fsetpos() is not portable.

> IRIX says:
> 
> DIAGNOSTICS
>      If successful, both fsetpos and fgetpos return zero.  On failure,
>      they return non-zero and set errno to indicate the error.
> 


-- 
au revoir, alain
----
Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!

- Raw text -


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