Compare commits

...

5 Commits

Author SHA1 Message Date
Dave Vasilevsky 294875b108
Merge pull request #112 from vasi/wincpu
msys2 support
6 months ago
Dave Vasilevsky ebeb225a07 win can return >1 for isatty 6 months ago
Dave Vasilevsky 7ed15497be check for seekability on win 6 months ago
Dave Vasilevsky 446087ed7a use binary mode for win files 6 months ago
Dave Vasilevsky cb961a54b0 detect windows cpus 6 months ago

@ -68,7 +68,8 @@ AC_SYS_LARGEFILE
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_STRTOD
AC_CHECK_FUNCS([memchr memmove memset strerror strtol sched_getaffinity])
AC_CHECK_FUNCS([memchr memmove memset strerror strtol sched_getaffinity sysconf
GetSystemInfo _setmode _get_osfhandle])
AC_CHECK_HEADER([sys/endian.h],
[
AC_CHECK_DECLS([htole64, le64toh], [], [], [

@ -4,6 +4,9 @@
#include <stdarg.h>
#include <math.h>
#if HAVE__GET_OSFHANDLE
#include <windows.h>
#endif
#pragma mark UTILS
@ -344,6 +347,17 @@ static lzma_index *next_index(off_t *pos) {
}
bool decode_index(void) {
#if HAVE__GET_OSFHANDLE
// windows pretends that seeking works on pipes, but then it doesn't
// try to check that this is a "regular" file with win api
intptr_t hdl = _get_osfhandle(_fileno(gInFile));
DWORD ftype = GetFileType((HANDLE)hdl);
if (ftype != FILE_TYPE_DISK) {
fprintf(stderr, "can not seek in input\n");
return false;
}
#endif
if (fseeko(gInFile, 0, SEEK_END) == -1) {
fprintf(stderr, "can not seek in input: %s\n", strerror(errno));
return false; // not seekable

@ -1,28 +1,35 @@
#define _GNU_SOURCE
#include <unistd.h>
#include "config.h"
#ifdef HAVE_SCHED_GETAFFINITY
#include <sched.h>
#include <stdio.h>
#endif
#ifdef HAVE_SYSCONF
#include <unistd.h>
#endif
#ifdef HAVE_GETSYSTEMINFO
#include <sysinfoapi.h>
#endif
size_t num_threads(void) {
#ifdef HAVE_SCHED_GETAFFINITY
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
if (sched_getaffinity(0, sizeof cpu_set, &cpu_set) == -1)
return sysconf(_SC_NPROCESSORS_ONLN);
else
if (sched_getaffinity(0, sizeof cpu_set, &cpu_set) == 0)
return CPU_COUNT(&cpu_set);
}
#else
#endif
size_t num_threads(void) {
#ifdef HAVE_SYSCONF
return sysconf(_SC_NPROCESSORS_ONLN);
}
#elif HAVE_GETSYSTEMINFO
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
#else
#warning "No processor-detection enabled! Assuming 2 CPUs"
return 2;
#endif
}

@ -164,9 +164,15 @@ int main(int argc, char **argv) {
}
}
#ifdef HAVE__SETMODE
// Set files to binary encoding
_setmode(_fileno(gInFile), O_BINARY);
_setmode(_fileno(gOutFile), O_BINARY);
#endif
switch (op) {
case OP_WRITE:
if (isatty(fileno(gOutFile)) == 1)
if (isatty(fileno(gOutFile)))
usage("Refusing to output to a TTY");
if (extreme)
level |= LZMA_PRESET_EXTREME;

Loading…
Cancel
Save