RAM file basic operations.

This commit is contained in:
Jean-François DEL NERO
2023-11-11 12:14:32 +01:00
parent f59dd26f51
commit ed78c121c9
2 changed files with 49 additions and 0 deletions
+39
View File
@@ -700,3 +700,42 @@ int hxc_getfilesize(char * path)
return filesize;
}
FILE * hxc_ram_fopen(char* fn, char * mode, HXCRAMFILE * rf)
{
if(!rf)
return NULL;
rf->ramfile = NULL;
rf->ramfile_size = 0;
return (FILE *)1;
};
int hxc_ram_fwrite(void * buffer,int size,int mul,FILE * file,HXCRAMFILE * rf)
{
rf->ramfile = realloc(rf->ramfile,rf->ramfile_size+size);
if(rf->ramfile)
{
memcpy(&rf->ramfile[rf->ramfile_size],buffer,size);
rf->ramfile_size = rf->ramfile_size + size;
}
else
{
rf->ramfile_size = 0;
size = 0;
}
return size;
}
int hxc_ram_fclose(FILE *f,HXCRAMFILE * rf)
{
if(rf->ramfile)
{
free(rf->ramfile);
rf->ramfile = NULL;
}
return 0;
};
+10
View File
@@ -90,6 +90,16 @@ int hxc_getpathfolder( char * fullpath, char * folder, int type );
int hxc_checkfileext( char * path, char *ext, int type );
int hxc_getfilesize( char * path );
typedef struct HXCRAMFILE_
{
uint8_t * ramfile;
int32_t ramfile_size;
}HXCRAMFILE;
FILE * hxc_ram_fopen(char* fn, char * mode, HXCRAMFILE * rf);
int hxc_ram_fwrite(void * buffer,int size,int mul,FILE * file,HXCRAMFILE * rf);
int hxc_ram_fclose(FILE *f,HXCRAMFILE * rf);
/////////////// Network functions ////////////////
void * network_connect(char * address,unsigned short port);