Hi,

A linux app that I want to build on SX using sunpro uses "struct
dirent" that has non-standard gcc extensions (ex: d_type) that are not
available in sunpro.
I wrote a test program using stat and mask mode S_IFMT as defined
sys/stat.h to get a substitute(snippet below), but the output does not
recognize symlinks. Why so?

Code snippet
-----------------------
/* Loop through directory entries. */
while ((dp = readdir(dir)) != NULL) {
        /* Get file type information. */
        if (stat(dp->d_name, &statbuf) == -1)
                continue;
        filetypeInformation = statbuf.st_mode & S_IFMT ;
        printf("TYPE = %x  %20s    ",filetypeInformation, dp->d_name);
        switch(filetypeInformation)
        {
                case S_IFREG : printf("Regular file. ");                        
break;
                case S_IFDIR : printf("Directory. ");                           
break;
                case S_IFLNK : printf("Symbolic link. ");                       
break;
                case default : printf("I do not care about 
block/chr/fifo/socket. "); break;
        }
        printf("\n");
}

Output
------------------
bash-3.00$ ./a.out
TYPE = 4000                     .     Directory.
TYPE = 4000                    ..     Directory.
TYPE = 8000           hi.softlink     Regular file.
TYPE = 8000                 a.out     Regular file.
TYPE = 8000                    hi     Regular file.
TYPE = 8000            filetype.c     Regular file.
TYPE = 8000           hi.hardlink     Regular file.
TYPE = 8000           filetype2.c     Regular file.

hi.hardlink and hi.softlink are links to hi, but they are shown as Regular file.

regards
Shiv
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to