util-src/crand.c
changeset 12474 80f3123053e2
parent 8454 770f79a9635c
child 12579 1f6f05a98fcd
equal deleted inserted replaced
12473:2b3adaa6d38e 12474:80f3123053e2
    43 #ifndef SYS_getrandom
    43 #ifndef SYS_getrandom
    44 #error getrandom() requires Linux 3.17 or later
    44 #error getrandom() requires Linux 3.17 or later
    45 #endif
    45 #endif
    46 
    46 
    47 /* This wasn't present before glibc 2.25 */
    47 /* This wasn't present before glibc 2.25 */
    48 int getrandom(void *buf, size_t buflen, unsigned int flags) {
    48 static int getrandom(void *buf, size_t buflen, unsigned int flags) {
    49 	return syscall(SYS_getrandom, buf, buflen, flags);
    49 	return syscall(SYS_getrandom, buf, buflen, flags);
    50 }
    50 }
    51 #else
    51 #else
    52 #include <sys/random.h>
    52 #include <sys/random.h>
    53 #endif
    53 #endif
    64 
    64 
    65 #ifndef SMALLBUFSIZ
    65 #ifndef SMALLBUFSIZ
    66 #define SMALLBUFSIZ 32
    66 #define SMALLBUFSIZ 32
    67 #endif
    67 #endif
    68 
    68 
    69 int Lrandom(lua_State *L) {
    69 static int Lrandom(lua_State *L) {
    70 	char smallbuf[SMALLBUFSIZ];
    70 	char smallbuf[SMALLBUFSIZ];
    71 	char *buf = &smallbuf[0];
    71 	char *buf = &smallbuf[0];
    72 	const lua_Integer l = luaL_checkinteger(L, 1);
    72 	const lua_Integer l = luaL_checkinteger(L, 1);
    73 	const size_t len = l;
    73 	const size_t len = l;
    74 	luaL_argcheck(L, l >= 0, 1, "must be > 0");
    74 	luaL_argcheck(L, l >= 0, 1, "must be > 0");