Avatar of eng_h
 asked on

stimulate ls -l

Hi. If anyone can help me with ls –l  I appreciate that. I've written program in c to stimulate ls -l.
 it's works well except the link. I need to print out the line like this
 lrwxrwxrwx 1 admin admin 11 Feb 27 19:08 figC.18 -> ipc/fifo1.c.  
 but it’s just print   lrwxrwxrwx 1 admin admin 11 Feb 27 19:08 figC.18.  I need to make my program print the link also.
Thanks for your help

Avatar of undefined
Last Comment

8/22/2022 - Mon

You saw https://www.experts-exchange.com/questions/20416430/Emulating-the-unix-LS-command-in-C.html , right?

Also, look at http://www.ibm.com/developerworks/aix/library/au-unix-readdir.html :

•S_ISBLK(mode) -- Is this a block special file? (usually a block-based device of some sort)
•S_ISCHR(mode) -- Is this a character special file? (again, usually a character-based device of some sort)
•S_ISDIR(mode) -- Is this a directory?
•S_ISFIFO(mode) -- Is this a pipe or FIFO special file?
•S_ISLNK(mode) -- Is this a symbolic link?
•S_ISREG(mode) -- Is this a regular file?

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

The solution was so helpful.

I used this part  in my program
                  char targetName[PATH_MAX + 1];
                if( readlink( pathName, targetName, PATH_MAX ) != -1 )
                    printf( "\t%s -> %s\n", pathName, targetName );
                      printf( "\t%s -> (invalid symbolic link!)\n", pathName );

and it worked with me.
Thanks so much for your time phoffric !!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

Glad you found it helpful.