From: Nicle <ynicle@gmail.com>
To: Michal Nazarewicz <mina86@tlen.pl>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: How to lseek the larger file > 2GB under linux
Date: Mon, 18 May 2009 12:38:50 +0800 [thread overview]
Message-ID: <d13fb4990905172138y2a30ed5cq412874621f605282@mail.gmail.com> (raw)
In-Reply-To: <d13fb4990905172137l1a4a9c92k47988da28ad4b7b1@mail.gmail.com>
Hi Michal,
The "LL" does make my prog work :)
Thanks for your help!!
Best Regard
Nicle Yang
>
>
> 2009/5/18 Michal Nazarewicz <mina86@tlen.pl>
>>
>> Nicle <ynicle@gmail.com> writes:
>> > I have a file > 2GB, and my job is seeking the file to pos: 2.1G.
>> > But, it seems that the lseek64 doesn't work.
>>
>> > #define _LARGEFILE64_SOURCE
>> > #include ...
>> >
>> > int main() {
>> > int fd = -1;
>> > long long pos = (long long) 2*1024*1024*1024 + 10; // over 2G
>>
>> A long shot, but try (2LL << 30) (the "LL" is important). I don't
>> expect that will make it work but if you're out of ideas... ;)
>>
>> > fd = open(FILENAME, O_WRONLY|O_LARGEFILE);
>> > if (fd < 0) { /* ... */ }
>> >
>> > if (lseek64(fd, pos, SEEK_SET) < 0)
>> > fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
>> >
>> > return 0;
>> > }
>>
>> > Then the building cmd: gcc -o test test.c -D_FILE_OFFSET_BITS=64
>> > Output: > Failed seeking to 2147483658, Success.
>> >
>> > The return val of lseek64 was "<0", but the strerror told me "Success".
>>
>> BTW. The following works fine for me:
>>
>> #v+
>> #define _LARGEFILE64_SOURCE
>>
>> #include <errno.h>
>> #include <fcntl.h>
>> #include <stdio.h>
>> #include <string.h>
>> #include <sys/stat.h>
>> #include <sys/types.h>
>> #include <unistd.h>
>>
>> #define RUN(expr) if ((expr) < 0) { perror(#expr); return 1; } else (void)0
>>
>> int main(void) {
>> const long long pos = (2LL << 30) + 10;
>> int fd;
>>
>> RUN(fd = open("deleteme", O_WRONLY | O_LARGEFILE | O_CREAT, 0600));
>> RUN(lseek64(fd, pos, SEEK_SET));
>> RUN(write(fd, "a", 1));
>> return 0;
>> }
>> #v-
>>
>> --
>> Best regards, _ _
>> .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
>> ..o | Computer Science, Michal "mina86" Nazarewicz (o o)
>> ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2009-05-18 4:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <d13fb4990905170840j6ac84b0ej758582e5ffb5fa8c@mail.gmail.com>
2009-05-17 15:42 ` How to lseek the larger file > 2GB under linux Nicle
2009-05-17 16:20 ` Michal Nazarewicz
[not found] ` <d13fb4990905172137l1a4a9c92k47988da28ad4b7b1@mail.gmail.com>
2009-05-18 4:38 ` Nicle [this message]
2009-05-17 18:10 ` LDB
2009-05-17 20:09 ` Glynn Clements
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=d13fb4990905172138y2a30ed5cq412874621f605282@mail.gmail.com \
--to=ynicle@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=mina86@tlen.pl \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).