"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
"$(core-y)" \
"$(libs-y)" \
- "$(LDLIBS)"
+ "$(LDLIBS)" \
+ && $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
# Generate System.map
quiet_cmd_sysmap = SYSMAP
# Split autoconf.h into include/linux/config/*
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h
+quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h
+ cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
#bbox# piggybacked generation of few .h files
include/config/MARKER: scripts/basic/split-include include/autoconf.h
$(call cmd,split_autoconf)
$(call cmd,gen_bbconfigopts)
+ $(call cmd,gen_common_bufsiz)
@touch $@
# Generate some files
MRPROPER_DIRS += include/config include2
MRPROPER_FILES += .config .config.old include/asm .version .old_version \
include/NUM_APPLETS.h \
+ include/common_bufsiz.h \
include/autoconf.h \
include/bbconfigopts.h \
include/bbconfigopts_bz2.h \
* Only supports new ASCII and CRC formats
*/
#include "libbb.h"
+#include "common_bufsiz.h"
#include "bb_archive.h"
//config:config CPIO
struct globals {
struct bb_uidgid_t owner_ugid;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
void BUG_cpio_globals_too_big(void);
#define INIT_G() do { \
G.owner_ugid.uid = -1L; \
//usage: "\n -F Don't store or verify checksum"
#include "libbb.h"
+#include "common_bufsiz.h"
#include "bb_archive.h"
#include "liblzo_interface.h"
chksum_t chksum_in;
chksum_t chksum_out;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
//#define G (*ptr_to_globals)
//#define INIT_G() do {
//usage: "\n -qpc List config files"
#include "libbb.h"
+#include "common_bufsiz.h"
#include "bb_archive.h"
#include "rpm.h"
rpm_index **mytags;
int tagcount;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void extract_cpio(int fd, const char *source_rpm)
#include <fnmatch.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#include "bb_archive.h"
/* FIXME: Stop using this non-standard feature */
#ifndef FNM_LEADING_DIR
//usage: "$ dumpkmap > keymap\n"
#include "libbb.h"
+#include "common_bufsiz.h"
/* From <linux/kd.h> */
struct kbentry {
//usage: "Resize the screen"
#include "libbb.h"
+#include "common_bufsiz.h"
#define ESC "\033"
-#define old_termios_p ((struct termios*)&bb_common_bufsiz1)
+#define old_termios_p ((struct termios*)bb_common_bufsiz1)
static void
onintr(int sig UNUSED_PARAM)
//usage: "\n -v Don't use ^x or M-x escapes"
#include "libbb.h"
+#include "common_bufsiz.h"
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
//usage: "Calculate the CRC32 checksums of FILES"
#include "libbb.h"
+#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
crc = 0;
length = 0;
-#define read_buf bb_common_bufsiz1
- while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) {
+#define read_buf bb_common_bufsiz1
+#define sizeof_read_buf COMMON_BUFSIZE
+ while ((bytes_read = safe_read(fd, read_buf, sizeof_read_buf)) > 0) {
length += bytes_read;
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
}
//usage: "Wed Apr 12 18:52:41 MDT 2000\n"
#include "libbb.h"
+#include "common_bufsiz.h"
#if ENABLE_FEATURE_DATE_NANO
# include <sys/syscall.h>
#endif
}
#endif
-#define date_buf bb_common_bufsiz1
+#define date_buf bb_common_bufsiz1
+#define sizeof_date_buf COMMON_BUFSIZE
if (*fmt_dt2str == '\0') {
/* With no format string, just print a blank line */
date_buf[0] = '\0';
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
}
/* Generate output string */
- strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);
+ strftime(date_buf, sizeof_date_buf, fmt_dt2str, &tm_time);
}
puts(date_buf);
//usage: "4+0 records out\n"
#include "libbb.h"
+#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
#endif
int flags;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
//usage: "2417 .\n"
#include "libbb.h"
+#include "common_bufsiz.h"
enum {
OPT_a_files_too = (1 << 0),
int du_depth;
dev_t dir_dev;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
//usage: "of characters matched or 0."
#include "libbb.h"
+#include "common_bufsiz.h"
#include "xregex.h"
#if ENABLE_EXPR_MATH_SUPPORT_64
struct globals {
char **args;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
/* forward declarations */
//usage: )
#include "libbb.h"
+#include "common_bufsiz.h"
#include "unicode.h"
time_t current_time_t;
#endif
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
/* #include "libbb.h" - done in od.c */
+#include "common_bufsiz.h"
#define assert(a) ((void)0)
#if !ENABLE_LONG_OPTS
enum { G_pseudo_offset = 0 };
#endif
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
G.bytes_per_block = 32; \
//usage: "$ cat TODO | split -a 2 -l 2 TODO_\n"
#include "libbb.h"
+#include "common_bufsiz.h"
#if ENABLE_FEATURE_SPLIT_FANCY
static const struct suffix_mult split_suffixes[] = {
//usage: )
#include "libbb.h"
+#include "common_bufsiz.h"
enum {
OPT_TERSE = (1 << 0),
/* coreutils 6.3 compat: */
/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
-#define buf bb_common_bufsiz1
+#define buf bb_common_bufsiz1
+#define sizeof_buf COMMON_BUFSIZE
- strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000");
+ strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof_buf, &t), ".000000000");
return buf;
#undef buf
}
//usage: "\n [SETTING] See manpage"
#include "libbb.h"
+#include "common_bufsiz.h"
#ifndef _POSIX_VDISABLE
# define _POSIX_VDISABLE ((unsigned char) 0)
unsigned current_col;
char buf[10];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.device_name = bb_msg_standard_input; \
G.max_col = 80; \
//usage: "\n -s Use System V sum algorithm (512byte blocks)"
#include "libbb.h"
+#include "common_bufsiz.h"
enum { SUM_BSD, PRINT_NAME, SUM_SYSV };
return 0;
while (1) {
- size_t bytes_read = safe_read(fd, buf, BUFSIZ);
+ size_t bytes_read = safe_read(fd, buf, COMMON_BUFSIZE);
if ((ssize_t)bytes_read <= 0) {
r = (fd && close(fd) != 0);
//usage: "nameserver 10.0.0.1\n"
#include "libbb.h"
+#include "common_bufsiz.h"
struct globals {
bool from_top;
bool exitcode;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void tail_xprint_header(const char *fmt, const char *filename)
//usage: "Hello\n"
#include "libbb.h"
+#include "common_bufsiz.h"
int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int tee_main(int argc, char **argv)
//TODO: make unconditional
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
ssize_t c;
-# define buf bb_common_bufsiz1
+# define buf bb_common_bufsiz1
+# define sizeof_buf COMMON_BUFSIZE
#else
int c;
#endif
/* names[0] will be filled later */
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
- while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
+ while ((c = safe_read(STDIN_FILENO, buf, sizeof_buf)) > 0) {
fp = files;
do
fwrite(buf, 1, c, *fp);
//usage: "+ shutdown -h +4m"
#include "libbb.h"
+#include "common_bufsiz.h"
struct globals {
char **names;
int cur;
char *cmd[2 /* using 1 provokes compiler warning */];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define names (G.names)
#define cur (G.cur )
#define cmd (G.cmd )
/* Override ENABLE_FEATURE_PIDFILE */
#define WANT_PIDFILE 1
#include "libbb.h"
+#include "common_bufsiz.h"
struct pid_list {
struct pid_list *next;
int user_id;
smallint signal_nr;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define userspec (G.userspec )
#define cmdname (G.cmdname )
#define execname (G.execname )
//usage: "\n -t TYPE List of filesystem types to check"
#include "libbb.h"
+#include "common_bufsiz.h"
/* "progress indicator" code is somewhat buggy and ext[23] specific.
* We should be filesystem agnostic. IOW: there should be a well-defined
struct fs_info *filesys_last;
struct fsck_instance *instance_list;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
//usage: "\n -w Ignore all whitespace"
#include "libbb.h"
+#include "common_bufsiz.h"
#if 0
# define dbg_error_msg(...) bb_error_msg(__VA_ARGS__)
//usage:#define ed_full_usage ""
#include "libbb.h"
+#include "common_bufsiz.h"
typedef struct LINE {
struct LINE *next;
} LINE;
-#define searchString bb_common_bufsiz1
+#define searchString bb_common_bufsiz1
+#define sizeof_searchString COMMON_BUFSIZE
enum {
- USERSIZE = sizeof(searchString) > 1024 ? 1024
- : sizeof(searchString) - 1, /* max line length typed in by user */
+ USERSIZE = sizeof_searchString > 1024 ? 1024
+ : sizeof_searchString - 1, /* max line length typed in by user */
INITBUF_SIZE = 1024, /* initial buffer size */
};
//usage: "bar\n"
#include "libbb.h"
+#include "common_bufsiz.h"
#include "xregex.h"
#if 0
int len; /* Space allocated */
} pipeline;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
G.sed_cmd_tail = &G.sed_cmd_head; \
#include <fnmatch.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#if ENABLE_FEATURE_FIND_REGEX
# include "xregex.h"
#endif
recurse_flags_t recurse_flags;
IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;)
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
/* we have to zero it out because of NOEXEC */ \
//config: Print the specified number of context lines (-C).
#include "libbb.h"
+#include "common_bufsiz.h"
#include "xregex.h"
llist_t *pattern_head; /* growable list of patterns to match */
const char *cur_file; /* the current file we are reading */
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
//kbuild:lib-$(CONFIG_XARGS) += xargs.o
#include "libbb.h"
+#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
const char *eof_str;
int idx;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \
extern const int const_int_0;
//extern const int const_int_1;
-
-/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
-enum { COMMON_BUFSIZE = (BUFSIZ >= 256*sizeof(void*) ? BUFSIZ+1 : 256*sizeof(void*)) };
-extern char bb_common_bufsiz1[COMMON_BUFSIZE];
/* This struct is deliberately not defined. */
/* See docs/keep_data_small.txt */
struct globals;
//config: and /etc/bootchartd.conf files.
#include "libbb.h"
+#include "common_bufsiz.h"
/* After libbb.h, since it needs sys/types.h on some systems */
#include <sys/utsname.h>
struct globals {
char jiffy_line[COMMON_BUFSIZE];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void dump_file(FILE *fp, const char *filename)
--- /dev/null
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2016 Denys Vlasenko
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
+//config:config FEATURE_USE_BSS_TAIL
+//config: bool "Use the end of BSS page"
+//config: default n
+//config: help
+//config: Attempt to reclaim a small unused part of BSS.
+//config:
+//config: Executables have the following parts:
+//config: = read-only executable code and constants, also known as "text"
+//config: = read-write data
+//config: = non-initialized (zeroed on demand) data, also known as "bss"
+//config:
+//config: At link time, "text" is padded to a full page. At runtime, all "text"
+//config: pages are mapped RO and executable.
+//config: "Data" starts on the next page boundary, but is not padded
+//config: to a full page at the end. "Bss" starts wherever "data" ends.
+//config: At runtime, "data" pages are mapped RW and they are file-backed
+//config: (this includes a small portion of "bss" which may live in the last
+//config: partial page of "data").
+//config: Pages which are fully in "bss" are mapped to anonymous memory.
+//config:
+//config: "Bss" end is usually not page-aligned. There is an unused space
+//config: in the last page. Linker marks its start with the "_end" symbol.
+//config:
+//config: This option will attempt to use that space for bb_common_bufsiz1[]
+//config: array. If it fits after _end, it will be used, and COMMON_BUFSIZE
+//config: will be enlarged from its guaranteed minimum size of 1 kbyte.
+//config: This may require recompilation a second time, since value of _end
+//config: is known only after final link.
+//config:
+//config: If you are getting a build error like this:
+//config: appletlib.c:(.text.main+0xd): undefined reference to '_end'
+//config: disable this option.
+
+//kbuild:lib-y += common_bufsiz.o
+
+#include "libbb.h"
+#include "common_bufsiz.h"
+
+#if !ENABLE_FEATURE_USE_BSS_TAIL
+
+/* We use it for "global" data via *(struct global*)bb_common_bufsiz1.
+ * Since gcc insists on aligning struct global's members, it would be a pity
+ * (and an alignment fault on some CPUs) to mess it up. */
+char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
+
+#else
+
+# ifndef setup_common_bufsiz
+/*
+ * It is not a "((void)0)" macro. It means we have to provide this function.
+ */
+char* bb_common_bufsiz1;
+char* setup_common_bufsiz(void)
+{
+ if (!bb_common_bufsiz1)
+ bb_common_bufsiz1 = xzalloc(COMMON_BUFSIZE);
+ return bb_common_bufsiz1;
+}
+# else
+# ifndef bb_common_bufsiz1
+ /* bb_common_bufsiz1[] is not aliased to _end[] */
+char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
+# endif
+# endif
+
+#endif
# error unknown path to wtmp file
# endif
#endif
-
-/* We use it for "global" data via *(struct global*)&bb_common_bufsiz1.
- * Since gcc insists on aligning struct global's members, it would be a pity
- * (and an alignment fault on some CPUs) to mess it up. */
-char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
//usage: "\n -p Preserve environment"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <syslog.h>
#include <sys/resource.h>
struct globals {
struct termios tty_attrs;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
//usage: "chat '' ATZ OK ATD123456 CONNECT '' ogin: pppuser word: ppppass '~'"
#include "libbb.h"
+#include "common_bufsiz.h"
// default timeout: 45 sec
#define DEFAULT_CHAT_TIMEOUT 45*1000
//usage: "\n -y LINE Starting line"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <sys/kd.h>
#define ESC "\033"
int conspy_main(int argc UNUSED_PARAM, char **argv)
{
char tty_name[sizeof(DEV_TTY "NN")];
-#define keybuf bb_common_bufsiz1
+#define keybuf bb_common_bufsiz1
+#define sizeof_keybuf COMMON_BUFSIZE
struct termios termbuf;
unsigned opts;
unsigned ttynum;
default:
// Read the keys pressed
k = keybuf + G.key_count;
- bytes_read = read(G.kbd_fd, k, sizeof(keybuf) - G.key_count);
+ bytes_read = read(G.kbd_fd, k, sizeof_keybuf - G.key_count);
if (bytes_read < 0)
goto abort;
//usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <syslog.h>
/* glibc frees previous setenv'ed value when we do next setenv()
char *env_var_logname;
#endif
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.log_level = 8; \
G.crontab_dir_name = CRONTABS; \
*/
#include "libbb.h"
+#include "common_bufsiz.h"
#include <math.h>
//usage:#define dc_trivial_usage
double stack[1];
} FIX_ALIASING;
enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) };
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define pointer (G.pointer )
#define base (G.base )
#define stack (G.stack )
//usage: "\n commands: 'NN' (% for progress bar) or 'exit'"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <linux/fb.h>
/* If you want logging messages on /tmp/fbsplash.log... */
* - A raster of Width * Height pixels in triplets of rgb
* in pure binary by 1 or 2 bytes. (we support only 1 byte)
*/
-#define concat_buf bb_common_bufsiz1
+#define concat_buf bb_common_bufsiz1
+#define sizeof_concat_buf COMMON_BUFSIZE
read_ptr = concat_buf;
while (1) {
int w, h, max_color_val;
- int rem = concat_buf + sizeof(concat_buf) - read_ptr;
+ int rem = concat_buf + sizeof_concat_buf - read_ptr;
if (rem < 2
|| fgets(read_ptr, rem, theme_file) == NULL
) {
//usage: "\n -z Reread partition table"
#include "libbb.h"
+#include "common_bufsiz.h"
/* must be _after_ libbb.h: */
#include <linux/hdreg.h>
#include <sys/mount.h>
unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 };
#endif
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define get_identity (G.get_identity )
#define get_geom (G.get_geom )
#define do_flush (G.do_flush )
*/
#include "libbb.h"
+#include "common_bufsiz.h"
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
//usage: "\nWhen x event happens for all FILEs, inotifyd exits."
#include "libbb.h"
+#include "common_bufsiz.h"
#include <sys/inotify.h>
static const char mask_names[] ALIGN1 =
// read out all pending events
// (NB: len must be int, not ssize_t or long!)
xioctl(pfd.fd, FIONREAD, &len);
-#define eventbuf bb_common_bufsiz1
- ie = buf = (len <= sizeof(eventbuf)) ? eventbuf : xmalloc(len);
+#define eventbuf bb_common_bufsiz1
+#define sizeof_eventbuf COMMON_BUFSIZE
+ ie = buf = (len <= sizeof_eventbuf) ? eventbuf : xmalloc(len);
len = full_read(pfd.fd, buf, len);
// process events. N.B. events may vary in length
while (len > 0) {
#include <sched.h> /* sched_yield() */
#include "libbb.h"
+#include "common_bufsiz.h"
#if ENABLE_FEATURE_LESS_REGEXP
#include "xregex.h"
#endif
*/
static void read_lines(void)
{
-#define readbuf bb_common_bufsiz1
+#define readbuf bb_common_bufsiz1
+#define sizeof_readbuf COMMON_BUFSIZE
char *current_line, *p;
int w = width;
char last_terminated = terminated;
time_t t;
errno = 0;
- eof_error = safe_read(STDIN_FILENO, readbuf, sizeof(readbuf));
+ eof_error = safe_read(STDIN_FILENO, readbuf, sizeof_readbuf);
if (errno != EAGAIN)
break;
t = time(NULL);
//usage: "\n -X Disable special meaning of NUL and Ctrl-X from stdin"
#include "libbb.h"
+#include "common_bufsiz.h"
// set raw tty mode
static void xget1(int fd, struct termios *t, struct termios *oldt)
skip_write: ;
}
if (pfd[0].revents) {
-#define iobuf bb_common_bufsiz1
+#define iobuf bb_common_bufsiz1
+#define sizeof_iobuf COMMON_BUFSIZE
ssize_t len;
// read from device -> write to stdout
- len = safe_read(sfd, iobuf, sizeof(iobuf));
+ len = safe_read(sfd, iobuf, sizeof_iobuf);
if (len > 0)
full_write(STDOUT_FILENO, iobuf, len);
else {
//usage: "\n -H HWTYPE Hardware address type"
#include "libbb.h"
+#include "common_bufsiz.h"
#include "inet_common.h"
#include <arpa/inet.h>
const char *device; /* current device */
smallint hw_set; /* flag if hw-type was set (-H) */
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define ap (G.ap )
#define hw (G.hw )
#define device (G.device )
#include <netpacket/packet.h>
#include "libbb.h"
+#include "common_bufsiz.h"
/* We don't expect to see 1000+ seconds delay, unsigned is enough */
#define MONOTONIC_US() ((unsigned)monotonic_us())
unsigned brd_recv;
unsigned req_recv;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define src (G.src )
#define dst (G.dst )
#define me (G.me )
//usage: "\n DIR Change root to this directory"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <syslog.h>
#include <netinet/tcp.h>
char msg_ok [(sizeof("NNN " MSG_OK ) + 3) & 0xfffc];
char msg_err[(sizeof("NNN " MSG_ERR) + 3) & 0xfffc];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
/* Moved to main */ \
/*strcpy(G.msg_ok + 4, MSG_OK );*/ \
//usage: )
#include "libbb.h"
+#include "common_bufsiz.h"
struct globals {
const char *user;
int do_continue;
char buf[4]; /* actually [BUFSZ] */
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
#define user (G.user )
#define password (G.password )
//usage: "\n -d STRING URL decode STRING"
#include "libbb.h"
+#include "common_bufsiz.h"
#if ENABLE_PAM
/* PAM may include <locale.h>. We may need to undefine bbox's stub define: */
# undef setlocale
Htaccess *script_i; /* config script interpreters */
#endif
char *iobuf; /* [IOBUF_SIZE] */
-#define hdr_buf bb_common_bufsiz1
+#define hdr_buf bb_common_bufsiz1
+#define sizeof_hdr_buf COMMON_BUFSIZE
char *hdr_ptr;
int hdr_cnt;
#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
alarm(HEADER_READ_TIMEOUT);
while (1) {
if (hdr_cnt <= 0) {
- hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf));
+ hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
if (hdr_cnt <= 0)
break;
hdr_ptr = hdr_buf;
/* We expect data, prev data portion is eaten by CGI
* and there *is* data to read from the peer
* (POSTDATA) */
- //count = post_len > (int)sizeof(hdr_buf) ? (int)sizeof(hdr_buf) : post_len;
+ //count = post_len > (int)sizeof_hdr_buf ? (int)sizeof_hdr_buf : post_len;
//count = safe_read(STDIN_FILENO, hdr_buf, count);
- count = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf));
+ count = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
if (count > 0) {
hdr_cnt = count;
hdr_ptr = hdr_buf;
//usage: "\n -f Force de/configuration"
#include "libbb.h"
+#include "common_bufsiz.h"
/* After libbb.h, since it needs sys/types.h on some systems */
#include <sys/utsname.h>
#include <fnmatch.h>
const char *startup_PATH;
char *shell;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#include <sys/un.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#if ENABLE_FEATURE_INETD_RPC
# if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__)
/* Used in next_line(), and as scratch read buffer */
char line[256]; /* _at least_ 256, see LINE_SIZE */
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) };
#define rlim_ofile_cur (G.rlim_ofile_cur )
#define rlim_ofile (G.rlim_ofile )
//usage: "\n STRING Ident answer string (default: nobody)"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <syslog.h>
#include "isrv.h"
char buf[64 - sizeof(int)];
} identd_buf_t;
-#define bogouser bb_common_bufsiz1
+#define bogouser bb_common_bufsiz1
+#define sizeof_bogouser COMMON_BUFSIZE
static int new_peer(isrv_state_t *state, int fd)
{
opt = getopt32(argv, "fiwb:", &bind_address);
strcpy(bogouser, "nobody");
if (argv[optind])
- strncpy(bogouser, argv[optind], sizeof(bogouser) - 1);
+ strncpy(bogouser, argv[optind], sizeof_bogouser - 1);
/* Daemonize if no -f and no -i and no -w */
if (!(opt & OPT_fiw))
#include <net/if_arp.h>
#include "ip_common.h" /* #include "libbb.h" is inside */
+#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
} FIX_ALIASING;
typedef struct filter_t filter_t;
-#define G_filter (*(filter_t*)&bb_common_bufsiz1)
+#define G_filter (*(filter_t*)bb_common_bufsiz1)
static void print_link_flags(unsigned flags, unsigned mdown)
*/
#include "ip_common.h" /* #include "libbb.h" is inside */
+#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
#include <linux/neighbour.h>
} FIX_ALIASING;
typedef struct filter_t filter_t;
-#define G_filter (*(filter_t*)&bb_common_bufsiz1)
+#define G_filter (*(filter_t*)bb_common_bufsiz1)
static int flush_update(void)
{
*/
#include "ip_common.h" /* #include "libbb.h" is inside */
+#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
} FIX_ALIASING;
typedef struct filter_t filter_t;
-#define G_filter (*(filter_t*)&bb_common_bufsiz1)
+#define G_filter (*(filter_t*)bb_common_bufsiz1)
static int flush_update(void)
{
*/
#include "libbb.h"
+#include "common_bufsiz.h"
//config:config NC
//config: bool "nc"
fd = STDIN_FILENO;
while (1) {
if (FD_ISSET(fd, &testfds)) {
- nread = safe_read(fd, iobuf, sizeof(iobuf));
+ nread = safe_read(fd, iobuf, COMMON_BUFSIZE);
if (fd == cfd) {
if (nread < 1)
exit(EXIT_SUCCESS);
#include <net/if.h>
#include <netinet/ip_icmp.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#ifdef __BIONIC__
/* should be in netinet/ip_icmp.h */
char *hostname;
char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void noresp(int ign UNUSED_PARAM)
} pingaddr;
unsigned char rcvd_tbl[MAX_DUP_CHK / 8];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define if_index (G.if_index )
#define source_lsa (G.source_lsa )
#define str_I (G.str_I )
//usage: "\n -F Disable RTS/CTS flow control"
#include "libbb.h"
+#include "common_bufsiz.h"
#include "libiproute/utils.h" /* invarg_1_to_2() */
struct globals {
int saved_disc;
struct termios saved_state;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define handle (G.handle )
#define saved_disc (G.saved_disc )
#define saved_state (G.saved_state )
//usage: "filter show [ dev STRING ] [ root | parent CLASSID ]"
#include "libbb.h"
+#include "common_bufsiz.h"
#include "libiproute/utils.h"
#include "libiproute/ip_common.h"
uint32_t filter_prio;
uint32_t filter_proto;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define filter_ifindex (G.filter_ifindex)
#define filter_qdisc (G.filter_qdisc)
#define filter_parent (G.filter_parent)
//usage: "\n -v Verbose"
#include "libbb.h"
+#include "common_bufsiz.h"
/* Wants <limits.h> etc, thus included after libbb.h: */
#ifdef __linux__
char **env_cur;
char *env_var[1]; /* actually bigger */
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define verbose (G.verbose )
#define max_per_host (G.max_per_host)
#define cur_per_host (G.cur_per_host)
#include <arpa/telnet.h>
#include <netinet/in.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#ifdef __BIONIC__
/* should be in arpa/telnet.h */
struct termios termios_def;
struct termios termios_raw;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
#define DEBUG 0
#include "libbb.h"
+#include "common_bufsiz.h"
#include <syslog.h>
#if DEBUG
const char *issuefile;
int maxfd;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.loginpath = "/bin/login"; \
G.issuefile = "/etc/issue.net"; \
//usage: "\n -l Log to syslog (inetd mode requires this)"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <syslog.h>
#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT
bb_progress_t pmt;
#endif
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
{
len_and_sockaddr *our_lsa;
len_and_sockaddr *peer_lsa;
- char *local_file, *mode, *user_opt;
+ char *mode, *user_opt;
+ char *local_file = local_file;
const char *error_msg;
int opt, result, opcode;
IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;)
#define UDHCP_COMMON_H 1
#include "libbb.h"
+#include "common_bufsiz.h"
#include <netinet/udp.h>
#include <netinet/ip.h>
struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */
} FIX_ALIASING;
-#define server_config (*(struct server_config_t*)&bb_common_bufsiz1)
+#define server_config (*(struct server_config_t*)bb_common_bufsiz1)
/* client_config sits in 2nd half of bb_common_bufsiz1 */
#if ENABLE_FEATURE_UDHCP_PORT
struct xid_item *next;
} FIX_ALIASING;
-#define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1)
+#define dhcprelay_xid_list (*(struct xid_item*)bb_common_bufsiz1)
static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client)
{
struct config_keyword {
const char *keyword;
int (*handler)(const char *line, void *var) FAST_FUNC;
- void *var;
+ unsigned ofs;
const char *def;
};
+#define OFS(field) offsetof(struct server_config_t, field)
+
static const struct config_keyword keywords[] = {
/* keyword handler variable address default */
- {"start" , udhcp_str2nip , &server_config.start_ip , "192.168.0.20"},
- {"end" , udhcp_str2nip , &server_config.end_ip , "192.168.0.254"},
- {"interface" , read_str , &server_config.interface , "eth0"},
+ {"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"},
+ {"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"},
+ {"interface" , read_str , OFS(interface ), "eth0"},
/* Avoid "max_leases value not sane" warning by setting default
* to default_end_ip - default_start_ip + 1: */
- {"max_leases" , read_u32 , &server_config.max_leases , "235"},
- {"auto_time" , read_u32 , &server_config.auto_time , "7200"},
- {"decline_time" , read_u32 , &server_config.decline_time , "3600"},
- {"conflict_time", read_u32 , &server_config.conflict_time, "3600"},
- {"offer_time" , read_u32 , &server_config.offer_time , "60"},
- {"min_lease" , read_u32 , &server_config.min_lease_sec, "60"},
- {"lease_file" , read_str , &server_config.lease_file , LEASES_FILE},
- {"pidfile" , read_str , &server_config.pidfile , "/var/run/udhcpd.pid"},
- {"siaddr" , udhcp_str2nip , &server_config.siaddr_nip , "0.0.0.0"},
+ {"max_leases" , read_u32 , OFS(max_leases ), "235"},
+ {"auto_time" , read_u32 , OFS(auto_time ), "7200"},
+ {"decline_time" , read_u32 , OFS(decline_time ), "3600"},
+ {"conflict_time", read_u32 , OFS(conflict_time), "3600"},
+ {"offer_time" , read_u32 , OFS(offer_time ), "60"},
+ {"min_lease" , read_u32 , OFS(min_lease_sec), "60"},
+ {"lease_file" , read_str , OFS(lease_file ), LEASES_FILE},
+ {"pidfile" , read_str , OFS(pidfile ), "/var/run/udhcpd.pid"},
+ {"siaddr" , udhcp_str2nip , OFS(siaddr_nip ), "0.0.0.0"},
/* keywords with no defaults must be last! */
- {"option" , udhcp_str2optset, &server_config.options , ""},
- {"opt" , udhcp_str2optset, &server_config.options , ""},
- {"notify_file" , read_str , &server_config.notify_file , NULL},
- {"sname" , read_str , &server_config.sname , NULL},
- {"boot_file" , read_str , &server_config.boot_file , NULL},
- {"static_lease" , read_staticlease, &server_config.static_leases, ""},
+ {"option" , udhcp_str2optset, OFS(options ), ""},
+ {"opt" , udhcp_str2optset, OFS(options ), ""},
+ {"notify_file" , read_str , OFS(notify_file ), NULL},
+ {"sname" , read_str , OFS(sname ), NULL},
+ {"boot_file" , read_str , OFS(boot_file ), NULL},
+ {"static_lease" , read_staticlease, OFS(static_leases), ""},
};
enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
char *token[2];
for (i = 0; i < KWS_WITH_DEFAULTS; i++)
- keywords[i].handler(keywords[i].def, keywords[i].var);
+ keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs);
parser = config_open(file);
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
if (strcasecmp(token[0], k->keyword) == 0) {
- if (!k->handler(token[1], k->var)) {
+ if (!k->handler(token[1], (char*)&server_config + k->ofs)) {
bb_error_msg("can't parse line %u in %s",
parser->lineno, file);
/* reset back to the default value */
- k->handler(k->def, k->var);
+ k->handler(k->def, (char*)&server_config + k->ofs);
}
break;
}
//usage: "\nexits only on I/O errors (link down etc)"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <netinet/ether.h>
#include <net/if.h>
#include <net/if_arp.h>
struct ether_addr our_ethaddr;
uint32_t localnet_ip;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
//usage: "Total: 386144 257128 129016\n"
#include "libbb.h"
+#include "common_bufsiz.h"
#ifdef __linux__
# include <sys/sysinfo.h>
#endif
# define G_unit_steps 10
#endif
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
//usage: "\n -SIGNAL Signal to send (default: KILL)"
#include "libbb.h"
+#include "common_bufsiz.h"
#define MAX_LINE 255
smallint kill_failed;
int killsig;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.mypid = getpid(); \
G.killsig = SIGKILL; \
// totalswap=134209536, freeswap=134209536, procs=157})
#include "libbb.h"
+#include "common_bufsiz.h"
typedef unsigned long long ullong;
G.deltanz = G.delta = 1000000; \
} while (0)
-// We depend on this being a char[], not char* - we take sizeof() of it
-#define outbuf bb_common_bufsiz1
+#define outbuf bb_common_bufsiz1
+#define sizeof_outbuf COMMON_BUFSIZE
static inline void reset_outbuf(void)
{
static void put(const char *s)
{
char *p = cur_outbuf;
- int sz = outbuf + sizeof(outbuf) - p;
+ int sz = outbuf + sizeof_outbuf - p;
while (*s && --sz >= 0)
*p++ = *s++;
cur_outbuf = p;
static void put_c(char c)
{
- if (cur_outbuf < outbuf + sizeof(outbuf))
+ if (cur_outbuf < outbuf + sizeof_outbuf)
*cur_outbuf++ = c;
}
//usage: " 2990 andersen andersen R ps\n"
#include "libbb.h"
+#include "common_bufsiz.h"
#ifdef __linux__
# include <sys/sysinfo.h>
#endif
unsigned long seconds_since_boot;
#endif
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define out (G.out )
#define out_cnt (G.out_cnt )
#define print_header (G.print_header )
//config: Enable 's' in top (gives lots of memory info).
#include "libbb.h"
+#include "common_bufsiz.h"
typedef struct top_status_t {
char line_buf[80];
}; //FIX_ALIASING; - large code growth
enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define top (G.top )
#define ntop (G.ntop )
#define sort_field (G.sort_field )
#include <sys/file.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#include "runit_lib.h"
#if ENABLE_MONOTONIC_SYSCALL
char *dir;
struct svdir svd[2];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define haslog (G.haslog )
#define sigterm (G.sigterm )
#define pidchanged (G.pidchanged )
#include <sys/file.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#include "runit_lib.h"
#define MAXSERVICES 1000
unsigned stamplog;
#endif
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define sv (G.sv )
#define svdir (G.svdir )
#define svnum (G.svnum )
#include <sys/file.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#include "runit_lib.h"
struct globals {
uint64_t tstart, tnow;
svstatus_t svstatus;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define acts (G.acts )
#define service (G.service )
#define rc (G.rc )
#include <sys/file.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#include "runit_lib.h"
#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
}
if (opt & 2) if (!repl) repl = '_'; // -R
if (opt & 4) { // -l
- linemax = xatou_range(l, 0, BUFSIZ-26);
+ linemax = xatou_range(l, 0, COMMON_BUFSIZE-26);
if (linemax == 0)
- linemax = BUFSIZ-26;
+ linemax = COMMON_BUFSIZE-26;
if (linemax < 256)
linemax = 256;
}
--- /dev/null
+#!/bin/sh
+# Called from top-level directory a-la
+#
+# scripts/generate_BUFSIZ.sh include/common_bufsiz.h
+
+. ./.config || exit 1
+
+debug=false
+
+common_bufsiz_h=$1
+
+test x"$NM" = x"" && NM="${CONFIG_CROSS_COMPILER_PREFIX}nm"
+test x"$CC" = x"" && CC="${CONFIG_CROSS_COMPILER_PREFIX}gcc"
+
+regenerate() {
+ cat >"$1.$$"
+ test -f "$1" && diff "$1.$$" "$1" >/dev/null && rm "$1.$$" && return
+ mv "$1.$$" "$1"
+}
+
+generate_std_and_exit() {
+ $debug && echo "Default: bb_common_bufsiz1[] in bss"
+ {
+ echo "enum { COMMON_BUFSIZE = 1024 };"
+ echo "extern char bb_common_bufsiz1[];"
+ echo "#define setup_common_bufsiz() ((void)0)"
+ } | regenerate "$common_bufsiz_h"
+ exit 0
+}
+
+# User does not want any funky stuff?
+test x"$CONFIG_FEATURE_USE_BSS_TAIL" = x"y" || generate_std_and_exit
+
+test -f busybox_unstripped || {
+ # We did not try anything yet
+ $debug && echo "Will try to fit bb_common_bufsiz1[] into _end[]"
+ {
+ echo "enum { COMMON_BUFSIZE = 1024 };"
+ echo "extern char _end[]; /* linker-provided label */"
+ echo "#define bb_common_bufsiz1 _end"
+ echo "#define setup_common_bufsiz() ((void)0)"
+ } | regenerate "$common_bufsiz_h"
+ echo 1024 >"$common_bufsiz_h.BUFSIZE"
+ exit 0
+}
+
+# Get _end address
+END=`$NM busybox_unstripped | grep ' . _end$'| cut -d' ' -f1`
+test x"$END" = x"" && generate_std_and_exit
+$debug && echo "END:0x$END $((0x$END))"
+END=$((0x$END))
+
+# Get PAGE_SIZE
+echo "\
+#include <sys/user.h>
+#if defined(PAGE_SIZE) && PAGE_SIZE > 0
+char page_size[PAGE_SIZE];
+#else
+char page_size[1];
+#endif
+" >page_size_$$.c
+$CC -c "page_size_$$.c" || generate_std_and_exit
+PAGE_SIZE=`$NM --size-sort "page_size_$$.o" | cut -d' ' -f1`
+rm "page_size_$$.c" "page_size_$$.o"
+test x"$PAGE_SIZE" = x"" && generate_std_and_exit
+$debug && echo "PAGE_SIZE:0x$PAGE_SIZE $((0x$PAGE_SIZE))"
+PAGE_SIZE=$((0x$PAGE_SIZE))
+test $PAGE_SIZE -lt 1024 && generate_std_and_exit
+
+# How much space between _end[] and next page?
+PAGE_MASK=$((PAGE_SIZE-1))
+REM=$(( (-END) & PAGE_MASK ))
+$debug && echo "REM:$REM"
+
+if test $REM -lt 1024; then
+ # _end[] has no enough space for bb_common_bufsiz1[],
+ # users will need to malloc it.
+ {
+ echo "enum { COMMON_BUFSIZE = 1024 };"
+ echo "extern char *bb_common_bufsiz1;"
+ echo "void setup_common_bufsiz(void);"
+ } | regenerate "$common_bufsiz_h"
+ # Check that we aren't left with a buggy binary:
+ if test -f "$common_bufsiz_h.BUFSIZE"; then
+ rm "$common_bufsiz_h.BUFSIZE"
+ echo "Warning! Space in _end[] is too small ($REM bytes)!"
+ echo "Rerun make to build a binary which doesn't use it!"
+ exit 1
+ fi
+ exit 0
+fi
+
+# _end[] has REM bytes for bb_common_bufsiz1[]
+OLD=1024
+test -f "$common_bufsiz_h.BUFSIZE" && OLD=`cat "$common_bufsiz_h.BUFSIZE"`
+$debug && echo "OLD:$OLD"
+{
+echo "enum { COMMON_BUFSIZE = $REM };"
+echo "extern char _end[]; /* linker-provided label */"
+echo "#define bb_common_bufsiz1 _end"
+echo "#define setup_common_bufsiz() ((void)0)"
+} | regenerate "$common_bufsiz_h"
+echo $REM >"$common_bufsiz_h.BUFSIZE"
+
+# Check that code did not grow too much and thus _end[] did not shink:
+if test $OLD -gt $REM; then
+ echo "Warning! Space in _end[] has decreased from $OLD to $REM bytes!"
+ echo "Rerun make!"
+ exit 1
+fi
+
+if test $OLD != $REM; then
+ echo "Space in _end[] is $REM bytes. Rerun make to use larger COMMON_BUFSIZE."
+fi
int nerr;
struct edir excludeArray[MAX_EXCLUDES];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
void BUG_setfiles_globals_too_big(void);
#define INIT_G() do { \
if (sizeof(G) > COMMON_BUFSIZE) \
//usage: "\n -n Run in foreground"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <syslog.h>
#endif
-#define log_buffer bb_common_bufsiz1
+#define log_buffer bb_common_bufsiz1
+#define sizeof_log_buffer COMMON_BUFSIZE
enum {
- KLOGD_LOGBUF_SIZE = sizeof(log_buffer),
+ KLOGD_LOGBUF_SIZE = sizeof_log_buffer,
OPT_LEVEL = (1 << 0),
OPT_FOREGROUND = (1 << 1),
};
//usage: "\n -F Same as -f, but dump buffer first"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
struct sembuf SMrdn[2]; // {1, 0}, {0, +1, SEM_UNDO}
struct shbuf_ds *shbuf;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define SMrup (G.SMrup)
#define SMrdn (G.SMrdn)
#define shbuf (G.shbuf)
*/
#include "libbb.h"
+#include "common_bufsiz.h"
#define SYSLOG_NAMES
#define SYSLOG_NAMES_CONST
#include <syslog.h>
//usage: "If /dev/mdev.log file exists, debug log will be appended to it."
#include "libbb.h"
+#include "common_bufsiz.h"
#include "xregex.h"
/* "mdev -s" scans /sys/class/xxx, looking for directories which have dev
struct rule cur_rule;
char timestr[sizeof("HH:MM:SS.123456")];
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \
IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \
//usage: "\n -L LBL Label"
#include "libbb.h"
+#include "common_bufsiz.h"
#if ENABLE_SELINUX
static void mkswap_selinux_setcontext(int fd, const char *path)
//usage: "$ dmesg | more\n"
#include "libbb.h"
+#include "common_bufsiz.h"
/* Support for FEATURE_USE_TERMIOS */
#define BB_MS_INVERTED_VALUE (1u << 31)
#include "libbb.h"
+#include "common_bufsiz.h"
#if ENABLE_FEATURE_MOUNT_LABEL
# include "volume_id.h"
#else
char getmntent_buf[1];
} FIX_ALIASING;
enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_buf) };
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define nfs_mount_version (G.nfs_mount_version)
#if ENABLE_FEATURE_MOUNT_VERBOSE
#define verbose (G.verbose )
//usage: )
#include "libbb.h"
+#include "common_bufsiz.h"
int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int script_main(int argc UNUSED_PARAM, char **argv)
if (child_pid) {
/* parent */
-#define buf bb_common_bufsiz1
+#define buf bb_common_bufsiz1
+#define sizeof_buf COMMON_BUFSIZE
struct pollfd pfd[2];
int outfd, count, loop;
double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0;
}
if (pfd[0].revents) {
errno = 0;
- count = safe_read(pty, buf, sizeof(buf));
+ count = safe_read(pty, buf, sizeof_buf);
if (count <= 0 && errno != EAGAIN) {
/* err/eof from pty: exit */
goto restore;
}
}
if (pfd[1].revents) {
- count = safe_read(STDIN_FILENO, buf, sizeof(buf));
+ count = safe_read(STDIN_FILENO, buf, sizeof_buf);
if (count <= 0) {
/* err/eof from stdin: don't read stdin anymore */
pfd[1].revents = 0;
* (util-linux's script doesn't do this. buggy :) */
loop = 999;
/* pty is in O_NONBLOCK mode, we exit as soon as buffer is empty */
- while (--loop && (count = safe_read(pty, buf, sizeof(buf))) > 0) {
+ while (--loop && (count = safe_read(pty, buf, sizeof_buf)) > 0) {
full_write(STDOUT_FILENO, buf, count);
full_write(outfd, buf, count);
}
//usage: "\n -a Stop swapping on all swap devices"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <mntent.h>
#ifndef __BIONIC__
# include <sys/swap.h>
struct globals {
int flags;
} FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
#define g_flags (G.flags)
#define save_g_flags() int save_g_flags = g_flags
#define restore_g_flags() g_flags = save_g_flags
//usage: "\n"" # uevent mdev & mdev -s"
#include "libbb.h"
+#include "common_bufsiz.h"
#include <linux/netlink.h>
#define BUFFER_SIZE 16*1024
-#define env ((char **)&bb_common_bufsiz1)
+#define env ((char **)bb_common_bufsiz1)
enum {
MAX_ENV = COMMON_BUFSIZE / sizeof(env[0]) - 1,
};
# define MNT_DETACH 0x00000002
#endif
#include "libbb.h"
+#include "common_bufsiz.h"
#if defined(__dietlibc__)
// TODO: This does not belong here.
if (opt & OPT_ALL)
bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file);
} else {
- while (getmntent_r(fp, &me, bb_common_bufsiz1, sizeof(bb_common_bufsiz1))) {
+ while (getmntent_r(fp, &me, bb_common_bufsiz1, COMMON_BUFSIZE)) {
/* Match fstype if passed */
if (!match_fstype(&me, fstype))
continue;