#define block_buf bb_common_bufsiz1
+#define INIT_G() do { setup_common_bufsiz(); } while (0)
#if ENABLE_FEATURE_TAR_CREATE
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
llist_t *excludes = NULL;
#endif
+ INIT_G();
/* Initialise default values */
tar_handle = init_handle();
struct kbentry ke;
int i, j, fd;
#define flags bb_common_bufsiz1
+ setup_common_bufsiz();
/* When user accidentally runs "dumpkmap FILE"
* instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
/* Read from stdin if there's nothing else to do. */
if (!argv[0])
*--argv = (char*)"-";
+
+#define read_buf bb_common_bufsiz1
+ setup_common_bufsiz();
do {
fd = open_or_warn_stdin(*argv);
if (fd < 0) {
for (;;) {
int i, res;
-#define read_buf bb_common_bufsiz1
res = read(fd, read_buf, COMMON_BUFSIZE);
if (res < 0)
retval = EXIT_FAILURE;
argv++;
#endif
+ setup_common_bufsiz();
do {
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
crc = 0;
length = 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) {
+#define read_buf bb_common_bufsiz1
+ while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) {
length += bytes_read;
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
}
}
#endif
-#define date_buf bb_common_bufsiz1
-#define sizeof_date_buf COMMON_BUFSIZE
+#define date_buf bb_common_bufsiz1
+ setup_common_bufsiz();
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, COMMON_BUFSIZE, fmt_dt2str, &tm_time);
}
puts(date_buf);
ssize_t bytes_read, to_write;
char *src;
+ setup_common_bufsiz();
+
opt_complementary = "?2:a+"; /* max 2 args; -a N */
opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len);
/* coreutils 6.3 compat: */
/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
-#define buf bb_common_bufsiz1
-#define sizeof_buf COMMON_BUFSIZE
-
- strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof_buf, &t), ".000000000");
+#define buf bb_common_bufsiz1
+ setup_common_bufsiz();
+ strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000");
return buf;
#undef buf
}
/* Return 1 if successful. */
static unsigned sum_file(const char *file, unsigned type)
{
-#define buf bb_common_bufsiz1
unsigned long long total_bytes = 0;
int fd, r;
/* The sum of all the input bytes, modulo (UINT_MAX + 1). */
unsigned s = 0;
+#define buf bb_common_bufsiz1
+ setup_common_bufsiz();
+
fd = open_or_warn_stdin(file);
if (fd == -1)
return 0;
//TODO: make unconditional
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
ssize_t c;
-# define buf bb_common_bufsiz1
-# define sizeof_buf COMMON_BUFSIZE
+# define buf bb_common_bufsiz1
+ setup_common_bufsiz();
#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, COMMON_BUFSIZE)) > 0) {
fp = files;
do
fwrite(buf, 1, c, *fp);
fp[i] = fdopen(fd, "r");
}
+ setup_common_bufsiz();
while (1) {
const size_t sz = COMMON_BUFSIZE / 2;
char *const buf0 = bb_common_bufsiz1;
} LINE;
-#define searchString bb_common_bufsiz1
-#define sizeof_searchString COMMON_BUFSIZE
+#define searchString bb_common_bufsiz1
enum {
- USERSIZE = sizeof_searchString > 1024 ? 1024
- : sizeof_searchString - 1, /* max line length typed in by user */
+ USERSIZE = COMMON_BUFSIZE > 1024 ? 1024
+ : COMMON_BUFSIZE - 1, /* max line length typed in by user */
INITBUF_SIZE = 1024, /* initial buffer size */
};
#define lines (G.lines )
#define marks (G.marks )
#define INIT_G() do { \
+ setup_common_bufsiz(); \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
} while (0)
&& poll(&pfd, 1, timeout) > 0
&& (pfd.revents & POLLIN)
) {
-#define buf bb_common_bufsiz1
llist_t *l;
ssize_t delta;
+#define buf bb_common_bufsiz1
+ setup_common_bufsiz();
// read next char from device
if (safe_read(STDIN_FILENO, buf+buf_len, 1) > 0) {
int conspy_main(int argc UNUSED_PARAM, char **argv)
{
char tty_name[sizeof(DEV_TTY "NN")];
-#define keybuf bb_common_bufsiz1
-#define sizeof_keybuf COMMON_BUFSIZE
struct termios termbuf;
unsigned opts;
unsigned ttynum;
applet_long_options = getopt_longopts;
#endif
+#define keybuf bb_common_bufsiz1
+ setup_common_bufsiz();
+
INIT_G();
strcpy(G.vcsa_name, DEV_VCSA);
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, COMMON_BUFSIZE - G.key_count);
if (bytes_read < 0)
goto abort;
* - 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 sizeof_concat_buf COMMON_BUFSIZE
+#define concat_buf bb_common_bufsiz1
+ setup_common_bufsiz();
+
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 + COMMON_BUFSIZE - read_ptr;
if (rem < 2
|| fgets(read_ptr, rem, theme_file) == NULL
) {
// read out all pending events
// (NB: len must be int, not ssize_t or long!)
+#define eventbuf bb_common_bufsiz1
+ setup_common_bufsiz();
xioctl(pfd.fd, FIONREAD, &len);
-#define eventbuf bb_common_bufsiz1
-#define sizeof_eventbuf COMMON_BUFSIZE
- ie = buf = (len <= sizeof_eventbuf) ? eventbuf : xmalloc(len);
+ ie = buf = (len <= COMMON_BUFSIZE) ? eventbuf : xmalloc(len);
len = full_read(pfd.fd, buf, len);
// process events. N.B. events may vary in length
while (len > 0) {
*/
static void read_lines(void)
{
-#define readbuf bb_common_bufsiz1
-#define sizeof_readbuf COMMON_BUFSIZE
char *current_line, *p;
int w = width;
char last_terminated = terminated;
unsigned old_max_fline = max_fline;
#endif
+#define readbuf bb_common_bufsiz1
+ setup_common_bufsiz();
+
/* (careful: max_fline can be -1) */
if (max_fline + 1 > MAXLINES)
return;
time_t t;
errno = 0;
- eof_error = safe_read(STDIN_FILENO, readbuf, sizeof_readbuf);
+ eof_error = safe_read(STDIN_FILENO, readbuf, COMMON_BUFSIZE);
if (errno != EAGAIN)
break;
t = time(NULL);
skip_write: ;
}
if (pfd[0].revents) {
-#define iobuf bb_common_bufsiz1
-#define sizeof_iobuf COMMON_BUFSIZE
ssize_t len;
+#define iobuf bb_common_bufsiz1
+ setup_common_bufsiz();
// read from device -> write to stdout
- len = safe_read(sfd, iobuf, sizeof_iobuf);
+ len = safe_read(sfd, iobuf, COMMON_BUFSIZE);
if (len > 0)
full_write(STDOUT_FILENO, iobuf, len);
else {
# define content_gzip 0
#endif
#define INIT_G() do { \
+ setup_common_bufsiz(); \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \
IF_FEATURE_HTTPD_RANGES(range_start = -1;) \
char buf[64 - sizeof(int)];
} identd_buf_t;
-#define bogouser bb_common_bufsiz1
-#define sizeof_bogouser COMMON_BUFSIZE
+#define bogouser bb_common_bufsiz1
static int new_peer(isrv_state_t *state, int fd)
{
unsigned opt;
int fd;
+ setup_common_bufsiz();
+
opt = getopt32(argv, "fiwb:", &bind_address);
strcpy(bogouser, "nobody");
if (argv[optind])
- strncpy(bogouser, argv[optind], sizeof_bogouser - 1);
+ strncpy(bogouser, argv[optind], COMMON_BUFSIZE - 1);
/* Daemonize if no -f and no -i and no -w */
if (!(opt & OPT_fiw))
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)bb_common_bufsiz1)
-
+#define INIT_G() do { setup_common_bufsiz(); } while (0)
static void print_link_flags(unsigned flags, unsigned mdown)
{
/* 0 1 2 3 4 5 6 7 8 */
"add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0";
int cmd = 2;
+
+ INIT_G();
+
if (*argv) {
cmd = index_in_substrings(commands, *argv);
if (cmd < 0)
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)bb_common_bufsiz1)
+#define INIT_G() do { setup_common_bufsiz(); } while (0)
static int flush_update(void)
{
/*0-1*/ "show\0" "flush\0";
int command_num;
+ INIT_G();
+
if (!*argv)
return ipneigh_list_or_flush(argv, 0);
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)bb_common_bufsiz1)
+#define INIT_G() do { setup_common_bufsiz(); } while (0)
static int flush_update(void)
{
unsigned flags = 0;
int cmd = RTM_NEWROUTE;
+ INIT_G();
+
if (!*argv)
return iproute_list_or_flush(argv, 0);
FD_SET(cfd, &readfds);
FD_SET(STDIN_FILENO, &readfds);
+#define iobuf bb_common_bufsiz1
+ setup_common_bufsiz();
for (;;) {
int fd;
int ofd;
if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0)
bb_perror_msg_and_die("select");
-#define iobuf bb_common_bufsiz1
fd = STDIN_FILENO;
while (1) {
if (FD_ISSET(fd, &testfds)) {
#define proc_meminfo (G.proc_meminfo )
#define proc_diskstats (G.proc_diskstats )
#define proc_sys_fs_filenr (G.proc_sys_fs_filenr)
+#define outbuf bb_common_bufsiz1
#define INIT_G() do { \
+ setup_common_bufsiz(); \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
cur_outbuf = outbuf; \
G.final_char = '\n'; \
G.deltanz = G.delta = 1000000; \
} while (0)
-#define outbuf bb_common_bufsiz1
-#define sizeof_outbuf COMMON_BUFSIZE
-
static inline void reset_outbuf(void)
{
cur_outbuf = outbuf;
static void put(const char *s)
{
char *p = cur_outbuf;
- int sz = outbuf + sizeof_outbuf - p;
+ int sz = outbuf + COMMON_BUFSIZE - 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 + COMMON_BUFSIZE)
*cur_outbuf++ = c;
}
#define blocked_sigset (G.blocked_sigset)
#define fl_flag_0 (G.fl_flag_0 )
#define dirn (G.dirn )
+#define line bb_common_bufsiz1
#define INIT_G() do { \
+ setup_common_bufsiz(); \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
linemax = 1000; \
/*buflen = 1024;*/ \
replace = ""; \
} while (0)
-#define line bb_common_bufsiz1
-
#define FATAL "fatal: "
#define WARNING "warning: "
#endif
-#define log_buffer bb_common_bufsiz1
-#define sizeof_log_buffer COMMON_BUFSIZE
+#define log_buffer bb_common_bufsiz1
enum {
- KLOGD_LOGBUF_SIZE = sizeof_log_buffer,
+ KLOGD_LOGBUF_SIZE = COMMON_BUFSIZE,
OPT_LEVEL = (1 << 0),
OPT_FOREGROUND = (1 << 1),
};
int opt;
int used;
+ setup_common_bufsiz();
+
opt = getopt32(argv, "c:n", &opt_c);
if (opt & OPT_LEVEL) {
/* Valid levels are between 1 and 8 */
int opt;
int i = 0;
+ setup_common_bufsiz();
+
/* Fill out the name string early (may be overwritten later) */
str_t = uid2uname_utoa(geteuid());
if (child_pid) {
/* parent */
-#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;
smallint fd_count = 2;
+#define buf bb_common_bufsiz1
+ setup_common_bufsiz();
outfd = xopen(fname, mode);
pfd[0].fd = pty;
}
if (pfd[0].revents) {
errno = 0;
- count = safe_read(pty, buf, sizeof_buf);
+ count = safe_read(pty, buf, COMMON_BUFSIZE);
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, COMMON_BUFSIZE);
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, COMMON_BUFSIZE)) > 0) {
full_write(STDOUT_FILENO, buf, count);
full_write(outfd, buf, count);
}
if (opt & OPT_ALL)
bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file);
} else {
+ setup_common_bufsiz();
while (getmntent_r(fp, &me, bb_common_bufsiz1, COMMON_BUFSIZE)) {
/* Match fstype if passed */
if (!match_fstype(&me, fstype))