public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: dmeyer@dmeyer.net
To: linux-kernel@vger.kernel.org
Subject: Re: Documenting stat(2)
Date: Thu, 18 Jan 2001 10:54:31 -0500	[thread overview]
Message-ID: <20010118105430.A4461@jhereg.dmeyer.net> (raw)
In-Reply-To: <20010118020528.A16871@jhereg.dmeyer.net>
In-Reply-To: <3A66D93C.8090500@AnteFacto.com>

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/

  reply	other threads:[~2001-01-18 15:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-18  7:05 Documenting stat(2) dmeyer
2001-01-18 11:53 ` Padraig Brady
2001-01-18 15:54   ` dmeyer [this message]
2001-01-18 20:52   ` Igmar Palsenberg
2001-01-19  1:00     ` Mike Castle
2001-01-20 19:39       ` Igmar Palsenberg
2001-01-19 10:18   ` Andreas Schwab
  -- strict thread matches above, loose matches on Subject: below --
2001-01-18  5:28 Eric S. Raymond
2001-01-18  6:46 ` Linus Torvalds
2001-01-18 12:56 ` Felix von Leitner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010118105430.A4461@jhereg.dmeyer.net \
    --to=dmeyer@dmeyer.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox