X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fwrite.c;h=ea3f583c77442ec960ec4517b515caee91a3e8f5;hp=4e59b851ae2a17aafc04799eecfe4b02c7d11fc1;hb=2a33c303e30fd740f740e21632fd06b9e414b0c7;hpb=6cc8db9fac4dcfdcd474ee49790a30a54b83c798 diff --git a/src/write.c b/src/write.c index 4e59b851..ea3f583c 100644 --- a/src/write.c +++ b/src/write.c @@ -32,6 +32,13 @@ #include #endif +#ifdef __WIN32__ +# include +# ifdef ERROR +# undef ERROR +# endif +#endif + #include "list.h" #include "wimlib_internal.h" #include "buffer_io.h" @@ -61,6 +68,13 @@ #include #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; @@ -1205,6 +1219,16 @@ out: 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, @@ -1220,8 +1244,8 @@ static int write_stream_list_parallel(struct list_head *stream_list, 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 {