Subject: Semantics of lseek system call
To: None <current-users@NetBSD.ORG>
From: Uwe Klaus <uklaus@info015.informatik.uni-leipzig.de>
List: current-users
Date: 11/29/1994 11:39:11
The lseek system call is described as follows:

----------------------------------------------------------------------------
off_t lseek(int fildes, off_t offset, int whence)
   .
   .
   .
Upon successful completion, lseek() returns the resulting offset location
as measured in bytes from the beginning of the file.  Otherwise, a value
of -1 is returned and errno is set to indicate the error.
----------------------------------------------------------------------------

Trying to locate before the begin of a file is accepted without a returning 
error. Run e.g. the following program:

----------------------------------------------------------------------------
#include	<unistd.h>
#include	<sys/syscall.h>
#include	<sys/errno.h>
#include	<fcntl.h>

extern int errno;

main()
{
  int error, offset;
  offset = (int)lseek(open("/netbsd",O_RDONLY,0),-2L,SEEK_SET);
  error  = errno;
  printf("Offset: %d; Errno: %d\n",offset,error);
}
----------------------------------------------------------------------------

This contradicts with the former semantics of lseek which reports the
error EINVAL (invalid argument).

Are these changes intended or is it a bug ?

-------------------------------------------------------------------------------
 Uwe Klaus                             email: uklaus@informatik.uni-leipzig.de
 Department of Computer Science
 University Leipzig                    voice: +49 341 7192389
 Augustusplatz 10/11
 D - 04109 Leipzig                     FAX:   +49 341 7192399
-------------------------------------------------------------------------------