hi,
On Thu, Sep 20, 2001 at 12:24:15PM -0400, Min Yuan wrote:
> Redhat7.1 supports large file(>2GB), but you have to add
> -D_FILE_OFFSET_BITS=64 to gcc
>
> The following is a very simple program:
>
> #include <sys/types.h>
> #include <stdio.h>
> #include <dirent.h>
>
> int main() {
> DIR *dr;
> struct dirent *dent;
> dr = opendir("/var/run");
> while ((dent = readdir(dr)) != NULL) {
> printf("inode:%d and d_name:%s\n", dent->d_ino, dent->d_name);
> }
> return 0;
> }
Your program has a bug in it. ;)
When compiled with -D_FILE_OFFSET_BITS=64 you need to change the line:
printf("inode:%d and d_name:%s\n", dent->d_ino, dent->d_name);
^^
to:
printf("inode:%lld and d_name:%s\n", dent->d_ino, dent->d_name);
^^^^
and then you should find it works as expected.
If you want the same source to work correctly either with or
without the compile option, you need to use the second printf
but cast "dent->d_ino" to "(long long)dent->d_ino".
To be even more correct, you should be using unsigned long long
(%llu) because __ino64_t maps to __u_quad_t which is unsigned.
Hope this helps.
cheers.
--
Nathan
|