problem of readdir on IA64 suse

Dear Experts,

i am trying to find whether the given name is file or a directory

dirp = opendir(dirname);
direntp = readdir(dirp);
if(direntp->d_type & DT_DIR)
 {
   printf("\n is a dirctory");
 }
else
  {
    //dir_or_file = Mtrue;
   printf("\n not a directory");
  }

it always gives me not a directory but the same code works with red hat 64 bit but not working with suse ia 64 m/c please can you give the reason.

thanks in advance.

are the versions of the libraries you are calling identical on both? Have you looked at both libraries and header files you are using? I am assuming this is C code, as if you were using a shell you could use the built in test function to test for directories or not.

Have you checked any intel documentation?

Dear experts,
thank you for the reply,

no both of them are not the same version.
can you please what is the reason why this is failing in ia64 ,
version i have got 2.6.16,whether it is version dependent or any calls have been replaced,

apart from comparison with Red Hat linux i just wanted to know is it a common issue or specific.

direntp->d_type & DT_DIR

Wait.....regardless of them being 64bit, is the Red Hat machine ia64 (Itanium) or is it x86-64 or some other architecture? If it is not, ia64 is a totally different instruction set with different compilers and libraries and function calls.

Thank you for the reply,

the Red Hat machine is x86-64 not IA64 , so according to you this ia64 architecture is the problem for this, is it so.

That is very possible. Just because they are both 64bit does not mean they both behave the same way.

ia64 is a totally different instruction set with different compile and runtime options. I would look over the documentation as I am not adept at coding enough to make any sort of recommendation here, but it would be a somewhat safe choice to think that different architectures might behave differently with different levels of libraries.

---------- Post updated at 02:45 PM ---------- Previous update was at 08:43 AM ----------

I just spoke to another admin here who is a C coder. His suggestion is remove this:

->d_type & DT_DIR

and make your code look like this:

dirp = opendir(dirname);
direntp = readdir(dirp);
if(direntp)
{
printf("\n is a dirctory");
}
else
{
//dir_or_file = Mtrue;
printf("\n not a directory");
}

And it should work on both

Thanks you for the reply,

i have already replaced my code with

dirp = opendir(dirname);
direntp = readdir(dirp);

which is even working but wanted to know what exactly the resaon of failure on IA64 thats all as you are saying as may be the instruction set difference,

i have to be very carefull with respect to other functions on IA 64 no idea with what it fails.

thanks again.

man 3 readdir gives me this:

       On Linux, the dirent structure is defined as follows:

           struct dirent {
               ino_t          d_ino;       /* inode number */
               off_t          d_off;       /* offset to the next dirent */
               unsigned short d_reclen;    /* length of this record */
               unsigned char  d_type;      /* type of file; not supported
                                              by all file system types */
               char           d_name[256]; /* filename */
           };

So it may not be the architecture per se, but the filesystem. Not something to be depended on in any case.

can anybody tell me what is the exact difference between readdirand readdir_r i have written a small program using readdir which is working fine#include #include int main(){ DIR *dirp; struct dirent *direntp; if (( dirp = opendir ("."))== NULL) printf("Failed to open current directory"); while (( direntp = readdir (dirp))!= NULL ) printf( "%s\n", direntp->d_name );closedir( dirp );}its generating all the files and directory in the current directorynow i want to know how readdir_r works and how is it different from readdirplease show with some example thanks in advance,haris

  1. Please use linebreaks and punctuation. I'm not a grammar nazi, but your post was very difficult to understand at all without them.
  2. Please use code tags for code, [ code ] stuff [ /code] without the extra spaces. It makes it easier to read, and stops the forum from eating your #include tags.
  3. Please make new threads for new topics instead of dumping new questions into tangentially related threads.

readdir() is not context-safe. The data in the pointer it returns gets overwritten every time you call it. If you opened two directories at the same time like this:

struct dirent *p1, *p2;
DIR *d1, *d2;
d1=popen("/bin");
d2=popen("/dev");
p1=readdir(d1);
p2=readdir(d2);

...both p1 and p2 would point to the same data: Whatever the last readdir() found.

readdir_r() avoids this by writing data to wherever you tell it instead of giving you a pointer to its own memory.

struct dirent p1, p2;
DIR *d1, *d2;
d1=popen("/bin");
d2=popen("/dev");
readdir_r(d1, &p1);
readdir(d2, &p2);

This way, p1 and p2 both contain the expected data, instead of just containing whatever the last value read by readdir() was.