[PATCH v3] io: Use gnulib fts implementation (BZ 22944, BZ 20331)

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Mar 30 22:11:58 GMT 2026



On 27/03/26 01:37, Collin Funk wrote:
> Hi Adhemerval,
> 
> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> 
>> diff --git a/include/stdbit.h b/include/stdbit.h
>> index ebd9795f28..f1e36e6815 100644
>> --- a/include/stdbit.h
>> +++ b/include/stdbit.h
>> @@ -1 +1,56 @@
>> +#ifndef _STDBIT_H
>>  #include <stdlib/stdbit.h>
>> +
>> +#ifndef _ISOMAC
>> +# include <stdint.h>
>> +
>> +#  if __glibc_has_builtin (___builtin_stdc_rotate_right)
>> +#   define stdc_rotate_right(__x, __n) \
>> +  (___builtin_stdc_rotate_right (__x, __n))
>> +#  else
>> +#   if __WORDSIZE == 64
>> +#    define __ROR_UL_GENERIC __ror64
>> +#   else
>> +#    define __ROR_UL_GENERIC __ror32
>> +#   endif
>> +#   define stdc_rotate_right(__x, __n)		\
>> +   _Generic((__x),				\
>> +      unsigned char: __ror8,			\
>> +      unsigned short: __ror16,			\
>> +      unsigned int: __ror32,			\
>> +      unsigned long: __ROR_UL_GENERIC,		\
>> +      unsigned long long: __ror64		\
>> +   )(__x, __n)
>> +
>> +#define __ror_generic(__v, __n)			\
>> + ((__v >> (__n & (sizeof __v * 8 - 1)))		\
>> +  | (__v << ((-__n) & (sizeof __v * 8 - 1))))
>> +
>> +static __always_inline uint8_t
>> +__ror8 (uint8_t __x, unsigned int __n)
>> +{
>> +  return __ror_generic (__x, __n);
>> +}
>> +
>> +static __always_inline uint16_t
>> +__ror16 (uint16_t __x, unsigned int __n)
>> +{
>> +  return __ror_generic (__x, __n);
>> +}
>> +
>> +static __always_inline  unsigned int
>> +__ror32 (uint32_t __x, unsigned int __n)
>> +{
>> +  return __ror_generic (__x, __n);
>> +}
>> +
>> +static __always_inline  unsigned long
>> +__ror64 (uint64_t __x, unsigned int __n)
>> +{
>> +  return __ror_generic (__x, __n);
>> +}
>> +#  endif
>> +
>> +# endif /* _ISOMAC */
>> +
>> +#endif  /* _STDBIT_H */
> 
> I had a quick skim over the fts patch and it generally looks good. But I
> would prefer adding these stdbit.h functions along with tests.
> 
> How about separating this into another patch and adding my tests from
> Gnulib [1] [2]? I am the sole author of those files, and am okay with
> relicensing them under the LGPLv2+. We import some stdbit.h tests
> already from glibc, so maybe you could take inspiration from those [3].
> 
> WDYT?

Sounds reasonable, I will split the patch and add these tests. I think for
now I will add only the stdc_rotate_right.

> 
> Collin
> 
> [1] https://github.com/coreutils/gnulib/blob/master/tests/test-stdc_rotate_left.c
> [2] https://github.com/coreutils/gnulib/blob/master/tests/test-stdc_rotate_right.c
> [3] https://github.com/coreutils/gnulib/blob/master/tests/from-glibc/tst-stdc_count_ones.c



More information about the Libc-alpha mailing list