Subversion Repositories SvarDOS

Rev

Rev 257 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 257 Rev 268
Line 1... Line 1...
1
/*
1
/*
2
 * This file is part of the FDNPKG project
2
 * This file is part of pkg (SvarDOS)
3
 * http://fdnpkg.sourceforge.net
-
 
4
 *
-
 
5
 * Copyright (C) 2012-2016 Mateusz Viste. All rights reserved.
3
 * Copyright (C) 2012-2021 Mateusz Viste.
6
 *
4
 *
7
 * Simple library providing functions to unzip files from zip archives.
5
 * Simple library providing functions to unzip files from zip archives.
8
 */
6
 */
9
 
7
 
10
#include <stdio.h>     /* printf(), FILE, fclose()... */
8
#include <stdio.h>     /* printf(), FILE, fclose()... */
Line 14... Line 12...
14
#include <utime.h>     /* utime() */
12
#include <utime.h>     /* utime() */
15
#include <unistd.h>   /* unlink() */
13
#include <unistd.h>   /* unlink() */
16
 
14
 
17
#include "crc32.h"
15
#include "crc32.h"
18
#include "kprintf.h"
16
#include "kprintf.h"
19
#include "inf.h"   /* DEFLATE support */
17
#include "inf.h"   /* INFLATE support */
20
 
18
 
21
#include "libunzip.h"  /* include self for control */
19
#include "libunzip.h"  /* include self for control */
22
 
20
 
23
 
21
 
24
/* 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:
Line 28... Line 26...
28
 * month is always within 1-12 range;
26
 * month is always within 1-12 range;
29
 * year starts from 1980 and continues for 127 years
27
 * year starts from 1980 and continues for 127 years
30
 * 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;
31
 * minutes are always within 0-59 range;
29
 * minutes are always within 0-59 range;
32
 * hours are always within 0-23 range.     */
30
 * hours are always within 0-23 range.     */
33
static time_t dostime2unix(unsigned char *buff) {
31
static time_t dostime2unix(const unsigned char *buff) {
34
  struct tm curtime;
32
  struct tm curtime;
35
  time_t result;
33
  time_t result;
36
  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 */
37
  curtime.tm_sec = (buff[0] & 31) << 1; /* seconds (0..60) */
35
  curtime.tm_sec = (buff[0] & 31) << 1; /* seconds (0..60) */
38
  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) */
Line 162... Line 160...
162
}
160
}
163
 
161
 
164
 
162
 
165
 
163
 
166
/* 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. */
164
/* 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. */
167
int zip_unzip(FILE *zipfd, struct ziplist *curzipnode, char *fulldestfilename) {
165
int zip_unzip(FILE *zipfd, struct ziplist *curzipnode, const char *fulldestfilename) {
168
  #define buffsize 32 * 1024l /* MUST be at least 32K */
166
  #define buffsize 32 * 1024l /* MUST be at least 32K */
169
  FILE *filefd;
167
  FILE *filefd;
170
  unsigned long cksum;
168
  unsigned long cksum;
171
  int extract_res;
169
  int extract_res;
172
  unsigned char *buff;
170
  unsigned char *buff;