pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:2070:    }    break;       default:    SIMPLE_ARG_TYPE_ERROR("function_program", 1, "function");    }    pop_n_elems(args);    push_int(0);   }    + /*! @class RandomInterface +  */   PIKECLASS RandomInterface   {    CVAR UINT64 int_buffer;    CVAR int buffer_bits;       INIT    {    THIS->int_buffer = 0;    THIS->buffer_bits = 0;    }    -  +  /*! @decl string(8bit) random_string(int(0..)) +  *! +  *! Prototype for the randomness generating function. +  *! +  *! Override this symbol to implement a useable class. +  */    PIKEFUN string(8bit) random_string(int(0..))    prototype;    {}       static void fill_int_buffer()    {    push_int(8);    apply_current(f_RandomInterface_random_string_fun_num, 1);    if( TYPEOF(Pike_sp[-1]) != T_STRING ||    Pike_sp[-1].u.string->len != 8 )
pike.git/src/builtin.cmod:2229:    Pike_error("Calling undefined lfun::%s.\n", lfun_names[LFUN__RANDOM]);    struct object *co = Pike_fp->current_object;    ref_push_function(co, f_RandomInterface_random_string_fun_num);    /* FIXME: precompiler doesn't generate usable fun_nums for variant    symbols. */    ref_push_function(co, find_shared_string_identifier(MK_STRING("random"),    co->prog));    apply_low(o, f, 2);    }   } + /*! @endclass +  */      /**    * 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.git/src/builtin.cmod:2253:    Pike_sp[-1].u.string->size_shift != 0)    Pike_error("Couldn't generate random string.\n");   }      #ifdef __NT__   #include <wincrypt.h>   static HCRYPTPROV crypto_handle;   #else   static int random_fd = -1;   #endif + /*! @class RandomSystem +  */   PIKECLASS RandomSystem   { -  +  /*! @decl inherit RandomInterface +  */    INHERIT RandomInterface;    -  +  /*! @decl string(8bit) random_string(int(0..) len) +  *! +  *! Return a string of random data from the system randomness pool. +  *! +  *! On POSIX platforms this reads random data from @tt{/dev/urandom@} +  *! on other platforms it may use other methods. +  *! +  *! @throws +  *! May throw errors on unexpected state. +  */    PIKEFUN string(8bit) random_string(int(0..) len)    {    if( !len )    RETURN empty_pike_string;    if( len<0 )    Pike_error("Bad argument 1 to random_string(). Expected int(0..).\n");      #ifdef __NT__    if(!crypto_handle)    {
pike.git/src/builtin.cmod:2308:    Pike_error("Failed to read %d bytes from /dev/urandom.\n", len);    }    str += sz;    len -= sz;    }   #endif /* !__NT__ */       RETURN end_shared_string(ret);    }   } + /*! @endclass +  */      #if defined(HAVE_SETENV) && defined(HAVE_UNSETENV)   #define USE_SETENV   #else   /* Used to hold refs to the strings that we feed to putenv. Indexed on    * variable names, values are the "name=value" strings.    *    * This is not needed when using {,un}setenv(), since they maintain    * their own corresponding table. */   static struct mapping *env_allocs = NULL;