Skip to content

File System Helpers

Functions

Name
int wc_FileLoad(const char * fname, unsigned char ** buf, size_t * bufLen, void * heap)
Loads file into buffer.
int wc_ReadDirFirst(ReadDirCtx * ctx, const char * path, char ** name)
Reads first entry in directory.
int wc_ReadDirNext(ReadDirCtx * ctx, const char * path, char ** name)
Reads next entry in directory.
void wc_ReadDirClose(ReadDirCtx * ctx)
Closes directory reading.
int wc_FileExists(const char * fname)
Checks if file exists.

Functions Documentation

function wc_FileLoad

int wc_FileLoad(
    const char * fname,
    unsigned char ** buf,
    size_t * bufLen,
    void * heap
)

Loads file into buffer.

Parameters:

  • fname File name
  • buf Buffer pointer
  • bufLen Buffer length pointer
  • heap Heap hint

See: wc_FileExists

Return:

  • 0 on success
  • negative on error

Example

unsigned char* buf = NULL;
size_t len = 0;
int ret = wc_FileLoad("file.txt", &buf, &len, NULL);

function wc_ReadDirFirst

int wc_ReadDirFirst(
    ReadDirCtx * ctx,
    const char * path,
    char ** name
)

Reads first entry in directory.

Parameters:

  • ctx Directory context
  • path Directory path
  • name Pointer to store entry name

See: wc_ReadDirNext

Return:

  • 0 on success
  • negative on error

Example

ReadDirCtx ctx;
char* name;
int ret = wc_ReadDirFirst(&ctx, "/path", &name);

function wc_ReadDirNext

int wc_ReadDirNext(
    ReadDirCtx * ctx,
    const char * path,
    char ** name
)

Reads next entry in directory.

Parameters:

  • ctx Directory context
  • path Directory path
  • name Pointer to store entry name

See: wc_ReadDirFirst

Return:

  • 0 on success
  • negative on error

Example

ReadDirCtx ctx;
char* name;
int ret = wc_ReadDirNext(&ctx, "/path", &name);

function wc_ReadDirClose

void wc_ReadDirClose(
    ReadDirCtx * ctx
)

Closes directory reading.

Parameters:

  • ctx Directory context

See: wc_ReadDirFirst

Return: none No returns

Example

ReadDirCtx ctx;
wc_ReadDirClose(&ctx);

function wc_FileExists

int wc_FileExists(
    const char * fname
)

Checks if file exists.

Parameters:

  • fname File name

See: wc_FileLoad

Return:

  • 1 if file exists
  • 0 if file does not exist

Example

if (wc_FileExists("file.txt")) {
    // file exists
}

Updated on 2026-11-17 at 01:15:29 +0000