At Thu, 13 Jan 2005 05:01:50 -0800, Johan Walles wrote: > According to the man page: > > " > RETURN VALUE > 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 indi- > cate the error. > " > > I.e. fseek() should return 0 on success or -1 on failure. > > You're saying: > > " > file->f_pos always > becomes minus values. Return value from lseek() and fseek() functions > are negative, but from POSIX or ANSI point of view, those are > interpreted as error condition. > " > > Why would the actual file position affect the return value from > fseek()? Especially without > being a bug (possibly in the man page, but still)?
This is special case. Your program passed offset as negative, and kernel should return it's EINVAL case. However mem_lseek is special, and it accepts even negative value. So glibc is worked as undefined behavior. The current glibc _IO_new_file_seekoff() checks return value of _IO_file_seek (thus lseek64) as follows: result = _IO_SYSSEEK (fp, new_offset, 0); if (result < 0) return EOF; In this case result < 0 && result != EOF. But it should not be interpreted because result is also off_t type and the offset pointer becomes negative position. I forgot to write in previous mail that you should use lseek system call directory instead of fseek/fseeko to handle such special offset condition. Regards, -- gotom -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]