Skip to content

Commit

Permalink
Use fixed size types
Browse files Browse the repository at this point in the history
  • Loading branch information
rw-r-r-0644 committed Oct 9, 2018
1 parent b6f385e commit 8e127ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ This library is made for use with WUT
**** API ****
<romfs-wiiu.h> is the main header

int romfsInit(void)
int32_t romfsInit(void)
Mounts app's romfs. Returns 0 if succesfull or a negative
value if there was an error

int romfsExit(void)
int32_t romfsExit(void)
Unmounts app's romfs. Returns 0 if succesfull or a negative
value if there was an error

Expand Down
18 changes: 16 additions & 2 deletions include/romfs-wiiu.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@
extern "C" {
#endif

#include <stdint.h>

int romfsInit(void);
/*
romfsInit()
Mounts app's romfs.
Returns 0 if succesfull or a negative
value if there was an error
*/
int32_t romfsInit(void);

int romfsExit(void);
/*
romfsExit()
Unmounts app's romfs.
Returns 0 if succesfull or a negative
value if there was an error
*/
int32_t romfsExit(void);


#ifdef __cplusplus
Expand Down
34 changes: 17 additions & 17 deletions source/romfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ typedef enum {
typedef struct _node node_t;
struct _node {
char * name;
unsigned inode;
unsigned size;
uint32_t inode;
uint32_t size;
node_type_t type;
time_t mtime;
union {
Expand All @@ -50,10 +50,10 @@ static node_t fs_root = {
};
static node_t *fs_cwd = &fs_root;

static unsigned n_nodes = 0;
static uint32_t n_nodes = 0;

// Create a node and all its parent directories
static void node_createfilepath (const char *_path, time_t mtime, int isdir, unsigned size, uint8_t *content) {
static void node_createfilepath (const char *_path, time_t mtime, int32_t isdir, uint32_t size, uint8_t *content) {
node_t *n = &fs_root;
char *path = strdup(_path), *path_s;
char *cur = strtok_r(path, "/", &path_s);
Expand Down Expand Up @@ -101,10 +101,10 @@ static void node_createfilepath (const char *_path, time_t mtime, int isdir, uns
}

// Frees the tree of nodes
static void node_destroytree (node_t *n, int recursion) {
static void node_destroytree (node_t *n, int32_t recursion) {
// this is the easier way, to prevent freeing the wrong part of tree first
static node_t **l_free = NULL;
static unsigned l_freecnt = 0;
static uint32_t l_freecnt = 0;
if (!l_free)
l_free = malloc(n_nodes * sizeof(node_t *));
if (!n)
Expand All @@ -123,7 +123,7 @@ static void node_destroytree (node_t *n, int recursion) {
if (recursion)
return;
// we're freeing the fs_root node; shall the free() start
for (int i = 0; i < l_freecnt; i++)
for (int32_t i = 0; i < l_freecnt; i++)
free(l_free[i]);
// finish freeing stuff
free(l_free);
Expand Down Expand Up @@ -181,8 +181,8 @@ typedef struct __attribute__((packed)) {
char pad[12];
} tar_header_t;

static unsigned oct2bin(uint8_t *c, int size) {
unsigned n = 0;
static uint32_t oct2bin(uint8_t *c, int32_t size) {
uint32_t n = 0;
while (size-- > 0)
n = (n * 8) + (*(c++) - '0');
return n;
Expand All @@ -193,10 +193,10 @@ static void tar_create_entries(uint8_t *ptr, uint8_t *end) {
tar_header_t *hdr = (tar_header_t *)ptr;
tar_header_t *ehdr = (tar_header_t *)end;
while ((hdr < ehdr) && !memcmp(hdr->tar_magic, "ustar", 5)) {
unsigned fsize = oct2bin(hdr->fsize, 11);
unsigned mtime = oct2bin(hdr->mtime, 11);
int isdir = hdr->typeflag[0] == '5';
int isfile = hdr->typeflag[0] == '0';
uint32_t fsize = oct2bin(hdr->fsize, 11);
uint32_t mtime = oct2bin(hdr->mtime, 11);
int32_t isdir = hdr->typeflag[0] == '5';
int32_t isfile = hdr->typeflag[0] == '0';
if (isfile || isdir)
node_createfilepath(hdr->fname, mtime, isdir, fsize, (uint8_t *)(hdr + 1));
hdr += ((fsize + 511) / 512) + 1;
Expand All @@ -215,7 +215,7 @@ typedef struct {
typedef struct {
node_t *fsdir;
node_t *ent;
int idx;
int32_t idx;
} romfs_dir_t;

#define ROMFS_DIR_MODE (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH)
Expand Down Expand Up @@ -419,9 +419,9 @@ static devoptab_t romfs_devoptab = {
extern char _binary_romfs_tar_start[] __attribute__((weak));
extern char _binary_romfs_tar_end[] __attribute__((weak));

static int romfs_initialised = 0;
static int32_t romfs_initialised = 0;

int romfsInit(void) {
int32_t romfsInit(void) {
if (romfs_initialised)
return 0;
if (!_binary_romfs_tar_start || !_binary_romfs_tar_end)
Expand All @@ -435,7 +435,7 @@ int romfsInit(void) {
return 0;
}

int romfsExit(void) {
int32_t romfsExit(void) {
if (!romfs_initialised)
return -1;
RemoveDevice("romfs:");
Expand Down

0 comments on commit 8e127ad

Please sign in to comment.