00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "defs.h"
00022
00023 const char *get_file_type(mode_t mode)
00024 {
00025 if (S_ISBLK(mode))
00026 return "block special file";
00027 if (S_ISCHR(mode))
00028 return "character special file";
00029 if (S_ISDIR(mode))
00030 return "directory";
00031 if (S_ISFIFO(mode))
00032 return "pipe or FIFO special file";
00033 if (S_ISREG(mode))
00034 return "regular file";
00035 if (S_ISLNK(mode))
00036 return "symbolic link";
00037 if (S_ISSOCK(mode))
00038 return "socket";
00039 return "unknown type";
00040 }
00041
00042 int main(void)
00043 {
00044 struct stat sbuf;
00045
00046 (void)unlink("a.tmp");
00047 (void)creat("b.tmp", PERM_FILE);
00048
00049 if (symlink("b.tmp", "a.tmp") == -1)
00050 syserr("symlink");
00051 if (link("b.tmp", "c.tmp") == -1)
00052 syserr("link");
00053
00054 if (stat("b.tmp", &sbuf) == -1)
00055 syserr("stat 1");
00056 printf("stat(\"b.tmp\"):\n");
00057 printf("\tst_ino = %u\n", (unsigned)sbuf.st_ino);
00058 printf("\tst_nlink = %u\n", (unsigned)sbuf.st_nlink);
00059 printf("\tst_mode = 0%o\n", (unsigned)sbuf.st_mode);
00060 printf("\tfile type: %s\n", get_file_type(sbuf.st_mode));
00061
00062 if (stat("a.tmp", &sbuf) == -1)
00063 syserr("stat 2");
00064 printf("\nstat(\"a.tmp\"):\n");
00065 printf("\tst_ino = %u\n", (unsigned)sbuf.st_ino);
00066 printf("\tst_nlink = %u\n", (unsigned)sbuf.st_nlink);
00067 printf("\tst_mode = 0%o\n", (unsigned)sbuf.st_mode);
00068 printf("\tfile type: %s\n", get_file_type(sbuf.st_mode));
00069
00070 if (lstat("a.tmp", &sbuf) == -1)
00071 syserr("lstat 1");
00072 printf("\nlstat(\"a.tmp\"):\n");
00073 printf("\tst_ino = %u\n", (unsigned)sbuf.st_ino);
00074 printf("\tst_nlink = %u\n", (unsigned)sbuf.st_nlink);
00075 printf("\tst_mode = 0%o\n", (unsigned)sbuf.st_mode);
00076 printf("\tfile type: %s\n", get_file_type(sbuf.st_mode));
00077
00078 if (stat("c.tmp", &sbuf) == -1)
00079 syserr("stat 3");
00080 printf("\nstat(\"c.tmp\"):\n");
00081 printf("\tst_ino = %u\n", (unsigned)sbuf.st_ino);
00082 printf("\tst_nlink = %u\n", (unsigned)sbuf.st_nlink);
00083 printf("\tst_mode = 0%o\n", (unsigned)sbuf.st_mode);
00084 printf("\tfile type: %s\n", get_file_type(sbuf.st_mode));
00085
00086 if (lstat("c.tmp", &sbuf) == -1)
00087 syserr("lstat 2");
00088 printf("\nlstat(\"c.tmp\"):\n");
00089 printf("\tst_ino = %u\n", (unsigned)sbuf.st_ino);
00090 printf("\tst_nlink = %u\n", (unsigned)sbuf.st_nlink);
00091 printf("\tst_mode = 0%o\n", (unsigned)sbuf.st_mode);
00092 printf("\tfile type: %s\n", get_file_type(sbuf.st_mode));
00093
00094 exit(EXIT_SUCCESS);
00095 }