mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-27 20:04:21 +00:00
change(esp_libc): rename newlib component to esp_libc
This commit is contained in:
36
components/esp_libc/src/getentropy.c
Normal file
36
components/esp_libc/src/getentropy.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <sys/random.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int getentropy(void *buffer, size_t length)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
if (buffer == NULL) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (length > 256) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = getrandom(buffer, length, 0);
|
||||
if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void esp_libc_include_getentropy_impl(void)
|
||||
{
|
||||
// Linker hook, exists for no other purpose
|
||||
}
|
||||
Reference in New Issue
Block a user