Help C program in linux help help help !!!!!!!

Help C program in linux help help help !!!!!!!

Post by Patric » Tue, 19 May 1998 04:00:00



Hello Everybody

if the file is a symbolic link , display where it points to (readlink)
how to use readlink in C code

How to show all the file information under current directory and then output
to a file  use C code

Thank You

Patrick

 
 
 

Help C program in linux help help help !!!!!!!

Post by Eunseok Cho » Tue, 19 May 1998 04:00:00


Here is a sample source.

#include <dirent.h>
#include <sys/stat.h>

/*------------------------------------------------------------------------*/
 main ()
 {
     DIR           *dirp;
     struct dirent *dntp;
     struct stat   stbuf;
     int           rtn;
     int           rtn;
     char          linkname[256];

     if ( (dirp  = opendir ( "." )) == NULL ) {
           perror ( "opendir" );
           exit (1);
     }
     while ( (dntp = readdir (dirp)) != NULL ) {
              rtn = lstat ( dntp->d_name, &stbuf );
              if  ( rtn < 0 ) continue;
              printf ( "%8d %s", stbuf.st_size, dntp->d_name );
              if ( (stbuf.st_mode&0xF000) == 0xA000 ) {
                   rtn = readlink ( dntp->d_name, linkname, 255 );
                   if ( rtn >= 0 ) {

                   }
              }
              putchar ( '\n' );
     }
     closedir (dirp);
 }

/*------------------------------------------------------------------------*/


Quote:>Hello Everybody

>if the file is a symbolic link , display where it points to (readlink)
>how to use readlink in C code

>How to show all the file information under current directory and then
output
>to a file  use C code

>Thank You

>Patrick