pike.git / src / post_modules / Nettle / hash.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/hash.cmod:1:   /* hash.cmod -*- c -*- */      #include "global.h" - RCSID("$Id: hash.cmod,v 1.20 2004/04/28 19:36:16 nilsson Exp $"); + RCSID("$Id: hash.cmod,v 1.21 2004/04/28 19:54:31 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   #include "threads.h"      /* For this_object() */   #include "object.h"   #include "module_support.h"      #include "nettle_config.h"   
pike.git/src/post_modules/Nettle/hash.cmod:138:    *! @expr{obj->update(Stdio.read_file(file))->digest()@}.    *!    *! @seealso    *! @[Stdio.File], @[HashState()->update()] and    *! @[HashState()->digest()].    */    PIKEFUN string hash(object in)    optflags OPT_EXTERNAL_DEPEND;    {    void *ctx; -  unsigned block_size; +     int len;    char *read_buffer;    PIKE_STAT_T st;    struct pike_string *out;    const struct nettle_hash *meta = THIS->meta;       if (!meta)    Pike_error("HashInfo not properly initialized.\n");       /* Verify that the input is a Stdio.Fd_ref */
pike.git/src/post_modules/Nettle/hash.cmod:175:    safe_apply(in, "query_fd", 0);    int fd = Pike_sp[-1].u.integer;    pop_stack();       if (fd_fstat(fd, &st)<0)    Pike_error("File not found!\n");       if (!S_ISREG(st.st_mode))    Pike_error("Non-regular file.\n");    -  block_size = meta->block_size; -  read_buffer=(char *)alloca(block_size); -  if (!read_buffer) -  Pike_error("Out of memory.\n"); -  +     ctx = (void *)alloca(meta->context_size);    if (!ctx)    Pike_error("Out of memory.\n");    -  +  read_buffer=(char *)malloc(8192); +  if (!read_buffer) +  Pike_error("Out of memory.\n"); +     THREADS_ALLOW();    meta->init(ctx); -  while((len=fd_read(fd, read_buffer, block_size))>0) { +  while((len=fd_read(fd, read_buffer, 8192))>0)    meta->update(ctx, len, read_buffer); -  } +     -  +  free(read_buffer); +     out = begin_shared_string(meta->digest_size);    meta->digest(ctx, meta->digest_size, out->str);    THREADS_DISALLOW();       pop_n_elems(args);    push_string(end_shared_string(out));    }       INIT    {