hexedit: fixes for redraw and down movement causing SEGV on attempt to access
[oweals/busybox.git] / miscutils / bbconfig.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * This file was released into the public domain by Paul Fox.
4  */
5 //config:config BBCONFIG
6 //config:       bool "bbconfig (9.7 kb)"
7 //config:       default n
8 //config:       help
9 //config:       The bbconfig applet will print the config file with which
10 //config:       busybox was built.
11 //config:
12 //config:config FEATURE_COMPRESS_BBCONFIG
13 //config:       bool "Compress bbconfig data"
14 //config:       default y
15 //config:       depends on BBCONFIG
16 //config:       help
17 //config:       Store bbconfig data in compressed form, uncompress them on-the-fly
18 //config:       before output.
19 //config:
20 //config:       If you have a really tiny busybox with few applets enabled (and
21 //config:       bunzip2 isn't one of them), the overhead of the decompressor might
22 //config:       be noticeable. Also, if you run executables directly from ROM
23 //config:       and have very little memory, this might not be a win. Otherwise,
24 //config:       you probably want this.
25
26 //applet:IF_BBCONFIG(APPLET(bbconfig, BB_DIR_BIN, BB_SUID_DROP))
27
28 //kbuild:lib-$(CONFIG_BBCONFIG) += bbconfig.o
29
30 //usage:#define bbconfig_trivial_usage
31 //usage:       ""
32 //usage:#define bbconfig_full_usage "\n\n"
33 //usage:       "Print the config file used by busybox build"
34
35 #include "libbb.h"
36 #include "bbconfigopts.h"
37 #if ENABLE_FEATURE_COMPRESS_BBCONFIG
38 # include "bb_archive.h"
39 # include "bbconfigopts_bz2.h"
40 #endif
41
42 int bbconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
43 int bbconfig_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
44 {
45 #if ENABLE_FEATURE_COMPRESS_BBCONFIG
46         bunzip_data *bd;
47         int i;
48         jmp_buf jmpbuf;
49
50         /* Setup for I/O error handling via longjmp */
51         i = setjmp(jmpbuf);
52         if (i == 0) {
53                 i = start_bunzip(&jmpbuf,
54                         &bd,
55                         /* src_fd: */ -1,
56                         /* inbuf:  */ bbconfig_config_bz2,
57                         /* len:    */ sizeof(bbconfig_config_bz2)
58                 );
59         }
60         /* read_bunzip can longjmp and end up here with i != 0
61          * on read data errors! Not trivial */
62         if (i == 0) {
63                 /* Cannot use xmalloc: will leak bd in NOFORK case! */
64                 char *outbuf = malloc_or_warn(sizeof(bbconfig_config));
65                 if (outbuf) {
66                         read_bunzip(bd, outbuf, sizeof(bbconfig_config));
67                         full_write1_str(outbuf);
68                 }
69         }
70 #else
71         full_write1_str(bbconfig_config);
72 #endif
73         return 0;
74 }