add get_error_message error code return value mapping util function
This commit is contained in:
parent
18e331819b
commit
e0b8c6a022
|
@ -146,7 +146,7 @@ int main(int argc, char *argv[]) {
|
||||||
GCI_DECRYPTED_DLQUEST_HEADER bin_gci_header;
|
GCI_DECRYPTED_DLQUEST_HEADER bin_gci_header;
|
||||||
result = get_quest_data(bin_gci_filename, &bin_data, &bin_data_size, &bin_gci_header);
|
result = get_quest_data(bin_gci_filename, &bin_data, &bin_data_size, &bin_gci_header);
|
||||||
if (result) {
|
if (result) {
|
||||||
printf("Error code %d reading quest .bin data.\n", result);
|
printf("Error code %d reading quest .bin data: %s\n", result, get_error_message(result));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ int main(int argc, char *argv[]) {
|
||||||
GCI_DECRYPTED_DLQUEST_HEADER dat_gci_header;
|
GCI_DECRYPTED_DLQUEST_HEADER dat_gci_header;
|
||||||
result = get_quest_data(dat_gci_filename, &dat_data, &dat_data_size, &dat_gci_header);
|
result = get_quest_data(dat_gci_filename, &dat_data, &dat_data_size, &dat_gci_header);
|
||||||
if (result) {
|
if (result) {
|
||||||
printf("Error code %d reading quest .dat data.\n", result);
|
printf("Error code %d reading quest .dat data: %s\n", result, get_error_message(result));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
utils.c
25
utils.c
|
@ -1,4 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
@ -6,6 +7,17 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "retvals.h"
|
#include "retvals.h"
|
||||||
|
|
||||||
|
// from error codes defined in retvals.h
|
||||||
|
static const char *error_messages[] = {
|
||||||
|
"No error", // SUCCESS
|
||||||
|
"Invalid parameter(s)", // ERROR_INVALID_PARAMS
|
||||||
|
"File not found", // ERROR_FILE_NOT_FOUND
|
||||||
|
"Cannot create file", // ERROR_CREATING_FILE
|
||||||
|
"Bad data", // ERROR_BAD_DATA
|
||||||
|
"I/O error", // ERROR_IO
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
int read_file(const char *filename, uint8_t** out_file_data, uint32_t *out_file_size) {
|
int read_file(const char *filename, uint8_t** out_file_data, uint32_t *out_file_size) {
|
||||||
if (!filename || !out_file_size || !out_file_data)
|
if (!filename || !out_file_size || !out_file_data)
|
||||||
return ERROR_INVALID_PARAMS;
|
return ERROR_INVALID_PARAMS;
|
||||||
|
@ -88,3 +100,16 @@ char* append_string(const char *a, const char *b) {
|
||||||
strcat(result, b);
|
strcat(result, b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* get_error_message(int retvals_error_code) {
|
||||||
|
retvals_error_code = abs(retvals_error_code);
|
||||||
|
|
||||||
|
int max_error_index;
|
||||||
|
for (max_error_index = 0; error_messages[max_error_index]; ++max_error_index) {}
|
||||||
|
max_error_index = max_error_index;
|
||||||
|
|
||||||
|
if (retvals_error_code >= max_error_index)
|
||||||
|
return "Unknown error";
|
||||||
|
else
|
||||||
|
return error_messages[retvals_error_code];
|
||||||
|
}
|
||||||
|
|
2
utils.h
2
utils.h
|
@ -11,4 +11,6 @@ int get_filesize(const char *filename, size_t *out_size);
|
||||||
const char* path_to_filename(const char *path);
|
const char* path_to_filename(const char *path);
|
||||||
char* append_string(const char *a, const char *b);
|
char* append_string(const char *a, const char *b);
|
||||||
|
|
||||||
|
const char* get_error_message(int retvals_error_code);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue