xfs
[Top] [All Lists]

Re: readdir() problem when using -D_FILE_OFFSET_BITS=64 in gcc

To: Min Yuan <Min.Yuan@xxxxxxxxxxxx>
Subject: Re: readdir() problem when using -D_FILE_OFFSET_BITS=64 in gcc
From: Nathan Scott <nathans@xxxxxxx>
Date: Fri, 21 Sep 2001 10:45:23 +1100
Cc: linux-xfs@xxxxxxxxxxx
In-reply-to: <02c601c141f0$b3f07000$4201a8c0@vytalnet.com>; from Min.Yuan@VytalNet.com on Thu, Sep 20, 2001 at 12:24:15PM -0400
References: <02c601c141f0$b3f07000$4201a8c0@vytalnet.com>
Sender: owner-linux-xfs@xxxxxxxxxxx
User-agent: Mutt/1.2.5i
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


<Prev in Thread] Current Thread [Next in Thread>