ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/lzf.c
(Generate patch)

Comparing liblzf/lzf.c (file contents):
Revision 1.4 by pcg, Tue Apr 20 18:11:57 2004 UTC vs.
Revision 1.9 by root, Fri Sep 29 19:43:01 2006 UTC

1/* 1/*
2 * Copyright (c) 2000-2003 Marc Alexander Lehmann <pcg@goof.com> 2 * Copyright (c) 2000-2005 Marc Alexander Lehmann <schmorp@schmorp.de>
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without modifica- 4 * Redistribution and use in source and binary forms, with or without modifica-
5 * tion, are permitted provided that the following conditions are met: 5 * tion, are permitted provided that the following conditions are met:
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright notice, 7 * 1. Redistributions of source code must retain the above copyright notice,
38 38
39#include "config.h" 39#include "config.h"
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h>
43#include <assert.h> 44#include <assert.h>
44 45
45#include <unistd.h> 46#include <unistd.h>
46#include <getopt.h> 47#include <getopt.h>
47 48
52static void 53static void
53usage (int ec) 54usage (int ec)
54{ 55{
55 fprintf (stderr, "\n" 56 fprintf (stderr, "\n"
56 "lzf, a very lightweight compression/decompression filter\n" 57 "lzf, a very lightweight compression/decompression filter\n"
57 "written by Marc Lehmann <pcg@goof.com> You can find more info at\n" 58 "written by Marc Lehmann <schmorp@schmorp.de> You can find more info at\n"
58 "http://liblzf.plan9.de/\n" 59 "http://liblzf.plan9.de/\n"
59 "\n" 60 "\n"
60 "USAGE: lzf -c [-b blocksize] | -d\n" 61 "USAGE: lzf -c [-b blocksize] | -d\n"
61 " -c compress\n" 62 " -c compress\n"
62 " -d decompress\n" 63 " -d decompress\n"
68} 69}
69 70
70/* 71/*
71 * Anatomy: an lzf file consists of any number of blocks in the following format: 72 * Anatomy: an lzf file consists of any number of blocks in the following format:
72 * 73 *
74 * \x00 EOF (optional)
73 * "ZV\0" 2-byte-usize <uncompressed data> 75 * "ZV\0" 2-byte-usize <uncompressed data>
74 * "ZV\1" 2-byte-csize 2-byte-usize <compressed data> 76 * "ZV\1" 2-byte-csize 2-byte-usize <compressed data>
75 * "ZV\2" 4-byte-crc32-0xdebb20e3 (NYI) 77 * "ZV\2" 4-byte-crc32-0xdebb20e3 (NYI)
76 * 78 *
77 */ 79 */
121 header[4] = us & 0xff; 123 header[4] = us & 0xff;
122 124
123 fwrite (header, 3+2, 1, stdout); 125 fwrite (header, 3+2, 1, stdout);
124 fwrite (buff1, us, 1, stdout); 126 fwrite (buff1, us, 1, stdout);
125 } 127 }
126 } while (!feof (stdin)); 128 }
127} 129}
128 130
129static void decompress (void) 131static void decompress (void)
130{ 132{
131 ssize_t us; 133 ssize_t us;
133 u8 buff1[64*1024]; 135 u8 buff1[64*1024];
134 u8 buff2[64*1024]; 136 u8 buff2[64*1024];
135 u8 header[3+2+2]; 137 u8 header[3+2+2];
136 138
137 for(;;) { 139 for(;;) {
138 if (fread (header, 3+2, 1, stdin) != 1) 140 int hdrsize = fread (header, 1, 3+2, stdin);
141
142 /* check for \0 record */
143 if (hdrsize)
144 {
145 if (!header[0])
146 break;
147 else if (hdrsize != 3+2)
148 {
149 if (feof (stdin))
150 fprintf (stderr, "decompress: invalid stream - short header\n");
151 else
152 perror ("decompress");
153
154 exit (1);
155 }
156 }
157 else
139 { 158 {
140 if (feof (stdin)) 159 if (feof (stdin))
141 break; 160 break;
142 else 161 else
143 { 162 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines