lkml.org 
[lkml]   [2001]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Documenting stat(2)
In article <3A66D93C.8090500@AnteFacto.com> you write:
> Nope stat should return the details of the symlink
> whereas lstat should return the details of the symlink target.

Not according to my manpages. From stat(2):

stat stats the file pointed to by file_name and fills in
buf.

lstat is identical to stat, only the link itself is
stated, not the file that is obtained by tracing the
links.

Actually, the Solaris manpage is clearer:

The lstat() function obtains file attributes similar to
stat(), except when the named file is a symbolic link; in
that case lstat() returns information about the link, while
stat() returns information about the file the link refer-
ences.

and a short test program:

#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

main()
{
struct stat buf;

stat("stattest.c",&buf);
printf("stat original file: %d\n",buf.st_size);

symlink("stattest.c","a_symlink");

stat("a_symlink",&buf);
printf("stat symlink: %d\n",buf.st_size);

lstat("a_symlink",&buf);
printf("lstat symlink: %d\n",buf.st_size);
}

jhereg|dmeyer|~/dl> ./stattest
stat original file: 358
stat symlink: 358
lstat symlink: 10

stat clearly is giving the size of the target, and lstat the size of
the link.

--
David M. Meyer
dmeyer@dmeyer.net
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:25    [W:0.090 / U:5.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site