muteki
Loading...
Searching...
No Matches
file.h File Reference

Low-level and built-in high-level file operation API. More...

#include <muteki/common.h>

Go to the source code of this file.

Typedefs

typedef struct file_descriptor_s file_descriptor_t
 

Enumerations

enum  sys_seek_whence_e { _SYS_SEEK_SET = 0 , _SYS_SEEK_CUR , _SYS_SEEK_END }
 whence values for __fseek(). More...
 

Functions

file_descriptor_t * _afopen (const char *pathname, const char *mode)
 Open a file located at pathname.
 
file_descriptor_t * __wfopen (const UTF16 *pathname, const UTF16 *mode)
 Open a file located at UTF-16-encoded pathname.
 
size_t _fread (void *ptr, size_t size, size_t nmemb, file_descriptor_t *stream)
 Read nmemb data units of size size from a file.
 
size_t _fwrite (const void *ptr, size_t size, size_t nmemb, file_descriptor_t *stream)
 Write nmemb data units of size size to a file.
 
int __fseek (file_descriptor_t *stream, long offset, int whence)
 Seek to a specific position in an opened file.
 
long _ftell (file_descriptor_t *stream)
 Return the current position of the file.
 
int __fflush (file_descriptor_t *stream)
 Flush the cached writes to the file.
 
int _fclose (file_descriptor_t *stream)
 Close a file.
 

Detailed Description

Low-level and built-in high-level file operation API.

Enumeration Type Documentation

◆ sys_seek_whence_e

whence values for __fseek().

Enumerator
_SYS_SEEK_SET 

Seek from the beginning of file.

_SYS_SEEK_CUR 

Seek from current offset.

_SYS_SEEK_END 

Seek from the end of file.

Function Documentation

◆ __fflush()

int __fflush ( file_descriptor_t *  stream)
extern

Flush the cached writes to the file.

Analogous to the fflush() function in POSIX.

Parameters
streamPointer reference returned by _afopen() or _wfopen().
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ __fseek()

int __fseek ( file_descriptor_t *  stream,
long  offset,
int  whence 
)
extern

Seek to a specific position in an opened file.

Analogous to the fseek() function in POSIX.

Parameters
streamPointer reference returned by _afopen() or _wfopen().
offsetSeek offset.
whenceTreat offset as relative to start of file/current offset/end of file.
Return values
0The operation was completed successfully.
-1The operation failed with error.
See also
sys_seek_whence_e

◆ __wfopen()

file_descriptor_t * __wfopen ( const UTF16 pathname,
const UTF16 mode 
)
extern

Open a file located at UTF-16-encoded pathname.

Analogous to the _wfopen() function in Windows.

Parameters
pathnamePath to the file to be opened. LFN (long filename) is supported.
modeMode. Tested modes are _BUL("rb") and _BUL("wb+").
Returns
Pointer reference to the opened file.

◆ _afopen()

file_descriptor_t * _afopen ( const char *  pathname,
const char *  mode 
)
extern

Open a file located at pathname.

Analogous to the fopen() function in POSIX and Windows.

Parameters
pathnameDOS 8.3 path to the file to be opened.
modeMode. Tested modes are "rb" and "wb+".
Returns
Pointer reference to the opened file.

◆ _fclose()

int _fclose ( file_descriptor_t *  stream)
extern

Close a file.

Analogous to the fclose() function in POSIX.

Parameters
streamPointer reference returned by _afopen() or _wfopen().
Returns
Unclear. Could be similar to POSIX fclose().

◆ _fread()

size_t _fread ( void *  ptr,
size_t  size,
size_t  nmemb,
file_descriptor_t *  stream 
)
extern

Read nmemb data units of size size from a file.

Analogous to the POSIX fread() function.

Parameters
ptrPointer reference to a buffer that will hold the data read from the file.
sizeSize of individual data unit.
nmembNumber of data units to read.
streamPointer reference returned by _afopen() or _wfopen().
Returns
Number of data units read.

◆ _ftell()

long _ftell ( file_descriptor_t *  stream)
extern

Return the current position of the file.

Analogous to the ftell() function in POSIX.

Parameters
streamPointer reference returned by _afopen() or _wfopen().
Returns
Current position when successful, -1 when there's an error.

◆ _fwrite()

size_t _fwrite ( const void *  ptr,
size_t  size,
size_t  nmemb,
file_descriptor_t *  stream 
)
extern

Write nmemb data units of size size to a file.

Analogous to the fwrite() function in POSIX.

Parameters
ptrPointer reference to data that will be written to the file.
sizeSize of individual data unit.
nmembNumber of data units to write.
streamPointer reference returned by _afopen() or _wfopen().
Returns
Number of data units written.