Branch: Tag:

2016-03-18

2016-03-18 20:39:47 by Martin Nilsson <nilsson@fastmail.com>

Deduplication of push_random_string

2225:    }   }    + /** +  * Generates a random string of length len, using the current +  * random_string() function, and pushes it on the stack. +  */ + PMOD_EXPORT void push_random_string(unsigned len) + { +  struct svalue *random = +  simple_mapping_string_lookup(get_builtin_constants(), "random_string"); +  if(!random || (TYPEOF(*random) != T_FUNCTION)) +  Pike_error("Unable to resolve random function.\n"); +  push_int(len); +  apply_svalue(random, 1); +  if(TYPEOF(Pike_sp[-1])!=T_STRING || Pike_sp[-1].u.string->len != len) +  Pike_error("Couldn't generate random string.\n"); + } +    #ifdef __NT__   #include <wincrypt.h>   static HCRYPTPROV crypto_handle;