|
CS456 - Systems Programming
Spring 2026
|
Displaying ./code/h2ex/extras.h
/*
This custom header file has functions written by me for use in other programs
To use in your source code add this line: #include "extras.h"
*/
//needed header files for functions
#include <sys/stat.h>
//definining stat structure for functions that use the stat structure
struct stat st;
//this function gets the size of a file
int get_fdSize(int fd){
//fstat is a fuction that gets the status of a file(from a file descriptor) and stores it in st.
fstat(fd, &st);
return st.st_size; //returning the value in the size field
}
//gets the file opermissions
int get_fdPerms(int fd){
fstat(fd, &st);
//binary AND'ing the octal value 0777 with the mode field to get the permissions
//then returning that value
return st.st_mode & 0777;
}
|