extern "C" {
#endif
+int ass_errno;
+
void ass_set_option(int opt, int val);
int ass_get_option(int opt);
struct ass_fileops *ass_alloc_url(const char *url);
void ass_free_url(struct ass_fileops *fop);
+int ass_mod_url_max_threads;
+char ass_mod_url_cachedir[512];
#endif /* ASSMAN_IMPL_H_ */
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "assman_impl.h"
+
+struct ass_fileops *ass_alloc_archive(const char *fname)
+{
+ fprintf(stderr, "assman: archive asset handler not implemented yet\n");
+ return 0; /* TODO */
+}
+
+void ass_free_archive(struct ass_fileops *fop)
+{
+}
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+
+#ifdef __MSVCRT__
+#include <malloc.h>
+#else
+#include <alloca.h>
+#endif
#include "assman_impl.h"
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;
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);
+}
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef BUILD_MOD_URL
+#include <curl/curl.h>
+
+static const char *get_temp_dir(void);
+
+static char *tmpdir, *cachedir;
+
+struct ass_fileops *ass_alloc_url(const char *url)
+{
+ static int done_init;
+ struct ass_fileops *fop;
+
+ if(!done_init) {
+ curl_global_init(CURL_GLOBAL_ALL);
+ atexit(curl_global_cleanup);
+ done_init = 1;
+
+ if(!*ass_mod_url_cachedir) {
+ strcpy(ass_mod_url_cachedir, "assman_cache");
+ }
+ tmpdir = get_temp_dir();
+ if(!(cachedir = malloc(strlen(ass_mod_url_cachedir) + strlen(tmpdir) + 2))) {
+ fprintf(stderr, "assman: failed to allocate cachedir path buffer\n");
+ return 0;
+ }
+ sprintf(cachedir, "%s/%s", tmpdir, ass_mod_url_cachedir);
+ }
+
+ if(!(fop = malloc(sizeof *fop))) {
+ return 0;
+ }
+
+ fop->udata = 0;
+ fop->open = fop_open;
+ fop->close = fop_close;
+ fop->seek = fop_seek;
+ fop->read = fop_read;
+ return fop;
+}
+
+void ass_free_url(struct ass_fileops *fop)
+{
+}
+
+static void *fop_open(const char *fname, void *udata)
+{
+ return 0; /* TODO */
+}
+
+static void fop_close(void *fp, void *udata)
+{
+}
+
+static long fop_seek(void *fp, long offs, int whence, void *udata)
+{
+ return 0;
+}
+
+static long fop_read(void *fp, void *buf, long size, void *udata)
+{
+ return 0;
+}
+
+#else
+int ass_mod_url_disabled;
+#endif