/* PSPP - a program for statistical analysis.
- Copyright (C) 2011, 2013, 2014 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2013, 2014, 2021 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <config.h>
+#include "libpspp/zip-reader.h"
+#include "libpspp/zip-private.h"
+
+#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-#include <xalloc.h>
-#include <libpspp/assertion.h>
-#include <libpspp/compiler.h>
-
-#include "str.h"
+#include "libpspp/assertion.h"
+#include "libpspp/cast.h"
+#include "libpspp/compiler.h"
+#include "libpspp/integer-format.h"
+#include "libpspp/str.h"
-#include "integer-format.h"
-#include "zip-reader.h"
-#include "zip-private.h"
+#include "gl/xalloc.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
struct zip_reader
{
+ int ref_cnt;
char *file_name; /* The name of the file from which the data is read */
uint16_t n_entries; /* Number of directory entries. */
struct zip_entry *entries; /* Directory entries. */
}
}
+struct zip_reader *
+zip_reader_ref (const struct zip_reader *zr_)
+{
+ struct zip_reader *zr = CONST_CAST (struct zip_reader *, zr_);
+ assert (zr->ref_cnt > 0);
+ zr->ref_cnt++;
+ return zr;
+}
+
/* Destroy the zip reader */
void
-zip_reader_destroy (struct zip_reader *zr)
+zip_reader_unref (struct zip_reader *zr)
{
- int i;
if (zr == NULL)
return;
+ assert (zr->ref_cnt > 0);
+ if (--zr->ref_cnt)
+ return;
free (zr->file_name);
- for (i = 0; i < zr->n_entries; ++i)
+ for (int i = 0; i < zr->n_entries; ++i)
{
struct zip_entry *ze = &zr->entries[i];
free (ze->name);
return NULL;
}
- struct zip_reader *zr = xzalloc (sizeof *zr);
+ struct zip_reader *zr = XZALLOC (struct zip_reader);
+ zr->ref_cnt = 1;
zr->file_name = xstrdup (file_name);
zr->entries = xcalloc (n_members, sizeof *zr->entries);
for (int i = 0; i < n_members; i++)
if (error)
{
fclose (file);
- zip_reader_destroy (zr);
+ zip_reader_unref (zr);
return error;
}
zr->n_entries++;
if (0 > fseeko (fp, start, SEEK_SET))
{
- return -1;
+ return false;
}
for (i = 0; i < 4 ; ++i)
inflate_init (struct zip_member *zm)
{
int r;
- struct inflator *inf = xzalloc (sizeof *inf);
+ struct inflator *inf = XZALLOC (struct inflator);
uint16_t flg = 0 ;
uint16_t cmf = 0x8; /* Always 8 for inflate */