projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add namespace to some names
[pspp]
/
src
/
libpspp
/
zip-reader.c
diff --git
a/src/libpspp/zip-reader.c
b/src/libpspp/zip-reader.c
index 7b5aabadfbf870c9e54899984f33adb3d0edba91..00249e0bae41be64128720410c0079c7e819a230 100644
(file)
--- a/
src/libpspp/zip-reader.c
+++ b/
src/libpspp/zip-reader.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* 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
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
@@
-16,22
+16,23
@@
#include <config.h>
#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 <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)
#include "gettext.h"
#define _(msgid) gettext (msgid)
@@
-81,6
+82,7
@@
get_decompressor (uint16_t c)
struct zip_reader
{
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. */
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. */
@@
-116,17
+118,28
@@
zip_member_finish (struct zip_member *zm)
}
}
}
}
+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
/* 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;
if (zr == NULL)
return;
+ assert (zr->ref_cnt > 0);
+ if (--zr->ref_cnt)
+ return;
free (zr->file_name);
free (zr->file_name);
- for (i = 0; i < zr->n_entries; ++i)
+ for (i
nt i
= 0; i < zr->n_entries; ++i)
{
struct zip_entry *ze = &zr->entries[i];
free (ze->name);
{
struct zip_entry *ze = &zr->entries[i];
free (ze->name);
@@
-365,7
+378,8
@@
zip_reader_create (const char *file_name, struct zip_reader **zrp)
return NULL;
}
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++)
zr->file_name = xstrdup (file_name);
zr->entries = xcalloc (n_members, sizeof *zr->entries);
for (int i = 0; i < n_members; i++)
@@
-375,7
+389,7
@@
zip_reader_create (const char *file_name, struct zip_reader **zrp)
if (error)
{
fclose (file);
if (error)
{
fclose (file);
- zip_reader_
destroy
(zr);
+ zip_reader_
unref
(zr);
return error;
}
zr->n_entries++;
return error;
}
zr->n_entries++;
@@
-563,7
+577,7
@@
probe_magic (FILE *fp, uint32_t magic, off_t start, off_t stop, off_t *off)
if (0 > fseeko (fp, start, SEEK_SET))
{
if (0 > fseeko (fp, start, SEEK_SET))
{
- return
-1
;
+ return
false
;
}
for (i = 0; i < 4 ; ++i)
}
for (i = 0; i < 4 ; ++i)
@@
-654,7
+668,7
@@
static char *
inflate_init (struct zip_member *zm)
{
int r;
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 */
uint16_t flg = 0 ;
uint16_t cmf = 0x8; /* Always 8 for inflate */