Fix for Build error in Arduino Due Build
authorkoushik.girijala <g.koushik@samsung.com>
Tue, 1 Dec 2015 07:28:52 +0000 (12:58 +0530)
committerJon A. Cruz <jonc@osg.samsung.com>
Thu, 10 Dec 2015 22:26:25 +0000 (22:26 +0000)
Fixed Random Function calls as per random func availability for avr and arm  boards.

Change-Id: I2d4e9aea56d35dd5a8112f1ec90b1215dbc728be
Signed-off-by: koushik.girijala <g.koushik@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4383
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/c_common/ocrandom/src/ocrandom.c

index 78d2bc9..ff09112 100644 (file)
 #ifdef ARDUINO
 #include "Arduino.h"
 
+// ARM GCC compiler doesnt define srandom function.
+#if defined(ARDUINO) && !defined(ARDUINO_ARCH_SAM)
+#define HAVE_SRANDOM 1
+#endif
+
 uint8_t GetRandomBitRaw()
 {
     return analogRead((uint8_t)ANALOG_IN) & 0x1;
@@ -143,7 +148,11 @@ int8_t OCSeedRandom()
     {
         result += result + GetRandomBit();
     }
+#if HAVE_SRANDOM
     srandom(result);
+#else
+    srand(result);
+#endif
     return 0;
 #endif
 
@@ -173,7 +182,11 @@ uint8_t OCGetRandomByte(void)
 #if defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__)
     return rand() & 0x00FF;
 #elif defined ARDUINO
+#ifdef HAVE_SRANDOM
     return random() & 0x00FF;
+#else
+    return rand() & 0x00FF;
+#endif
 #endif
 }