This commit is contained in:
twinaphex 2021-10-02 08:52:31 +02:00
parent 13d213f36f
commit 380ec577fe
2 changed files with 0 additions and 80 deletions

View File

@ -67,76 +67,3 @@ int file_close(struct MDFNFILE *file)
return 1; 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;
}

View File

@ -22,13 +22,6 @@ struct MDFNFILE *file_open(const char *path);
int file_close(struct MDFNFILE *file); 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 #ifdef __cplusplus
} }
#endif #endif