CS350 COS
COS
Loading...
Searching...
No Matches
stat.c
Go to the documentation of this file.
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <time.h>
6#include <sys/stat.h>
7
8// Castor Only
9#include <syscall.h>
10
11int
12main(int argc, const char *argv[])
13{
14 int status;
15 struct stat sb;
16
17 if (argc < 2) {
18 fputs("Requires an argument\n", stdout);
19 return 1;
20 }
21
22 if (argc > 2) {
23 fputs("Too many arguments, expected one\n", stdout);
24 return 1;
25 }
26
27 status = OSStat(argv[1], &sb);
28 if (status != 0) {
29 fputs("Cannot stat file\n", stdout);
30 return 0;
31 }
32
33 printf(" File: \"%s\"\n", argv[1]);
34 printf(" Size: %d\n", sb.st_size);
35 printf("Blocks: %d\n", sb.st_blocks);
36 printf(" Inode: %d\n", sb.st_ino);
37
38 return 0;
39}
40
int OSStat(const char *path, struct stat *sb)
Definition: syscall.c:89
int main(int argc, const char *argv[])
Definition: stat.c:12
off_t st_size
Definition: stat.h:11
ino_t st_ino
Definition: stat.h:6
size_t st_blocks
Definition: stat.h:12
Definition: stat.h:5
int printf(const char *fmt,...)
Definition: printf.c:212
int fputs(const char *str, FILE *fh)
Definition: file.c:132
FILE * stdout
Definition: file.c:16