public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* lseek/llseek allows the negative offset
@ 2000-11-17 23:59 H . J . Lu
  2000-11-18  0:09 ` H . J . Lu
  0 siblings, 1 reply; 9+ messages in thread
From: H . J . Lu @ 2000-11-17 23:59 UTC (permalink / raw)
  To: linux kernel

# 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/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2000-11-20  2:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-17 23:59 lseek/llseek allows the negative offset H . J . Lu
2000-11-18  0:09 ` H . J . Lu
2000-11-18 18:25   ` Andrea Arcangeli
2000-11-18 22:41     ` H . J . Lu
2000-11-19  0:45     ` Andrea Arcangeli
2000-11-19  1:20       ` H . J . Lu
2000-11-19  3:07         ` Andrea Arcangeli
2000-11-19  3:46           ` H . J . Lu
2000-11-20  1:56         ` Andrea Arcangeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox