

#include <sys/types.h> #include <sys/stat.h> int lstat(const char *pathname, struct stat *buf);
lstat gets status information about a file or symbolic link.
pathname is the file. buf is the memory area for storing the
status information.
The status information is returned in the stat structure defined
in <sys/stat.h>:
mode_t st_mode
ino_t st_ino
dev_t st_dev
nlink_t st_nlink
uid_t st_uid
gid_t st_gid
off_t st_size
time_t st_atime
time_t st_ctime
time_t st_mtime
The pathname must be specified as an OpenEdition HFS file. For programs
not compiled with the posix option, a style prefix may be required.
See Low-level and Standard I/O for information on specifying OpenEdition filenames.
The <sys/stat.h> header file contains a collection of macros that
you can use to examine properties of a mode_t value from the
st_mode field. For a list of these macros, see the documentation on
the fstat function.
lstat returns 0 if it is successful
and - 1 if it is not successful.
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
main()
{
char flname[] ="link.file";
char lkname[] ="link.example";
int fd;
struct stat info;
/* Create a file for linking. */
if ((fd = open(flname,O_CREAT)) < 0)
perror("open() error");
else {
close(fd);
/* Check the status of the file. */
puts("Status before link:");
system("ls -il link.*");
/* Create an alternative path for the existing file. */
if (link(flname,lkname) != 0) {
perror("link() error");
unlink(flname);
}
else {
puts("Status after linking:");
system("ls -il link.*");
if (lstat(lkname, &info) != 0)
perror("lstat() error");
else {
printf("nlstat() for link %s returned:n", lkname);
printf("inode: %dn", (int) info.st_ino);
printf("dev id: %dn", (int) info.st_dev);
printf("user id: %dn", (int) info.st_uid);
printf("links: %dn", info.st_nlink);
printf("file size: %dn", (int) info.st_size);
printf("mode: %08xn", info.st_mode);
printf("created: %s", ctime(&info.st_createtime));
}
}
unlink(flname);
unlink(lkname);
}
}
fstat, stat, symlink
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.