Permalink
Browse files

Merge pull request #16 from SegFault42/master

correct fread, fwrite, fopen return value
  • Loading branch information...
Reisyukaku committed Jul 24, 2018
2 parents 6e90d61 + 3da44e8 commit b0998835d50834e7c50e6d95d6ceab9cd2eff4d9
Showing with 21 additions and 20 deletions.
  1. +3 −2 Makefile
  2. +3 −3 src/firmware.c
  3. +6 −6 src/fs.c
  4. +4 −4 src/fs.h
  5. +1 −1 src/hwinit/util.c
  6. +3 −3 src/package.c
  7. +1 −1 src/start.s
View
@@ -16,7 +16,7 @@ dir_build := build
dir_out := out
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork
CFLAGS = $(ARCH) -Os -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11# -Wall
CFLAGS = $(ARCH) -Os -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -fno-builtin -std=gnu11# -Wall
LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
@@ -32,6 +32,7 @@ all: $(dir_out)/$(name).bin
.PHONY: clean
clean:
@echo "clean ..."
@rm -rf $(dir_build)
@rm -rf $(dir_out)
@@ -51,4 +52,4 @@ $(dir_build)/%.o: $(dir_source)/%.c
$(dir_build)/%.o: $(dir_source)/%.s
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) -c $< -o $@
View
@@ -57,7 +57,7 @@ static void SE_lock() {
void drawSplash() {
// Draw splashscreen to framebuffer.
if(fopen("/ReiNX/splash.bin", "rb") != NULL) {
if(fopen("/ReiNX/splash.bin", "rb") != 0) {
fread((void*)0xC0000000, fsize(), 1);
fclose();
}
@@ -67,7 +67,7 @@ void drawSplash() {
pk11_offs *pkg11_offsentify(u8 *pkg1) {
for (u32 i = 0; _pk11_offs[i].id; i++)
if (!memcmp(pkg1 + 0x10, _pk11_offs[i].id, 12))
return &_pk11_offs[i];
return (pk11_offs *)&_pk11_offs[i];
return NULL;
}
@@ -94,7 +94,7 @@ void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2) {
}
void loadKip(link_t *info, char *path) {
if(fopen(path, "rb") == NULL) return;
if(fopen(path, "rb") == 0) return;
pkg2_kip1_t *ckip = malloc(fsize());
fread(ckip, fsize(), 1);
fclose();
View
@@ -40,19 +40,19 @@ u32 sd_mount() {
return 0;
}
u32 *fopen(const char *path, const char *mode) {
u32 fopen(const char *path, const char *mode) {
if (f_open(&fp, path, mode[0] == 'w' ? FA_WRITE : FA_READ) != FR_OK)
return NULL;
return 0;
return 1;
}
u32 *fread(void *buf, size_t size, size_t ntimes) {
u32 fread(void *buf, size_t size, size_t ntimes) {
u8 *ptr = buf;
while (size > 0) {
u32 rsize = MIN(ntimes * size, size);
if (f_read(&fp, ptr, rsize, NULL) != FR_OK) {
error("Failed read!\n");
return NULL;
return 0;
}
ptr += rsize;
@@ -61,13 +61,13 @@ u32 *fread(void *buf, size_t size, size_t ntimes) {
return 1;
}
u32 *fwrite(void *buf, size_t size, size_t ntimes) {
u32 fwrite(void *buf, size_t size, size_t ntimes) {
u8 *ptr = buf;
while (size > 0) {
u32 rsize = MIN(ntimes * size, size);
if (f_write(&fp, ptr, rsize, NULL) != FR_OK) {
error("Failed write!\n");
return NULL;
return 0;
}
ptr += rsize;
View
@@ -1,9 +1,9 @@
#pragma once
u32 sd_mount();
u32 *fopen(const char *path, const char *mode);
u32 *fread(void *buf, size_t size, size_t ntimes);
u32 *fwrite(void *buf, size_t size, size_t ntimes);
u32 fopen(const char *path, const char *mode);
u32 fread(void *buf, size_t size, size_t ntimes);
u32 fwrite(void *buf, size_t size, size_t ntimes);
size_t fsize();
void fclose();
size_t enumerateDir(char ***output, char *path, char *pattern);
size_t enumerateDir(char ***output, char *path, char *pattern);
View
@@ -57,7 +57,7 @@ void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops)
uPtr memsearch(const u8 *startPos, u32 searchSize, const void *pattern, u32 patternSize) {
if(!searchSize) return 0;
for (void *pos = startPos; pos <= startPos + searchSize - patternSize; pos++) {
for (u8 *pos = (u8 *)startPos; pos <= startPos + searchSize - patternSize; pos++) {
if (memcmp(pos, pattern, patternSize) == 0) return (uPtr)pos;
}
return 0;
View
@@ -59,15 +59,15 @@ u8 pkg1_unpack(pk11_offs *offs, u8 *pkg1) {
for (u32 i = 0; i < 3; i++) {
if (offs->sec_map[i] == 0 && offs->warmboot_base) {
u8 *extWb = NULL;
if(fopen("/ReiNX/warmboot.bin", "rb") != NULL) {
if(fopen("/ReiNX/warmboot.bin", "rb") != 0) {
extWb = malloc(fsize());
fread(extWb, fsize(), 1);
fclose();
}
memcpy((void *)offs->warmboot_base, extWb == NULL ? pdata : extWb, sec_size[offs->sec_map[i]]);
} else if (offs->sec_map[i] == 2 && offs->secmon_base) {
u8 *extSec = NULL;
if(fopen("/ReiNX/secmon.bin", "rb") != NULL) {
if(fopen("/ReiNX/secmon.bin", "rb") != 0) {
extSec = malloc(fsize());
fread(extSec, fsize(), 1);
fclose();
@@ -104,7 +104,7 @@ void buildFirmwarePackage(u8 *kernel, u32 kernel_size, link_t *kips_info) {
// Kernel.
u8 *extKern = NULL;
if(fopen("/ReiNX/kernel.bin", "rb") != NULL) {
if(fopen("/ReiNX/kernel.bin", "rb") != 0) {
extKern = malloc(fsize());
fread(extKern, fsize(), 1);
fclose();
View
@@ -87,4 +87,4 @@ rebootRCM:
LDR R1, [R2]
ORRS R3, R1
MOVS R0, #0
STR R3, [R2]
STR R3, [R2]

0 comments on commit b099883

Please sign in to comment.