ClickHouse/libs/libglibc-compatibility/musl/getrandom.c

24 lines
727 B
C
Raw Normal View History

/** We have to replace glibc getrandom only when glibc version is higher than 2.25.
* In previous versions of glibc this function doesn't exist
* and old kernels may be missing SYS_getrandom syscall.
*/
#include <features.h>
#if defined(__GLIBC__) && __GLIBC__ >= 2
# define GLIBC_MINOR __GLIBC_MINOR__
#elif defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 2
# define GLIBC_MINOR __GNU_LIBRARY_MINOR__
#endif
#if defined(GLIBC_MINOR) && GLIBC_MINOR >= 25
2018-12-10 18:16:15 +00:00
#include <unistd.h>
#include <syscall.h>
#include "syscall.h"
ssize_t getrandom(void *buf, size_t buflen, unsigned flags)
{
/// There was cancellable syscall (syscall_cp), but I don't care too.
2018-12-10 18:17:35 +00:00
return syscall(SYS_getrandom, buf, buflen, flags);
2018-12-10 18:16:15 +00:00
}
#endif