|
CS456 - Systems Programming
Spring 2026
|
Displaying ./code/h4/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"
Here, you will finish the function PrintType.h. refer to man 7 inode for assistance
*/
//needed header files for functions
#include <sys/stat.h>
//takes two strings representing filenames, checks if they're the same file
int fileMatchStr(char **f1, char **f2){
//calling stat on both files
struct stat file1;
struct stat file2;
lstat(f1, &file1);
lstat(f2, &file2);
//check if devices are different
if(file1.st_dev != file2.st_dev)
return 0;
//checking if inodes are different
if(file1.st_ino != file2.st_ino)
return 0;
//if we get here, it's the same file, so return 1
return 1;
}
//checking if file has a certain permission
int checkPermissions(int mode, int perm){
if((mode & perm) == perm)
return 1;
else
return 0;
}
int getType(int mode){
//return what filetype this file is
int type = mode & 0170000;
return type;
}
void printType(int type){
//print message indicating type
//find these values in man 7 inode
//regular file
if(S_IFREG == type)
printf("Regular File\n");
//directory
if(S_IFDIR == type)
printf("Directory\n");
//character device
//block device
//FIFO
//symbolic link
//socket
}
|