From: "H . J . Lu" <hjl@valinux.com>
To: linux kernel <linux-kernel@vger.kernel.org>
Subject: lseek/llseek allows the negative offset
Date: Fri, 17 Nov 2000 15:59:13 -0800 [thread overview]
Message-ID: <20001117155913.A26622@valinux.com> (raw)
# 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/
next reply other threads:[~2000-11-18 0:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-17 23:59 H . J . Lu [this message]
2000-11-18 0:09 ` lseek/llseek allows the negative offset 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20001117155913.A26622@valinux.com \
--to=hjl@valinux.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.