Differences between version 8 and previous revision of fstat(2).
Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 8 | Last edited on Wednesday, November 6, 2002 11:48:56 pm | by PerryLorier | Revert |
Older page: | version 7 | Last edited on Wednesday, November 6, 2002 11:22:41 pm | by PerryLorier | Revert |
@@ -150,9 +150,8 @@
#include <string.h> /* for strerror(3) */
#include <stdio.h> /* for printf(3) etc */
#include <time.h> /* for asctime(3) */
#include <unistd.h> /* for close(2) */
-
int do_stat(char *filename)
{
int fd;
@@ -182,19 +181,40 @@
else if (S_ISFIFO(statbuf.st_mode)) printf("Fifo");
else if (S_ISLNK(statbuf.st_mode)) printf("Symbolic Link");
else if (S_ISSOCK(statbuf.st_mode)) printf("Socket");
printf(": \"%s\"\n",filename);
- printf("Size: %-17i
Blocks: %-10i Block Size: %-10i\n",
+ printf("Size: %-20i
Blocks: %-10i Block Size: %-10i\n",
(int)statbuf.st_size,
(int)statbuf.st_blocks,
(int)statbuf.st_blksize);
- printf("Device: 0x%04llx
(%6llu
) Inode: %-10li Links: %i\n",
+ printf("Device: 0x%06llx
(%7llu
) Inode: %-10li Links: %i\n",
statbuf.st_dev,
statbuf.st_dev,
statbuf.st_ino,
statbuf.st_nlink);
- printf("Access: (%o
) User ID: %i (%s) Group ID: %i (%s)\n",
- statbuf.st_mode & ~
S_IFMT
,
+ printf("Access: %c%c%c%c%c%c%c%c%c
(%-5o
) User ID: %i(%s) Group ID: %i(%s)\n",
+ statbuf.st_mode & S_IRUSR ? 'r' : '-',
+ statbuf.st_mode & S_IWUSR ? 'w' : '-',
+ statbuf.st_mode & S_ISUID ? (
+ statbuf.st_mode & S_IXUSR ? 's' : 'S'
+ ) : (
+ statbuf.st_mode & S_IXUSR ? 'x' : '-'
+ ),
+ statbuf.st_mode & S_IRGRP ? 'r' : '-',
+ statbuf.st_mode & S_IWGRP ? 'w' : '-',
+ statbuf.st_mode & S_ISGID ? (
+ statbuf.st_mode & S_IXGRP ? 's' : 'S'
+ ) : (
+ statbuf.st_mode & S_IXGRP ? 'x' : '-'
+ ),
+ statbuf.st_mode & S_IROTH ? 'r' : '-',
+ statbuf.st_mode & S_IWOTH ? 'w' : '-',
+ statbuf.st_mode & S_ISVTX ? (
+ statbuf.st_mode & S_IXGRP ? 't' : 'T'
+ ) : (
+ statbuf.st_mode & S_IXGRP ? 'x' : '-'
+ ),
+ statbuf.st_mode
,
statbuf.st_uid,getpwuid(statbuf.st_uid)->pw_name,
statbuf.st_gid,getpwuid(statbuf.st_gid)->pw_name);
printf("Access Time: %s", ctime(&statbuf.st_atime));
printf("Modify Time: %s", ctime(&statbuf.st_mtime));