2
2
3
3
#include < cstdio>
4
4
5
- UFile::UFile () : fp (nullptr ) {}
5
+ UFile::UFile () : filePointer (nullptr ) {}
6
6
7
- UFile::UFile (const char * path) : fp (nullptr ), path(path) {}
7
+ UFile::UFile (const char * path) : filePointer (nullptr ), path(path) {}
8
8
9
9
UFile::~UFile () {
10
10
close ();
@@ -36,10 +36,10 @@ bool UFile::open(const char* filename, FileMode fileMode) {
36
36
}
37
37
38
38
// Open the file
39
- fp = fopen (filename, mode);
40
- fm = fileMode;
39
+ filePointer = fopen (filename, mode);
40
+ this -> fileMode = fileMode;
41
41
42
- if (fp == nullptr ) {
42
+ if (filePointer == nullptr ) {
43
43
// Failed to open the file
44
44
return false ;
45
45
}
@@ -53,61 +53,61 @@ bool UFile::open(String filename, FileMode mode) {
53
53
54
54
void UFile::close () {
55
55
// Close the file
56
- if (fp != nullptr ) {
57
- fclose (fp );
56
+ if (filePointer != nullptr ) {
57
+ fclose (filePointer );
58
58
}
59
59
}
60
60
61
61
bool UFile::seek (size_t offset) {
62
62
// Seek to a specific position in the file
63
- if (fp == nullptr ) {
63
+ if (filePointer == nullptr ) {
64
64
// File pointer is not valid
65
65
return false ;
66
66
}
67
67
68
- int result = fseek (fp , offset, SEEK_SET);
68
+ int result = fseek (filePointer , offset, SEEK_SET);
69
69
return (result == 0 );
70
70
}
71
71
72
72
int UFile::available () {
73
73
// Check the available data in the file
74
- if (fp == nullptr ) {
74
+ if (filePointer == nullptr ) {
75
75
// File pointer is not valid
76
76
return 0 ;
77
77
}
78
78
79
- int currentPosition = ftell (fp );
80
- fseek (fp , 0 , SEEK_END);
81
- int fileSize = ftell (fp );
82
- fseek (fp , currentPosition, SEEK_SET);
79
+ int currentPosition = ftell (filePointer );
80
+ fseek (filePointer , 0 , SEEK_END);
81
+ int fileSize = ftell (filePointer );
82
+ fseek (filePointer , currentPosition, SEEK_SET);
83
83
84
84
return (fileSize - currentPosition);
85
85
}
86
86
87
87
int UFile::read () {
88
88
// Read a single byte from the file
89
- if (fp == nullptr ) {
89
+ if (filePointer == nullptr ) {
90
90
// File pointer is not valid
91
91
return 0 ;
92
92
}
93
93
94
- int value = fgetc (fp );
94
+ int value = fgetc (filePointer );
95
95
return value;
96
96
}
97
97
98
98
size_t UFile::read (uint8_t * buffer, size_t size) {
99
99
// Read data from the file into the buffer
100
- if (fp == nullptr ) {
100
+ if (filePointer == nullptr ) {
101
101
// File pointer is not valid
102
102
return 0 ;
103
103
}
104
104
105
- size_t bytesRead = fread (buffer, sizeof (uint8_t ), size, fp );
105
+ size_t bytesRead = fread (buffer, sizeof (uint8_t ), size, filePointer );
106
106
return bytesRead;
107
107
}
108
108
109
109
String UFile::readAsString () {
110
- if (fp == nullptr ) {
110
+ if (filePointer == nullptr ) {
111
111
return String (" " );
112
112
}
113
113
@@ -128,33 +128,33 @@ String UFile::readAsString() {
128
128
129
129
size_t UFile::write (uint8_t value) {
130
130
// Write a single byte to the file
131
- if (fp == nullptr ) {
131
+ if (filePointer == nullptr ) {
132
132
// File pointer is not valid
133
133
return 0 ;
134
134
}
135
135
136
- int result = fputc (value, fp );
136
+ int result = fputc (value, filePointer );
137
137
return (result != EOF) ? 1 : 0 ;
138
138
}
139
139
140
140
size_t UFile::write (String data) {
141
- if (fp == nullptr ) {
141
+ if (filePointer == nullptr ) {
142
142
// File pointer is not valid
143
143
return 0 ;
144
144
}
145
145
146
146
// Write data to the file
147
- size_t bytesWritten = fwrite (data.c_str (), sizeof (char ), data.length (), fp );
147
+ size_t bytesWritten = fwrite (data.c_str (), sizeof (char ), data.length (), filePointer );
148
148
return bytesWritten;
149
149
}
150
150
151
151
size_t UFile::write (const uint8_t * buffer, size_t size) {
152
- if (fp == nullptr ) {
152
+ if (filePointer == nullptr ) {
153
153
// File pointer is not valid
154
154
return 0 ;
155
155
}
156
156
157
- size_t bytesWritten = fwrite (buffer, sizeof (uint8_t ), size, fp );
157
+ size_t bytesWritten = fwrite (buffer, sizeof (uint8_t ), size, filePointer );
158
158
return bytesWritten;
159
159
}
160
160
@@ -271,7 +271,7 @@ bool UFile::moveTo(const char* destinationPath, bool overwrite){
271
271
272
272
FILE* destinationFile = fopen (newPath.c_str (), " r" );
273
273
274
- fclose (fp );
274
+ fclose (filePointer );
275
275
if (!copyTo (destinationPath, overwrite)) {
276
276
return false ; // Return false if the copy operation fails
277
277
}
@@ -281,7 +281,7 @@ bool UFile::moveTo(const char* destinationPath, bool overwrite){
281
281
return false ;
282
282
}
283
283
284
- open (newPath.c_str (), fm ); // sure about that ?
284
+ open (newPath.c_str (), fileMode ); // sure about that ?
285
285
path = newPath;
286
286
287
287
return true ;
0 commit comments