D
Deleted member 67440
Guest
I ran into a little problem.
The /home directory is, very often, a symbolic link
In this example it is quite clear
The readlink(2) function transforms /home into usr/home, and OK
BUT
the path, in order to access it, should actually be
/usr/home
The first / is missing (arrrrgggghhh!!)
Is there some function (gcc) that allows to get the "really full" path of a link?
The /home directory is, very often, a symbolic link
In this example it is quite clear
Code:
root@aserver:/tmp/zp # ls -l /
total 173
-rw-r--r-- 2 root wheel 957 Oct 20 2018 .cshrc
-rw-r--r-- 2 root wheel 474 Oct 20 2018 .profile
-rw------- 1 root wheel 1024 Aug 8 2017 .rnd
dr-xr-xr-x+ 3 root wheel 3 Jul 21 2017 .zfs
-r--r--r-- 1 root wheel 6197 Oct 20 2018 COPYRIGHT
drwxr-xr-x 2 root wheel 47 Dec 27 16:16 bin
drwxr-xr-x 9 root wheel 55 Nov 23 19:09 boot
dr-xr-xr-x 35 root wheel 512 Nov 23 20:10 dev
-rw------- 1 root wheel 4096 Nov 23 19:10 entropy
drwxr-xr-x 27 root wheel 114 Jan 16 2019 etc
lrwxr-xr-x 1 root wheel 8 Aug 8 2017 home -> usr/home
The readlink(2) function transforms /home into usr/home, and OK
BUT
the path, in order to access it, should actually be
/usr/home
Code:
root@aserver:/tmp/zp # readlink /home
usr/home
Code:
string my_readlink(std::string const& path)
{
char buf[PATH_MAX];
ssize_t len=readlink(path.c_str(),buf,sizeof(buf)-1);
if (len!=-1)
{
buf[len] = '\0';
return std::string(buf);
}
return path;
}
Is there some function (gcc) that allows to get the "really full" path of a link?