]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Issue #594 - provide an OVERRIDE_GET_RANDOM_SEED cmake variable to override json_c_ge...
authorEric Haszlakiewicz <erh+git@nimenees.com>
Wed, 22 Jul 2020 02:25:03 +0000 (02:25 +0000)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Wed, 22 Jul 2020 02:25:03 +0000 (02:25 +0000)
Example:
mkdir build && cd build
cmake -DOVERRIDE_GET_RANDOM_SEED='do { extern uint32_t getMsTicks(void); int ms = getMsTicks() * 433494437; return ms; } while(0)' ..

CMakeLists.txt
README.md
cmake/config.h.in
random_seed.c

index da0af963edb07c67b155b2246e3dc22d704a1675..7362a8471ccc7625570892981a9b65ec74918265 100644 (file)
@@ -96,6 +96,8 @@ option(DISABLE_THREAD_LOCAL_STORAGE   "Disable using Thread-Local Storage (HAVE_
 option(DISABLE_WERROR                 "Avoid treating compiler warnings as fatal errors."     OFF)
 option(ENABLE_RDRAND                  "Enable RDRAND Hardware RNG Hash Seed."                 OFF)
 option(ENABLE_THREADING               "Enable partial threading support."                     OFF)
+option(OVERRIDE_GET_RANDOM_SEED       "Override json_c_get_random_seed() with custom code."   OFF)
+
 
 if (UNIX OR MINGW OR CYGWIN)
     list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
index fc128f51f1e429b1e239d4e8279e72830b1d7bf1..cd66d49181d4257481329a96c4ef710b206af963 100644 (file)
--- a/README.md
+++ b/README.md
@@ -107,6 +107,7 @@ DISABLE_THREAD_LOCAL_STORAGE | Bool   | Disable use of Thread-Local Storage (HAV
 DISABLE_WERROR               | Bool   | Disable use of -Werror.
 ENABLE_RDRAND                | Bool   | Enable RDRAND Hardware RNG Hash Seed.
 ENABLE_THREADING             | Bool   | Enable partial threading support.
+OVERRIDE_GET_RANDOM_SEED     | String | A block of code to use instead of the default implementation of json_c_get_random_seed(), e.g. on embedded platforms where not even the fallback to time() works.  Must be a single line.
 
 Pass these options as `-D` on CMake's command-line.
 
index 8b3116431975148b07db9d1a1ba4997ae4215a3c..547a5854f307cda2d95a1df6644104c1cc9ba2e3 100644 (file)
@@ -2,6 +2,9 @@
 /* Enable RDRAND Hardware RNG Hash Seed */
 #cmakedefine ENABLE_RDRAND "@ENABLE_RDRAND@"
 
+/* Override json_c_get_random_seed() with custom code */
+#cmakedefine OVERRIDE_GET_RANDOM_SEED @OVERRIDE_GET_RANDOM_SEED@
+
 /* Enable partial threading support */
 #cmakedefine ENABLE_THREADING "@@"
 
index 833b1a53860e0b2410802cf4adf6644f152454a7..1a15350c92786a2a202224c71cc188350e8e43ba 100644 (file)
@@ -276,6 +276,9 @@ static int get_time_seed(void)
 
 int json_c_get_random_seed(void)
 {
+#ifdef OVERRIDE_GET_RANDOM_SEED
+       OVERRIDE_GET_RANDOM_SEED;
+#endif
 #if defined HAVE_RDRAND && HAVE_RDRAND
        if (has_rdrand())
                return get_rdrand_seed();