lseek/llseek allows the negative offset

From: H . J . Lu (hjl@valinux.com)
Date: Fri Nov 17 2000 - 18:59:13 EST


# gcc x.c
# ./a.out
lseek on -100000: -100000
write: File too large

Should kernel allow negative offsets for lseek/llseek?

-- 
H.J. Lu (hjl@valinux.com)
---
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

extern loff_t llseek (int fd, loff_t offset, int whence);

int main () { int fd = open ("/tmp/foo.out", O_CREAT | O_RDWR, 0600); off_t res, pos; loff_t lres, lpos; char buffer [] = "negative offset";

if (fd < 0) { perror ("open"); return 1; }

pos = -100000; res = lseek (fd, pos, SEEK_SET); if (res == (off_t) -1L) { perror ("lseek"); close (fd); return 1; } printf ("lseek on %ld: %ld\n", pos, res);

if (write (fd, buffer, sizeof (buffer)) != sizeof (buffer)) { perror ("write"); close (fd); return 1; }

lpos = -100000LL; lres = llseek (fd, lpos, SEEK_SET); if (lres == (loff_t) -1L) { perror ("llseek"); close (fd); return 1; }

printf ("llseek on %lld: %lld\n", lpos, lres);

if (write (fd, buffer, sizeof (buffer)) != sizeof (buffer)) { perror ("write"); close (fd); return 1; }

close (fd);

return 0; } - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Nov 23 2000 - 21:00:14 EST