akaros/tests/stat.c
<<
>>
Prefs
   1#include <stdio.h> 
   2#include <sys/types.h>
   3#include <sys/stat.h>
   4#include <fcntl.h>
   5#include <unistd.h>
   6#include <errno.h>
   7#include <stdlib.h>
   8#include <string.h>
   9
  10int main(int argc, char *argv[]) 
  11{ 
  12        int retval;
  13
  14        if (argc < 2) {
  15                printf("Prints out stats for a file\n");
  16                printf("Usage: stat FILENAME\n");
  17                return -1;
  18        }
  19        struct stat st = {0};
  20
  21        retval = stat(argv[1], &st);
  22        if (retval < 0) {
  23                perror("Stat failed");
  24        } else {
  25                printf("STAT RESULTS\n---------------------\n");
  26                printf("dev       : %d\n", st.st_dev);
  27                printf("ino       : %d\n", st.st_ino);
  28                printf("mode      : %o(oct)\n", st.st_mode);
  29                printf("nlink     : %d\n", st.st_nlink);
  30                printf("uid       : %d\n", st.st_uid);
  31                printf("gid       : %d\n", st.st_gid);
  32                printf("rdev      : %d\n", st.st_rdev);
  33                printf("size      : %d\n", st.st_size);
  34                printf("blksize   : %d\n", st.st_blksize);
  35                printf("blocks    : %d\n", st.st_blocks);
  36                printf("atime     : %d\n", st.st_atime);
  37                printf("mtime     : %d\n", st.st_mtime);
  38                printf("ctime     : %d\n", st.st_ctime);
  39        }
  40}
  41