22
33#include < cstdio>
44
5- UFile::UFile () : fp (nullptr ) {}
5+ UFile::UFile () : filePointer (nullptr ) {}
66
7- UFile::UFile (const char * path) : fp (nullptr ), path(path) {}
7+ UFile::UFile (const char * path) : filePointer (nullptr ), path(path) {}
88
99UFile::~UFile () {
1010 close ();
@@ -36,10 +36,10 @@ bool UFile::open(const char* filename, FileMode fileMode) {
3636 }
3737
3838 // Open the file
39- fp = fopen (filename, mode);
40- fm = fileMode;
39+ filePointer = fopen (filename, mode);
40+ this -> fileMode = fileMode;
4141
42- if (fp == nullptr ) {
42+ if (filePointer == nullptr ) {
4343 // Failed to open the file
4444 return false ;
4545 }
@@ -53,61 +53,61 @@ bool UFile::open(String filename, FileMode mode) {
5353
5454void UFile::close () {
5555 // Close the file
56- if (fp != nullptr ) {
57- fclose (fp );
56+ if (filePointer != nullptr ) {
57+ fclose (filePointer );
5858 }
5959}
6060
6161bool UFile::seek (size_t offset) {
6262 // Seek to a specific position in the file
63- if (fp == nullptr ) {
63+ if (filePointer == nullptr ) {
6464 // File pointer is not valid
6565 return false ;
6666 }
6767
68- int result = fseek (fp , offset, SEEK_SET);
68+ int result = fseek (filePointer , offset, SEEK_SET);
6969 return (result == 0 );
7070}
7171
7272int UFile::available () {
7373 // Check the available data in the file
74- if (fp == nullptr ) {
74+ if (filePointer == nullptr ) {
7575 // File pointer is not valid
7676 return 0 ;
7777 }
7878
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);
8383
8484 return (fileSize - currentPosition);
8585}
8686
8787int UFile::read () {
8888 // Read a single byte from the file
89- if (fp == nullptr ) {
89+ if (filePointer == nullptr ) {
9090 // File pointer is not valid
9191 return 0 ;
9292 }
9393
94- int value = fgetc (fp );
94+ int value = fgetc (filePointer );
9595 return value;
9696}
9797
9898size_t UFile::read (uint8_t * buffer, size_t size) {
9999 // Read data from the file into the buffer
100- if (fp == nullptr ) {
100+ if (filePointer == nullptr ) {
101101 // File pointer is not valid
102102 return 0 ;
103103 }
104104
105- size_t bytesRead = fread (buffer, sizeof (uint8_t ), size, fp );
105+ size_t bytesRead = fread (buffer, sizeof (uint8_t ), size, filePointer );
106106 return bytesRead;
107107}
108108
109109String UFile::readAsString () {
110- if (fp == nullptr ) {
110+ if (filePointer == nullptr ) {
111111 return String (" " );
112112 }
113113
@@ -128,33 +128,33 @@ String UFile::readAsString() {
128128
129129size_t UFile::write (uint8_t value) {
130130 // Write a single byte to the file
131- if (fp == nullptr ) {
131+ if (filePointer == nullptr ) {
132132 // File pointer is not valid
133133 return 0 ;
134134 }
135135
136- int result = fputc (value, fp );
136+ int result = fputc (value, filePointer );
137137 return (result != EOF) ? 1 : 0 ;
138138}
139139
140140size_t UFile::write (String data) {
141- if (fp == nullptr ) {
141+ if (filePointer == nullptr ) {
142142 // File pointer is not valid
143143 return 0 ;
144144 }
145145
146146 // 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 );
148148 return bytesWritten;
149149}
150150
151151size_t UFile::write (const uint8_t * buffer, size_t size) {
152- if (fp == nullptr ) {
152+ if (filePointer == nullptr ) {
153153 // File pointer is not valid
154154 return 0 ;
155155 }
156156
157- size_t bytesWritten = fwrite (buffer, sizeof (uint8_t ), size, fp );
157+ size_t bytesWritten = fwrite (buffer, sizeof (uint8_t ), size, filePointer );
158158 return bytesWritten;
159159}
160160
@@ -271,7 +271,7 @@ bool UFile::moveTo(const char* destinationPath, bool overwrite){
271271
272272 FILE* destinationFile = fopen (newPath.c_str (), " r" );
273273
274- fclose (fp );
274+ fclose (filePointer );
275275 if (!copyTo (destinationPath, overwrite)) {
276276 return false ; // Return false if the copy operation fails
277277 }
@@ -281,7 +281,7 @@ bool UFile::moveTo(const char* destinationPath, bool overwrite){
281281 return false ;
282282 }
283283
284- open (newPath.c_str (), fm ); // sure about that ?
284+ open (newPath.c_str (), fileMode ); // sure about that ?
285285 path = newPath;
286286
287287 return true ;
0 commit comments