summaryrefslogtreecommitdiff
path: root/src/common
Commit message (Collapse)AuthorAgeFilesLines
* tuklib_integer.h: Fix a recent copypaste error in Clang detection.Lasse Collin2023-05-031-2/+2
| | | | | | Wrong line was changed in 7062348bf35c1e4cbfee00ad9fffb4a21aa6eff7. Also, this has >= instead of == since ints larger than 32 bits would work too even if not relevant in practice.
* Windows: Include <intrin.h> when needed.Jia Tan2023-05-031-0/+6
| | | | | | | | | | Legacy Windows did not need to #include <intrin.h> to use the MSVC intrinsics. Newer versions likely just issue a warning, but the MSVC documentation says to include the header file for the intrinsics we use. GCC and Clang can "pretend" to be MSVC on Windows, so extra checks are needed in tuklib_integer.h to only include <intrin.h> when it will is actually needed.
* tuklib_integer: Use __builtin_clz() with Clang.Jia Tan2023-05-031-3/+3
| | | | | | | | | Clang has support for __builtin_clz(), but previously Clang would fallback to either the MSVC intrinsic or the regular C code. This was discovered due to a bug where a new version of Clang required the <intrin.h> header file in order to use the MSVC intrinsics. Thanks to Anton Kochkov for notifying us about the bug.
* tuklib_physmem: Silence warning from -Wcast-function-type on MinGW-w64.Jia Tan2023-03-111-0/+18
| | | | | | | | tuklib_physmem depends on GetProcAddress() for both MSVC and MinGW-w64 to retrieve a function address. The proper way to do this is to cast the return value to the type of function pointer retrieved. Unfortunately, this causes a cast-function-type warning, so the best solution is to simply ignore the warning.
* Windows: Fix mythread_once() macro with Vista threads.Lasse Collin2022-11-111-3/+4
| | | | | | | | | | Don't call InitOnceComplete() if initialization was already done. So far mythread_once() has been needed only when building with --enable-small. windows/build.bash does this together with --disable-threads so the Vista-specific mythread_once() is never needed by those builds. VS project files or CMake-builds don't support HAVE_SMALL builds at all.
* tuklib_cpucores: Use HW_NCPUONLINE on OpenBSD.Lasse Collin2022-11-111-0/+9
| | | | | | | | On OpenBSD the number of cores online is often less than what HW_NCPU would return because OpenBSD disables simultaneous multi-threading (SMT) by default. Thanks to Christian Weisgerber.
* tuklib_physmem: Fix Unicode builds on Windows.Lasse Collin2022-09-291-1/+1
| | | | Thanks to ArSaCiA Game.
* Windows: Fix building of resource files when config.h isn't used.Lasse Collin2022-07-121-1/+3
| | | | | | Now CMake + Visual Studio works for building liblzma.dll. Thanks to Markus Rickert.
* Use defined(__GNUC__) before __GNUC__ in preprocessor lines.Lasse Collin2020-03-111-1/+2
| | | | | This should silence the equivalent of -Wundef in compilers that don't define __GNUC__.
* tuklib_exit: Add missing header.Lasse Collin2020-03-111-0/+1
| | | | | | | strerror() needs <string.h> which happened to be included via tuklib_common.h -> tuklib_config.h -> sysdefs.h if HAVE_CONFIG_H was defined. This wasn't tested without config.h before so it had worked fine.
* sysdefs.h: Omit the conditionals around string.h and limits.h.Lasse Collin2020-03-111-6/+2
| | | | | | | string.h is used unconditionally elsewhere in the project and configure has always stopped if limits.h is missing, so these headers must have been always available even on the weirdest systems.
* Rename unaligned_read32ne to read32ne, and similarly for the others.Lasse Collin2019-12-311-34/+30
|
* Rename read32ne to aligned_read32ne, and similarly for the others.Lasse Collin2019-12-311-28/+28
| | | | | | | | Using the aligned methods requires more care to ensure that the address really is aligned, so it's nicer if the aligned methods are prefixed. The next commit will remove the unaligned_ prefix from the unaligned methods which in liblzma are used in more places than the aligned ones.
* Revise tuklib_integer.h and .m4.Lasse Collin2019-12-311-217/+271
| | | | | | | | | | | | | | | | | | | | | | | Add a configure option --enable-unsafe-type-punning to get the old non-conforming memory access methods. It can be useful with old compilers or in some other less typical situations but shouldn't normally be used. Omit the packed struct trick for unaligned access. While it's best in some cases, this is simpler. If the memcpy trick doesn't work, one can request unsafe type punning from configure. Because CRC32/CRC64 code needs fast aligned reads, if no very safe way to do it is found, type punning is used as a fallback. This sucks but since it currently works in practice, it seems to be the least bad option. It's never needed with GCC >= 4.7 or Clang >= 3.6 since these support __builtin_assume_aligned and thus fast aligned access can be done with the memcpy trick. Other things: - Support GCC/Clang __builtin_bswapXX - Cleaner bswap fallback macros - Minor cleanups
* Fix comment typos in tuklib_mbstr* files.Lasse Collin2019-12-313-3/+3
|
* Add missing include to tuklib_mbstr_width.c.Lasse Collin2019-12-311-0/+1
| | | | | It didn't matter in XZ Utils because sysdefs.h includes string.h anyway.
* tuklib_mbstr_width: Fix a warning from -Wsign-conversion.Lasse Collin2019-12-311-1/+1
|
* tuklib_cpucores: Silence warnings from -Wsign-conversion.Lasse Collin2019-12-311-5/+5
|
* tuklib_integer: Silence warnings from -Wsign-conversion.Lasse Collin2019-12-311-3/+3
|
* tuklib_integer: Fix usage of conv macros.Lasse Collin2019-12-311-4/+8
| | | | | | Use a temporary variable instead of e.g. conv32le(unaligned_read32ne(buf)) because the macro can evaluate its argument multiple times.
* tuklib_integer: Cleanup MSVC-specific code.Lasse Collin2019-12-311-11/+9
|
* tuklib_integer: Improve unaligned memory access.Lasse Collin2019-12-311-12/+168
| | | | | | | | | | | Now memcpy() or GNU C packed structs for unaligned access instead of type punning. See the comment in this commit for details. Avoiding type punning with unaligned access is needed to silence gcc -fsanitize=undefined. New functions: unaliged_readXXne and unaligned_writeXXne where XX is 16, 32, or 64.
* tuklib_integer: New Intel C compiler needs immintrin.h.Lasse Collin2018-03-281-0/+11
| | | | Thanks to Melanie Blower (Intel) for the patch.
* Update the home page URLs to HTTPS.Lasse Collin2018-03-281-1/+1
|
* tuklib_cpucores: Add support for sched_getaffinity().Lasse Collin2016-12-261-0/+9
| | | | | | | | | | | | | | | | It's available in glibc (GNU/Linux, GNU/kFreeBSD). It's better than sysconf(_SC_NPROCESSORS_ONLN) because sched_getaffinity() gives the number of cores available to the process instead of the total number of cores online. As a side effect, this commit fixes a bug on GNU/kFreeBSD where configure would detect the FreeBSD-specific cpuset_getaffinity() but it wouldn't actually work because on GNU/kFreeBSD it requires using -lfreebsd-glue when linking. Now the glibc-specific function will be used instead. Thanks to Sebastian Andrzej Siewior for the original patch and testing.
* tuklib_physmem: Hopefully silence a warning on Windows.Lasse Collin2016-06-281-1/+2
|
* Fix the detection of installed RAM on QNX.Lasse Collin2015-03-291-1/+13
| | | | | | | The earlier version compiled but didn't actually work since sysconf(_SC_PHYS_PAGES) always fails (or so I was told). Thanks to Ole André Vadla Ravnås for the patch and testing.
* tuklib_cpucores: Use cpuset_getaffinity() on FreeBSD if available.Lasse Collin2015-02-101-0/+18
| | | | | | | | In FreeBSD, cpuset_getaffinity() is the preferred way to get the number of available cores. Thanks to Rui Paulo for the patch. I edited it slightly, but hopefully I didn't break anything.
* Add a few casts to tuklib_integer.h to silence possible warnings.Lasse Collin2015-02-031-12/+12
| | | | | | I heard that Visual Studio 2013 gave warnings without the casts. Thanks to Gabi Davar.
* Fix build when --disable-threads is used.Lasse Collin2014-12-211-0/+2
|
* Add support for AmigaOS/AROS to tuklib_physmem().Lasse Collin2014-10-091-0/+7
| | | | Thanks to Fredrik Wikstrom.
* Windows: Add MSVC defines for inline and restrict keywords.Lasse Collin2014-01-121-0/+10
|
* Fix typos in comments.Lasse Collin2014-01-121-1/+1
|
* Add native threading support on Windows.Lasse Collin2013-09-171-111/+402
| | | | | | | | | | | | | | Now liblzma only uses "mythread" functions and types which are defined in mythread.h matching the desired threading method. Before Windows Vista, there is no direct equivalent to pthread condition variables. Since this package doesn't use pthread_cond_broadcast(), pre-Vista threading can still be kept quite simple. The pre-Vista code doesn't use anything that wasn't already available in Windows 95, so the binaries should run even on Windows 95 if someone happens to care.
* Fix the previous commit which broke the build.Lasse Collin2013-08-041-1/+1
| | | | | | Apparently I didn't even compile-test the previous commit. Thanks to Christian Hesse.
* Windows: Add Windows support to tuklib_cpucores().Lasse Collin2013-08-031-1/+12
| | | | | | | It is used for Cygwin too. I'm not sure if that is a good or bad idea. Thanks to Vincent Torri.
* liblzma: Fix mythread_sync for nested locking.Lasse Collin2012-12-141-2/+3
|
* Workaround unusual SIZE_MAX on SCO OpenServer.Lasse Collin2011-08-091-3/+6
|
* Don't call close(-1) in tuklib_open_stdxxx() on error.Lasse Collin2011-05-281-1/+3
| | | | Thanks to Jim Meyering.
* Don't use clockid_t in mythread.h when clock_gettime() isn't available.Lasse Collin2011-05-171-0/+2
| | | | Thanks to Wim Lewis for the patch.
* Fix portability problems in mythread.h.Lasse Collin2011-04-191-4/+27
| | | | | | | | | | | | | | | | Use gettimeofday() if clock_gettime() isn't available (e.g. Darwin). The test for availability of pthread_condattr_setclock() and CLOCK_MONOTONIC was incorrect. Instead of fixing the #ifdefs, use an Autoconf test. That way if there exists a system that supports them but doesn't specify the matching POSIX #defines, the features will still get detected. Don't try to use pthread_sigmask() on OpenVMS. It doesn't have that function. Guard mythread.h against being #included multiple times.
* Revise mythread.h.Lasse Collin2011-04-101-20/+180
| | | | | | | | | | | | | | | | | | | | This adds: - mythread_sync() macro to create synchronized blocks - mythread_cond structure and related functions and macros for condition variables with timed waiting using a relative timeout - mythread_create() to create a thread with all signals blocked Some of these wouldn't need to be inline functions, but I'll keep them this way for now for simplicity. For timed waiting on a condition variable, librt is now required on some systems to use clock_gettime(). configure.ac was updated to handle this.
* Add alloc_size and malloc attributes to a few functions.Lasse Collin2011-01-181-0/+6
| | | | Thanks to Cristian Rodríguez for the original patch.
* Add missing PRIx32 and PRIx64 compatibility definitions.Lasse Collin2010-12-121-0/+9
| | | | | | This fixes portability to systems that lack C99 inttypes.h. Thanks to Juan Manuel Guerrero.
* Windows: Use MinGW's stdio functions.Lasse Collin2010-10-231-0/+5
| | | | | | | | The non-standard ones from msvcrt.dll appear to work most of the time with XZ Utils, but there are some corner cases where things may go very wrong. So it's good to use the better replacements provided by MinGW(-w64) runtime.
* Windows: Update common_w32res.rc.Lasse Collin2010-10-091-6/+3
|
* xz: Multiple fixes.Lasse Collin2010-09-103-0/+161
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code assumed that printing numbers with thousand separators and decimal points would always produce only US-ASCII characters. This was used for buffer sizes (with snprintf(), no overflows) and aligning columns of the progress indicator and --list. That assumption was wrong (e.g. LC_ALL=fi_FI.UTF-8 with glibc), so multibyte character support was added in this commit. The old way is used if the operating system doesn't have enough multibyte support (e.g. lacks wcwidth()). The sizes of buffers were increased to accomodate multibyte characters. I don't know how big they should be exactly, but they aren't used for anything critical, so it's not too bad. If they still aren't big enough, I hopefully get a bug report. snprintf() takes care of avoiding buffer overflows. Some static buffers were replaced with buffers allocated on stack. double_to_str() was removed. uint64_to_str() and uint64_to_nicestr() now share the static buffer and test for thousand separator support. Integrity check names "None" and "Unknown-N" (2 <= N <= 15) were marked to be translated. I had forgot these, plus they wouldn't have worked correctly anyway before this commit, because printing tables with multibyte strings didn't work. Thanks to Marek Černocký for reporting the bug about misaligned table columns in --list output.
* Fix use of N_() and ngettext().Lasse Collin2010-09-071-2/+2
| | | | | | | I had somehow thought that N_() is usually used as shorthand for ngettext(). This also fixes a missing \n from a call to ngettext().
* Rename MIN() and MAX() to my_min() and my_max().Lasse Collin2010-05-261-7/+5
| | | | This should avoid some minor portability issues.
* Better #error message.Lasse Collin2010-05-261-2/+2
|