"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "htmldoc/zipc.c" between
htmldoc-1.9.11-source.tar.gz and htmldoc-1.9.12-source.tar.gz

About: HTMLDOC converts HTML and Markdown source files into indexed HTML, EPUB, PostScript, or PDF files (but doesn’t support CSS).

zipc.c  (htmldoc-1.9.11-source):zipc.c  (htmldoc-1.9.12-source)
/* /*
* Implementation of ZIP container mini-library. * Implementation of ZIP container mini-library.
* *
* https://github.com/michaelrsweet/zipc * https://github.com/michaelrsweet/zipc
* *
* Define ZIPC_ONLY_READ to compile with just the ZIP reading code, or * Define ZIPC_ONLY_READ to compile with just the ZIP reading code, or
* ZIPC_ONLY_WRITE to compile with just the ZIP writing code. Otherwise both * ZIPC_ONLY_WRITE to compile with just the ZIP writing code. Otherwise both
* ZIP reader and writer code is built. * ZIP reader and writer code is built.
* *
* Copyright 2017-2019 by Michael R Sweet. * Copyright © 2017-2021 by Michael R Sweet.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
skipping to change at line 479 skipping to change at line 479
* 'zipcFileGets()' - Read a line from a file. * 'zipcFileGets()' - Read a line from a file.
* *
* The trailing newline is omitted from the string for the line. * The trailing newline is omitted from the string for the line.
*/ */
int /* O - 0 on success, -1 on error */ int /* O - 0 on success, -1 on error */
zipcFileGets(zipc_file_t *zf, /* I - ZIP container file */ zipcFileGets(zipc_file_t *zf, /* I - ZIP container file */
char *line, /* I - Line string buffer */ char *line, /* I - Line string buffer */
size_t linesize) /* I - Size of buffer */ size_t linesize) /* I - Size of buffer */
{ {
char ch, /* Current character */ int ch; /* Current character */
*lineptr, /* Pointer into buffer */ char *lineptr, /* Pointer into buffer */
*lineend; /* Pointer to end of buffer */ *lineend; /* Pointer to end of buffer */
/* /*
* Read the line... * Read the line...
*/ */
lineptr = line; lineptr = line;
lineend = line + linesize - 1; lineend = line + linesize - 1;
while ((ch = zipc_read_char(zf)) > 0) while ((ch = zipc_read_char(zf)) > 0)
skipping to change at line 707 skipping to change at line 707
* *
* An XML fragment is an element like "<element attr='value'>", "some text", and * An XML fragment is an element like "<element attr='value'>", "some text", and
* "</element>". * "</element>".
*/ */
int /* O - 0 on success, -1 on error */ int /* O - 0 on success, -1 on error */
zipcFileXMLGets(zipc_file_t *zf, /* I - ZIP container file */ zipcFileXMLGets(zipc_file_t *zf, /* I - ZIP container file */
char *fragment, /* I - Fragment string buffer */ char *fragment, /* I - Fragment string buffer */
size_t fragsize) /* I - Size of buffer */ size_t fragsize) /* I - Size of buffer */
{ {
char ch, /* Current character */ int ch; /* Current character */
*fragptr, /* Pointer into buffer */ char *fragptr, /* Pointer into buffer */
*fragend; /* Pointer to end of buffer */ *fragend; /* Pointer to end of buffer */
/* /*
* Read the fragment... * Read the fragment...
*/ */
fragptr = fragment; fragptr = fragment;
fragend = fragment + fragsize - 1; fragend = fragment + fragsize - 1;
if ((ch = zipc_read_char(zf)) <= 0) if ((ch = zipc_read_char(zf)) <= 0)
skipping to change at line 1014 skipping to change at line 1014
/* /*
* Read all of the file headers... * Read all of the file headers...
*/ */
while (!done && (signature = zipc_read_u32(zc)) != 0xffffffff) while (!done && (signature = zipc_read_u32(zc)) != 0xffffffff)
{ {
switch (signature) switch (signature)
{ {
case ZIPC_LOCAL_HEADER : case ZIPC_LOCAL_HEADER :
offset = ftell(zc->fp) - 4; offset = ftell(zc->fp) - 4;
/*version = */zipc_read_u16(zc); /*version =*/ zipc_read_u16(zc);
flags = zipc_read_u16(zc); flags = zipc_read_u16(zc);
method = zipc_read_u16(zc); method = zipc_read_u16(zc);
/*modtime = */zipc_read_u32(zc); /*modtime =*/ zipc_read_u32(zc);
crc32 = zipc_read_u32(zc); crc32 = zipc_read_u32(zc);
compressed_size = zipc_read_u32(zc); compressed_size = zipc_read_u32(zc);
uncompressed_size = zipc_read_u32(zc); uncompressed_size = zipc_read_u32(zc);
cfile_len = zipc_read_u16(zc); cfile_len = zipc_read_u16(zc);
extra_field_len = zipc_read_u16(zc); extra_field_len = zipc_read_u16(zc);
if (cfile_len > (sizeof(cfile) - 1)) if (cfile_len > (sizeof(cfile) - 1))
{ {
zc->error = "Filename too long."; zc->error = "Filename too long.";
done = 1; done = 1;
skipping to change at line 1040 skipping to change at line 1040
if (zipc_read(zc, cfile, cfile_len) < cfile_len) if (zipc_read(zc, cfile, cfile_len) < cfile_len)
{ {
done = 1; done = 1;
break; break;
} }
cfile[cfile_len] = '\0'; cfile[cfile_len] = '\0';
if (extra_field_len > 0) if (extra_field_len > 0)
fseek(zc->fp, extra_field_len, SEEK_CUR); {
if (fseek(zc->fp, extra_field_len, SEEK_CUR) < 0)
{
fclose(zc->fp);
free(zc->files);
free(zc);
return (NULL);
}
}
if (zc->num_files >= zc->alloc_files) if (zc->num_files >= zc->alloc_files)
{ {
zc->alloc_files += 10; zc->alloc_files += 10;
if (!zc->files) zf = realloc(zc->files, zc->alloc_files * sizeof(zipc_file_t));
zf = malloc(zc->alloc_files * sizeof(zipc_file_t));
else
zf = realloc(zc->files, zc->alloc_files * sizeof(zipc_file_t));
if (!zf) if (!zf)
{ {
zc->error = strerror(errno); fclose(zc->fp);
free(zc->files);
free(zc);
return (NULL); return (NULL);
} }
zc->files = zf; zc->files = zf;
} }
zf = zc->files + zc->num_files; zf = zc->files + zc->num_files;
zc->num_files ++; zc->num_files ++;
memset(zf, 0, sizeof(zipc_file_t)); memset(zf, 0, sizeof(zipc_file_t));
skipping to change at line 1075 skipping to change at line 1082
strncpy(zf->filename, cfile, sizeof(zf->filename) - 1); strncpy(zf->filename, cfile, sizeof(zf->filename) - 1);
zf->zc = zc; zf->zc = zc;
zf->flags = flags; zf->flags = flags;
zf->method = method; zf->method = method;
zf->crc32 = crc32; zf->crc32 = crc32;
zf->compressed_size = compressed_size; zf->compressed_size = compressed_size;
zf->uncompressed_size = uncompressed_size; zf->uncompressed_size = uncompressed_size;
zf->offset = (size_t)offset; zf->offset = (size_t)offset;
zf->local_size = (size_t)(ftell(zc->fp) - offset); zf->local_size = (size_t)(ftell(zc->fp) - offset);
fseek(zc->fp, compressed_size, SEEK_CUR); if (fseek(zc->fp, compressed_size, SEEK_CUR) < 0)
{
fclose(zc->fp);
free(zc->files);
free(zc);
return (NULL);
}
break; break;
default : default :
snprintf(zc->error_msg, sizeof(zc->error_msg), "Unknown ZIP signature 0x%08x.", signature); snprintf(zc->error_msg, sizeof(zc->error_msg), "Unknown ZIP signature 0x%08x.", signature);
zc->error = zc->error_msg; zc->error = zc->error_msg;
fprintf(stderr, "zipcOpen: %s\n", zc->error_msg); fprintf(stderr, "zipcOpen: %s\n", zc->error_msg);
case ZIPC_DIR_HEADER : case ZIPC_DIR_HEADER :
case ZIPC_END_RECORD : case ZIPC_END_RECORD :
skipping to change at line 1160 skipping to change at line 1173
zipcOpenFile(zipc_t *zc, /* I - ZIP container */ zipcOpenFile(zipc_t *zc, /* I - ZIP container */
const char *filename) /* I - Name of file */ const char *filename) /* I - Name of file */
{ {
size_t count; /* Number of files */ size_t count; /* Number of files */
zipc_file_t *current; /* Current file */ zipc_file_t *current; /* Current file */
for (count = zc->num_files, current = zc->files; count > 0; count --, current ++) for (count = zc->num_files, current = zc->files; count > 0; count --, current ++)
{ {
if (!strcmp(filename, current->filename)) if (!strcmp(filename, current->filename))
{ {
fseek(zc->fp, current->offset + current->local_size, SEEK_SET); if (fseek(zc->fp, current->offset + current->local_size, SEEK_SET) < 0)
break;
if (current->method == ZIPC_COMP_DEFLATE) if (current->method == ZIPC_COMP_DEFLATE)
{ {
int err; /* Error status from inflateInit2 */
zc->stream.zalloc = (alloc_func)0; zc->stream.zalloc = (alloc_func)0;
zc->stream.zfree = (free_func)0; zc->stream.zfree = (free_func)0;
zc->stream.opaque = (voidpf)0; zc->stream.opaque = (voidpf)0;
inflateInit2(&zc->stream, -15); if ((err = inflateInit2(&zc->stream, -15)) < 0)
{
if (err == Z_STREAM_ERROR)
zc->error = strerror(EINVAL);
else
zc->error = strerror(ENOMEM);
return (NULL);
}
zc->stream.next_in = (Bytef *)zc->buffer; zc->stream.next_in = (Bytef *)zc->buffer;
zc->stream.avail_in = 0; zc->stream.avail_in = 0;
} }
current->compressed_pos = 0; current->compressed_pos = 0;
current->uncompressed_pos = 0; current->uncompressed_pos = 0;
zc->readptr = NULL; zc->readptr = NULL;
skipping to change at line 1358 skipping to change at line 1382
if (compression) if (compression)
{ {
temp->flags = ZIPC_FLAG_CMAX; temp->flags = ZIPC_FLAG_CMAX;
temp->method = ZIPC_COMP_DEFLATE; temp->method = ZIPC_COMP_DEFLATE;
zc->stream.zalloc = (alloc_func)0; zc->stream.zalloc = (alloc_func)0;
zc->stream.zfree = (free_func)0; zc->stream.zfree = (free_func)0;
zc->stream.opaque = (voidpf)0; zc->stream.opaque = (voidpf)0;
deflateInit2(&zc->stream, Z_BEST_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_ if (deflateInit2(&zc->stream, Z_BEST_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFA
STRATEGY); ULT_STRATEGY) < 0)
{
zc->num_files --;
zc->error = strerror(ENOMEM);
return (NULL);
}
zc->stream.next_out = (Bytef *)zc->buffer; zc->stream.next_out = (Bytef *)zc->buffer;
zc->stream.avail_out = sizeof(zc->buffer); zc->stream.avail_out = sizeof(zc->buffer);
} }
return (temp); return (temp);
} }
#endif /* !ZIPC_ONLY_READ */ #endif /* !ZIPC_ONLY_READ */
#ifndef ZIPC_ONLY_WRITE #ifndef ZIPC_ONLY_WRITE
skipping to change at line 1614 skipping to change at line 1643
zipc_file_t *zf) /* I - ZIP container file */ zipc_file_t *zf) /* I - ZIP container file */
{ {
int status = 0; /* Return status */ int status = 0; /* Return status */
if (zf->flags & ZIPC_FLAG_STREAMED) if (zf->flags & ZIPC_FLAG_STREAMED)
{ {
/* /*
* Update the CRC-32, compressed size, and uncompressed size fields... * Update the CRC-32, compressed size, and uncompressed size fields...
*/ */
fseek(zc->fp, (long)(zf->offset + 14), SEEK_SET); if (fseek(zc->fp, (long)(zf->offset + 14), SEEK_SET) < 0)
{
zc->error = strerror(errno);
return (-1);
}
status |= zipc_write_u32(zc, zf->crc32); status |= zipc_write_u32(zc, zf->crc32);
status |= zipc_write_u32(zc, (unsigned)zf->compressed_size); status |= zipc_write_u32(zc, (unsigned)zf->compressed_size);
status |= zipc_write_u32(zc, (unsigned)zf->uncompressed_size); status |= zipc_write_u32(zc, (unsigned)zf->uncompressed_size);
fseek(zc->fp, 0, SEEK_END); if (fseek(zc->fp, 0, SEEK_END) < 0)
{
zc->error = strerror(errno);
return (-1);
}
zf->flags &= ZIPC_FLAG_MASK; zf->flags &= ZIPC_FLAG_MASK;
} }
return (status); return (status);
} }
/* /*
* 'zipc_write_u16()' - Write a 16-bit unsigned integer. * 'zipc_write_u16()' - Write a 16-bit unsigned integer.
*/ */
 End of changes. 15 change blocks. 
20 lines changed or deleted 57 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)