Subversion Repositories SvarDOS

Rev

Rev 614 | Rev 1963 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 614 Rev 1609
1
/*
1
/*
2
 * This file is part of pkg (SvarDOS)
2
 * This file is part of pkg (SvarDOS)
3
 * Copyright (C) 2012-2021 Mateusz Viste.
3
 * Copyright (C) 2012-2021 Mateusz Viste.
4
 *
4
 *
5
 * Simple library providing functions to unzip files from zip archives.
5
 * Simple library providing functions to unzip files from zip archives.
6
 */
6
 */
7
 
7
 
8
#include <stdio.h>     /* printf(), FILE, fclose()... */
8
#include <stdio.h>     /* printf(), FILE, fclose()... */
9
#include <stdlib.h>    /* NULL */
9
#include <stdlib.h>    /* NULL */
10
#include <string.h>    /* memset() */
10
#include <string.h>    /* memset() */
11
#include <time.h>      /* mktime() */
11
#include <time.h>      /* mktime() */
12
#include <utime.h>     /* utime() */
12
#include <utime.h>     /* utime() */
13
#include <unistd.h>   /* unlink() */
13
#include <unistd.h>   /* unlink() */
14
 
14
 
15
#include "crc32.h"
15
#include "crc32.h"
16
#include "kprintf.h"
16
#include "kprintf.h"
17
#include "inf.h"   /* INFLATE support */
17
#include "inf.h"   /* INFLATE support */
18
 
18
 
19
#include "libunzip.h"  /* include self for control */
19
#include "libunzip.h"  /* include self for control */
20
 
20
 
21
 
21
 
22
/* converts a "DOS format" timestamp into unix timestamp. The DOS timestamp is constructed an array of 4 bytes, that contains following data at the bit level:
22
/* converts a "DOS format" timestamp into unix timestamp. The DOS timestamp is constructed an array of 4 bytes, that contains following data at the bit level:
23
 * HHHHHMMM MMMSSSSS YYYYYYYM MMMDDDDD
23
 * HHHHHMMM MMMSSSSS YYYYYYYM MMMDDDDD
24
 *  where:
24
 *  where:
25
 * day of month is always within 1-31 range;
25
 * day of month is always within 1-31 range;
26
 * month is always within 1-12 range;
26
 * month is always within 1-12 range;
27
 * year starts from 1980 and continues for 127 years
27
 * year starts from 1980 and continues for 127 years
28
 * seconds are actually not 0-59 but rather 0-29 as there are only 32 possible values – to get actual seconds multiply this field by 2;
28
 * seconds are actually not 0-59 but rather 0-29 as there are only 32 possible values – to get actual seconds multiply this field by 2;
29
 * minutes are always within 0-59 range;
29
 * minutes are always within 0-59 range;
30
 * hours are always within 0-23 range.     */
30
 * hours are always within 0-23 range.     */
31
static time_t dostime2unix(const unsigned char *buff) {
31
static time_t dostime2unix(const unsigned char *buff) {
32
  struct tm curtime;
32
  struct tm curtime;
33
  time_t result;
33
  time_t result;
34
  memset(&curtime, 0, sizeof(curtime)); /* make sure to set everything in curtime to 0's */
34
  memset(&curtime, 0, sizeof(curtime)); /* make sure to set everything in curtime to 0's */
35
  curtime.tm_sec = (buff[0] & 31) << 1; /* seconds (0..60) */
35
  curtime.tm_sec = (buff[0] & 31) << 1; /* seconds (0..60) */
36
  curtime.tm_min = (((buff[1] << 8) | buff[0]) >> 5) & 63 ; /* minutes after the hour (0..59) */
36
  curtime.tm_min = (((buff[1] << 8) | buff[0]) >> 5) & 63 ; /* minutes after the hour (0..59) */
37
  curtime.tm_hour = (buff[1] >> 3); /* hours since midnight (0..23) */
37
  curtime.tm_hour = (buff[1] >> 3); /* hours since midnight (0..23) */
38
  curtime.tm_mday = buff[2] & 31; /* day of the month (1..31) */
38
  curtime.tm_mday = buff[2] & 31; /* day of the month (1..31) */
39
  curtime.tm_mon = ((((buff[3] << 8) | buff[2]) >> 5) & 15) - 1; /* months since January (0, 11) */
39
  curtime.tm_mon = ((((buff[3] << 8) | buff[2]) >> 5) & 15) - 1; /* months since January (0, 11) */
40
  curtime.tm_year = (buff[3] >> 1) + 80; /* years since 1900 */
40
  curtime.tm_year = (buff[3] >> 1) + 80; /* years since 1900 */
41
  curtime.tm_wday = 0; /* days since Sunday (0..6) - leave 0, mktime() will set it */
41
  curtime.tm_wday = 0; /* days since Sunday (0..6) - leave 0, mktime() will set it */
42
  curtime.tm_yday = 0; /* days since January 1 (0..365]) - leave 0, mktime() will set it */
42
  curtime.tm_yday = 0; /* days since January 1 (0..365]) - leave 0, mktime() will set it */
43
  curtime.tm_isdst = -1; /* Daylight Saving Time flag. Positive if DST is in effect, zero if not and negative if no information is available */
43
  curtime.tm_isdst = -1; /* Daylight Saving Time flag. Positive if DST is in effect, zero if not and negative if no information is available */
44
  result = mktime(&curtime);
44
  result = mktime(&curtime);
45
  if (result == (time_t)-1) return(0);
45
  if (result == (time_t)-1) return(0);
46
  return(result);
46
  return(result);
47
}
47
}
48
 
48
 
49
 
49
 
50
/* opens a zip file and provides the list of files in the archive.
50
/* opens a zip file and provides the list of files in the archive.
51
   returns a pointer to a ziplist (linked list) with all records, or NULL on error.
51
   returns a pointer to a ziplist (linked list) with all records, or NULL on error.
52
   The ziplist is allocated automatically, and must be freed via zip_freelist. */
52
   The ziplist is allocated automatically, and must be freed via zip_freelist. */
53
struct ziplist *zip_listfiles(FILE *fd) {
53
struct ziplist *zip_listfiles(FILE *fd) {
54
  struct ziplist *reslist = NULL;
54
  struct ziplist *reslist = NULL;
55
  struct ziplist *newentry;
55
  struct ziplist *newentry;
56
  unsigned long entrysig;
56
  unsigned long entrysig;
57
  unsigned short filenamelen, extrafieldlen, filecommentlen;
57
  unsigned short filenamelen, extrafieldlen, filecommentlen;
58
  unsigned long compfilelen;
58
  unsigned long compfilelen;
59
  int centraldirectoryfound = 0;
59
  int centraldirectoryfound = 0;
60
  unsigned int ux;
60
  unsigned int ux;
61
  unsigned char hdrbuff[64];
61
  unsigned char hdrbuff[64];
62
 
62
 
63
  rewind(fd);  /* make sure the file cursor is at the very beginning of the file */
63
  rewind(fd);  /* make sure the file cursor is at the very beginning of the file */
64
 
64
 
65
  for (;;) { /* read entry after entry */
65
  for (;;) { /* read entry after entry */
66
    int x, eofflag;
66
    int x, eofflag;
67
    long longbuff;
67
    long longbuff;
68
    entrysig = 0;
68
    entrysig = 0;
69
    eofflag = 0;
69
    eofflag = 0;
70
    /* read the entry signature first */
70
    /* read the entry signature first */
71
    for (x = 0; x < 32; x += 8) {
71
    for (x = 0; x < 32; x += 8) {
72
      if ((longbuff = fgetc(fd)) == EOF) {
72
      if ((longbuff = fgetc(fd)) == EOF) {
73
        eofflag = 1;
73
        eofflag = 1;
74
        break;
74
        break;
75
      }
75
      }
76
      entrysig |= (longbuff << x);
76
      entrysig |= (longbuff << x);
77
    }
77
    }
78
    if (eofflag != 0) break;
78
    if (eofflag != 0) break;
79
    /* printf("sig: 0x%08x\n", entrysig); */
79
    /* printf("sig: 0x%08x\n", entrysig); */
80
    if (entrysig == 0x04034b50ul) { /* local file */
80
    if (entrysig == 0x04034b50ul) { /* local file */
81
      unsigned int generalpurposeflags;
81
      unsigned int generalpurposeflags;
82
      /* read and parse the zip header */
82
      /* read and parse the zip header */
83
      fread(hdrbuff, 1, 26, fd);
83
      fread(hdrbuff, 1, 26, fd);
84
      /* read filename's length so I can allocate the proper amound of mem */
84
      /* read filename's length so I can allocate the proper amound of mem */
85
      filenamelen = hdrbuff[23];
85
      filenamelen = hdrbuff[23];
86
      filenamelen <<= 8;
86
      filenamelen <<= 8;
87
      filenamelen |= hdrbuff[22];
87
      filenamelen |= hdrbuff[22];
88
      /* create new entry and link it into the list */
88
      /* create new entry and link it into the list */
89
      newentry = calloc(sizeof(struct ziplist) + filenamelen, 1);
89
      newentry = calloc(sizeof(struct ziplist) + filenamelen, 1);
90
      if (newentry == NULL) {
90
      if (newentry == NULL) {
91
        kitten_printf(2, 14, "libunzip"); /* "Out of memory! (%s)" */
91
        kitten_printf(2, 14, "libunzip"); /* "Out of memory! (%s)" */
92
        puts("");
92
        puts("");
93
        zip_freelist(&reslist);
93
        zip_freelist(&reslist);
94
        break;
94
        break;
95
      }
95
      }
96
      newentry->nextfile = reslist;
96
      newentry->nextfile = reslist;
97
      newentry->flags = 0;
97
      newentry->flags = 0;
98
      reslist = newentry;
98
      reslist = newentry;
99
      /* read further areas of the header, and fill zip entry */
99
      /* read further areas of the header, and fill zip entry */
100
      generalpurposeflags = hdrbuff[3];  /* parse the general */
100
      generalpurposeflags = hdrbuff[3];  /* parse the general */
101
      generalpurposeflags <<= 8;         /* purpose flags and */
101
      generalpurposeflags <<= 8;         /* purpose flags and */
102
      generalpurposeflags |= hdrbuff[2]; /* save them for later */
102
      generalpurposeflags |= hdrbuff[2]; /* save them for later */
103
      newentry->compmethod = hdrbuff[4] | (hdrbuff[5] << 8);
103
      newentry->compmethod = hdrbuff[4] | (hdrbuff[5] << 8);
104
      newentry->timestamp = dostime2unix(&hdrbuff[6]);
104
      newentry->timestamp = dostime2unix(&hdrbuff[6]);
105
      newentry->crc32 = 0;
105
      newentry->crc32 = 0;
106
      for (x = 13; x >= 10; x--) {
106
      for (x = 13; x >= 10; x--) {
107
        newentry->crc32 <<= 8;
107
        newentry->crc32 <<= 8;
108
        newentry->crc32 |= hdrbuff[x];
108
        newentry->crc32 |= hdrbuff[x];
109
      }
109
      }
110
      newentry->compressedfilelen = 0;
110
      newentry->compressedfilelen = 0;
111
      for (x = 17; x >= 14; x--) {
111
      for (x = 17; x >= 14; x--) {
112
        newentry->compressedfilelen <<= 8;
112
        newentry->compressedfilelen <<= 8;
113
        newentry->compressedfilelen |= hdrbuff[x];
113
        newentry->compressedfilelen |= hdrbuff[x];
114
      }
114
      }
115
      newentry->filelen = 0;
115
      newentry->filelen = 0;
116
      for (x = 21; x >= 18; x--) {
116
      for (x = 21; x >= 18; x--) {
117
        newentry->filelen <<= 8;
117
        newentry->filelen <<= 8;
118
        newentry->filelen |= hdrbuff[x];
118
        newentry->filelen |= hdrbuff[x];
119
      }
119
      }
120
      extrafieldlen = hdrbuff[25];
120
      extrafieldlen = hdrbuff[25];
121
      extrafieldlen <<= 8;
121
      extrafieldlen <<= 8;
122
      extrafieldlen |= hdrbuff[24];
122
      extrafieldlen |= hdrbuff[24];
123
      /* printf("Filename len: %d / extrafield len: %d / compfile len: %ld / filelen: %ld\n", filenamelen, extrafieldlen, newentry->compressedfilelen, newentry->filelen); */
123
      /* printf("Filename len: %d / extrafield len: %d / compfile len: %ld / filelen: %ld\n", filenamelen, extrafieldlen, newentry->compressedfilelen, newentry->filelen); */
124
      /* check general purpose flags */
124
      /* check general purpose flags */
125
      if ((generalpurposeflags & 1) != 0) newentry->flags |= ZIP_FLAG_ENCRYPTED;
125
      if ((generalpurposeflags & 1) != 0) newentry->flags |= ZIP_FLAG_ENCRYPTED;
126
      /* parse the filename */
126
      /* parse the filename */
127
      for (ux = 0; ux < filenamelen; ux++) newentry->filename[ux] = fgetc(fd); /* store filename */
127
      for (ux = 0; ux < filenamelen; ux++) newentry->filename[ux] = fgetc(fd); /* store filename */
128
      if (newentry->filename[filenamelen - 1] == '/') newentry->flags |= ZIP_FLAG_ISADIR; /* if filename ends with / it's a dir. Note that ZIP forbids the usage of '\' in ZIP paths anyway */
128
      if (newentry->filename[filenamelen - 1] == '/') newentry->flags |= ZIP_FLAG_ISADIR; /* if filename ends with / it's a dir. Note that ZIP forbids the usage of '\' in ZIP paths anyway */
129
      /* printf("Filename: %s (%ld bytes compressed)\n", newentry->filename, newentry->compressedfilelen); */
129
      /* printf("Filename: %s (%ld bytes compressed)\n", newentry->filename, newentry->compressedfilelen); */
130
      newentry->dataoffset = ftell(fd) + extrafieldlen;
130
      newentry->dataoffset = ftell(fd) + extrafieldlen;
131
      /* skip rest of fields and data */
131
      /* skip rest of fields and data */
132
      fseek(fd, (extrafieldlen + newentry->compressedfilelen), SEEK_CUR);
132
      fseek(fd, (extrafieldlen + newentry->compressedfilelen), SEEK_CUR);
133
    } else if (entrysig == 0x02014b50ul) { /* central directory */
133
    } else if (entrysig == 0x02014b50ul) { /* central directory */
134
      centraldirectoryfound = 1;
134
      centraldirectoryfound = 1;
135
      /* parse header now */
135
      /* parse header now */
136
      fread(hdrbuff, 1, 42, fd);
136
      fread(hdrbuff, 1, 42, fd);
137
      filenamelen = hdrbuff[22] | (hdrbuff[23] << 8);
137
      filenamelen = hdrbuff[22] | (hdrbuff[23] << 8);
138
      extrafieldlen = hdrbuff[24] | (hdrbuff[25] << 8);
138
      extrafieldlen = hdrbuff[24] | (hdrbuff[25] << 8);
139
      filecommentlen = hdrbuff[26] | (hdrbuff[27] << 8);
139
      filecommentlen = hdrbuff[26] | (hdrbuff[27] << 8);
140
      compfilelen = 0;
140
      compfilelen = 0;
141
      for (x = 17; x >= 14; x--) {
141
      for (x = 17; x >= 14; x--) {
142
        compfilelen <<= 8;
142
        compfilelen <<= 8;
143
        compfilelen |= hdrbuff[x];
143
        compfilelen |= hdrbuff[x];
144
      }
144
      }
145
      /* printf("central dir\n"); */
145
      /* printf("central dir\n"); */
146
      /* skip rest of fields and data */
146
      /* skip rest of fields and data */
147
      fseek(fd, (filenamelen + extrafieldlen + compfilelen + filecommentlen), SEEK_CUR);
147
      fseek(fd, (filenamelen + extrafieldlen + compfilelen + filecommentlen), SEEK_CUR);
148
    } else if (entrysig == 0x08074b50ul) { /* Data descriptor header */
148
    } else if (entrysig == 0x08074b50ul) { /* Data descriptor header */
149
      /* no need to read the header we just have to skip it */
149
      /* no need to read the header we just have to skip it */
150
      fseek(fd, 12, SEEK_CUR); /* the header is 3x4 bytes (CRC + compressed len + uncompressed len) */
150
      fseek(fd, 12, SEEK_CUR); /* the header is 3x4 bytes (CRC + compressed len + uncompressed len) */
151
    } else { /* unknown sig */
151
    } else { /* unknown sig */
152
      kitten_printf(8, 1, entrysig); /* "unknown zip sig: 0x%08lx" */
152
      kitten_printf(8, 1, entrysig); /* "unknown zip sig: 0x%08lx" */
153
      puts("");
153
      puts("");
154
      zip_freelist(&reslist);
154
      zip_freelist(&reslist);
155
      break;
155
      break;
156
    }
156
    }
157
  }
157
  }
158
  /* if we got no central directory record, the file is incomplete */
158
  /* if we got no central directory record, the file is incomplete */
159
  if (centraldirectoryfound == 0) zip_freelist(&reslist);
159
  if (centraldirectoryfound == 0) zip_freelist(&reslist);
160
  return(reslist);
160
  return(reslist);
161
}
161
}
162
 
162
 
163
 
163
 
164
 
164
 
165
/* unzips a file. zipfd points to the open zip file, curzipnode to the entry to extract, and fulldestfilename is the destination file where to unzip it. returns 0 on success, non-zero otherwise. */
165
/* unzips a file. zipfd points to the open zip file, curzipnode to the entry to extract, and fulldestfilename is the destination file where to unzip it. returns 0 on success, non-zero otherwise. */
166
int zip_unzip(FILE *zipfd, struct ziplist *curzipnode, const char *fulldestfilename) {
166
int zip_unzip(FILE *zipfd, struct ziplist *curzipnode, const char *fulldestfilename) {
167
  #define buffsize 32 * 1024l /* MUST be at least 32K */
167
  #define buffsize (12 * 1024) /* bigger buffer is better, but pkg has to work on a 256K PC so let's not get too crazy with RAM */
168
  FILE *filefd;
168
  FILE *filefd;
169
  unsigned long cksum;
169
  unsigned long cksum;
170
  int extract_res;
170
  int extract_res;
171
  unsigned char *buff;
171
  unsigned char *buff;
172
  struct utimbuf filetimestamp;
172
  struct utimbuf filetimestamp;
173
 
173
 
174
  /* first of all, check we support the compression method */
174
  /* first of all, check we support the compression method */
175
  switch (curzipnode->compmethod) {
175
  switch (curzipnode->compmethod) {
176
    case ZIP_METH_STORE:
176
    case ZIP_METH_STORE:
177
    case ZIP_METH_DEFLATE:
177
    case ZIP_METH_DEFLATE:
178
      break;
178
      break;
179
    default: /* unsupported compression method, sorry */
179
    default: /* unsupported compression method, sorry */
180
      return(-1);
180
      return(-1);
181
      break;
181
      break;
182
  }
182
  }
183
 
183
 
184
  /* open the dst file */
184
  /* open the dst file */
185
  filefd = fopen(fulldestfilename, "wb");
185
  filefd = fopen(fulldestfilename, "wb");
186
  if (filefd == NULL) return(-2);  /* failed to open the dst file */
186
  if (filefd == NULL) return(-2);  /* failed to open the dst file */
187
 
187
 
188
  /* allocate buffers for data I/O */
188
  /* allocate buffers for data I/O */
189
  buff = malloc(buffsize);
189
  buff = malloc(buffsize);
190
  if (buff == NULL) {
190
  if (buff == NULL) {
191
    fclose(filefd);
191
    fclose(filefd);
192
    unlink(fulldestfilename); /* remove the failed file once it is closed */
192
    unlink(fulldestfilename); /* remove the failed file once it is closed */
193
    return(-6);
193
    return(-6);
194
  }
194
  }
195
 
195
 
196
  if (fseek(zipfd, curzipnode->dataoffset, SEEK_SET) != 0) { /* set the reading position inside the zip file */
196
  if (fseek(zipfd, curzipnode->dataoffset, SEEK_SET) != 0) { /* set the reading position inside the zip file */
197
    free(buff);
197
    free(buff);
198
    fclose(filefd);
198
    fclose(filefd);
199
    unlink(fulldestfilename); /* remove the failed file once it is closed */
199
    unlink(fulldestfilename); /* remove the failed file once it is closed */
200
    return(-7);
200
    return(-7);
201
  }
201
  }
202
  extract_res = -255;
202
  extract_res = -255;
203
 
203
 
204
  cksum = crc32_init(); /* init the crc32 */
204
  cksum = crc32_init(); /* init the crc32 */
205
 
205
 
206
  if (curzipnode->compmethod == 0) { /* if the file is stored, copy it over */
206
  if (curzipnode->compmethod == 0) { /* if the file is stored, copy it over */
207
    long i, toread;
207
    long i, toread;
208
    extract_res = 0;   /* assume we will succeed */
208
    extract_res = 0;   /* assume we will succeed */
209
    for (i = 0; i < curzipnode->filelen;) {
209
    for (i = 0; i < curzipnode->filelen;) {
210
      toread = curzipnode->filelen - i;
210
      toread = curzipnode->filelen - i;
211
      if (toread > buffsize) toread = buffsize;
211
      if (toread > buffsize) toread = buffsize;
212
      if (fread(buff, toread, 1, zipfd) != 1) extract_res = -3;   /* read a chunk of data */
212
      if (fread(buff, toread, 1, zipfd) != 1) extract_res = -3;   /* read a chunk of data */
213
      crc32_feed(&cksum, buff, toread); /* update the crc32 checksum */
213
      crc32_feed(&cksum, buff, toread); /* update the crc32 checksum */
214
      if (fwrite(buff, toread, 1, filefd) != 1) extract_res = -4; /* write data chunk to dst file */
214
      if (fwrite(buff, toread, 1, filefd) != 1) extract_res = -4; /* write data chunk to dst file */
215
      i += toread;
215
      i += toread;
216
    }
216
    }
217
  } else if (curzipnode->compmethod == 8) {  /* if the file is deflated, inflate it */
217
  } else if (curzipnode->compmethod == 8) {  /* if the file is deflated, inflate it */
-
 
218
    /* use 1/3 of my buffer as input and 2/3 as output */
218
    extract_res = inf(zipfd, filefd, buff, &cksum, curzipnode->compressedfilelen);
219
    extract_res = inf(zipfd, filefd, buff, buffsize / 3, buff + (buffsize / 3), buffsize / 3 * 2, &cksum, curzipnode->compressedfilelen);
219
  }
220
  }
220
 
221
 
221
  /* clean up memory, close the dst file and terminates crc32 */
222
  /* clean up memory, close the dst file and terminates crc32 */
222
  free(buff);
223
  free(buff);
223
  fclose(filefd);   /* close the dst file */
224
  fclose(filefd);   /* close the dst file */
224
  crc32_finish(&cksum);
225
  crc32_finish(&cksum);
225
 
226
 
226
  /* printf("extract_res=%d / cksum_expected=%08lX / cksum_obtained=%08lX\n", extract_res, curzipnode->crc32, cksum); */
227
  /* printf("extract_res=%d / cksum_expected=%08lX / cksum_obtained=%08lX\n", extract_res, curzipnode->crc32, cksum); */
227
  if (extract_res != 0) {  /* was the extraction process successful? */
228
  if (extract_res != 0) {  /* was the extraction process successful? */
228
    unlink(fulldestfilename); /* remove the failed file */
229
    unlink(fulldestfilename); /* remove the failed file */
229
    return(extract_res);
230
    return(extract_res);
230
  }
231
  }
231
  if (cksum != curzipnode->crc32) { /* is the crc32 ok after extraction? */
232
  if (cksum != curzipnode->crc32) { /* is the crc32 ok after extraction? */
232
    unlink(fulldestfilename); /* remove the failed file */
233
    unlink(fulldestfilename); /* remove the failed file */
233
    return(-9);
234
    return(-9);
234
  }
235
  }
235
  /* Set the timestamp of the new file to what was set in the zip file */
236
  /* Set the timestamp of the new file to what was set in the zip file */
236
  filetimestamp.actime  = curzipnode->timestamp;
237
  filetimestamp.actime  = curzipnode->timestamp;
237
  filetimestamp.modtime = curzipnode->timestamp;
238
  filetimestamp.modtime = curzipnode->timestamp;
238
  utime(fulldestfilename, &filetimestamp);
239
  utime(fulldestfilename, &filetimestamp);
239
  return(0);
240
  return(0);
-
 
241
#undef buffsize
240
}
242
}
241
 
243
 
242
 
244
 
243
 
245
 
244
/* Call this to free a ziplist computed by zip_listfiles() */
246
/* Call this to free a ziplist computed by zip_listfiles() */
245
void zip_freelist(struct ziplist **ziplist) {
247
void zip_freelist(struct ziplist **ziplist) {
246
  struct ziplist *zipentrytobefreed;
248
  struct ziplist *zipentrytobefreed;
247
  while (*ziplist != NULL) { /* iterate through the linked list and free all nodes */
249
  while (*ziplist != NULL) { /* iterate through the linked list and free all nodes */
248
    zipentrytobefreed = *ziplist;
250
    zipentrytobefreed = *ziplist;
249
    *ziplist = zipentrytobefreed->nextfile;
251
    *ziplist = zipentrytobefreed->nextfile;
250
    /* free the node entry */
252
    /* free the node entry */
251
    free(zipentrytobefreed);
253
    free(zipentrytobefreed);
252
  }
254
  }
253
  *ziplist = NULL;
255
  *ziplist = NULL;
254
}
256
}
255
 
257