X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fwim.c;h=8022423c98c52dc2796ed5244ef1f616ffc7b82f;hb=794ecd09fc527e3328e469c14e563d42a7a70a39;hp=27cf93f4587f3e477da4a33a1ffdc85cd2e9f3cf;hpb=f9695b9f40035f1a20968293255761a8301eaba0;p=wimlib diff --git a/src/wim.c b/src/wim.c index 27cf93f4..8022423c 100644 --- a/src/wim.c +++ b/src/wim.c @@ -65,9 +65,10 @@ static WIMStruct * new_wim_struct() { WIMStruct *w = CALLOC(1, sizeof(WIMStruct)); - w->in_fd = INVALID_FILEDES; - w->out_fd = INVALID_FILEDES; - w->current_image = WIMLIB_NO_IMAGE; + if (w) { + w->in_fd = -1; + w->out_fd = -1; + } return w; } @@ -196,7 +197,7 @@ select_wim_image(WIMStruct *w, int image) } w->current_image = image; imd = wim_get_current_image_metadata(w); - if (imd->root_dentry) { + if (imd->root_dentry || imd->modified) { ret = 0; } else { #ifdef ENABLE_DEBUG @@ -384,11 +385,11 @@ wimlib_get_boot_idx(const WIMStruct *w) } static int -do_open_wim(const tchar *filename, filedes_t *fd_ret) +do_open_wim(const tchar *filename, int *fd_ret) { int fd; - fd = open(filename, O_RDONLY); + fd = topen(filename, O_RDONLY | O_BINARY); if (fd == -1) { ERROR_WITH_ERRNO("Can't open \"%"TS"\" read-only", filename); return WIMLIB_ERR_OPEN; @@ -400,15 +401,17 @@ do_open_wim(const tchar *filename, filedes_t *fd_ret) int reopen_wim(WIMStruct *w) { - wimlib_assert(w->in_fd == INVALID_FILEDES); + wimlib_assert(w->in_fd == -1); return do_open_wim(w->filename, &w->in_fd); } int close_wim(WIMStruct *w) { - close(w->in_fd); - w->in_fd = INVALID_FILEDES; + if (w->in_fd != -1) { + close(w->in_fd); + w->in_fd = -1; + } return 0; } @@ -450,7 +453,7 @@ begin_read(WIMStruct *w, const tchar *in_wim_path, int open_flags, return WIMLIB_ERR_OPEN; } - ret = read_header(w->in_fd, &w->hdr, open_flags); + ret = read_header(w->filename, w->in_fd, &w->hdr, open_flags); if (ret) return ret; @@ -668,9 +671,9 @@ wimlib_free(WIMStruct *w) if (!w) return; - if (w->in_fd != INVALID_FILEDES) + if (w->in_fd != -1) close(w->in_fd); - if (w->out_fd != INVALID_FILEDES) + if (w->out_fd != -1) close(w->out_fd); free_lookup_table(w->lookup_table);