[lkml]   [2001]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Documenting stat(2)
In article <> 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

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

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-

and a short test program:

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

struct stat buf;

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


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

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
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  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