logoISU  

CS 456 - Systems Programming

Spring 2024

Displaying ./code/feb01/stat1.c

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>

int main (int argc, char **argv){

	if (argc < 2){
	   fprintf(stderr, "Usage %s file\n",argv[0]);
	   exit(1);
	}

	struct stat st;

	int rt = stat(argv[1], &st);

	if(rt < 0){
		perror("Error");
		exit(-1);
	}

	printf("Size is %lld bytes\n", st.st_size);
	printf("uid of owner: %d\n", st.st_uid);

	if(S_ISREG(st.st_mode))
		printf("This is a Regular File\n");

	return 0;

}