Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: symlink destination



Uvator,

There is a readlink(2) system call on HP/UX.

So.....

#include <unistd.h>
#include <limits.h>
#include <stdio.h>
 
int main(int argc, char** argv) {
        char buf[PATH_MAX + 1];
 
        if ( (argc < 2) || (!argv[1]) ) {
                fprintf(stderr, "%s: usage: <symlink>\n", argv[0]);
                return 1;
        }
 
        if ( readlink(argv[1], buf, PATH_MAX) == -1) {
                perror("readlink");
                return 1;
        }
 
        printf("%s\n", buf);
 
        return 0;
} 

I can compile this for you on HP/UX 10.2 if you like.

Regards,
Jake

Viktor Pavlenko wrote:
> 
> A shell programming question:
> 
> Is there a way to find out the destination of a symbolic link (the
> file it links to) from a sh script? Parsing the output of `ls -l' is a
> possibility but it doesn't feel right.
> 
> Thanks.
> 
> Viktor
> 
> -----------------------------------------------------------------------
> Next Technical Meeting: November 11 (Sat) 13:30  Place: LinuxProbe Hall
> Next Nomikai (and Bonenkai!): December 15 (Fri)
> -----------------------------------------------------------------------
> more info: http://www.tlug.gr.jp           Sponsor: Global Online Japan


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links