AnimaEngine  1.0.0
Nintendo DS Pokemon Black, White, Black 2, and White 2 sprite extraction and preview toolchain
Functions
file_util.h File Reference

File system utilities and light binary reading helper functions. More...

#include "common.h"

Go to the source code of this file.

Functions

int File_ReadAll (const char *path, u8 **out_data, size_t *out_size)
 Reads the entire contents of a file into a newly allocated buffer. More...
 
int File_WriteAll (const char *path, const u8 *data, size_t size)
 Writes a buffer to a file, creating or overwriting it. More...
 
int File_MkdirRecursive (const char *path)
 Creates a directory structure recursively (equivalent to mkdir -p). More...
 
int File_RemoveRecursive (const char *path)
 Deletes a file or recursively deletes a directory. More...
 
u16 ReadU16LE (const u8 *p)
 Helper to read a little-endian unsigned 16-bit value. More...
 
u32 ReadU32LE (const u8 *p)
 Helper to read a little-endian unsigned 32-bit value. More...
 
int CopyBytes (const u8 *data, size_t size, u8 **out_data, size_t *out_size)
 Allocates and duplicates a byte array. More...
 

Detailed Description

File system utilities and light binary reading helper functions.

Function Documentation

◆ CopyBytes()

int CopyBytes ( const u8 data,
size_t  size,
u8 **  out_data,
size_t *  out_size 
)

Allocates and duplicates a byte array.

Parameters
dataSource data to copy.
sizeNumber of bytes to copy.
out_dataPointer to the destination buffer pointer.
out_sizePointer to store the size of the duplicated buffer.
Returns
0 on success; negative value on memory failure.

◆ File_MkdirRecursive()

int File_MkdirRecursive ( const char *  path)

Creates a directory structure recursively (equivalent to mkdir -p).

Parameters
pathPath of directory structure to create.
Returns
0 on success; negative value on failure.

◆ File_ReadAll()

int File_ReadAll ( const char *  path,
u8 **  out_data,
size_t *  out_size 
)

Reads the entire contents of a file into a newly allocated buffer.

Parameters
pathPath to the file to read.
out_dataPointer to the destination buffer pointer, allocated inside this function.
out_sizePointer to store the size of the read file in bytes.
Returns
0 on success; negative value on read failure.

◆ File_RemoveRecursive()

int File_RemoveRecursive ( const char *  path)

Deletes a file or recursively deletes a directory.

Parameters
pathPath of target file or directory.
Returns
0 on success; negative value on deletion failure.

◆ File_WriteAll()

int File_WriteAll ( const char *  path,
const u8 data,
size_t  size 
)

Writes a buffer to a file, creating or overwriting it.

Parameters
pathPath to the file to write.
dataPointer to the buffer containing data to write.
sizeNumber of bytes to write.
Returns
0 on success; negative value on write failure.

◆ ReadU16LE()

u16 ReadU16LE ( const u8 p)

Helper to read a little-endian unsigned 16-bit value.

Parameters
pPointer to the start bytes.
Returns
The parsed u16 value.

◆ ReadU32LE()

u32 ReadU32LE ( const u8 p)

Helper to read a little-endian unsigned 32-bit value.

Parameters
pPointer to the start bytes.
Returns
The parsed u32 value.