Add filestream_get_ext

This commit is contained in:
twinaphex 2017-02-18 02:16:40 +01:00
parent acb20e2d28
commit e9524f1b95
2 changed files with 15 additions and 0 deletions

View File

@ -47,6 +47,8 @@ enum
RFILE_HINT_MMAP = 1<<9 /* requires RFILE_MODE_READ */
};
const char *filestream_get_ext(RFILE *stream);
RFILE *filestream_open(const char *path, unsigned mode, ssize_t len);
ssize_t filestream_seek(RFILE *stream, ssize_t offset, int whence);

View File

@ -68,6 +68,7 @@
struct RFILE
{
unsigned hints;
char *ext;
#if defined(PSP)
SceUID fd;
#else
@ -102,6 +103,13 @@ int filestream_get_fd(RFILE *stream)
return stream->fd;
}
const char *filestream_get_ext(RFILE *stream)
{
if (!stream)
return NULL;
return stream->ext;
}
RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
{
int flags = 0;
@ -236,6 +244,11 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
goto error;
#endif
{
const char *ld = (const char*)strrchr(path, '.');
stream->ext = strdup(ld ? ld + 1 : "");
}
return stream;
error: