forked from gpellicci/Secure-File-Storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileManipulation.h
More file actions
47 lines (39 loc) · 890 Bytes
/
fileManipulation.h
File metadata and controls
47 lines (39 loc) · 890 Bytes
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
const uint64_t maxFileSize = (1ULL << 32);
bool getFileSize( std::string path, uint64_t &size){
//in case of error:
//size = 0
//return false;
size = 0;
// get the file stream
FILE* pFile = fopen( path.c_str(), "rb" );
if(pFile == NULL){
perror("Could not open the file. Error");
return false;
}
// set the file pointer to end of file
int ret = fseek( pFile, 0, SEEK_END );
if(ret < 0){
perror("Could not seek to the end of the file. Error:\n");
return false;
}
// get the file size
long long int tmp = ftell(pFile);
if(tmp < 0){
perror("ftell() Error:");
return false;
}
/* check 4GB costraint */
if(tmp > maxFileSize){
printf("too big file. Error:\n");
return false;
}
size = (uint64_t)tmp;
// close file
ret = fclose( pFile );
if(ret != 0){
perror("Could not close the file. Error:\n");
size = 0;
return false;
}
return true;
}