13 #include "assman_impl.h"
16 static void *fop_open(const char *fname, void *udata);
17 static void fop_close(void *fp, void *udata);
18 static long fop_seek(void *fp, long offs, int whence, void *udata);
19 static long fop_read(void *fp, void *buf, long size, void *udata);
22 struct ass_fileops *ass_alloc_path(const char *path)
25 struct ass_fileops *fop;
27 if(!(fop = malloc(sizeof *fop))) {
30 if(!(p = malloc(strlen(path) + 1))) {
39 while(p > (char*)fop->udata && (p[-1] == '/' || isspace(p[-1]))) p--;
43 fop->close = fop_close;
49 void ass_free_path(struct ass_fileops *fop)
54 static void *fop_open(const char *fname, void *udata)
56 const char *asspath = (char*)udata;
60 path = alloca(strlen(asspath) + strlen(fname) + 2);
61 sprintf(path, "%s/%s", asspath, fname);
63 if(!(fp = fopen(path, "rb"))) {
70 static void fop_close(void *fp, void *udata)
75 static long fop_seek(void *fp, long offs, int whence, void *udata)
77 fseek(fp, offs, whence);
81 static long fop_read(void *fp, void *buf, long size, void *udata)
83 return fread(buf, 1, size, fp);