Virtual Files
Detailed Description
Virtual File support for OSLib. This API is meant to be an universal mean to manipulate every file source possible as you can define your own.
Enumeration Type Documentation
Enumeration describing the available file open modes. Please note that some sources do not support some modes like READWRITE or WRITE, in this case they'll fail when an attempt to open a file in one of these modes is made. The resulting file returned by VirtualFileOpen will be NULL.
- Enumerator:
-
VF_O_READ |
Read only. |
VF_O_READWRITE |
Read & Write. |
VF_O_WRITE |
Write only. |
Function Documentation
Initializes the virtual filesystem. Done by default by OSLib, so there is no need to call it by yourself.
VIRTUAL_FILE* VirtualFileOpen |
( |
void * |
param1, |
|
|
int |
param2, |
|
|
int |
type, |
|
|
int |
mode | |
|
) |
| | |
Open a new file.
- Parameters:
-
| param1 | Pointer to a string representing the file name. |
| type | File type. By default, can be:
- VF_MEMORY: read/write from a memory block
- VF_FILE: read from standard stdio routines.
|
| mode | One of VF_OPEN_MODES. |
Adds a new file source to the virtual file system.
- Parameters:
-
| vfs | Must be a pointer to a valid VIRTUAL_FILE_SOURCE interface containing all your functions for handling the file source. |
- Returns:
- Returns the identifier of your source or -1 if it has failed. You can then use this ID as a file type (parameter for VirtualFileOpen).
Call this function in your virtual file source OPEN handler, if it's a RAM based device and param2 == 0 (means null size, impossible). It will return a UL_VIRTUALFILENAME where you can get a pointer to the data and their size. Note that the return value can be NULL if the file has not been found or an error occured (e.g. fname is NULL).
void* oslReadEntireFileToMemory |
( |
VIRTUAL_FILE * |
f, |
|
|
int * |
size | |
|
) |
| | |
Reads an entire file to memory and returns a pointer to the memory block. The block memory usage is stepped by 4 kB, so even a 1 kB file will take 16 kB, so this function is not recommended for opening a lot of small files. The bloc must be freed (using free) once you've finished with it!
- Parameters:
-
| f | Pointer to an open virtual file. |
| size | Pointer to an integer that will contain the number of bytes read from the file. Can be NULL (in this case the value is discarded). |