Skip to content

Commit

Permalink
#87: update word size detection
Browse files Browse the repository at this point in the history
The detection for word size was dependent on `__LONG_WIDTH__` for at
least gcc Alpine Linux (probably other musl distros too).

This is not working with clang which does not define `__LONG_WIDTH__`.
Replace `__LONG_WIDTH__` by `__SIZE_WIDTH__`.

As this will not work as expected for x32 ABI, add robust x32 detection
first.

Closes #87.
  • Loading branch information
mayeut authored and aklomp committed Jun 5, 2022
1 parent 79eb06b commit ddc8183
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@
#endif

// Detect word size:
#if defined(_INTEGRAL_MAX_BITS)
#if defined (__x86_64__)
// This also works for the x32 ABI, which has a 64-bit word size.
# define BASE64_WORDSIZE 64
#elif defined (_INTEGRAL_MAX_BITS)
# define BASE64_WORDSIZE _INTEGRAL_MAX_BITS
#elif defined(__WORDSIZE)
#elif defined (__WORDSIZE)
# define BASE64_WORDSIZE __WORDSIZE
#elif defined (__LONG_WIDTH__)
# define BASE64_WORDSIZE __LONG_WIDTH__
#elif defined (__SIZE_WIDTH__)
# define BASE64_WORDSIZE __SIZE_WIDTH__
#else
# error BASE64_WORDSIZE_NOT_DEFINED
#endif
Expand Down

0 comments on commit ddc8183

Please sign in to comment.