all: relax compiler requirements

- Do not check __STDC_HOSTED__.
- Do not use atomic builtins.
- Do not use thread-local storage for PRNG state.
This commit is contained in:
CismonX 2025-01-28 20:20:20 +08:00
parent 56fa90397d
commit 50f05d2bd3
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
4 changed files with 10 additions and 10 deletions

View file

@ -23,8 +23,7 @@
#ifndef BOOKMARKFS_DEFS_H_ #ifndef BOOKMARKFS_DEFS_H_
#define BOOKMARKFS_DEFS_H_ #define BOOKMARKFS_DEFS_H_
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) \ #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
|| (__STDC_HOSTED__ != 1)
# error "unsupported compiler" # error "unsupported compiler"
#elif __STDC_VERSION__ >= 202311L #elif __STDC_VERSION__ >= 202311L
# define HAVE_STDC_23 1 # define HAVE_STDC_23 1

View file

@ -25,6 +25,13 @@
#include <string.h> #include <string.h>
// No need for atomic json_incref()/json_decref(),
// since we're only using Jansson in a single thread.
#include <jansson_config.h>
#undef JSON_HAVE_ATOMIC_BUILTINS
#define JSON_HAVE_ATOMIC_BUILTINS 0
#undef JSON_HAVE_SYNC_BUILTINS
#define JSON_HAVE_SYNC_BUILTINS 0
#include <jansson.h> #include <jansson.h>
// The following helper macros are useful with literal keys, // The following helper macros are useful with literal keys,

View file

@ -39,10 +39,7 @@
static uint64_t rotl64 (uint64_t, unsigned); static uint64_t rotl64 (uint64_t, unsigned);
// Forward declaration end // Forward declaration end
#ifndef BOOKMARKFS_TLS static uint64_t state[4];
# error "compiler does not support thread-local storage"
#endif
static BOOKMARKFS_TLS uint64_t state[4];
static uint64_t static uint64_t
rotl64 ( rotl64 (

View file

@ -31,7 +31,7 @@
* Returns a pseudo-random 64-bit unsigned integer. * Returns a pseudo-random 64-bit unsigned integer.
* The PRNG should be seeded before calling this function. * The PRNG should be seeded before calling this function.
* *
* This function is MT-Safe. * This function is MT-Unsafe.
*/ */
uint64_t uint64_t
prng_rand (void); prng_rand (void);
@ -40,9 +40,6 @@ prng_rand (void);
* Seed the PRNG with the given values. * Seed the PRNG with the given values.
* If `s` is NULL, the values will be read from /dev/urandom. * If `s` is NULL, the values will be read from /dev/urandom.
* *
* When used in a multi-threaded environment,
* each thread should seed the PRNG separately.
*
* Returns 0 on success, -1 on failure. * Returns 0 on success, -1 on failure.
* If `s` is not NULL, this function never fails. * If `s` is not NULL, this function never fails.
*/ */