]> wimlib.net Git - wimlib/blobdiff - src/write.c
Windows native build
[wimlib] / src / write.c
index c346e61c65c57e51b629e5d306799724255d18f4..ea3f583c77442ec960ec4517b515caee91a3e8f5 100644 (file)
 #include <sys/file.h>
 #endif
 
 #include <sys/file.h>
 #endif
 
+#ifdef __WIN32__
+#      include <windows.h>
+#      ifdef ERROR
+#              undef ERROR
+#      endif
+#endif
+
 #include "list.h"
 #include "wimlib_internal.h"
 #include "buffer_io.h"
 #include "list.h"
 #include "wimlib_internal.h"
 #include "buffer_io.h"
 #include <stdlib.h>
 #endif
 
 #include <stdlib.h>
 #endif
 
+#ifdef __WIN32__
+#      ifdef fsync
+#              undef fsync
+#      endif
+#      define fsync(fd) 0
+#endif
+
 static int fflush_and_ftruncate(FILE *fp, off_t size)
 {
        int ret;
 static int fflush_and_ftruncate(FILE *fp, off_t size)
 {
        int ret;
@@ -297,7 +311,7 @@ static int prepare_resource_for_read(struct wim_lookup_table_entry *lte
 #if defined(__CYGWIN__) || defined(__WIN32__)
        case RESOURCE_WIN32:
                if (!lte->file_on_disk_fp) {
 #if defined(__CYGWIN__) || defined(__WIN32__)
        case RESOURCE_WIN32:
                if (!lte->file_on_disk_fp) {
-                       lte->file_on_disk_fp = win32_open_handle(lte->file_on_disk);
+                       lte->file_on_disk_fp = win32_open_file_readonly(lte->file_on_disk);
                        if (!lte->file_on_disk_fp)
                                return WIMLIB_ERR_OPEN;
                }
                        if (!lte->file_on_disk_fp)
                                return WIMLIB_ERR_OPEN;
                }
@@ -337,7 +351,7 @@ static void end_wim_resource_read(struct wim_lookup_table_entry *lte
        else if (lte->resource_location == RESOURCE_WIN32
                 && lte->file_on_disk_fp)
        {
        else if (lte->resource_location == RESOURCE_WIN32
                 && lte->file_on_disk_fp)
        {
-               win32_close_handle(lte->file_on_disk_fp);
+               win32_close_file(lte->file_on_disk_fp);
                lte->file_on_disk_fp = NULL;
        }
 #endif
                lte->file_on_disk_fp = NULL;
        }
 #endif
@@ -1205,6 +1219,16 @@ out:
        return ret;
 }
 
        return ret;
 }
 
+static long get_default_num_threads()
+{
+#ifdef __WIN32__
+       SYSTEM_INFO sysinfo;
+       GetSystemInfo(&sysinfo);
+       return sysinfo.dwNumberOfProcessors;
+#else
+       return sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+}
 
 static int write_stream_list_parallel(struct list_head *stream_list,
                                      FILE *out_fp,
 
 static int write_stream_list_parallel(struct list_head *stream_list,
                                      FILE *out_fp,
@@ -1220,8 +1244,8 @@ static int write_stream_list_parallel(struct list_head *stream_list,
        pthread_t *compressor_threads = NULL;
 
        if (num_threads == 0) {
        pthread_t *compressor_threads = NULL;
 
        if (num_threads == 0) {
-               long nthreads = sysconf(_SC_NPROCESSORS_ONLN);
-               if (nthreads < 1) {
+               long nthreads = get_default_num_threads();
+               if (nthreads < 1 || nthreads > UINT_MAX) {
                        WARNING("Could not determine number of processors! Assuming 1");
                        goto out_serial;
                } else {
                        WARNING("Could not determine number of processors! Assuming 1");
                        goto out_serial;
                } else {