Displaying ./code/h2ex/getinfo.c/*
takes a file via command line, prints size and permissions
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
//this is the header file I wrote,
//note that header files i create use quotes as opposed to angle brackets
#include "extras.h"
int main(int argc, char **argv){
// prints usage statement if not enough arguments found
if(argc < 2){
fprintf(stderr, "Usage %s file\n", argv[0]);
exit(1);
}
//opening file, getting file descriptor
int fd = open(argv[1], O_RDONLY);
// checking return value for open
if(fd == -1){
perror("open");
exit(-1);
}
//using the get_fdSize function to get file size
int size = get_fdSize(fd);
//using get_fdPerms to get file permissions
int perms = get_fdPerms(fd);
//print out values
printf("size= %d bytes, perms %o\n", size, perms);
close(fd);
return 0;
}
|