Commit Graph

175 Commits

Author SHA1 Message Date
Rémi Denis-Courmont
dbc3f839d8 stdbit: fix CTZ fall-back
The computed value was incorrect for types smaller than long long. The
code is not really used by anything at the moment, since we pretty much
compile with Clang or GCC only.
2024-10-06 12:05:10 +00:00
Rémi Denis-Courmont
38c1029176 stdckdint: add compatibility header
This only implements unsigned types for now, as there are no known use
cases for signed checked arithmetic as of yet. The macros will safely
error out at compilation time if signed types are misused.
2024-02-20 19:34:53 +00:00
Rémi Denis-Courmont
7a970a3332 stdbit: fix std_bit_width*() 2024-01-18 20:34:12 +00:00
Rémi Denis-Courmont
623ee542ad stdbit: factor stdc_count_zeros*()
No functional changes.
2024-01-18 20:34:12 +00:00
Rémi Denis-Courmont
1931ecd606 stdbit: factor stdc_first_trailing_zero*()
No functional changes.
2024-01-18 20:34:12 +00:00
Rémi Denis-Courmont
585c4f854c stdbit: fix stdc_first_leading_*() 2024-01-18 20:34:12 +00:00
Rémi Denis-Courmont
a1245addb0 stdbit: use GCC / Clang built-ins where applicable 2024-01-06 13:23:18 +00:00
Rémi Denis-Courmont
a7707435a6 compat: add fallback for C23 <stdbit.h> 2024-01-06 13:23:18 +00:00
Steve Lhomme
465ed5f36f build: ignore more test generated files 2023-11-02 07:40:10 +00:00
Steve Lhomme
d91e21aec0 compat: always use _aligned_malloc/_aligned_free on Windows
We don't need the mingw custom code. It's available in msvcrt.dll and UCRT. It's better
to use the same code between mingw and MSVC builds.
2023-04-06 17:12:47 +00:00
Steve Lhomme
f3da50cde9 windows: use inline functions to redirect POSIX file API
Depend on _CRT_INTERNAL_NONSTDC_NAMES to detect if the aliases are
missing or not.
2023-03-03 13:57:15 +00:00
Steve Lhomme
105babe317 windows: use the native read/write/etc calls
When compiling with the GDK the POSIX variants are defined but not available
for linking. We can just the Windows variants that are always available.

Do the proper redirection in our custom unistd.h used with the Platform SDK.
2023-02-28 10:10:27 +00:00
Steve Lhomme
cedea4d018 configure: don't the check presence of stricmp
_stricmp a Windows thing that is present in all the CRT, even in UCRT.
The stricmp() deprecated variant doesn't seem to exist elsewhere.

In some configuration it's not possible to link with stricmp() even though
_stricmp() is available.
2023-02-28 10:10:27 +00:00
Steve Lhomme
6946b06a17 vlc_fixups: do warn about "deprecated" ANSI calls on Windows GDK
These functions are not available when linking, so we should avoid using them.
Also mingw-w64 understands _CRT_NONSTDC_NO_DEPRECATE but not
_CRT_NONSTDC_NO_WARNINGS.
2023-02-28 10:10:27 +00:00
Steve Lhomme
a81b06bf92 realpath: use the proper type returned by MultiByteToWideChar() 2023-02-10 18:18:54 +00:00
Romain Vimont
a632b0dfe2 compat: fix jrand48()
According to the manpage, jrand48() must return a signed long integer
uniformly distributed over the interval [-2^31, 2^31).

The old implementation first computed iterate48(), which returns a
positive 48-bit integer (as 'uint64_t', then cast to 'int64_t'). Once
right-shifted by 16 bits, the result is guaranteed to be a 32-bit
positive integer as 'int64_t'.

It is then (implicitly) cast to 'long' to match the return type.

When the 32th bit is 0 (i.e. the value fits in 31-bit), then everything
is ok. However, when the 32nd bit is 1, then there are two cases (which
are both incorrect):
 - if the 'long' type is 32-bit on the platform, then conversion from
   'int64_t' to 'long' is undefined;
 - if the 'long' type is more than 32-bit, then the resulting value will
   be a positive integer in the interval [0, 2^32), whereas jrand48()
   must return a value in the interval [-2^31, 2^31).
2023-01-23 15:01:48 +00:00
Steve Lhomme
571cda1958 localtime_r: don't set errno on success 2023-01-20 07:17:07 +00:00
Steve Lhomme
6f240f6cdd compat: implement windows specific gmtime_r
gmtime_s is the counterpart variant. Just like we use localtime_s for
localtime_r.
2023-01-20 07:17:07 +00:00
Steve Lhomme
86611b340b win32: provide a dirent.h when compiling with the Windows SDK
We don't need actual implementations as none of the dirent API ends up being
used in Windows builds.
2023-01-11 07:57:22 +00:00
Steve Lhomme
9f36f8d72c win32: provide a unistd.h when compiling with the Windows SDK 2023-01-11 07:57:22 +00:00
Steve Lhomme
6a46f1152d compat: define tfind family of functions regardless of the search.h status
The existence of search.h is not relevant for that. search.h may exist but does
not provide tfind, as on Windows.

If tfind.c is included for compilation, then the code needs to be built.
2023-01-06 14:46:46 +00:00
Marvin Scholz
d5f07af209 meson: add initial meson build system
Co-authored-by: Tanguy Dubroca <tanguy.dubroca@lse.epita.fr>
Co-authored-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Co-authored-by: Alexandre Janniaux <ajanni@videolabs.io>
2023-01-04 14:48:39 +00:00
Steve Lhomme
e12783288c compat: update tdelete/tfind/tsearch/twalk from NetBSD sources
See functions in https://github.com/NetBSD/src/tree/trunk/lib/libc/stdlib

Fixes a leak in tdelete().
2022-07-12 21:01:17 +00:00
Rémi Denis-Courmont
a29ba2f99a compat: add writev() replacement 2022-07-03 17:31:24 +00:00
Rémi Denis-Courmont
488162f210 compat: add readv() replacement 2022-07-03 17:31:24 +00:00
Steve Lhomme
4e6f2c60a3 inet_pton: don't redefine EAFNOSUPPORT for Win32
It's officially supported by the Windows SDK. Callers of these POSIX API's
don't expect to check errno is WSAEAFNOSUPPORT.
2022-06-30 12:58:50 +00:00
Steve Lhomme
ddcc2cdcff compat: add missing errno on Winsock errors
Some of the error codes [1] correspond to errno values [2]

[1] https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
[2] https://docs.microsoft.com/en-us/cpp/c-runtime-library/errno-constants
2022-06-28 17:24:51 +00:00
Rémi Denis-Courmont
ea93bcb8d3 compat: Linux getauxval() replacement
This was added over a decade ago, but 🤷...
2022-02-23 21:10:16 +00:00
Mehdi Sabwat
2d6897fd01 compat: remove deprecated platform
This commit removes conditional code for the Nacl platform.
2021-09-16 16:46:02 +00:00
Mehdi Sabwat
3f3296b03f compat: make clock_nanosleep usable by other OSes
This is to allow clock_nanosleep to be used by emscripten
and potentially other platforms.

The file should not be compiled on windows platforms, as it won't
find sys/errno.h

mach/clock_types.h is needed for clock_id_t, and is only available on
macos.
2021-09-05 14:58:30 +00:00
Mehdi Sabwat
d4b029ee5f compat: remove NSEC_PER_SEC in clock_nanosleep
This is to allow clock_nanosleep code to be used on platforms other
than Macosx.
2021-09-05 14:58:30 +00:00
Hugo Beauzée-Luyssen
86cb8efc29 compat: tfind: Don't use K&R prototypes
Some compilers are now refusing that syntax
2020-12-04 10:21:25 +01:00
Lyndon Brown
77431823c3 compat: gitignore test binaries
Signed-off-by: Steve Lhomme <robux4@ycbcr.xyz>
2020-10-06 14:21:51 +02:00
Alexandre Janniaux
e1c1eac150 compat: tfind: fix prototype
Use prototype from tsearch(3), fixes the following warning when
targetin Android arm API 17.

../../src/misc/variables.c:154:32: warning: passing 'void **' to
parameter of type 'const void **' discards qualifiers in nested
pointer types [-Wincompatible-pointer-types-discards-qualifiers]

    pp_var = tfind( &psz_name, &priv->var_root, varcmp );
                               ^~~~~~~~~~~~~~~
2020-06-30 10:49:18 +02:00
Marvin Scholz
be62319887 compat: add test for clock_nanosleep on darwin 2020-03-24 20:08:48 +01:00
Marvin Scholz
9999b4f54c compat: add clock_getres for darwin 2020-03-24 20:08:48 +01:00
Marvin Scholz
97fe588cbc compat: add clock_nanosleep for darwin 2020-03-24 20:08:48 +01:00
Marvin Scholz
f3f02e4ce8 compat: add clock_gettime for darwin 2020-03-24 19:56:36 +01:00
Alexandre Janniaux
a2e2cf0ab0 compat: lfind: fix warnings
Signed-off-by: Thomas Guillem <thomas@gllm.fr>
2020-02-20 10:02:47 +01:00
Rémi Denis-Courmont
cc129a71d7 Remove old mail address from sources 2019-09-04 22:11:04 +03:00
Rémi Denis-Courmont
778b577bec compat: provide dummy.c, simplify Makefile 2019-07-26 21:31:19 +03:00
Rémi Denis-Courmont
07e3b65d24 compat: test heap allocation replacements 2019-07-26 21:31:19 +03:00
Rémi Denis-Courmont
cd80b6ab72 compat: restore posix_memalign()
aligned_alloc() is not portably suitable for over-alignments.
posix_memalign()/memalign() are still needed.

This essentially reverts commit 34cd965645.
2019-07-26 21:31:19 +03:00
Rémi Denis-Courmont
577ba74815 compat: fix default aligned_alloc() 2019-07-26 21:31:19 +03:00
Rémi Denis-Courmont
fa48f95c85 compat: missing #include, fix warning 2019-04-14 10:04:37 +03:00
Thomas Guillem
b3eaf5a239 compat: remove qsort_r 2019-01-22 18:55:32 +01:00
Rémi Denis-Courmont
5ffb9dfe0e compat: replace qsort_r() where missing
This should sort properly on Windows and any other platform without
qsort_r(). It does _not_ fix any potential issues on any platforms with
an incompatible qsort_r() prototype (such as FreeBSD < 13).
2018-11-20 17:59:15 +02:00
Victorien Le Couviour--Tuffet
cf9bd77c67 compat: add lfind
Fixes android build with NDK 17 as lfind is not always available.
2018-10-23 14:53:25 +02:00
Rémi Denis-Courmont
893432c251 strlcpy: simplify 2018-06-17 11:23:11 +03:00
Steve Lhomme
f0a7bc050f compat: provide a win32 specific version of timespec_get
On mingw64 clock_gettime() is defined in winpthread which we don't want to use.

This implementation is based on the winpthread internal processing.
2018-05-15 18:34:30 +02:00