implemented why2_fopen

This commit is contained in:
Václav Šmejkal 2023-02-05 18:43:43 +01:00
parent 395f78707a
commit c1e9a15529
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -99,7 +99,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//CURL VARIABLES //CURL VARIABLES
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
FILE *fileBuffer = fopen(WHY2_VERSIONS_NAME, "w+"); FILE *fileBuffer = why2_fopen(WHY2_VERSIONS_NAME, "w+");
//GET versions.json //GET versions.json
curl_easy_setopt(curl, CURLOPT_URL, WHY2_VERSIONS_URL); curl_easy_setopt(curl, CURLOPT_URL, WHY2_VERSIONS_URL);
@ -111,7 +111,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//CLEANUP //CLEANUP
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
fclose(fileBuffer); why2_deallocate(fileBuffer);
while (access(WHY2_VERSIONS_NAME, R_OK) != 0) while (access(WHY2_VERSIONS_NAME, R_OK) != 0)
{ {
@ -136,7 +136,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
int bufferSize; int bufferSize;
//COUNT LENGTH OF buffer AND STORE IT IN bufferSize //COUNT LENGTH OF buffer AND STORE IT IN bufferSize
fileBuffer = fopen(WHY2_VERSIONS_NAME, "r"); fileBuffer = why2_fopen(WHY2_VERSIONS_NAME, "r");
fseek(fileBuffer, 0, SEEK_END); fseek(fileBuffer, 0, SEEK_END);
bufferSize = ftell(fileBuffer); bufferSize = ftell(fileBuffer);
rewind(fileBuffer); //REWIND fileBuffer (NO SHIT) rewind(fileBuffer); //REWIND fileBuffer (NO SHIT)
@ -163,13 +163,12 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//WAIT FOR 5 SECONDS //WAIT FOR 5 SECONDS
sleep(5); sleep(5);
fclose(fileBuffer);
why2_clean_memory("core_version_check"); why2_clean_memory("core_version_check");
return WHY2_SUCCESS; return WHY2_SUCCESS;
} }
//CLEANUP //CLEANUP
fclose(fileBuffer); why2_deallocate(fileBuffer);
//GET //GET
parsedJson = json_tokener_parse(buffer); //yes, ik, i could use json_object_from_file, but I need to check for internet somehow parsedJson = json_tokener_parse(buffer); //yes, ik, i could use json_object_from_file, but I need to check for internet somehow
@ -422,7 +421,7 @@ void why2_generate_key(char *key, int keyLength)
//TRY TO MAKE RANDOM GENERATION REALLY "RANDOM" //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
FILE *fileBuffer; FILE *fileBuffer;
fileBuffer = fopen("/dev/urandom", "r"); fileBuffer = why2_fopen("/dev/urandom", "r");
if (fread(&numberBuffer, sizeof(numberBuffer), 1, fileBuffer) != 1) if (fread(&numberBuffer, sizeof(numberBuffer), 1, fileBuffer) != 1)
{ {
@ -435,7 +434,7 @@ void why2_generate_key(char *key, int keyLength)
numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE
srand(numberBuffer); srand(numberBuffer);
fclose(fileBuffer); why2_deallocate(fileBuffer);
seedSet = 1; seedSet = 1;