- added shared library build rules
[assman] / src / assman.c
index 2e263e6..1e692bc 100644 (file)
@@ -1,12 +1,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include "assman_impl.h"
 
 static int add_fop(const char *prefix, int type, struct ass_fileops *fop);
 static const char *match_prefix(const char *str, const char *prefix);
-static int add_file(ass_file *file);
-static int remove_file(ass_file *file);
 
 #define DEF_FLAGS      (1 << ASS_OPEN_FALLTHROUGH)
 
@@ -108,11 +107,12 @@ ass_file *ass_fopen(const char *fname, const char *mode)
        void *mfile;
        ass_file *file;
        FILE *fp;
+       const char *after_prefix;
 
        m = mlist;
        while(m) {
-               if(match_prefix(fname, m->prefix)) {
-                       if((mfile = m->fop->open(fname, m->fop->udata))) {
+               if((after_prefix = match_prefix(fname, m->prefix))) {
+                       if((mfile = m->fop->open(after_prefix, m->fop->udata))) {
                                if(!(file = malloc(sizeof *file))) {
                                        perror("assman: ass_fopen failed to allocate file structure");
                                        m->fop->close(mfile, m->fop->udata);
@@ -120,12 +120,6 @@ ass_file *ass_fopen(const char *fname, const char *mode)
                                }
                                file->file = mfile;
                                file->fop = m->fop;
-
-                               if(add_file(file) == -1) {
-                                       m->fop->close(mfile, m->fop->udata);
-                                       free(file);
-                                       return 0;
-                               }
                                return file;
                        } else {
                                if(!(assflags & (1 << ASS_OPEN_FALLTHROUGH))) {
@@ -139,20 +133,16 @@ ass_file *ass_fopen(const char *fname, const char *mode)
        /* nothing matched, or failed to open, try the filesystem */
        if((fp = fopen(fname, mode))) {
                if(!(file = malloc(sizeof *file))) {
+                       ass_errno = errno;
                        perror("assman: ass_fopen failed to allocate file structure");
                        fclose(fp);
                        return 0;
                }
                file->file = fp;
                file->fop = 0;
-
-               if(add_file(file) == -1) {
-                       fclose(fp);
-                       free(file);
-                       return 0;
-               }
                return file;
        }
+       ass_errno = errno;
        return 0;
 }
 
@@ -175,7 +165,6 @@ void ass_fclose(ass_file *fp)
        } else {
                fclose(fp->file);
        }
-       remove_file(fp);
        free(fp);
 }
 
@@ -238,14 +227,3 @@ char *ass_fgets(char *s, int size, ass_file *fp)
        *ptr = 0;
        return ptr == s ? 0 : s;
 }
-
-
-static int add_file(ass_file *file)
-{
-       return -1;      /* TODO */
-}
-
-static int remove_file(ass_file *file)
-{
-       return -1;      /* TODO */
-}