X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=assman;a=blobdiff_plain;f=src%2Fmod_path.c;h=1a680e621f4745b54e49257f22e774c93ef464c6;hp=1776eceedf711424cd8596a5de5ce7a3ed87951a;hb=b8fc7437862ca32cf79108c7715b8e2566211fb1;hpb=8d90197913f1c5d813b43854f5f769bade5296a8 diff --git a/src/mod_path.c b/src/mod_path.c index 1776ece..1a680e6 100644 --- a/src/mod_path.c +++ b/src/mod_path.c @@ -1,4 +1,14 @@ +#include #include +#include +#include +#include + +#ifdef __MSVCRT__ +#include +#else +#include +#endif #include "assman_impl.h" @@ -26,7 +36,7 @@ struct ass_fileops *ass_alloc_path(const char *path) while(*path) { *p++ = *path++; } - while(p > fop->udata && (p[-1] == '/' || isspace(p[-1]))) p--; + while(p > (char*)fop->udata && (p[-1] == '/' || isspace(p[-1]))) p--; *p = 0; fop->open = fop_open; @@ -36,10 +46,39 @@ struct ass_fileops *ass_alloc_path(const char *path) return fop; } +void ass_free_path(struct ass_fileops *fop) +{ + free(fop->udata); +} + static void *fop_open(const char *fname, void *udata) { + const char *prefix = (char*)udata; + char *path; + FILE *fp; + + path = alloca(strlen(prefix) + strlen(fname) + 2); + sprintf(path, "%s/%s", path, fname); + + if(!(fp = fopen(path, "rb"))) { + ass_errno = errno; + return 0; + } + return fp; } -static void fop_close(void *fp, void *udata); -static long fop_seek(void *fp, long offs, int whence, void *udata); -static long fop_read(void *fp, void *buf, long size, void *udata); +static void fop_close(void *fp, void *udata) +{ + fclose(fp); +} + +static long fop_seek(void *fp, long offs, int whence, void *udata) +{ + fseek(fp, offs, whence); + return ftell(fp); +} + +static long fop_read(void *fp, void *buf, long size, void *udata) +{ + return fread(buf, 1, size, fp); +}