This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, fortran] PR22539 implement FSEEK intrinsic

At 11:43 AM 5/1/2007, Daniel Franke wrote:
On Tuesday 01 May 2007 19:35:02 Brooks Moses wrote:
> > +  else if (*whence == 0)
> > +    sseek(u->s, *offset);                       /* SEEK_SET */
> > +  else if (*whence == 1)
> > +    sseek(u->s, file_position(u->s) + *offset); /* SEEK_CUR */
> > +  else if (*whence == 2)
> > +    sseek(u->s, file_length(u->s) + *offset);   /* SEEK_END */
> > +  else if (status)
> > +    *status = -1;  /* EINVAL */
> > +}
> I don't see how this returns a nonzero status if *offset is outside the
> limits of the file such that the sseek fails.  How does that work?

It does not fail.
The sseek macro, eventually, calls lseek(2):

  "The lseek() function allows the file offset to be set beyond the end of
  the file (but this does not change the size of the file).  If  data  is
  later written at this point, subsequent reads of the data in the gap (a
  "hole") return null bytes ('\0') until data is  actually  written  into
  the gap."

That accounts for when the offset is too large. However, what about the other end of the file, if we have an overall offset that's negative?

According to the lseek(2) documentation on my computer, lseek will fail with an EINVAL error "if the resulting file offset would be negative", as well as for invalid values of whence.

- Brooks

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]