mirror of
https://github.com/libretro/beetle-pce-fast-libretro.git
synced 2024-11-22 23:39:50 +00:00
Cleanups
This commit is contained in:
parent
13d213f36f
commit
380ec577fe
@ -67,76 +67,3 @@ int file_close(struct MDFNFILE *file)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint64_t file_read(struct MDFNFILE *file, void *ptr,
|
||||
size_t element_size, size_t nmemb)
|
||||
{
|
||||
uint32_t total = element_size * nmemb;
|
||||
|
||||
if (file->location >= file->size)
|
||||
return 0;
|
||||
|
||||
if ((file->location + total) > file->size)
|
||||
{
|
||||
int64_t ak = file->size - file->location;
|
||||
|
||||
memcpy((uint8_t*)ptr, file->data + file->location, ak);
|
||||
|
||||
file->location = file->size;
|
||||
|
||||
return(ak / element_size);
|
||||
}
|
||||
|
||||
memcpy((uint8_t*)ptr, file->data + file->location, total);
|
||||
|
||||
file->location += total;
|
||||
|
||||
return nmemb;
|
||||
}
|
||||
|
||||
int file_seek(struct MDFNFILE *file, int64_t offset, int whence)
|
||||
{
|
||||
switch(whence)
|
||||
{
|
||||
case SEEK_SET:
|
||||
if (offset >= file->size)
|
||||
return -1;
|
||||
|
||||
file->location = offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
if ((offset + file->location) > file->size)
|
||||
return -1;
|
||||
|
||||
file->location += offset;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *file_fgets(struct MDFNFILE *file, char *s, int len)
|
||||
{
|
||||
int pos = 0;
|
||||
|
||||
if (!len)
|
||||
return(NULL);
|
||||
|
||||
if (file->location >= len)
|
||||
return(NULL);
|
||||
|
||||
while(pos < (len - 1) && file->location < len)
|
||||
{
|
||||
int v = file->data[file->location];
|
||||
s[pos] = v;
|
||||
file->location++;
|
||||
pos++;
|
||||
if (v == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
if (len)
|
||||
s[pos] = 0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -22,13 +22,6 @@ struct MDFNFILE *file_open(const char *path);
|
||||
|
||||
int file_close(struct MDFNFILE *file);
|
||||
|
||||
uint64_t file_read(struct MDFNFILE *file, void *ptr,
|
||||
size_t element_size, size_t nmemb);
|
||||
|
||||
int file_seek(struct MDFNFILE *file, int64_t offset, int whence);
|
||||
|
||||
char *file_fgets(struct MDFNFILE *file, char *s, int buffer_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user