util-src/crand.c
changeset 8454 770f79a9635c
parent 8452 b572a708fd41
child 12474 80f3123053e2
equal deleted inserted replaced
8453:3a9a3d90c44c 8454:770f79a9635c
    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");
    75 
    75 
       
    76 	if(len == 0) {
       
    77 		lua_pushliteral(L, "");
       
    78 		return 1;
       
    79 	}
       
    80 
    76 	if(len > SMALLBUFSIZ) {
    81 	if(len > SMALLBUFSIZ) {
    77 		buf = lua_newuserdata(L, len);
    82 		buf = lua_newuserdata(L, len);
    78 	}
    83 	}
    79 
       
    80 
    84 
    81 #if defined(WITH_GETRANDOM)
    85 #if defined(WITH_GETRANDOM)
    82 	/*
    86 	/*
    83 	 * This acts like a read from /dev/urandom with the exception that it
    87 	 * This acts like a read from /dev/urandom with the exception that it
    84 	 * *does* block if the entropy pool is not yet initialized.
    88 	 * *does* block if the entropy pool is not yet initialized.