Chapter Contents |
Previous |
Next |
lstat |
Portability: | POSIX.1 conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <sys/types.h> #include <sys/stat.h> int lstat(const char *pathname, struct stat *buf);
DESCRIPTION |
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>
:
The pathname must be specified as an USS 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 USS 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.
RETURN VALUE |
lstat
returns 0 if it is successful and -1 if it is not successful.
EXAMPLE |
#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: %d\n", (int) info.st_ino); printf("dev id: %d\n", (int) info.st_dev); printf("user id: %d\n", (int) info.st_uid); printf("links: %d\n", info.st_nlink); printf("file size: %d\n", (int) info.st_size); printf("mode: %08x\n", info.st_mode); printf("created: %s", ctime(&info.st_createtime)); } } unlink(flname); unlink(lkname); } }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.