rust-random / getrandom

A small cross-platform library for retrieving random data from (operating) system source
Apache License 2.0
264 stars 166 forks source link

use_file: Use AtomicI32 instead of AtomicUsize to avoid conversions. #480

Closed briansmith closed 2 weeks ago

briansmith commented 2 weeks ago

All the targets that use use_file support AtomicI32. Using AtomicI32 eliminates as conversions and thus avoids any possibility of truncation or confusion between FD_UNINIT and a valid file descriptor.

Use -1 as the sentinel value for FD_UNINIT since libstd (only) guarantees that -1 is not a valid file descriptor value.

Minimize the scope of FD_UNINIT.