-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir.c
64 lines (60 loc) · 1.44 KB
/
dir.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
CPE 357 Lab05
Author: Dylan Baxter (dybaxter)
File: dir.c
Description: This file contains functions relating to Directory
operations
*/
#include"dir.h"
/*Checks is the current directory is the root directory*/
int isBaseDir(){
struct stat sb1;
struct stat sb2;
/*Open Current Directory*/
if(-1 == stat(".",&sb1)){
perror("Home stat fail");
exit(EXIT_FAILURE);
}
if(-1 == stat("..",&sb2)){
perror("Home stat fail");
exit(EXIT_FAILURE);
}
if(sb1.st_dev == sb2.st_dev && sb1.st_ino == sb2.st_ino){
return 1;
}
else{
return 0;
}
}
/*Checks if the stats of 2 file objects are equal*/
int statEquals(struct stat sb1, struct stat sb2){
if(sb1.st_dev == sb2.st_dev && sb1.st_ino == sb2.st_ino){
return 1;
}
else{
return 0;
}
}
/*Personal Implementation of strncat() functinoality*/
void limitConcat(char* dest, char* lim, int maxDestSize){
int i = strlen(dest);
int limSize = strlen(lim);
int charsWritten = 0;
while(i < maxDestSize && charsWritten < limSize){
dest[i] = lim[charsWritten];
i++;
charsWritten++;
}
dest[i] = '\0';
}
/*Personal Implementation of strdup functinoality*/
char* mystrdup(char* pt){
int ptLen = strlen(pt);
char* dup = (char*)malloc(sizeof(char)*(ptLen+1));
int i;
for(i=0; i < ptLen; i++){
dup[i] = pt[i];
}
dup[i] = '\0';
return dup;
}