*BSD News Article 8556


Return to BSD News archive

Newsgroups: comp.unix.bsd
Path: sserve!manuel.anu.edu.au!munnari.oz.au!spool.mu.edu!sol.ctr.columbia.edu!news.columbia.edu!cucbs.chem.columbia.edu!cucbs.chem.columbia.edu!russo
From: russo@cucbs.chem.columbia.edu (Thomas Russo)
Subject: [386BSD] bug in fgetpos
Message-ID: <RUSSO.92Dec6125119@cucbs.chem.columbia.edu>
Sender: russo@cucbs.chem.columbia.edu (Thomas Russo)
Organization: Center for Biomolecular Simulation, Department of Chemistry,
	Columbia University
Date: Sun, 6 Dec 1992 17:51:19 GMT
Lines: 48


I believe I've found a bug in fgetpos which caused xviewgl (and
presumably anything else which counted on the proper return values of
fgetpos) to puke.

The man says:

                                                 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.


But fgetpos itself said:

fgetpos(fp,pos)
FILE *fp;
fpos_t *pos;
{
     return((*pos = ftell(fp)) != (fpos_t)-1);
}


which returns 1 if (*pos !=-1) and returns 0 (setting errno through
ftell) if (*pos==-1).  A trivial fix:


*** /usr/src/lib/libc/stdio/fgetpos.c.broken    Sat Dec  5 22:30:05 1992
--- /usr/src/lib/libc/stdio/fgetpos.c   Sat Dec  5 22:30:49 1992
***************
*** 44,48 ****
        FILE *fp;
        fpos_t *pos;
  {
!       return((*pos = ftell(fp)) != (fpos_t)-1);
  }
--- 44,48 ----
        FILE *fp;
        fpos_t *pos;
  {
!       return(((*pos = ftell(fp)) != (fpos_t)-1) ? 0:-1);
  }


-- 
Thomas Russo			russo@nile.chem.columbia.edu
Department of Chemistry and Center for Biomolecular Simulation
Columbia University