Use error codes

This commit is contained in:
TheFloW 2018-08-27 09:54:46 +02:00
parent a14f4e3a4a
commit 57d1f62368
17 changed files with 94 additions and 54 deletions

View File

@ -359,7 +359,7 @@ int addArchiveNodeRecursive(ArchiveFileNode *parent, char *name, SceIoStat *stat
ArchiveFileNode *prev = NULL;
if (!parent)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
ArchiveFileNode *res = _findArchiveNode(parent, name, &parent, &prev, &name, &p);
@ -509,7 +509,7 @@ int fileListGetArchiveEntries(FileList *list, const char *path, int sort) {
int res;
if (!list)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
FileListEntry *entry = malloc(sizeof(FileListEntry));
if (entry) {
@ -771,7 +771,7 @@ int archiveFileGetstat(const char *file, SceIoStat *stat) {
ArchiveFileNode *node = findArchiveNode(file + archive_path_start);
if (!node)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
if (stat)
memcpy(stat, &node->stat, sizeof(SceIoStat));

View File

@ -160,7 +160,7 @@ static int decompressGzip(uint8_t *dst, int size_dst, uint8_t *src, int size_src
int coredumpViewer(const char *file) {
void *buffer = memalign(4096, BIG_BUFFER_SIZE);
if (!buffer)
return -1;
return VITASHELL_ERROR_NO_MEMORY;
int size = ReadFile(file, buffer, BIG_BUFFER_SIZE);
@ -168,7 +168,7 @@ int coredumpViewer(const char *file) {
void *out_buf = memalign(4096, BIG_BUFFER_SIZE);
if (!out_buf) {
free(buffer);
return -2;
return VITASHELL_ERROR_NO_MEMORY;
}
int out_size = decompressGzip(out_buf, BIG_BUFFER_SIZE, buffer, size);
@ -191,7 +191,7 @@ int coredumpViewer(const char *file) {
ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
ehdr->e_ident[EI_MAG3] != ELFMAG3) {
free(buffer);
return -4;
return VITASHELL_ERROR_INVALID_MAGIC;
}
char thname[32], modname[32];
@ -207,7 +207,7 @@ int coredumpViewer(const char *file) {
void *program = malloc(phdr[i].p_filesz);
if (!program) {
free(buffer);
return -5;
return VITASHELL_ERROR_NO_MEMORY;
}
memcpy(program, buffer + phdr[i].p_offset, phdr[i].p_filesz);

8
elf.c
View File

@ -99,10 +99,10 @@ int checkForUnsafeImports(void *buffer) {
Elf32_Phdr *phdr = (Elf32_Phdr *)((uint32_t)buffer + ehdr->e_phoff);
if (ehdr->e_ident[EI_MAG0] != ELFMAG0 ||
ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
ehdr->e_ident[EI_MAG3] != ELFMAG3) {
return -1;
ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
ehdr->e_ident[EI_MAG3] != ELFMAG3) {
return VITASHELL_ERROR_INVALID_MAGIC;
}
uint32_t segment = ehdr->e_entry >> 30;

26
file.c
View File

@ -56,7 +56,7 @@ int allocateReadFile(const char *file, void **buffer) {
*buffer = malloc(size);
if (!*buffer) {
sceIoClose(fd);
return -1;
return VITASHELL_ERROR_NO_MEMORY;
}
int read = sceIoRead(fd, *buffer, size);
@ -331,13 +331,13 @@ int removePath(const char *path, FileProcessParam *param) {
int copyFile(const char *src_path, const char *dst_path, FileProcessParam *param) {
// The source and destination paths are identical
if (strcasecmp(src_path, dst_path) == 0) {
return -1;
return VITASHELL_ERROR_SRC_AND_DST_IDENTICAL;
}
// The destination is a subfolder of the source folder
int len = strlen(src_path);
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len - 1] == '/')) {
return -2;
return VITASHELL_ERROR_DST_IS_SUBFOLDER_OF_SRC;
}
SceUID fdsrc = sceIoOpen(src_path, SCE_O_RDONLY, 0);
@ -419,13 +419,13 @@ int copyFile(const char *src_path, const char *dst_path, FileProcessParam *param
int copyPath(const char *src_path, const char *dst_path, FileProcessParam *param) {
// The source and destination paths are identical
if (strcasecmp(src_path, dst_path) == 0) {
return -1;
return VITASHELL_ERROR_SRC_AND_DST_IDENTICAL;
}
// The destination is a subfolder of the source folder
int len = strlen(src_path);
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len - 1] == '/')) {
return -2;
return VITASHELL_ERROR_DST_IS_SUBFOLDER_OF_SRC;
}
SceUID dfd = sceIoDopen(src_path);
@ -502,13 +502,13 @@ int copyPath(const char *src_path, const char *dst_path, FileProcessParam *param
int movePath(const char *src_path, const char *dst_path, int flags, FileProcessParam *param) {
// The source and destination paths are identical
if (strcasecmp(src_path, dst_path) == 0) {
return -1;
return VITASHELL_ERROR_SRC_AND_DST_IDENTICAL;
}
// The destination is a subfolder of the source folder
int len = strlen(src_path);
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len - 1] == '/')) {
return -2;
return VITASHELL_ERROR_DST_IS_SUBFOLDER_OF_SRC;
}
int res = sceIoRename(src_path, dst_path);
@ -534,7 +534,7 @@ int movePath(const char *src_path, const char *dst_path, int flags, FileProcessP
// One of them is a file and the other a directory, no replacement or integration possible
if (src_is_dir != dst_is_dir)
return -3;
return VITASHELL_ERROR_INVALID_TYPE;
// Replace file
if (!src_is_dir && !dst_is_dir && flags & MOVE_REPLACE) {
@ -718,7 +718,7 @@ FileListEntry *fileListGetNthEntry(FileList *list, int n) {
int fileListGetNumberByName(FileList *list, const char *name) {
if (!list)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
FileListEntry *entry = list->head;
@ -734,7 +734,7 @@ int fileListGetNumberByName(FileList *list, const char *name) {
entry = entry->next;
}
return -1;
return VITASHELL_ERROR_NOT_FOUND;
}
void fileListAddEntry(FileList *list, FileListEntry *entry, int sort) {
@ -946,7 +946,7 @@ void fileListEmpty(FileList *list) {
int fileListGetDeviceEntries(FileList *list) {
if (!list)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
int i;
for (i = 0; i < N_DEVICES; i++) {
@ -997,7 +997,7 @@ int fileListGetDeviceEntries(FileList *list) {
int fileListGetDirectoryEntries(FileList *list, const char *path, int sort) {
if (!list)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
SceUID dfd = sceIoDopen(path);
if (dfd < 0)
@ -1057,7 +1057,7 @@ int fileListGetDirectoryEntries(FileList *list, const char *path, int sort) {
int fileListGetEntries(FileList *list, const char *path, int sort) {
if (!list)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
if (isInArchive()) {
return fileListGetArchiveEntries(list, path, sort);

2
hex.c
View File

@ -76,7 +76,7 @@ int hexViewer(const char *file) {
uint8_t *buffer = memalign(4096, BIG_BUFFER_SIZE);
if (!buffer)
return -1;
return VITASHELL_ERROR_NO_MEMORY;
int size = 0;

View File

@ -73,7 +73,7 @@ static void utf8_to_utf16(const uint8_t *src, uint16_t *dst) {
int initImeDialog(const char *title, const char *initial_text, int max_text_length, int type, int option, int password) {
if (ime_dialog_running)
return -1;
return VITASHELL_ERROR_ALREADY_RUNNING;
ime_initial_text = initial_text;

1
main.h
View File

@ -48,6 +48,7 @@
#include "file.h"
#include "vitashell_config.h"
#include "vitashell_error.h"
#define INCLUDE_EXTERN_RESOURCE(name) extern unsigned char _binary_resources_##name##_start; extern unsigned char _binary_resources_##name##_size; \

View File

@ -228,7 +228,7 @@ static int zipAddPath(zipFile zf, const char *path, int filename_start, int leve
int makeZip(const char *zip_file, const char *src_path, int filename_start, int level, int append, FileProcessParam *param) {
zipFile zf = zipOpen64(zip_file, append);
if (zf == NULL)
return -1;
return VITASHELL_ERROR_NO_MEMORY;
int res = zipAddPath(zf, src_path, filename_start, level, param);

View File

@ -26,7 +26,7 @@ static char message_string[512];
int initMessageDialog(int type, const char *msg, ...) {
if (message_dialog_running)
return -1;
return VITASHELL_ERROR_ALREADY_RUNNING;
va_list list;
char string[512];

View File

@ -23,7 +23,7 @@ static int netcheck_dialog_running = 0;
int initNetCheckDialog(int mode, int timeoutUs) {
if (netcheck_dialog_running)
return -1;
return VITASHELL_ERROR_ALREADY_RUNNING;
SceNetCheckDialogParam param;
sceNetCheckDialogParamInit(&param);

View File

@ -206,7 +206,7 @@ int makeHeadBin() {
// Enforce TITLE_ID format
if (strlen(titleid) != 9)
return -1;
return VITASHELL_ERROR_INVALID_TITLEID;
// Get content id
char contentid[48];

View File

@ -170,12 +170,12 @@ static void resetImageInfo(vita2d_texture *tex, float *width, float *height, flo
int photoViewer(const char *file, int type, FileList *list, FileListEntry *entry, int *base_pos, int *rel_pos) {
char *buffer = memalign(4096, BIG_BUFFER_SIZE);
if (!buffer)
return -1;
return VITASHELL_ERROR_NO_MEMORY;
vita2d_texture *tex = loadImage(file, type, buffer);
if (!tex) {
free(buffer);
return -1;
return VITASHELL_ERROR_NO_MEMORY;
}
// Variables
@ -233,7 +233,7 @@ int photoViewer(const char *file, int type, FileList *list, FileListEntry *entry
tex = loadImage(path, type, buffer);
if (!tex) {
free(buffer);
return -1;
return VITASHELL_ERROR_NO_MEMORY;
}
// Reset image

View File

@ -210,7 +210,7 @@ int fileListGetPsarcEntries(FileList *list, const char *path, int sort) {
int res;
if (!list)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
SceFiosDH dh = -1;
SceFiosBuffer buf = SCE_FIOS_BUFFER_INITIALIZER;

20
sfo.c
View File

@ -32,7 +32,7 @@ int getSfoValue(void *buffer, const char *name, uint32_t *value) {
SfoEntry *entries = (SfoEntry *)((uint32_t)buffer + sizeof(SfoHeader));
if (header->magic != SFO_MAGIC)
return -1;
return VITASHELL_ERROR_INVALID_MAGIC;
int i;
for (i = 0; i < header->count; i++) {
@ -42,7 +42,7 @@ int getSfoValue(void *buffer, const char *name, uint32_t *value) {
}
}
return -2;
return VITASHELL_ERROR_NOT_FOUND;
}
int getSfoString(void *buffer, const char *name, char *string, int length) {
@ -50,7 +50,7 @@ int getSfoString(void *buffer, const char *name, char *string, int length) {
SfoEntry *entries = (SfoEntry *)((uint32_t)buffer + sizeof(SfoHeader));
if (header->magic != SFO_MAGIC)
return -1;
return VITASHELL_ERROR_INVALID_MAGIC;
int i;
for (i = 0; i < header->count; i++) {
@ -62,7 +62,7 @@ int getSfoString(void *buffer, const char *name, char *string, int length) {
}
}
return -2;
return VITASHELL_ERROR_NOT_FOUND;
}
int setSfoValue(void *buffer, const char *name, uint32_t value) {
@ -70,7 +70,7 @@ int setSfoValue(void *buffer, const char *name, uint32_t value) {
SfoEntry *entries = (SfoEntry *)((uint32_t)buffer + sizeof(SfoHeader));
if (header->magic != SFO_MAGIC)
return -1;
return VITASHELL_ERROR_INVALID_MAGIC;
int i;
for (i = 0; i < header->count; i++) {
@ -80,7 +80,7 @@ int setSfoValue(void *buffer, const char *name, uint32_t value) {
}
}
return -2;
return VITASHELL_ERROR_NOT_FOUND;
}
int setSfoString(void *buffer, const char *name, const char *string) {
@ -88,7 +88,7 @@ int setSfoString(void *buffer, const char *name, const char *string) {
SfoEntry *entries = (SfoEntry *)((uint32_t)buffer + sizeof(SfoHeader));
if (header->magic != SFO_MAGIC)
return -1;
return VITASHELL_ERROR_INVALID_MAGIC;
int i;
for (i = 0; i < header->count; i++) {
@ -98,13 +98,13 @@ int setSfoString(void *buffer, const char *name, const char *string) {
}
}
return -2;
return VITASHELL_ERROR_NOT_FOUND;
}
int SFOReader(const char *file) {
uint8_t *buffer = memalign(4096, BIG_BUFFER_SIZE);
if (!buffer)
return -1;
return VITASHELL_ERROR_NO_MEMORY;
int size = 0;
@ -121,7 +121,7 @@ int SFOReader(const char *file) {
SfoHeader *sfo_header = (SfoHeader *)buffer;
if (sfo_header->magic != SFO_MAGIC)
return -1;
return VITASHELL_ERROR_INVALID_MAGIC;
int base_pos = 0, rel_pos = 0;

4
text.c
View File

@ -506,11 +506,11 @@ static int search_thread(SceSize args, SearchParams *argp) {
int textViewer(const char *file) {
TextEditorState *s = malloc(sizeof(TextEditorState));
if (!s)
return -1;
return VITASHELL_ERROR_NO_MEMORY;
char *buffer_base = memalign(4096, BIG_BUFFER_SIZE);
if (!buffer_base)
return -1;
return VITASHELL_ERROR_NO_MEMORY;
s->running = 1;
s->hex_viewer = 0;

View File

@ -130,7 +130,7 @@ static void calculateDialogBoxSize() {
int sceMsgDialogInit(const SceMsgDialogParam *param) {
if (!param)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
memset(&uncommon_dialog, 0, sizeof(UncommonDialog));
@ -138,7 +138,7 @@ int sceMsgDialogInit(const SceMsgDialogParam *param) {
case SCE_MSG_DIALOG_MODE_USER_MSG:
{
if (!param->userMsgParam || !param->userMsgParam->msg)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
strncpy(uncommon_dialog.msg, (char *)param->userMsgParam->msg, sizeof(uncommon_dialog.msg) - 1);
uncommon_dialog.buttonType = param->userMsgParam->buttonType;
@ -148,7 +148,7 @@ int sceMsgDialogInit(const SceMsgDialogParam *param) {
case SCE_MSG_DIALOG_MODE_PROGRESS_BAR:
{
if (!param->progBarParam || !param->progBarParam->msg)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
strncpy(uncommon_dialog.msg, (char *)param->progBarParam->msg, sizeof(uncommon_dialog.msg) - 1);
uncommon_dialog.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_CANCEL;
@ -163,7 +163,7 @@ int sceMsgDialogInit(const SceMsgDialogParam *param) {
}
default:
return -1;
return VITASHELL_ERROR_INVALID_ARGUMENT;
}
uncommon_dialog.dialog_status = UNCOMMON_DIALOG_OPENING;
@ -234,7 +234,7 @@ SceCommonDialogStatus sceMsgDialogGetStatus(void) {
int sceMsgDialogClose(void) {
if (uncommon_dialog.status != SCE_COMMON_DIALOG_STATUS_RUNNING)
return -1;
return VITASHELL_ERROR_NOT_RUNNING;
uncommon_dialog.dialog_status = UNCOMMON_DIALOG_CLOSING;
return 0;
@ -242,7 +242,7 @@ int sceMsgDialogClose(void) {
int sceMsgDialogTerm(void) {
if (uncommon_dialog.status == SCE_COMMON_DIALOG_STATUS_NONE)
return -1;
return VITASHELL_ERROR_NOT_RUNNING;
uncommon_dialog.status = SCE_COMMON_DIALOG_STATUS_NONE;
return 0;
@ -250,7 +250,7 @@ int sceMsgDialogTerm(void) {
int sceMsgDialogGetResult(SceMsgDialogResult *result) {
if (!result)
return -1;
return VITASHELL_ERROR_ILLEGAL_ADDR;
result->buttonId = uncommon_dialog.buttonId;
return 0;
@ -268,7 +268,7 @@ int sceMsgDialogProgressBarSetMsg(SceMsgDialogProgressBarTarget target, const Sc
int sceMsgDialogProgressBarSetValue(SceMsgDialogProgressBarTarget target, SceUInt32 rate) {
if (rate > 100)
return -1;
return VITASHELL_ERROR_INVALID_ARGUMENT;
uncommon_dialog.progress = rate;
return 0;

39
vitashell_error.h Normal file
View File

@ -0,0 +1,39 @@
/*
VitaShell
Copyright (C) 2015-2018, TheFloW
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __VITASHELL_ERROR_H__
#define __VITASHELL_ERROR_H__
enum VitaShellErrors {
VITASHELL_ERROR_INTERNAL = 0xF0010000,
VITASHELL_ERROR_NO_MEMORY = 0xF0010001,
VITASHELL_ERROR_NOT_FOUND = 0xF0010002,
VITASHELL_ERROR_INVALID_ARGUMENT = 0xF0010003,
VITASHELL_ERROR_INVALID_MAGIC = 0xF0010004,
VITASHELL_ERROR_INVALID_TYPE = 0xF0010005,
VITASHELL_ERROR_ILLEGAL_ADDR = 0xF0010006,
VITASHELL_ERROR_ALREADY_RUNNING = 0xF0010007,
VITASHELL_ERROR_NOT_RUNNING = 0xF0010008,
VITASHELL_ERROR_SRC_AND_DST_IDENTICAL = 0xF0020000,
VITASHELL_ERROR_DST_IS_SUBFOLDER_OF_SRC = 0xF0020001,
VITASHELL_ERROR_INVALID_TITLEID = 0xF0030000,
};
#endif