compress.c revision e4e61fdbed832a2bd3f5dcd47623872d9081599c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <lzma.h>
#include "compress.h"
bool b = false;
/* Returns false if we couldn't compress the data or the
* compressed result is longer than the original */
return false;
/* Does it fit? */
goto fail;
/* Is it actually shorter? */
if (s.avail_out == 0)
goto fail;
b = true;
fail:
lzma_end(&s);
return b;
}
bool b = false;
return false;
if (*dst_alloc_size <= src_size) {
void *p;
if (!p)
return false;
*dst = p;
}
s.avail_out = *dst_alloc_size;
for (;;) {
void *p;
if (ret == LZMA_STREAM_END)
break;
goto fail;
if (!p)
goto fail;
s.avail_out += *dst_alloc_size;
*dst = p;
*dst_alloc_size *= 2;
}
b = true;
fail:
lzma_end(&s);
return b;
}
bool b = false;
/* Checks whether the uncompressed blob starts with the
* mentioned prefix. The byte extra needs to follow the
* prefix */
return false;
if (*buffer_size <= prefix_len) {
void *p;
if (!p)
return false;
*buffer = p;
}
s.avail_out = *buffer_size;
for (;;) {
void *p;
goto fail;
break;
if (ret == LZMA_STREAM_END)
goto fail;
if (!p)
goto fail;
s.avail_out += *buffer_size;
*buffer = p;
*buffer_size *= 2;
}
b = true;
fail:
lzma_end(&s);
return b;
}