Subject: Re: Semantics of lseek system call
To: None <mycroft@gnu.ai.mit.edu>
From: Kenneth Stailey <kstailey@leidecker.gsfc.nasa.gov>
List: current-users
Date: 12/01/1994 10:56:37
NeXTSTEP 3.0
test program:
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#if NORMAL_POSIX_SYSTEM
#include <unistd.h>
#else
/* whence values for lseek(2) */
#define SEEK_SET 0 /* set file offset to offset */
#define SEEK_CUR 1 /* set file offset to current plus offset */
#define SEEK_END 2 /* set file offset to EOF plus offset */
#endif
extern int errno;
void move_it(off_t where, int how)
{
int error;
off_t offset;
static int fd = -1;
if (fd == -1) {
if ((fd = open("/vmunix", O_RDONLY)) < 0) {
perror("open");
exit(1);
}
}
offset = (off_t)lseek(fd, where, how);
error = errno;
printf("Offset: %d; Errno: %d\n", offset, error);
}
main()
{
move_it(20, SEEK_SET);
move_it(-10, SEEK_CUR);
move_it(-10, SEEK_CUR);
move_it(-10, SEEK_CUR);
move_it(0, SEEK_END);
move_it(-10, SEEK_CUR);
}
------------------------- results ---------------------
kstailey@leidecker(8)$ ./seektest
Offset: 20; Errno: 0
Offset: 10; Errno: 0
Offset: 0; Errno: 0
Offset: -10; Errno: 0
Offset: 802493; Errno: 0
Offset: 802483; Errno: 0
It's not an error here either!
Ken