pike.git / src / modules / Gz / zlibmod.c

version» Context lines:

pike.git/src/modules/Gz/zlibmod.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: zlibmod.c,v 1.57 2002/10/21 17:06:13 marcus Exp $ + || $Id: zlibmod.c,v 1.58 2002/11/24 20:48:56 agehall Exp $   */      #include "global.h" - RCSID("$Id: zlibmod.c,v 1.57 2002/10/21 17:06:13 marcus Exp $"); + RCSID("$Id: zlibmod.c,v 1.58 2002/11/24 20:48:56 agehall Exp $");      #include "zlib_machine.h"   #include "module.h"      #if !defined(HAVE_LIBZ) && !defined(HAVE_LIBGZ)   #undef HAVE_ZLIB_H   #endif      #ifdef HAVE_ZLIB_H   
pike.git/src/modules/Gz/zlibmod.c:609:       push_int(1);   }      /*! @decl int|string read(int len)    *! Reads len (uncompressed) bytes from the file.    *! If read is unsuccessful, 0 is returned.    */   void gz_file_read(INT32 args)   { -  char *buf; +  struct pike_string *buf;    int len;    int res;       if (args!=1) {    Pike_error("Bad number of arguments to gz_file->read()\n"    "Got %d, expected 1.\n", args);    }       if (sp[-args].type != PIKE_T_INT) {    Pike_error("Bad argument 1 to gz_file->read()\n");    }       if (THIS->gzfile == NULL) {    Pike_error("File not open!\n");    }       len = sp[-args].u.integer;    -  buf = malloc(sizeof(char) * (len+1)); +  buf = begin_shared_string(len);       pop_n_elems(args);    -  res = gzread(THIS->gzfile, buf, len); +  res = gzread(THIS->gzfile, STR0(buf), len);    -  +  /* Check to make sure read went well */    if (res<0) {    push_int(0); -  free(buf); +  free_string(end_shared_string(buf));    return;    }    -  buf[res] = '\0'; +  /* Make sure the returned string is the same lenght as +  * the data read. +  */ +  push_string(end_and_resize_shared_string(buf, res));    -  push_string(make_shared_string(buf)); -  free(buf); +    }      /*! @decl int write(string data)    *! Writes the data to the file.    *! @returns    *! the number of bytes written to the file.    */   void gz_file_write(INT32 args)   {    int res = 0;