|
Home > Archive > Unix Programming > July 2006 > seek question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hello,
How does one seek beyond the size of an int?
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main( int argc, char argv[] ) {
/* int des,x;
char buf[1] = "\0";
des = open( "./test", O_CREAT|O_RDWR );
for( x=0; x<10; x++ ) {
lseek( des, 1024*1024*1024, SEEK_CUR );
}
write( des, buf, 1 );
close( des );*/
FILE *fp;
int x;
fp=fopen( "./test", "w+" );
for( x=0 ; x<1 ; x++ ) {
fseek( fp, 1024*1024*1024, SEEK_CUR );
}
fprintf( fp, "%c", 0 );
return( EXIT_SUCCESS );
}
--
Regards, Ed :: http://www.linuxwarez.co.uk
Say NO to LONGHORN/VISTA -- google this: "how microsoft is selling
out the public to please hollywood"
| |
| davids@webmaster.com 2006-07-14, 7:19 pm |
|
ed wrote:
> How does one seek beyond the size of an int?
There may be simple, non-portable ways on many UNIXes, but large file
support is now part of POSIX. See, for example:
http://www.unix.org/version2/whatsnew/lfs20mar.html
DS
| |
| Pascal Bourguignon 2006-07-14, 7:19 pm |
| ed <ed@noreply.com> writes:
> How does one seek beyond the size of an int?
Using lseek(2), which allows you to pass a long int.
On Linux, you can use llseek(2) which allows you to pass a long long int.
On some other systems, it's called lseek64(2).
If you want to do it portably, you could use lseek repeatitively.
But the most probable, is that if the OS provides no 64-bit API for
seek, then the file system won't support files bigger than 2 GB...
--
__Pascal Bourguignon__ http://www.informatimago.com/
Small brave carnivores
Kill pine cones and mosquitoes
Fear vacuum cleaner
| |
| Geoff Clare 2006-07-18, 1:29 pm |
| Pascal Bourguignon <pjb@informatimago.com> wrote, on Sat, 15 Jul 2006:
>
> Using lseek(2), which allows you to pass a long int.
No, the offset argument to lseek() has type off_t, not long int.
In some circumstances off_t might be defined as long int, in others
it might be defined as long long int or any other signed integer
type (including plain int).
> On Linux, you can use
> llseek(2) which allows you to pass a long long int. On some other systems,
> it's called lseek64(2).
It is more portable to use lseek() and ensure you select a
compilation environment where off_t is large enough. If long is
64-bit then off_t will almost certainly also be 64-bit. If long
is 32-bit then a 64-bit off_t can typically be obtained by compiling
with -D_FILE_OFFSET_BITS=64, but it can vary. On up-to-date systems
the compiler and linker flags for a standard set of compilation
environments can be queried using getconf.
E.g. on Linux (i386):
$ getconf POSIX_V6_ILP32_OFFBIG_CFLAGS
-D_FILE_OFFSET_BITS=64
$ getconf POSIX_V6_ILP32_OFFBIG_LDFLAGS
On Solaris 10 (SPARC64):
$ getconf POSIX_V6_LP64_OFF64_CFLAGS
-xarch=generic64
$ getconf POSIX_V6_LP64_OFF64_LDFLAGS
-xarch=generic64
(On slightly older systems you might need to use XBS5 instead of
POSIX_V6. Very old systems won't have it at all.)
> If you want to do it portably, you could use lseek repeatitively.
No, that won't work. Since lseek() returns the new (absolute) offset,
you can't seek to offsets larger than the maximum off_t value. If you
try, lseek() with fail with EOVERFLOW.
--
Geoff Clare <netnews@gclare.org.uk>
|
|
|
|
|