summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/nTox.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 15e209a9..3aea6b32 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -361,16 +361,18 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
361void load_key(char *path) 361void load_key(char *path)
362{ 362{
363 FILE *data_file = fopen(path, "r"); 363 FILE *data_file = fopen(path, "r");
364 int size = 0;
364 365
365 if (data_file) { 366 if (data_file) {
366 //load keys 367 //load keys
367 fseek(data_file, 0, SEEK_END); 368 fseek(data_file, 0, SEEK_END);
368 int size = ftell(data_file); 369 size = ftell(data_file);
369 fseek(data_file, 0, SEEK_SET); 370 rewind(data_file);
371
370 uint8_t data[size]; 372 uint8_t data[size];
371 if (fread(data, sizeof(uint8_t), size, data_file) != size){ 373 if (fread(data, sizeof(uint8_t), size, data_file) != size){
372 printf("[i] could not read data file\n[i] exiting\n"); 374 fputs("[!] could not read data file! exiting...\n", stderr);
373 exit(1); 375 goto FILE_ERROR;
374 } 376 }
375 Messenger_load(data, size); 377 Messenger_load(data, size);
376 378
@@ -387,11 +389,15 @@ void load_key(char *path)
387 } 389 }
388 390
389 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ 391 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){
390 puts("[i] could not write data file! exiting..."); 392 fputs("[!] could not write data file! exiting...", stderr);
391 exit(1); 393 goto FILE_ERROR;
392 } 394 }
393 } 395 }
394 fclose(data_file); 396
397FILE_ERROR:
398 if(fclose(data_file) < 0)
399 perror("[!] fclose failed");
400 exit(1);
395} 401}
396 402
397void print_help(void) 403void print_help(void)