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.58 2002/11/24 20:48:56 agehall Exp $ + || $Id: zlibmod.c,v 1.59 2002/11/25 11:39:37 grubba Exp $   */      #include "global.h" - RCSID("$Id: zlibmod.c,v 1.58 2002/11/24 20:48:56 agehall Exp $"); + RCSID("$Id: zlibmod.c,v 1.59 2002/11/25 11:39:37 grubba 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:491:    inflateEnd(& THIS->gz);   /* mt_unlock(& THIS->lock); */    mt_destroy( & THIS->lock );   }      /*! @endclass    */      /*! @decl int crc32(string data, void|int start_value)    *! -  *! This function calculates the standard ISO3309 Cyclic Redundancy Check. +  *! This function calculates the standard ISO3309 Cyclic Redundancy Check.    */   static void gz_crc32(INT32 args)   {    unsigned INT32 crc;    if (!args ||    sp[-args].type!=T_STRING)    Pike_error("Gz.crc32: illegal or missing argument 1 (expected string)\n");       if (args>1) {    if (sp[1-args].type!=T_INT)
pike.git/src/modules/Gz/zlibmod.c:521:       pop_n_elems(args);    push_int((INT32)crc);   }      /*! @class _file    *! Low-level implementation of read/write support for GZip files    */      /*! @decl int open(string|int file, void|string mode) -  *! Opens a file for I/O. +  *! Opens a file for I/O.    *! @param file -  *! The filename or an open filedescriptor for the GZip file to open. +  *! The filename or an open filedescriptor for the GZip file to use.    *! @param mode -  *! Mode for the fileoperations. Defaults to read only. +  *! Mode for the fileoperations. Defaults to read only.    *!    *! @note -  *! If the object represents a file, it will first be closed. +  *! If the object already has been opened, it will first be closed.    */   void gz_file_open(INT32 args)   { -  char default_mode[] = "rb"; -  char *mode = default_mode; +  char *mode = "rb";       if (THIS->gzfile!=NULL) {    gzclose(THIS->gzfile);    THIS->gzfile = NULL;    }       if (args<1 || args>2) {    Pike_error("Bad number of arguments to file->open()\n"    "Got %d, expected 1 or 2.\n", args);    }       if (sp[-args].type != PIKE_T_STRING &&    sp[-args].type != PIKE_T_INT) {    Pike_error("Bad parameter 1 to file->open()\n");    }       if (args == 2 && sp[1-args].type != PIKE_T_STRING) {    Pike_error("Bad parameter 2 to file->open()\n");    } else if (args == 2) { -  mode = sp[1-args].u.string->str; +  mode = STR0(sp[1-args].u.string);    }       if (sp[-args].type == PIKE_T_INT) { -  THIS->gzfile = gzdopen(sp[-args].u.integer, -  mode); +  /* FIXME: This is not likely to work on NT. */ +  THIS->gzfile = gzdopen(sp[-args].u.integer, mode);    } else { -  THIS->gzfile = gzopen(sp[-args].u.string->str, -  mode); +  THIS->gzfile = gzopen(STR0(sp[-args].u.string), mode);    }       pop_n_elems(args);    push_int(THIS->gzfile != NULL);   }      /*! @decl void create(void|string gzFile, void|string mode) -  *! Opens a gzip file for reading. +  *! Opens a gzip file for reading.    */   void gz_file_create(INT32 args)   {    THIS->gzfile = NULL;    if (args) {    gz_file_open(args);    if (sp[-1].u.integer == 0) {    Pike_error("Failed to open file.\n");    } -  pop_n_elems(1); +  pop_stack();    }   }      /*! @decl int close()    *! closes the file    *! @returns    *! 1 if successful    */   void gz_file_close(INT32 args)   {
pike.git/src/modules/Gz/zlibmod.c:641:       res = gzread(THIS->gzfile, STR0(buf), len);       /* Check to make sure read went well */    if (res<0) {    push_int(0);    free_string(end_shared_string(buf));    return;    }    -  /* Make sure the returned string is the same lenght as +  /* Make sure the returned string is the same length as    * the data read.    */    push_string(end_and_resize_shared_string(buf, res)); -  +    }      /*! @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;