File: decompress_demo.c

package info (click to toggle)
lrzip 0.641-1
  • links: PTS
  • area: main
  • in suites: bullseye, sid
  • size: 1,260 kB
  • sloc: ansic: 13,577; cpp: 2,864; sh: 568; makefile: 238; asm: 197
file content (58 lines) | stat: -rw-r--r-- 1,488 bytes parent folder | download | duplicates (4)
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
/*
   Copyright (C) 2012 Con Kolivas

   This program is free software; you can redistribute it and/or modify
   it 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.

   This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#undef NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <Lrzip.h>

static const char *suffix_me(const char *file)
{
	const char *p;
	static char buf[4096];

	p = strrchr(file, '.');
	if (p && (strlen(p + 1) < 4))
		strncat(buf, file, p - file);
	else
		strcat(buf, file);
	return &buf[0];
}

int main(int argc, char *argv[])
{
	Lrzip *lr;
	if ((argc != 2) && (argc != 3)) {
		fprintf(stderr, "Usage: %s file [outfile]\n", argv[0]);
		exit(1);
	}
	lr = lrzip_new(LRZIP_MODE_DECOMPRESS);
	assert(lr);
	lrzip_config_env(lr);
	assert(lrzip_filename_add(lr, argv[1]));
	if (argc == 2)
		lrzip_outfilename_set(lr, suffix_me(argv[1]));
	else
		lrzip_outfilename_set(lr, argv[2]);
	assert(lrzip_run(lr));
	return 0;
}