]> wimlib.net Git - wimlib/blobdiff - src/wim.c
begin_read(): Try fopen() before realpath()
[wimlib] / src / wim.c
index 3d6febf1ee7898a96a96a65e0941fa09bab27c2b..2278f2ebd051a1ff1d9a6df9e644c5262b3fcd89 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -60,11 +60,13 @@ static int print_files(WIMStruct *w)
 WIMStruct *new_wim_struct()
 {
        WIMStruct *w = CALLOC(1, sizeof(WIMStruct));
+#ifdef WITH_FUSE
        if (pthread_mutex_init(&w->fp_tab_mutex, NULL) != 0) {
                ERROR_WITH_ERRNO("Failed to initialize mutex");
                FREE(w);
                w = NULL;
        }
+#endif
        return w;
 
 }
@@ -416,12 +418,6 @@ static int begin_read(WIMStruct *w, const char *in_wim_path, int open_flags)
 
        DEBUG("Reading the WIM file `%s'", in_wim_path);
 
-       w->filename = realpath(in_wim_path, NULL);
-       if (!w->filename) {
-               ERROR("Failed to allocate memory for WIM filename");
-               return WIMLIB_ERR_NOMEM;
-       }
-
        w->fp = fopen(in_wim_path, "rb");
 
        if (!w->fp) {
@@ -430,6 +426,12 @@ static int begin_read(WIMStruct *w, const char *in_wim_path, int open_flags)
                return WIMLIB_ERR_OPEN;
        }
 
+       w->filename = realpath(in_wim_path, NULL);
+       if (!w->filename) {
+               ERROR("Failed to allocate memory for WIM filename");
+               return WIMLIB_ERR_NOMEM;
+       }
+
        ret = read_header(w->fp, &w->hdr, open_flags);
        if (ret != 0)
                return ret;
@@ -578,6 +580,7 @@ WIMLIBAPI void wimlib_free(WIMStruct *w)
        if (w->out_fp)
                fclose(w->out_fp);
 
+#ifdef WITH_FUSE
        if (w->fp_tab) {
                for (size_t i = 0; i < w->num_allocated_fps; i++)
                        if (w->fp_tab[i])
@@ -585,6 +588,7 @@ WIMLIBAPI void wimlib_free(WIMStruct *w)
                FREE(w->fp_tab);
        }
        pthread_mutex_destroy(&w->fp_tab_mutex);
+#endif
 
        free_lookup_table(w->lookup_table);