summaryrefslogtreecommitdiff
path: root/miscutils/bbconfig.c
blob: 045aca21122940db2e13cd79d7593e55e843c5f2 (plain)
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
/* vi: set sw=4 ts=4: */
/* This file was released into the public domain by Paul Fox.
 */
//config:config BBCONFIG
//config:	bool "bbconfig (9.7 kb)"
//config:	default n
//config:	help
//config:	The bbconfig applet will print the config file with which
//config:	busybox was built.
//config:
//config:config FEATURE_COMPRESS_BBCONFIG
//config:	bool "Compress bbconfig data"
//config:	default y
//config:	depends on BBCONFIG
//config:	help
//config:	Store bbconfig data in compressed form, uncompress them on-the-fly
//config:	before output.
//config:
//config:	If you have a really tiny busybox with few applets enabled (and
//config:	bunzip2 isn't one of them), the overhead of the decompressor might
//config:	be noticeable. Also, if you run executables directly from ROM
//config:	and have very little memory, this might not be a win. Otherwise,
//config:	you probably want this.

//applet:IF_BBCONFIG(APPLET(bbconfig, BB_DIR_BIN, BB_SUID_DROP))

//kbuild:lib-$(CONFIG_BBCONFIG) += bbconfig.o

//usage:#define bbconfig_trivial_usage
//usage:       ""
//usage:#define bbconfig_full_usage "\n\n"
//usage:       "Print the config file used by busybox build"

#include "libbb.h"
#include "bbconfigopts.h"
#if ENABLE_FEATURE_COMPRESS_BBCONFIG
# include "bb_archive.h"
# include "bbconfigopts_bz2.h"
#endif

int bbconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bbconfig_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
#if ENABLE_FEATURE_COMPRESS_BBCONFIG
	bunzip_data *bd;
	int i = start_bunzip(&bd,
			/* src_fd: */ -1,
			/* inbuf:  */ bbconfig_config_bz2,
			/* len:    */ sizeof(bbconfig_config_bz2));
	/* read_bunzip can longjmp to start_bunzip, and ultimately
	 * end up here with i != 0 on read data errors! Not trivial */
	if (!i) {
		/* Cannot use xmalloc: will leak bd in NOFORK case! */
		char *outbuf = malloc_or_warn(sizeof(bbconfig_config));
		if (outbuf) {
			read_bunzip(bd, outbuf, sizeof(bbconfig_config));
			full_write1_str(outbuf);
		}
	}
#else
	full_write1_str(bbconfig_config);
#endif
	return 0;
}