mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 07:28:13 +08:00
Fix mg_random() for ESP32
This commit is contained in:
parent
a204c80308
commit
6d398bd5c7
@ -4215,6 +4215,7 @@ void mg_random(void *buf, size_t len) {
|
|||||||
unsigned char *p = (unsigned char *) buf;
|
unsigned char *p = (unsigned char *) buf;
|
||||||
#if MG_ARCH == MG_ARCH_ESP32
|
#if MG_ARCH == MG_ARCH_ESP32
|
||||||
while (len--) *p++ = (unsigned char) (esp_random() & 255);
|
while (len--) *p++ = (unsigned char) (esp_random() & 255);
|
||||||
|
done = true;
|
||||||
#elif MG_ARCH == MG_ARCH_WIN32
|
#elif MG_ARCH == MG_ARCH_WIN32
|
||||||
#elif MG_ARCH_UNIX
|
#elif MG_ARCH_UNIX
|
||||||
FILE *fp = fopen("/dev/urandom", "rb");
|
FILE *fp = fopen("/dev/urandom", "rb");
|
||||||
@ -4223,10 +4224,8 @@ void mg_random(void *buf, size_t len) {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Fallback to a pseudo random gen
|
// If everything above did not work, fallback to a pseudo random generator
|
||||||
if (!done) {
|
while (!done && len--) *p++ = (unsigned char) (rand() & 255);
|
||||||
while (len--) *p++ = (unsigned char) (rand() & 255);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ void mg_random(void *buf, size_t len) {
|
|||||||
unsigned char *p = (unsigned char *) buf;
|
unsigned char *p = (unsigned char *) buf;
|
||||||
#if MG_ARCH == MG_ARCH_ESP32
|
#if MG_ARCH == MG_ARCH_ESP32
|
||||||
while (len--) *p++ = (unsigned char) (esp_random() & 255);
|
while (len--) *p++ = (unsigned char) (esp_random() & 255);
|
||||||
|
done = true;
|
||||||
#elif MG_ARCH == MG_ARCH_WIN32
|
#elif MG_ARCH == MG_ARCH_WIN32
|
||||||
#elif MG_ARCH_UNIX
|
#elif MG_ARCH_UNIX
|
||||||
FILE *fp = fopen("/dev/urandom", "rb");
|
FILE *fp = fopen("/dev/urandom", "rb");
|
||||||
@ -72,10 +73,8 @@ void mg_random(void *buf, size_t len) {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Fallback to a pseudo random gen
|
// If everything above did not work, fallback to a pseudo random generator
|
||||||
if (!done) {
|
while (!done && len--) *p++ = (unsigned char) (rand() & 255);
|
||||||
while (len--) *p++ = (unsigned char) (rand() & 255);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user