1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
Copyright (c) 2011, 2012, Simon Howard
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
// Simple program to read the headers from an .lzh file and dump
// the contents. These details can then be compared against a set
// of known good values.
#include <stdio.h>
#include "lib/lha_arch.h"
#include "lib/lha_basic_reader.h"
static void print_header(LHAFileHeader *header)
{
if (header->path != NULL) {
printf("path: %s\n", header->path);
}
if (header->filename != NULL) {
printf("filename: %s\n", header->filename);
}
if (header->symlink_target != NULL) {
printf("symlink_target: %s\n", header->symlink_target);
}
printf("compress_method: %s\n", header->compress_method);
printf("compressed_length: %" PRIu64 "\n", header->compressed_length);
printf("length: %" PRIu64 "\n", header->length);
printf("header_level: %i\n", header->header_level);
printf("os_type: %i", header->os_type);
if (header->os_type != LHA_OS_TYPE_UNKNOWN) {
printf(" ('%c')", header->os_type);
}
printf("\n");
printf("crc: %04x\n", header->crc);
if (header->timestamp != 0) {
printf("timestamp: %i\n", header->timestamp);
}
if (LHA_FILE_HAVE_EXTRA(header, LHA_FILE_WINDOWS_TIMESTAMPS)) {
printf("win_creation_time: %" PRIu64 "\n",
header->win_creation_time);
printf("win_modification_time: %" PRIu64 "\n",
header->win_modification_time);
printf("win_access_time: %" PRIu64 "\n",
header->win_access_time);
}
if (LHA_FILE_HAVE_EXTRA(header, LHA_FILE_UNIX_PERMS)) {
printf("unix_perms: 0%o\n", header->unix_perms);
}
if (LHA_FILE_HAVE_EXTRA(header, LHA_FILE_OS9_PERMS)) {
printf("os9_perms: 0%o\n", header->os9_perms);
}
if (LHA_FILE_HAVE_EXTRA(header, LHA_FILE_UNIX_UID_GID)) {
printf("unix_uid: %i\n", header->unix_uid);
printf("unix_gid: %i\n", header->unix_gid);
}
if (header->unix_group != NULL) {
printf("unix_group: %s\n", header->unix_group);
}
if (header->unix_username != NULL) {
printf("unix_username: %s\n", header->unix_username);
}
if (LHA_FILE_HAVE_EXTRA(header, LHA_FILE_COMMON_CRC)) {
printf("common_crc: %04x\n", header->common_crc);
}
}
int main(int argc, char *argv[])
{
LHAInputStream *stream;
LHABasicReader *reader;
LHAFileHeader *header;
if (argc < 2) {
printf("Usage: %s <filename>\n", argv[0]);
exit(-1);
}
// Give output in binary mode for cross-platform consistency,
// so that it can be compared correctly on Windows.
lha_arch_set_binary(stdout);
stream = lha_input_stream_from(argv[1]);
if (stream == NULL) {
fprintf(stderr, "Failed to open '%s'\n", argv[1]);
exit(-1);
}
reader = lha_basic_reader_new(stream);
for (;;) {
header = lha_basic_reader_next_file(reader);
if (header == NULL) {
break;
}
print_header(header);
printf("--\n");
}
lha_basic_reader_free(reader);
lha_input_stream_free(stream);
return 0;
}
|