struct stat {
dev_t st_dev; /* device */
ino_t st_ino; /* inode */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device type (if inode device) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for filesystem I/O */
blkcnt_t st_blocks; /* number of blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last change */
};
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
int i;
struct stat buf;
char *ptr;
for (i = 1 ; i < argc; i++) {
printf("%s : ", argv[i]);
if (lstat(argv[i], &buf) < 0) {
perror("lsat... ");
continue;
}
if (S_ISREG(buf.st_mode)) ptr = "regular";
else if (S_ISDIR(buf.st_mode)) ptr = "directory";
else if (S_ISCHR(buf.st_mode)) ptr = "ch special";
else if (S_ISBLK(buf.st_mode)) ptr = "block special";
else if (S_ISFIFO(buf.st_mode)) ptr = "fifo";
else if (S_ISLNK(buf.st_mode)) ptr = "symbolic link";
else if (S_ISSOCK(buf.st_mode)) ptr = "socket";
else ptr = "* unknown";
printf ("%s\n", ptr);