Compare commits

..
11 Commits
Author SHA1 Message Date
Samuel Sapalski dbd3b883a8 decompress_gunzip: Fix DoS if gzip is corrupt
On certain corrupt gzip files, huft_build will set the error bit on
the result pointer. If afterwards abort_unzip is called huft_free
might run into a segmentation fault or an invalid pointer to
free(p).

In order to mitigate this, we check in huft_free if the error bit
is set and clear it before the linked list is freed.

Signed-off-by: Samuel Sapalski <samuel.sapalski@nokia.com>
Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-31 15:00:27 +02:00
Denys Vlasenko 30ffa2bb15 ash: fix ${unset_var/pattern/repl}
function                                             old     new   delta
subevalvar                                          1349    1353      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-30 15:17:12 +02:00
Denys Vlasenko d811a8cd01 Bump version to 1.32.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:43:57 +01:00
Denys Vlasenko 71afe6c513 hush: output bash-compat killing signal names
This significantly syncronises ash-signals and hush-signals tests.

function                                             old     new   delta
process_wait_result                                  449     450      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:30:58 +01:00
Denys Vlasenko 0f668aad7f hush: do not print killing signal name in cmd_whihc_dies_on_signal
function                                             old     new   delta
process_wait_result                                  438     449     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:30:58 +01:00
Denys Vlasenko 06f7cf1487 shell: remove FAST_FUNC from a static function
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:30:58 +01:00
Denys Vlasenko 58cbf385e0 shell: add testsuite for "wait $pid" waiting for other tasks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:30:58 +01:00
Denys Vlasenko e7629ffbf5 ash: jobs: Fix waitcmd busy loop
Upstream commit:

    Date: Tue, 2 Jun 2020 23:46:48 +1000
    jobs: Fix waitcmd busy loop

    We need to clear gotsigchld in waitproc because it is used as
    a loop conditional for the waitcmd case.  Without it waitcmd
    may busy loop after a SIGCHLD.

    This patch also changes gotsigchld into a volatile sig_atomic_t
    to prevent compilers from optimising its accesses away.

    Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

This change also incorporates other changes to bring us closer to upstream.

function                                             old     new   delta
dowait                                               553     636     +83

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:30:58 +01:00
Denys Vlasenko e4c7cf3f8c ash: jobs: Fix infinite loop in waitproc
Upstream commit:

    Date: Fri, 10 Apr 2020 21:03:09 +1000
    jobs: Fix infinite loop in waitproc

    After we changed the resetting of gotsigchld so that it is only
    done if jp is NULL, we can now get an infinite loop in waitproc
    if gotsigchld is set but there is no outstanding child because
    everything had been waited for previously without gotsigchld being
    zeroed.

    This patch fixes it by always zeroing gotsigchld as we did before.
    The bug that the previous patch was trying to fix is now resolved
    by switching the blocking mode to DOWAIT_NORMAL after the specified
    job has been completed so that we really do wait for all outstanding
    dead children.

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
dowait                                               553     631     +78

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:30:58 +01:00
Denys Vlasenko 4ac4f60942 ash: remove a tentative TODO, it's a wrong idea
Upstream tried it, and then reverted by:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Tue, 26 May 2020 23:19:05 +1000
    parser: Fix double-backslash nl in old-style command sub

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:30:58 +01:00
Christian Eggers 94f6d1ece0 shell: Fix "read -d ''" behavior
With bash's read builtin it is possible to read from a file (e.g.
device-tree) until the first '\0' character:

IFS= read -r -d '' VARIABLE < file

In busybox ash the -d extension is also implemented, but checking the
read character for '\0' has to be performed after comparing with the
delimiter.

Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 14:30:58 +01:00
331 changed files with 2909 additions and 4517 deletions

No files matched your search

+12 -8
View File
@@ -312,6 +312,7 @@ config BUSYBOX_EXEC_PATH
config SELINUX
bool "Support NSA Security Enhanced Linux"
default n
select PLATFORM_LINUX
help
Enable support for SELinux in applets ls, ps, and id. Also provide
the option of compiling in SELinux applets.
@@ -357,6 +358,17 @@ config FEATURE_SYSLOG
#This option is auto-selected when you select any applet which may
#send its output to syslog. You do not need to select it manually.
config PLATFORM_LINUX
bool #No description makes it a hidden option
default n
#help
#For the most part, busybox requires only POSIX compatibility
#from the target system, but some applets and features use
#Linux-specific interfaces.
#
#This is automatically selected if any applet or feature requires
#Linux-specific interfaces. You do not need to select it manually.
comment 'Build Options'
config STATIC
@@ -529,14 +541,6 @@ config STACK_OPTIMIZATION_386
do not work with it (they use SSE instructions without
ensuring stack alignment).
config STATIC_LIBGCC
bool "Use -static-libgcc"
default y
help
This option instructs gcc to link in a static version of its
support library, libgcc. This means that the binary will require
one fewer dynamic library at run time.
comment 'Installation Options ("make install" behavior)'
choice
+2 -2
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 33
SUBLEVEL = 2
PATCHLEVEL = 32
SUBLEVEL = 1
EXTRAVERSION =
NAME = Unnamed
+1 -2
View File
@@ -58,8 +58,7 @@ CFLAGS += $(call cc-option,-fno-builtin-strlen -fomit-frame-pointer -ffunction-s
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
CFLAGS += $(call cc-option,-funsigned-char,)
ifeq ($(CONFIG_STATIC_LIBGCC),y)
# Disable it, for example, if you get
ifneq ($(CC),clang)
# "clang-9: warning: argument unused during compilation: '-static-libgcc'"
CFLAGS += $(call cc-option,-static-libgcc,)
endif
-4
View File
@@ -20,10 +20,6 @@
#undef ARRAY_SIZE
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
#include "../include/autoconf.h"
#include "../include/applet_metadata.h"
-8
View File
@@ -11,11 +11,3 @@ ifeq ($(CONFIG_STACK_OPTIMIZATION_386),y)
# from aligning stack to 16 bytes. (Which is gcc's way of supporting SSE).
CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2,)
endif
# "Control how GCC aligns variables.
# Supported values for type are compat uses increased alignment value
# compatible uses GCC 4.8 and earlier, abi uses alignment value as specified by the psABI,
# and cacheline uses increased alignment value to match the cache line size.
# compat is the default."
# "abi" seems to be somewhat successful in preventing oversealous data alignment.
CFLAGS += $(call cc-option,-malign-data=abi,)
-11
View File
@@ -1,11 +0,0 @@
# ==========================================================================
# Build system
# ==========================================================================
# "Control how GCC aligns variables.
# Supported values for type are compat uses increased alignment value
# compatible uses GCC 4.8 and earlier, abi uses alignment value as specified by the psABI,
# and cacheline uses increased alignment value to match the cache line size.
# compat is the default."
# "abi" seems to be somewhat successful in preventing oversealous data alignment.
CFLAGS += $(call cc-option,-malign-data=abi,)
+29 -32
View File
@@ -48,9 +48,19 @@
//kbuild:lib-$(CONFIG_AR) += ar.o
//usage:#define ar_trivial_usage
//usage: "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES"
//usage:#define ar_full_usage "\n\n"
//usage: "Extract or list FILES from an ar archive\n"
//usage: "\n -o Preserve original dates"
//usage: "\n -p Extract to stdout"
//usage: "\n -t List"
//usage: "\n -x Extract"
//usage: "\n -v Verbose"
#include "libbb.h"
#include "bb_archive.h"
#include "ar_.h"
#include "ar.h"
#if ENABLE_FEATURE_AR_CREATE
/* filter out entries with same names as specified on the command line */
@@ -210,36 +220,23 @@ static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
);
}
//usage:#define ar_trivial_usage
//usage: "x|p|t"IF_FEATURE_AR_CREATE("|r")" [-ov] ARCHIVE [FILE]..."
//usage:#define ar_full_usage "\n\n"
//usage: "Extract or list FILEs from an ar archive"IF_FEATURE_AR_CREATE(", or create it")"\n"
//usage: "\n x Extract"
//usage: "\n p Extract to stdout"
//usage: "\n t List"
//usage: IF_FEATURE_AR_CREATE(
//usage: "\n r Create"
//usage: )
//usage: "\n -o Restore mtime"
//usage: "\n -v Verbose"
#define AR_OPT_VERBOSE (1 << 0)
#define AR_OPT_PRESERVE_DATE (1 << 1)
/* "ar r" implies create, but warns about it. c suppresses warning.
* bbox accepts but ignores it: */
#define AR_OPT_CREATE (1 << 2)
#define AR_CMD_PRINT (1 << 3)
#define FIRST_CMD AR_CMD_PRINT
#define AR_CMD_LIST (1 << 4)
#define AR_CMD_EXTRACT (1 << 5)
#define AR_CMD_INSERT (1 << 6)
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ar_main(int argc UNUSED_PARAM, char **argv)
{
archive_handle_t *archive_handle;
unsigned opt, t;
enum {
OPT_VERBOSE = (1 << 0),
OPT_PRESERVE_DATE = (1 << 1),
/* "ar r" implies create, but warns about it. c suppresses warning.
* bbox accepts but ignores it: */
OPT_CREATE = (1 << 2),
CMD_PRINT = (1 << 3),
FIRST_CMD = CMD_PRINT,
CMD_LIST = (1 << 4),
CMD_EXTRACT = (1 << 5),
CMD_INSERT = ((1 << 6) * ENABLE_FEATURE_AR_CREATE),
};
archive_handle = init_handle();
@@ -259,26 +256,26 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
if (t & (t-1)) /* more than one of p,t,x[,r] are specified */
bb_show_usage();
if (opt & CMD_PRINT) {
if (opt & AR_CMD_PRINT) {
archive_handle->action_data = data_extract_to_stdout;
}
if (opt & CMD_LIST) {
if (opt & AR_CMD_LIST) {
archive_handle->action_header = header_list;
}
if (opt & CMD_EXTRACT) {
if (opt & AR_CMD_EXTRACT) {
archive_handle->action_data = data_extract_all;
}
if (opt & OPT_PRESERVE_DATE) {
if (opt & AR_OPT_PRESERVE_DATE) {
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
}
if (opt & OPT_VERBOSE) {
if (opt & AR_OPT_VERBOSE) {
archive_handle->action_header = header_verbose_list_ar;
}
#if ENABLE_FEATURE_AR_CREATE
archive_handle->ar__name = *argv;
#endif
archive_handle->src_fd = xopen(*argv++,
(opt & CMD_INSERT)
(opt & AR_CMD_INSERT)
? O_RDWR | O_CREAT
: O_RDONLY
);
@@ -290,7 +287,7 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
}
#if ENABLE_FEATURE_AR_CREATE
if (opt & CMD_INSERT)
if (opt & AR_CMD_INSERT)
return write_ar_archive(archive_handle);
#endif
+5 -5
View File
@@ -219,7 +219,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
//usage:#define uncompress_trivial_usage
//usage: "[-cf] [FILE]..."
//usage:#define uncompress_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "Decompress .Z file[s]\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Overwrite"
@@ -461,7 +461,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//usage:#define unlzma_trivial_usage
//usage: "[-cfk] [FILE]..."
//usage:#define unlzma_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
@@ -469,7 +469,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//usage:#define lzma_trivial_usage
//usage: "-d [-cfk] [FILE]..."
//usage:#define lzma_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
@@ -532,7 +532,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//usage:#define unxz_trivial_usage
//usage: "[-cfk] [FILE]..."
//usage:#define unxz_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
@@ -541,7 +541,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//usage:#define xz_trivial_usage
//usage: "-d [-cfk] [FILE]..."
//usage:#define xz_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
+1 -1
View File
@@ -50,7 +50,7 @@
//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
//usage:#define bzip2_trivial_usage
//usage: "[-cfk" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789] [FILE]..."
//usage: "[OPTIONS] [FILE]..."
//usage:#define bzip2_full_usage "\n\n"
//usage: "Compress FILEs (or stdin) with bzip2 algorithm\n"
//usage: "\n -1..9 Compression level"
+1 -1
View File
@@ -68,7 +68,7 @@
//usage: "\n -H newc Archive format"
//usage: )
//usage: "\n -d Make leading directories"
//usage: "\n -m Restore mtime"
//usage: "\n -m Preserve mtime"
//usage: "\n -v Verbose"
//usage: "\n -u Overwrite"
//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
+1 -24
View File
@@ -1204,27 +1204,6 @@ static char **create_list(const char *filename)
return file_list;
}
/** This tests if the filename is an "important" directory, which might be symlinked.
* Debians dpkg test if directories are used by other packages, this
* implementation doesn't and would remove for ex. an lib -> usr/lib symlink.
*/
static int is_builtin_exclude(const char *name)
{
if (*name++ != '/')
return 0;
if (index_in_strings(".\0" "etc\0" "opt\0" "srv\0" "var\0" "var/lib\0",
name) >= 0)
return 1;
if (is_prefixed_with(name, "usr/")) {
name += sizeof("usr/") - 1;
if (is_prefixed_with(name, "local/"))
name += sizeof("local/") - 1;
}
return index_in_strings("bin\0" "lib\0" "lib32\0" "lib64\0" "sbin\0",
name) >= 0;
}
/* maybe i should try and hook this into remove_file.c somehow */
static int remove_file_array(char **remove_names, char **exclude_names)
{
@@ -1236,8 +1215,6 @@ static int remove_file_array(char **remove_names, char **exclude_names)
return 0;
}
for (i = 0; remove_names[i] != NULL; i++) {
if (is_builtin_exclude(remove_names[i]))
continue;
if (exclude_names != NULL) {
for (j = 0; exclude_names[j] != NULL; j++) {
if (strcmp(remove_names[i], exclude_names[j]) == 0) {
@@ -1304,7 +1281,7 @@ postrm abort-install <old_version>
postrm abort-upgrade <old_version>
postrm disappear <overwriter> <version>
*/
static const char *const all_control_files[] ALIGN_PTR = {
static const char *const all_control_files[] = {
"preinst", "postinst", "prerm", "postrm",
"list", "md5sums", "shlibs", "conffiles",
"config", "templates"
+1 -1
View File
@@ -28,7 +28,7 @@
//usage: "\n -f Print control fields"
//usage: "\n -e Extract control files to DIR (default: ./DEBIAN)"
//usage: "\n -x Extract files to DIR (no default)"
//usage: "\n -X Verbose extract"
//usage: "\n -X Verbose -x"
//usage:
//usage:#define dpkg_deb_example_usage
//usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
+1 -1
View File
@@ -459,7 +459,7 @@ int mainGtU(EState* state,
* usually small, typically <= 20.
*/
static
const uint32_t incs[14] ALIGN4 = {
const uint32_t incs[14] = {
1, 4, 13, 40, 121, 364, 1093, 3280,
9841, 29524, 88573, 265720,
797161, 2391484
@@ -20,7 +20,7 @@ enum {
TAR_MAX,
};
static const char *const tar_var[] ALIGN_PTR = {
static const char *const tar_var[] = {
// "FILETYPE",
"MODE",
"FILENAME",
+2 -2
View File
@@ -194,14 +194,14 @@ struct cp_ext {
};
/* Copy lengths and extra bits for literal codes 257..285 */
/* note: see note #13 above about the 258 in this list. */
static const struct cp_ext lit ALIGN2 = {
static const struct cp_ext lit = {
/*257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 */
/*0 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 */
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 } /* 99 == invalid */
};
/* Copy offsets and extra bits for distance codes 0..29 */
static const struct cp_ext dist ALIGN2 = {
static const struct cp_ext dist = {
/*0 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 */
{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 },
{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }
+1 -4
View File
@@ -290,11 +290,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
uint32_t pos;
pos = buffer_pos - rep0;
if ((int32_t)pos < 0) {
if ((int32_t)pos < 0)
pos += header.dict_size;
if ((int32_t)pos < 0)
goto bad;
}
match_byte = buffer[pos];
do {
int bit;
+1 -1
View File
@@ -6,7 +6,7 @@
*/
#include "libbb.h"
#include "bb_archive.h"
#include "ar_.h"
#include "ar.h"
/* WARNING: Clobbers str[len], so fields must be read in reverse order! */
static unsigned read_num(char *str, int base, int len)
+1 -1
View File
@@ -352,7 +352,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* case 0: */
case '0':
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
if (file_header->name && last_char_is(file_header->name, '/')) {
if (last_char_is(file_header->name, '/')) {
goto set_dir;
}
#endif
+1 -1
View File
@@ -4,7 +4,7 @@
*/
#include "libbb.h"
#include "bb_archive.h"
#include "ar_.h"
#include "ar.h"
void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
{
+5 -7
View File
@@ -83,9 +83,7 @@ struct globals {
void *map;
rpm_index *mytags;
int tagcount;
unsigned mapsize;
IF_VARIABLE_ARCH_PAGESIZE(unsigned pagesize;)
#define G_pagesize cached_pagesize(G.pagesize)
unsigned mapsize, pagesize;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
@@ -143,11 +141,11 @@ static int rpm_gettags(const char *filename)
G.mytags = tags;
/* Map the store */
storepos = (storepos + G_pagesize) & -(int)G_pagesize;
storepos = (storepos + G.pagesize) & -(int)G.pagesize;
/* remember size for munmap */
G.mapsize = storepos;
/* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
G.map = mmap_read(fd, storepos);
G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0);
if (G.map == MAP_FAILED)
bb_perror_msg_and_die("mmap '%s'", filename);
@@ -358,7 +356,7 @@ int rpm_main(int argc, char **argv)
int opt, func = 0;
INIT_G();
INIT_PAGESIZE(G.pagesize);
G.pagesize = getpagesize();
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
switch (opt) {
@@ -525,7 +523,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
int rpm_fd;
INIT_G();
INIT_PAGESIZE(G.pagesize);
G.pagesize = getpagesize();
rpm_fd = rpm_gettags(argv[1]);
+16 -23
View File
@@ -297,8 +297,7 @@ static void writeLongname(int fd, int type, const char *name, int dir)
header.typeflag = type;
strcpy(header.name, "././@LongLink");
/* This sets mode/uid/gid/mtime to "00...00<NUL>" strings */
memset((char*)&header + offsetof(struct tar_header_t, mode), /* make gcc-9.x happy */
'0', sizeof(struct prefilled));
memset(header.mode, '0', sizeof(struct prefilled));
header.mode [sizeof(header.mode ) - 1] = '\0';
header.uid [sizeof(header.uid ) - 1] = '\0';
header.gid [sizeof(header.gid ) - 1] = '\0';
@@ -491,11 +490,10 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
# define exclude_file(excluded_files, file) 0
# endif
static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
const char *fileName,
struct stat *statbuf)
static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth UNUSED_PARAM)
{
struct TarBallInfo *tbInfo = (struct TarBallInfo *) state->userData;
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
const char *header_name;
int inputFileFd = -1;
@@ -701,7 +699,7 @@ static NOINLINE int writeTarFile(
/* Read the directory/files and iterate over them one at a time */
while (filelist) {
if (!recursive_action(filelist->data, recurseFlags,
writeFileToTarball, writeFileToTarball, tbInfo)
writeFileToTarball, writeFileToTarball, tbInfo, 0)
) {
errorFlag = TRUE;
}
@@ -775,7 +773,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
//usage: "vokO] "
//usage: "[-f TARFILE] [-C DIR] "
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[OPTION]... "))
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[--exclude PATTERN]... "))
//usage: "[FILE]..."
//usage:#define tar_full_usage "\n\n"
//usage: IF_FEATURE_TAR_CREATE("Create, extract, ")
@@ -809,11 +807,6 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_SEAMLESS_BZ2(
//usage: "\n -j (De)compress using bzip2"
//usage: )
//usage: IF_FEATURE_SEAMLESS_LZMA(
//usage: IF_FEATURE_TAR_LONG_OPTIONS(
//usage: "\n --lzma (De)compress using lzma"
//usage: )
//usage: )
//usage: "\n -a (De)compress based on extension"
//usage: IF_FEATURE_TAR_CREATE(
//usage: "\n -h Follow symlinks"
@@ -825,21 +818,21 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: "\n --exclude PATTERN Glob pattern to exclude"
//usage: )
//usage: )
//usage: IF_FEATURE_TAR_LONG_OPTIONS(
//usage: "\n --overwrite Replace existing files"
//usage: "\n --strip-components NUM NUM of leading components to strip"
//usage: "\n --no-recursion Don't descend in directories"
//usage: "\n --numeric-owner Use numeric user:group"
//usage: "\n --no-same-permissions Don't restore access permissions"
//usage: IF_FEATURE_TAR_TO_COMMAND(
//usage: "\n --to-command COMMAND Pipe files to COMMAND"
//usage: )
//usage: )
//usage:
//usage:#define tar_example_usage
//usage: "$ zcat /tmp/tarball.tar.gz | tar -xf -\n"
//usage: "$ tar -cf /tmp/tarball.tar /usr/local\n"
// Supported but aren't in --help:
// lzma
// no-recursion
// numeric-owner
// no-same-permissions
// overwrite
//IF_FEATURE_TAR_TO_COMMAND(
// to-command
//)
enum {
OPTBIT_KEEP_OLD = 8,
IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
+1
View File
@@ -16,6 +16,7 @@ CONFIG_HAVE_DOT_CONFIG=y
# CONFIG_EXTRA_COMPAT is not set
# CONFIG_INCLUDE_SUSv2 is not set
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
+1
View File
@@ -87,6 +87,7 @@ CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
CONFIG_INCLUDE_SUSv2=y
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
+1
View File
@@ -16,6 +16,7 @@ CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
# CONFIG_INCLUDE_SUSv2 is not set
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
+1
View File
@@ -16,6 +16,7 @@ CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
# CONFIG_INCLUDE_SUSv2 is not set
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
+1
View File
@@ -16,6 +16,7 @@ CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
CONFIG_INCLUDE_SUSv2=y
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
+1
View File
@@ -16,6 +16,7 @@ CONFIG_HAVE_DOT_CONFIG=y
# CONFIG_EXTRA_COMPAT is not set
CONFIG_INCLUDE_SUSv2=y
CONFIG_USE_PORTABLE_CODE=y
# CONFIG_PLATFORM_LINUX is not set
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
+1
View File
@@ -9,6 +9,7 @@
//config:config CHVT
//config: bool "chvt (2 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program is used to change to another terminal.
//config: Example: chvt 4 (change to terminal /dev/tty4)
+1
View File
@@ -10,6 +10,7 @@
//config:config DEALLOCVT
//config: bool "deallocvt (1.9 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program deallocates unused virtual consoles.
+1
View File
@@ -9,6 +9,7 @@
//config:config DUMPKMAP
//config: bool "dumpkmap (1.6 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program dumps the kernel's keyboard translation table to
//config: stdout, in binary format. You can then use loadkmap to load it.
+1
View File
@@ -9,6 +9,7 @@
//config:config FGCONSOLE
//config: bool "fgconsole (1.5 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program prints active (foreground) console number.
+1
View File
@@ -11,6 +11,7 @@
//config:config KBD_MODE
//config: bool "kbd_mode (4.1 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program reports and sets keyboard mode.
+2
View File
@@ -12,12 +12,14 @@
//config:config LOADFONT
//config: bool "loadfont (5.2 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads a console font from standard input.
//config:
//config:config SETFONT
//config: bool "setfont (24 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Allows to load console screen map. Useful for i18n.
//config:
+1
View File
@@ -9,6 +9,7 @@
//config:config LOADKMAP
//config: bool "loadkmap (1.8 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads a keyboard translation table from
//config: standard input.
+1
View File
@@ -10,6 +10,7 @@
//config:config OPENVT
//config: bool "openvt (7.2 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program is used to start a command on an unused
//config: virtual terminal.
+1
View File
@@ -10,6 +10,7 @@
//config:config SETCONSOLE
//config: bool "setconsole (3.6 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Redirect writes to /dev/console to another device,
//config: like the current tty while logged in via telnet.
+1
View File
@@ -11,6 +11,7 @@
//config:config SETKEYCODES
//config: bool "setkeycodes (2.1 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads entries into the kernel's scancode-to-keycode
//config: map, allowing unusual keyboards to generate usable keycodes.
+1
View File
@@ -11,6 +11,7 @@
//config:config SETLOGCONS
//config: bool "setlogcons (1.8 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program redirects the output console of kernel messages.
+1
View File
@@ -9,6 +9,7 @@
//config:config SHOWKEY
//config: bool "showkey (4.7 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Shows keys pressed.
+6 -7
View File
@@ -65,14 +65,12 @@
* symbolic links encountered during recursive directory traversals.
*/
static int FAST_FUNC fileAction(struct recursive_state *state,
const char *fileName,
struct stat *statbuf)
static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
{
mode_t newmode;
/* match coreutils behavior */
if (state->depth == 0) {
if (depth == 0) {
/* statbuf holds lstat result, but we need stat (follow link) */
if (stat(fileName, statbuf))
goto err;
@@ -81,9 +79,9 @@ static int FAST_FUNC fileAction(struct recursive_state *state,
return TRUE;
}
newmode = bb_parse_mode((char *)state->userData, statbuf->st_mode);
newmode = bb_parse_mode((char *)param, statbuf->st_mode);
if (newmode == (mode_t)-1)
bb_error_msg_and_die("invalid mode '%s'", (char *)state->userData);
bb_error_msg_and_die("invalid mode '%s'", (char *)param);
if (chmod(fileName, newmode) == 0) {
if (OPT_VERBOSE
@@ -138,7 +136,8 @@ int chmod_main(int argc UNUSED_PARAM, char **argv)
OPT_RECURSE, // recurse
fileAction, // file action
fileAction, // dir action
smode) // user data
smode, // user data
0) // depth
) {
retval = EXIT_FAILURE;
}
+5 -4
View File
@@ -97,10 +97,10 @@ struct param_t {
chown_fptr chown_func;
};
static int FAST_FUNC fileAction(struct recursive_state *state UNUSED_PARAM,
const char *fileName, struct stat *statbuf)
static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf,
void *vparam, int depth UNUSED_PARAM)
{
#define param (*(struct param_t*)state->userData)
#define param (*(struct param_t*)vparam)
#define opt option_mask32
uid_t u = (param.ugid.uid == (uid_t)-1L) ? statbuf->st_uid : param.ugid.uid;
gid_t g = (param.ugid.gid == (gid_t)-1L) ? statbuf->st_gid : param.ugid.gid;
@@ -159,7 +159,8 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
flags, /* flags */
fileAction, /* file action */
fileAction, /* dir action */
&param) /* user data */
&param, /* user data */
0) /* depth */
) {
retval = EXIT_FAILURE;
}
+1 -1
View File
@@ -38,7 +38,7 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */
//usage:#define cp_trivial_usage
//usage: "[-arPLHpfilsTu] SOURCE... DEST"
//usage: "[OPTIONS] SOURCE... DEST"
//usage:#define cp_full_usage "\n\n"
//usage: "Copy SOURCE(s) to DEST\n"
//usage: "\n -a Same as -dpR"
+55 -44
View File
@@ -37,6 +37,7 @@
//config: bool "Support %[num]N nanosecond format specifier"
//config: default n # stat's nanosecond field is a bit non-portable
//config: depends on DATE
//config: select PLATFORM_LINUX
//config: help
//config: Support %[num]N format specifier. Adds ~250 bytes of code.
//config:
@@ -93,25 +94,36 @@
*/
//usage:#define date_trivial_usage
//usage: "[OPTIONS] [+FMT] [[-s] TIME]"
//usage: "[OPTIONS] [+FMT] [TIME]"
//usage:#define date_full_usage "\n\n"
//usage: "Display time (using +FMT), or set time\n"
//usage: "\n -u Work in UTC (don't convert to local time)"
//usage: IF_NOT_LONG_OPTS(
//usage: "\n [-s] TIME Set time to TIME"
//usage: "\n -d TIME Display TIME, not 'now'"
//usage: IF_FEATURE_DATE_ISOFMT(
//usage: "\n -D FMT FMT (strptime format) for -s/-d TIME conversion"
////////^^^^^^^^^^^^^^^^^^^^^^ busybox invention, not compat
//usage: "\n -u Work in UTC (don't convert to local time)"
//usage: "\n -R Output RFC-2822 compliant date string"
//usage: ) IF_LONG_OPTS(
//usage: "\n [-s,--set] TIME Set time to TIME"
//usage: "\n -u,--utc Work in UTC (don't convert to local time)"
//usage: "\n -R,--rfc-2822 Output RFC-2822 compliant date string"
//usage: )
//usage: "\n -r FILE Display last modification time of FILE"
//usage: "\n -R Output RFC-2822 date"
//usage: IF_FEATURE_DATE_ISOFMT(
//usage: "\n -I[SPEC] Output ISO-8601 date"
//usage: "\n SPEC=date (default), hours, minutes, seconds or ns"
//usage: "\n -I[SPEC] Output ISO-8601 compliant date string"
//usage: "\n SPEC='date' (default) for date only,"
//usage: "\n 'hours', 'minutes', or 'seconds' for date and"
//usage: "\n time to the indicated precision"
//usage: )
//usage: IF_NOT_LONG_OPTS(
//usage: "\n -r FILE Display last modification time of FILE"
//usage: "\n -d TIME Display TIME, not 'now'"
//usage: ) IF_LONG_OPTS(
//usage: "\n -r,--reference FILE Display last modification time of FILE"
//usage: "\n -d,--date TIME Display TIME, not 'now'"
//usage: )
//usage: IF_FEATURE_DATE_ISOFMT(
//usage: "\n -D FMT Use FMT (strptime format) for -d TIME conversion"
//usage: )
//usage: "\n"
//usage: "\nRecognized TIME formats:"
//usage: "\n @seconds_since_1970"
//usage: "\n hh:mm[:ss]"
//usage: "\n [YYYY.]MM.DD-hh:mm[:ss]"
//usage: "\n YYYY-MM-DD hh:mm[:ss]"
@@ -136,8 +148,8 @@ enum {
OPT_UTC = (1 << 2), /* u */
OPT_DATE = (1 << 3), /* d */
OPT_REFERENCE = (1 << 4), /* r */
OPT_ISO8601 = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
OPT_STR2DT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
OPT_TIMESPEC = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
};
#if ENABLE_LONG_OPTS
@@ -159,6 +171,12 @@ static const char date_longopts[] ALIGN1 =
* - after xasprintf we use other xfuncs
*/
static void maybe_set_utc(int opt)
{
if (opt & OPT_UTC)
putenv((char*)"TZ=UTC0");
}
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int date_main(int argc UNUSED_PARAM, char **argv)
{
@@ -166,7 +184,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
struct tm tm_time;
char buf_fmt_dt2str[64];
unsigned opt;
int isofmt = -1;
int ifmt = -1;
char *date_str;
char *fmt_dt2str;
char *fmt_str2dt;
@@ -185,16 +203,15 @@ int date_main(int argc UNUSED_PARAM, char **argv)
);
argv += optind;
if (opt & OPT_UTC)
putenv((char*)"TZ=UTC0");
maybe_set_utc(opt);
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_ISO8601)) {
isofmt = 0; /* default is date */
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_TIMESPEC)) {
ifmt = 0; /* default is date */
if (isofmt_arg) {
static const char isoformats[] ALIGN1 =
"date\0""hours\0""minutes\0""seconds\0ns\0";
isofmt = index_in_substrings(isoformats, isofmt_arg);
if (isofmt < 0)
"date\0""hours\0""minutes\0""seconds\0"; /* ns? */
ifmt = index_in_substrings(isoformats, isofmt_arg);
if (ifmt < 0)
bb_show_usage();
}
}
@@ -204,7 +221,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
fmt_dt2str = &argv[0][1]; /* skip over the '+' */
argv++;
}
if (!(opt & (OPT_SET | OPT_DATE))) { /* neither -s TIME nor -d TIME? */
if (!(opt & (OPT_SET | OPT_DATE))) {
opt |= OPT_SET;
date_str = argv[0]; /* can be NULL */
if (date_str) {
@@ -272,7 +289,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
tm_time.tm_hour = 0;
/* Process any date input to UNIX time since 1 Jan 1970 */
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_STR2DT)) {
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_HINT)) {
if (strptime(date_str, fmt_str2dt, &tm_time) == NULL)
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
} else {
@@ -298,34 +315,24 @@ int date_main(int argc UNUSED_PARAM, char **argv)
if (fmt_dt2str == NULL) {
int i;
fmt_dt2str = buf_fmt_dt2str;
if (ENABLE_FEATURE_DATE_ISOFMT && isofmt >= 0) {
/* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds 4:ns*/
if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
/* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds */
strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S");
i = 8 + 3 * isofmt;
if (isofmt != 0) {
int n;
if (isofmt == 4) {
i -= 3;
i += sprintf(&fmt_dt2str[i], ",%09u", (unsigned)ts.tv_nsec);
}
/* %z prints "+hhmm" timezone, but coreutils-8.30 prints "+hh:mm"! */
/* ...therefore this atrocity: */
n = strftime(&fmt_dt2str[i], 8, "%z", &tm_time);
i += n;
if (n == 5 && (fmt_dt2str[i-5] == '+' || fmt_dt2str[i-5] == '-')) {
/* "mm" -> ":mm" */
fmt_dt2str[i ] = fmt_dt2str[i - 1];
fmt_dt2str[i - 1] = fmt_dt2str[i - 2];
fmt_dt2str[i - 2] = ':';
i++;
}
i = 8 + 3 * ifmt;
if (ifmt != 0) {
/* TODO: if (ifmt==4) i += sprintf(&fmt_dt2str[i], ",%09u", nanoseconds); */
format_utc:
fmt_dt2str[i++] = '%';
fmt_dt2str[i++] = (opt & OPT_UTC) ? 'Z' : 'z';
}
fmt_dt2str[i] = '\0';
} else if (opt & OPT_RFC2822) {
/* -R. undo busybox.c setlocale */
if (ENABLE_LOCALE_SUPPORT)
setlocale(LC_TIME, "C");
fmt_dt2str = (char*)"%a, %d %b %Y %H:%M:%S %z";
strcpy(fmt_dt2str, "%a, %d %b %Y %H:%M:%S ");
i = sizeof("%a, %d %b %Y %H:%M:%S ")-1;
goto format_utc;
} else { /* default case */
fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y";
}
@@ -377,6 +384,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)
/* With no format string, just print a blank line */
date_buf[0] = '\0';
} else {
/* Handle special conversions */
if (is_prefixed_with(fmt_dt2str, "%f")) {
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
}
/* Generate output string */
strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time);
}
+31 -80
View File
@@ -59,7 +59,7 @@
//usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]\n"
//usage: IF_FEATURE_DD_IBS_OBS(
//usage: " [conv=notrunc|noerror|sync|fsync]\n"
//usage: " [iflag=skip_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]"
//usage: " [iflag=skip_bytes|fullblock] [oflag=seek_bytes|append]"
//usage: )
//usage:#define dd_full_usage "\n\n"
//usage: "Copy a file with converting and formatting\n"
@@ -82,11 +82,9 @@
//usage: "\n conv=fsync Physically write data out before finishing"
//usage: "\n conv=swab Swap every pair of bytes"
//usage: "\n iflag=skip_bytes skip=N is in bytes"
//usage: "\n oflag=seek_bytes seek=N is in bytes"
//usage: "\n iflag=direct O_DIRECT input"
//usage: "\n oflag=direct O_DIRECT output"
//usage: "\n iflag=fullblock Read full blocks"
//usage: "\n oflag=append Open output in append mode"
//usage: "\n oflag=seek_bytes seek=N is in bytes"
//usage: "\n oflag=append Open output file in append mode"
//usage: )
//usage: IF_FEATURE_DD_STATUS(
//usage: "\n status=noxfer Suppress rate output"
@@ -139,18 +137,16 @@ enum {
FLAG_IFLAG_SHIFT = 5,
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_IDIRECT = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of input flags */
/* start of output flags */
FLAG_OFLAG_SHIFT = 8,
FLAG_SEEK_BYTES = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_APPEND = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_ODIRECT = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_OFLAG_SHIFT = 7,
FLAG_SEEK_BYTES = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_APPEND = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of output flags */
FLAG_TWOBUFS = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 12,
FLAG_STATUS_NONE = 1 << 13,
FLAG_STATUS_NOXFER = 1 << 14,
FLAG_TWOBUFS = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 10,
FLAG_STATUS_NONE = 1 << 11,
FLAG_STATUS_NOXFER = 1 << 12,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -196,50 +192,12 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
#endif
}
#if ENABLE_FEATURE_DD_IBS_OBS
static int clear_O_DIRECT(int fd)
{
if (errno == EINVAL) {
int fl = fcntl(fd, F_GETFL);
if (fl & O_DIRECT) {
fcntl(fd, F_SETFL, fl & ~O_DIRECT);
return 1;
}
}
return 0;
}
#endif
static ssize_t dd_read(void *ibuf, size_t ibs)
{
ssize_t n;
#if ENABLE_FEATURE_DD_IBS_OBS
read_again:
if (G.flags & FLAG_FULLBLOCK)
n = full_read(ifd, ibuf, ibs);
else
#endif
n = safe_read(ifd, ibuf, ibs);
#if ENABLE_FEATURE_DD_IBS_OBS
if (n < 0 && (G.flags & FLAG_IDIRECT) && clear_O_DIRECT(ifd))
goto read_again;
#endif
return n;
}
static bool write_and_stats(const void *buf, size_t len, size_t obs,
const char *filename)
{
ssize_t n;
IF_FEATURE_DD_IBS_OBS(write_again:)
n = full_write(ofd, buf, len);
#if ENABLE_FEATURE_DD_IBS_OBS
if (n < 0 && (G.flags & FLAG_ODIRECT) && clear_O_DIRECT(ofd))
goto write_again;
#endif
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
if (n > 0)
G.total_bytes += n;
@@ -296,14 +254,6 @@ static int parse_comma_flags(char *val, const char *words, const char *error_in)
}
#endif
static void *alloc_buf(size_t size)
{
/* Important for "{i,o}flag=direct" - buffers must be page aligned */
if (size >= bb_getpagesize())
return xmmap_anon(size);
return xmalloc(size);
}
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dd_main(int argc UNUSED_PARAM, char **argv)
{
@@ -317,9 +267,9 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
static const char conv_words[] ALIGN1 =
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
static const char iflag_words[] ALIGN1 =
"skip_bytes\0""fullblock\0""direct\0";
"skip_bytes\0""fullblock\0";
static const char oflag_words[] ALIGN1 =
"seek_bytes\0append\0""direct\0";
"seek_bytes\0append\0";
#endif
#if ENABLE_FEATURE_DD_STATUS
static const char status_words[] ALIGN1 =
@@ -360,9 +310,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
//swab swap every pair of input bytes: will abort on non-even reads
OP_iflag_skip_bytes,
OP_iflag_fullblock,
OP_iflag_direct,
OP_oflag_seek_bytes,
OP_oflag_direct,
#endif
};
smallint exitcode = EXIT_FAILURE;
@@ -478,12 +426,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
#endif
} /* end of "for (argv[i])" */
ibuf = alloc_buf(ibs);
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
ibuf = xmalloc(ibs);
obuf = ibuf;
#if ENABLE_FEATURE_DD_IBS_OBS
if (ibs != obs) {
G.flags |= FLAG_TWOBUFS;
obuf = alloc_buf(obs);
obuf = xmalloc(obs);
}
#endif
@@ -495,12 +444,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
#endif
if (infile) {
int iflag = O_RDONLY;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_IDIRECT)
iflag |= O_DIRECT;
#endif
xmove_fd(xopen(infile, iflag), ifd);
xmove_fd(xopen(infile, O_RDONLY), ifd);
} else {
infile = bb_msg_standard_input;
}
@@ -511,10 +455,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
oflag |= O_TRUNC;
if (G.flags & FLAG_APPEND)
oflag |= O_APPEND;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_ODIRECT)
oflag |= O_DIRECT;
#endif
xmove_fd(xopen(outfile, oflag), ofd);
if (seek && !(G.flags & FLAG_NOTRUNC)) {
@@ -537,7 +478,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
do {
ssize_t n = dd_read(ibuf, blocksz);
ssize_t n;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_FULLBLOCK)
n = full_read(ifd, ibuf, blocksz);
else
#endif
n = safe_read(ifd, ibuf, blocksz);
if (n < 0)
goto die_infile;
if (n == 0)
@@ -552,7 +499,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
}
while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
ssize_t n = dd_read(ibuf, ibs);
ssize_t n;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_FULLBLOCK)
n = full_read(ifd, ibuf, ibs);
else
#endif
n = safe_read(ifd, ibuf, ibs);
if (n == 0)
break;
if (n < 0) {
@@ -647,13 +600,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (!ENABLE_FEATURE_DD_STATUS || !(G.flags & FLAG_STATUS_NONE))
dd_output_status(0);
#if 0 /* can't just free(), they can be mmap()ed */
if (ENABLE_FEATURE_CLEAN_UP) {
free(obuf);
if (G.flags & FLAG_TWOBUFS)
free(ibuf);
}
#endif
return exitcode;
}
+77 -132
View File
@@ -19,7 +19,6 @@
//usage: "Print prime factors"
#include "libbb.h"
#include "common_bufsiz.h"
#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
@@ -43,116 +42,9 @@ typedef unsigned long half_t;
#error Cant find an integer type which is half as wide as ullong
#endif
/* The trial divisor increment wheel. Use it to skip over divisors that
* are composites of 2, 3, 5, 7, or 11.
* Larger wheels improve sieving only slightly, but quickly grow in size
* (adding just one prime, 13, results in 5766 element sieve).
*/
#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
(((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \
(((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31)
#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
R( (a/2),(b/2),(c/2),(d/2),(e/2),(f/2),(g/2),(h/2),(i/2),(j/2), \
(A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2) )
static const uint64_t packed_wheel[] = {
/*1, 2, 2, 4, 2,*/
P( 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4), //01
P( 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2, 4), //02
P( 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4), //03
P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2), //04
P( 6, 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4), //05
P( 2, 6, 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2), //06
P( 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6), //07
P( 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6), //08
P( 8, 6, 4, 2,10, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6), //09
P( 4, 2, 4, 6, 6, 2, 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4), //10
P( 6, 6, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2), //11
P( 6, 4, 6, 2, 6, 4, 2, 4, 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2), //12
P( 4, 8,10, 6, 2, 4, 8, 6, 6, 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2), //13
P(10, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 6, 6, 4, 6, 8), //14
P( 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6, 2, 6, 6, 4, 2, 4, 6, 8, 4), //15
P( 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2,10, 2, 4, 6, 8, 6, 4, 2), //16
P( 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 6), //17
P( 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2,10, 6), //18
P( 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4, 6, 2, 4, 6, 2), //19
P(12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4, 6, 2, 6, 4), //20
P( 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6, 4, 6, 2), //21
P( 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4, 2,10), //22
P( 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8, 6), //23
P( 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12), //24
};
#undef P
#undef R
#define WHEEL_START 5
#define WHEEL_SIZE (5 + 24 * 20)
#define square_count (((uint8_t*)&bb_common_bufsiz1)[0])
#define wheel_tab (((uint8_t*)&bb_common_bufsiz1) + 1)
/*
* Why, you ask?
* plain byte array:
* function old new delta
* wheel_tab - 485 +485
* 3-bit-packed insanity:
* packed_wheel - 192 +192
* factor_main 108 171 +63
*/
static void unpack_wheel(void)
{
int i;
uint8_t *p;
setup_common_bufsiz();
wheel_tab[0] = 1;
wheel_tab[1] = 2;
wheel_tab[2] = 2;
wheel_tab[3] = 4;
wheel_tab[4] = 2;
p = &wheel_tab[5];
for (i = 0; i < ARRAY_SIZE(packed_wheel); i++) {
uint64_t v = packed_wheel[i];
while ((v & 0xe) != 0) {
*p = v & 0xe;
//printf("%2u,", *p);
p++;
v >>= 3;
}
//printf("\n");
}
}
/* Prevent inlining, factorize() needs all help it can get with reducing register pressure */
static NOINLINE void print_w(wide_t n)
{
unsigned rep = square_count;
do
printf(" %llu", n);
while (--rep != 0);
}
static NOINLINE void print_h(half_t n)
{
print_w(n);
}
static void factorize(wide_t N);
static half_t isqrt_odd(wide_t N)
{
half_t s = isqrt(N);
/* s^2 is <= N, (s+1)^2 > N */
/* If s^2 in fact is EQUAL to N, it's very lucky.
* Examples:
* factor 18446743988964486098 = 2 * 3037000493 * 3037000493
* factor 18446743902517389507 = 3 * 2479700513 * 2479700513
*/
if ((wide_t)s * s == N) {
/* factorize sqrt(N), printing each factor twice */
square_count *= 2;
factorize(s);
/* Let caller know we recursed */
return 0;
}
/* Subtract 1 from even s, odd s won't change: */
/* (doesnt work for zero, but we know that s != 0 here) */
s = (s - 1) | 1;
@@ -161,20 +53,43 @@ static half_t isqrt_odd(wide_t N)
static NOINLINE void factorize(wide_t N)
{
unsigned w;
half_t factor;
half_t max_factor;
// unsigned count3;
// unsigned count5;
// unsigned count7;
// ^^^^^^^^^^^^^^^ commented-out simple sieving code (easier to grasp).
// Faster sieving, using one word for potentially up to 6 counters:
// count upwards in each mask, counter "triggers" when it sets its mask to "100[0]..."
// 10987654321098765432109876543210 - bits 31-0 in 32-bit word
// 17777713333311111777775555333 - bit masks for counters for primes 3,5,7,11,13,17
// 100000100001000010001001 - value for adding 1 to each mask
// 10000010000010000100001000100 - value for checking that any mask reached msb
enum {
SHIFT_3 = 1 << 0,
SHIFT_5 = 1 << 3,
SHIFT_7 = 1 << 7,
INCREMENT_EACH = SHIFT_3 | SHIFT_5 | SHIFT_7,
MULTIPLE_OF_3 = 1 << 2,
MULTIPLE_OF_5 = 1 << 6,
MULTIPLE_OF_7 = 1 << 11,
MULTIPLE_DETECTED = MULTIPLE_OF_3 | MULTIPLE_OF_5 | MULTIPLE_OF_7,
};
unsigned sieve_word;
if (N < 4)
goto end;
while (!(N & 1)) {
printf(" 2");
N >>= 1;
}
/* The code needs to be optimized for the case where
* there are large prime factors. For example,
* this is not hard:
* 8262075252869367027 = 3 7 17 23 47 101 113 127 131 137 823
* (the largest divisor to test for largest factor 823
* is only ~sqrt(823) = 28, the entire factorization needs
* only ~33 trial divisions)
* (the largest factor to test is only ~sqrt(823) = 28)
* but this is:
* 18446744073709551601 = 53 348051774975651917
* the last factor requires testing up to
@@ -183,37 +98,70 @@ static NOINLINE void factorize(wide_t N)
* factor 18446744073709551557 (0xffffffffffffffc5).
*/
max_factor = isqrt_odd(N);
if (!max_factor)
return; /* square was detected and recursively factored */
factor = 2;
w = 0;
// count3 = 3;
// count5 = 6;
// count7 = 9;
sieve_word = 0
/* initial count for SHIFT_n is (n-1)/2*3: */
+ (MULTIPLE_OF_3 - 3 * SHIFT_3)
+ (MULTIPLE_OF_5 - 6 * SHIFT_5)
+ (MULTIPLE_OF_7 - 9 * SHIFT_7)
//+ (MULTIPLE_OF_11 - 15 * SHIFT_11)
//+ (MULTIPLE_OF_13 - 18 * SHIFT_13)
//+ (MULTIPLE_OF_17 - 24 * SHIFT_17)
;
factor = 3;
for (;;) {
half_t fw;
/* The division is the most costly part of the loop.
* On 64bit CPUs, takes at best 12 cycles, often ~20.
*/
while ((N % factor) == 0) { /* not likely */
N = N / factor;
print_h(factor);
printf(" %"HALF_FMT"u", factor);
max_factor = isqrt_odd(N);
if (!max_factor)
return; /* square was detected */
}
next_factor:
if (factor >= max_factor)
break;
fw = factor + wheel_tab[w];
if (fw < factor)
break; /* overflow */
factor = fw;
w++;
if (w < WHEEL_SIZE)
factor += 2;
/* Rudimentary wheel sieving: skip multiples of 3, 5 and 7:
* Every third odd number is divisible by three and thus isn't a prime:
* 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47...
* ^ ^ ^ ^ ^ ^ ^ _ ^ ^ _ ^ ^ ^ ^
* (^ = primes, _ = would-be-primes-if-not-divisible-by-5)
* The numbers with space under them are excluded by sieve 3.
*/
// count7--;
// count5--;
// count3--;
// if (count3 && count5 && count7)
// continue;
sieve_word += INCREMENT_EACH;
if (!(sieve_word & MULTIPLE_DETECTED))
continue;
w = WHEEL_START;
/*
* "factor" is multiple of 3 33% of the time (count3 reached 0),
* else, multiple of 5 13% of the time,
* else, multiple of 7 7.6% of the time.
* Cumulatively, with 3,5,7 sieving we are here 54.3% of the time.
*/
// if (count3 == 0)
// count3 = 3;
if (sieve_word & MULTIPLE_OF_3)
sieve_word -= SHIFT_3 * 3;
// if (count5 == 0)
// count5 = 5;
if (sieve_word & MULTIPLE_OF_5)
sieve_word -= SHIFT_5 * 5;
// if (count7 == 0)
// count7 = 7;
if (sieve_word & MULTIPLE_OF_7)
sieve_word -= SHIFT_7 * 7;
goto next_factor;
}
end:
if (N > 1)
print_w(N);
printf(" %llu", N);
bb_putchar('\n');
}
@@ -228,15 +176,12 @@ static void factorize_numstr(const char *numstr)
if (errno)
bb_show_usage();
printf("%llu:", N);
square_count = 1;
factorize(N);
}
int factor_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int factor_main(int argc UNUSED_PARAM, char **argv)
{
unpack_wheel();
//// coreutils has undocumented option ---debug (three dashes)
//getopt32(argv, "");
//argv += optind;
+1 -1
View File
@@ -33,7 +33,7 @@
/* BB_AUDIT SUSv3 compliant. */
//usage:#define id_trivial_usage
//usage: "[-ugGnr"IF_SELINUX("Z")"] [USER]"
//usage: "[OPTIONS] [USER]"
//usage:#define id_full_usage "\n\n"
//usage: "Print information about USER or the current user\n"
//usage: IF_SELINUX(
+2 -2
View File
@@ -21,14 +21,14 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/ln.html */
//usage:#define ln_trivial_usage
//usage: "[-sfnbtv] [-S SUF] TARGET... LINK|DIR"
//usage: "[OPTIONS] TARGET... LINK|DIR"
//usage:#define ln_full_usage "\n\n"
//usage: "Create a link LINK or DIR/TARGET to the specified TARGET(s)\n"
//usage: "\n -s Make symlinks instead of hardlinks"
//usage: "\n -f Remove existing destinations"
//usage: "\n -n Don't dereference symlinks - treat like normal file"
//usage: "\n -b Make a backup of the target (if exists) before link operation"
//usage: "\n -S SUF Use suffix instead of ~ when making backup files"
//usage: "\n -S suf Use suffix instead of ~ when making backup files"
//usage: "\n -T Treat LINK as a file, not DIR"
//usage: "\n -v Verbose"
//usage:
+1 -1
View File
@@ -117,8 +117,8 @@
//usage: "\n -c Check sums against list in FILEs"
//usage: "\n -s Don't output anything, status code shows success"
//usage: "\n -w Warn about improperly formatted checksum lines"
//usage: )
//usage: "\n -a BITS 224 (default), 256, 384, 512"
//usage: )
//FIXME: GNU coreutils 8.25 has no -s option, it has only these two long opts:
// --quiet don't print OK for each successfully verified file
+1 -1
View File
@@ -27,7 +27,7 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
//usage:#define mkdir_trivial_usage
//usage: "[-m MODE] [-p] DIRECTORY..."
//usage: "[OPTIONS] DIRECTORY..."
//usage:#define mkdir_full_usage "\n\n"
//usage: "Create DIRECTORY\n"
//usage: "\n -m MODE Mode"
+1 -1
View File
@@ -19,7 +19,7 @@
//usage:#define nl_full_usage "\n\n"
//usage: "Write FILEs to standard output with line numbers added\n"
//usage: "\n -b STYLE Which lines to number - a: all, t: nonempty, n: none"
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TODO: support "pBRE": number only lines that match regexp BRE"
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TODO: support "pBRE": number only lines thatmatch regexp BRE"
////usage: "\n -f STYLE footer lines"
////usage: "\n -h STYLE header lines"
////usage: "\n -d CC use CC for separating logical pages"
+2 -2
View File
@@ -627,7 +627,7 @@ decode_one_format(const char *s_orig, const char *s, struct tspec *tspec)
bytes_to_unsigned_dec_digits,
bytes_to_hex_digits,
};
static const char doux_fmtstring[][sizeof(" %%0%u%s")] ALIGN1 = {
static const char doux_fmtstring[][sizeof(" %%0%u%s")] = {
" %%%u%s",
" %%0%u%s",
" %%%u%s",
@@ -1148,7 +1148,7 @@ dump_strings(off_t address, off_t end_offset)
static int
parse_old_offset(const char *s, off_t *offset)
{
static const struct suffix_mult Bb[] ALIGN_SUFFIX = {
static const struct suffix_mult Bb[] = {
{ "B", 1024 },
{ "b", 512 },
{ "", 0 }
+1 -1
View File
@@ -18,7 +18,7 @@
//kbuild:lib-$(CONFIG_PASTE) += paste.o
//usage:#define paste_trivial_usage
//usage: "[-d LIST] [-s] [FILE]..."
//usage: "[OPTIONS] [FILE]..."
//usage:#define paste_full_usage "\n\n"
//usage: "Paste lines from each input file, separated with tab\n"
//usage: "\n -d LIST Use delimiters from LIST, not tab"
+1 -1
View File
@@ -20,7 +20,7 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */
//usage:#define rmdir_trivial_usage
//usage: "[-p] DIRECTORY..."
//usage: "[OPTIONS] DIRECTORY..."
//usage:#define rmdir_full_usage "\n\n"
//usage: "Remove DIRECTORY if it is empty\n"
//usage: "\n -p Include parents"
+1 -1
View File
@@ -43,7 +43,7 @@
//usage:#define sort_trivial_usage
//usage: "[-nru"
//usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k START[.OFS][OPTS][,END[.OFS][OPTS]] [-t CHAR")
//usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR")
//usage: "] [FILE]..."
//usage:#define sort_full_usage "\n\n"
//usage: "Sort lines of text\n"
+1 -1
View File
@@ -44,7 +44,7 @@
#include "common_bufsiz.h"
#if ENABLE_FEATURE_SPLIT_FANCY
static const struct suffix_mult split_suffixes[] ALIGN_SUFFIX = {
static const struct suffix_mult split_suffixes[] = {
{ "b", 512 },
{ "k", 1024 },
{ "m", 1024*1024 },
+3 -2
View File
@@ -31,6 +31,7 @@
//config: bool "Enable display of filesystem status (-f)"
//config: default y
//config: depends on STAT
//config: select PLATFORM_LINUX # statfs()
//config: help
//config: Without this, stat will not support the '-f' option to display
//config: information about filesystem status.
@@ -40,7 +41,7 @@
//kbuild:lib-$(CONFIG_STAT) += stat.o
//usage:#define stat_trivial_usage
//usage: "[-lt"IF_FEATURE_STAT_FILESYSTEM("f")"] "IF_FEATURE_STAT_FORMAT("[-c FMT] ")"FILE..."
//usage: "[OPTIONS] FILE..."
//usage:#define stat_full_usage "\n\n"
//usage: "Display file"
//usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem")
@@ -208,7 +209,7 @@ FS_TYPE(0x62656572, "sysfs")
static const char *human_fstype(uint32_t f_type)
{
# define FS_TYPE(type, name) type,
static const uint32_t fstype[] ALIGN4 = {
static const uint32_t fstype[] = {
FS_TYPE_LIST
};
# undef FS_TYPE
+2 -2
View File
@@ -487,7 +487,7 @@ static const char mode_name[] ALIGN1 =
#undef MI_ENTRY
#define MI_ENTRY(N,T,F,B,M) { T, F, M, B },
static const struct mode_info mode_info[] ALIGN4 = {
static const struct mode_info mode_info[] = {
/* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 )
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 )
@@ -905,7 +905,7 @@ static void display_window_size(int fancy)
}
}
static const struct suffix_mult stty_suffixes[] ALIGN_SUFFIX = {
static const struct suffix_mult stty_suffixes[] = {
{ "b", 512 },
{ "k", 1024 },
{ "B", 1024 },
+1 -83
View File
@@ -76,8 +76,6 @@
//usage: "1\n"
#include "libbb.h"
#include <regex.h>
#include <fnmatch.h>
/* This is a NOFORK applet. Be very careful! */
@@ -148,14 +146,6 @@
#define TEST_DEBUG 0
#if ENABLE_TEST2 \
|| (ENABLE_ASH_BASH_COMPAT && ENABLE_ASH_TEST) \
|| (ENABLE_HUSH_BASH_COMPAT && ENABLE_HUSH_TEST)
# define BASH_TEST2 1
#else
# define BASH_TEST2 0
#endif
enum token {
EOI,
@@ -194,10 +184,6 @@ enum token {
STRLT,
STRGT,
#if BASH_TEST2
REGEX,
#endif
INTEQ, /* int ops */
INTNE,
INTGE,
@@ -271,9 +257,6 @@ static const char *const TOKSTR[] = {
"STRNE",
"STRLT",
"STRGT",
#if BASH_TEST2
"REGEX",
#endif
"INTEQ",
"INTNE",
"INTGE",
@@ -306,7 +289,7 @@ struct operator_t {
unsigned char op_num, op_type;
};
static const struct operator_t ops_table[] ALIGN2 = {
static const struct operator_t ops_table[] = {
{ /* "-r" */ FILRD , UNOP },
{ /* "-w" */ FILWR , UNOP },
{ /* "-x" */ FILEX , UNOP },
@@ -337,9 +320,6 @@ static const struct operator_t ops_table[] ALIGN2 = {
{ /* "!=" */ STRNE , BINOP },
{ /* "<" */ STRLT , BINOP },
{ /* ">" */ STRGT , BINOP },
#if BASH_TEST2
{ /* "=~" */ REGEX , BINOP },
#endif
{ /* "-eq"*/ INTEQ , BINOP },
{ /* "-ne"*/ INTNE , BINOP },
{ /* "-ge"*/ INTGE , BINOP },
@@ -352,10 +332,6 @@ static const struct operator_t ops_table[] ALIGN2 = {
{ /* "!" */ UNOT , BUNOP },
{ /* "-a" */ BAND , BBINOP },
{ /* "-o" */ BOR , BBINOP },
#if BASH_TEST2
{ /* "&&" */ BAND , BBINOP },
{ /* "||" */ BOR , BBINOP },
#endif
{ /* "(" */ LPAREN , PAREN },
{ /* ")" */ RPAREN , PAREN },
};
@@ -389,9 +365,6 @@ static const char ops_texts[] ALIGN1 =
"!=" "\0"
"<" "\0"
">" "\0"
#if BASH_TEST2
"=~" "\0"
#endif
"-eq" "\0"
"-ne" "\0"
"-ge" "\0"
@@ -404,10 +377,6 @@ static const char ops_texts[] ALIGN1 =
"!" "\0"
"-a" "\0"
"-o" "\0"
#if BASH_TEST2
"&&" "\0"
"||" "\0"
#endif
"(" "\0"
")" "\0"
;
@@ -428,9 +397,6 @@ struct test_statics {
const struct operator_t *last_operator;
gid_t *group_array;
int ngroups;
#if BASH_TEST2
bool bash_test2;
#endif
jmp_buf leaving;
};
@@ -442,7 +408,6 @@ extern struct test_statics *const test_ptr_to_statics;
#define last_operator (S.last_operator)
#define group_array (S.group_array )
#define ngroups (S.ngroups )
#define bash_test2 (S.bash_test2 )
#define leaving (S.leaving )
#define INIT_S() do { \
@@ -536,20 +501,6 @@ static enum token check_operator(const char *s)
n = index_in_strings(ops_texts, s);
if (n < 0)
return OPERAND;
#if BASH_TEST2
if (ops_table[n].op_num == REGEX && !bash_test2) {
/* =~ is only for [[ ]] */
return OPERAND;
}
if (ops_table[n].op_num == BAND || ops_table[n].op_num == BOR) {
/* [ ] accepts -a and -o but not && and || */
/* [[ ]] accepts && and || but not -a and -o */
if (bash_test2 == (s[0] == '-'))
return OPERAND;
}
#endif
last_operator = &ops_table[n];
return ops_table[n].op_num;
}
@@ -585,29 +536,6 @@ static int binop(void)
/*if (op->op_num == INTLT)*/
return val1 < val2;
}
#if BASH_TEST2
if (bash_test2) {
if (op->op_num == STREQ) {
val1 = fnmatch(opnd2, opnd1, 0);
return val1 == 0;
}
if (op->op_num == STRNE) {
val1 = fnmatch(opnd2, opnd1, 0);
return val1 != 0;
}
if (op->op_num == REGEX) {
regex_t re_buffer;
memset(&re_buffer, 0, sizeof(re_buffer));
if (regcomp(&re_buffer, opnd2, REG_EXTENDED)) { // REG_NEWLINE?
/* Bad regex */
longjmp(leaving, 2); /* [[ a =~ * ]]; echo $? - prints 2 (silently, no error msg) */
}
val1 = regexec(&re_buffer, opnd1, 0, NULL, 0);
regfree(&re_buffer);
return val1 == 0;
}
}
#endif
if (is_str_op(op->op_num)) {
val1 = strcmp(opnd1, opnd2);
if (op->op_num == STREQ)
@@ -896,9 +824,6 @@ int test_main(int argc, char **argv)
{
int res;
const char *arg0;
#if BASH_TEST2
bool bt2 = 0;
#endif
arg0 = bb_basename(argv[0]);
if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_TEST || ENABLE_HUSH_TEST)
@@ -915,9 +840,6 @@ int test_main(int argc, char **argv)
bb_simple_error_msg("missing ]]");
return 2;
}
#if BASH_TEST2
bt2 = 1;
#endif
}
argv[argc] = NULL;
}
@@ -926,10 +848,6 @@ int test_main(int argc, char **argv)
/* We must do DEINIT_S() prior to returning */
INIT_S();
#if BASH_TEST2
bash_test2 = bt2;
#endif
res = setjmp(leaving);
if (res)
goto ret;
+2 -2
View File
@@ -41,7 +41,7 @@
//usage:#define timeout_trivial_usage
//usage: "[-s SIG] SECS PROG ARGS"
//usage:#define timeout_full_usage "\n\n"
//usage: "Run PROG. Send SIG to it if it is not gone in SECS seconds.\n"
//usage: "Runs PROG. Sends SIG to it if it is not gone in SECS seconds.\n"
//usage: "Default SIG: TERM."
#include "libbb.h"
@@ -105,7 +105,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
grandchild:
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
while (1) {
sleep1();
sleep(1);
if (--timeout <= 0)
break;
if (kill(parent, 0)) {
+1 -1
View File
@@ -20,7 +20,7 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */
//usage:#define uniq_trivial_usage
//usage: "[-cdui] [-f,s,w N] [INPUT [OUTPUT]]"
//usage: "[-cdu][-f,s,w N] [INPUT [OUTPUT]]"
//usage:#define uniq_full_usage "\n\n"
//usage: "Discard duplicate lines\n"
//usage: "\n -c Prefix lines by the number of occurrences"
+24 -140
View File
@@ -110,7 +110,9 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
}
bb_simple_error_msg_and_die("short file");
}
#endif
#if ENABLE_UUDECODE
int uudecode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uudecode_main(int argc UNUSED_PARAM, char **argv)
{
@@ -168,11 +170,9 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
}
#endif
//config:config BASE32
//config: bool "base32 (4.9 kb)"
//config: default y
//config: help
//config: Base32 encode and decode
//applet:IF_BASE64(APPLET(base64, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_BASE64) += uudecode.o
//config:config BASE64
//config: bool "base64 (4.9 kb)"
@@ -180,165 +180,49 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
//config: help
//config: Base64 encode and decode
//usage:#define base32_trivial_usage
//usage: "[-d] [-w COL] [FILE]"
//usage:#define base32_full_usage "\n\n"
//usage: "Base32 encode or decode FILE to standard output"
//usage: "\n -d Decode data"
//usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)"
////usage: "\n -i When decoding, ignore non-alphabet characters"
//usage:#define base64_trivial_usage
//usage: "[-d] [-w COL] [FILE]"
//usage: "[-d] [FILE]"
//usage:#define base64_full_usage "\n\n"
//usage: "Base64 encode or decode FILE to standard output"
//usage: "\n -d Decode data"
//usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)"
////usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)"
////usage: "\n -i When decoding, ignore non-alphabet characters"
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_BASE32(APPLET_ODDNAME(base32, baseNUM, BB_DIR_BIN, BB_SUID_DROP, base32))
//applet:IF_BASE64(APPLET_ODDNAME(base64, baseNUM, BB_DIR_BIN, BB_SUID_DROP, base64))
//kbuild:lib-$(CONFIG_BASE64) += uudecode.o
//kbuild:lib-$(CONFIG_BASE32) += uudecode.o
#if ENABLE_BASE32 || ENABLE_BASE64
# if ENABLE_BASE32
static void bb_b32encode(char *p, const void *src, int length)
{
#define tbl bb_uuenc_tbl_base32
const unsigned char *s = src;
/* Transform 5x8 bits to 8x5 bits */
while (length > 0) {
unsigned cur, next;
length--;
cur = *s++;
*p++ = tbl[cur >> 3]; // xxxxx--- -------- -------- -------- --------
cur &= 7;
next = 0;
if (--length >= 0)
next = *s++;
*p++ = tbl[(cur << 2) + (next >> 6)]; // -----xxx xx------ -------- -------- --------
cur = next & 0x3f;
*p++ = tbl[cur >> 1]; // -------- --xxxxx- -------- -------- --------
cur &= 1;
next = 0;
if (--length >= 0)
next = *s++;
*p++ = tbl[(cur << 4) + (next >> 4)]; // -------- -------x xxxx---- -------- --------
cur = next & 0xf;
next = 0;
if (--length >= 0)
next = *s++;
*p++ = tbl[(cur << 1) + (next >> 7)]; // -------- -------- ----xxxx x------- --------
cur = next & 0x7f;
*p++ = tbl[cur >> 2]; // -------- -------- -------- -xxxxx-- --------
cur &= 3;
next = 0;
if (--length >= 0)
next = *s++;
*p++ = tbl[(cur << 3) + (next >> 5)]; // -------- -------- -------- ------xx xxx-----
cur = next & 0x1f;
*p++ = tbl[cur]; // -------- -------- -------- -------- ---xxxxx
}
#undef tbl
/* Zero-terminate */
*p = '\0';
/* Pad as necessary */
length = ((-length) * 3) >> 1; /* -4 => 6 pad chars, -3 => 4, -2 => 3, -1 => 1 */
while (length--) {
*--p = '=';
}
}
# else
void bb_b32encode(char *p, const void *src, int length); /* undefined */
# endif
int baseNUM_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int baseNUM_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_BASE64
int base64_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int base64_main(int argc UNUSED_PARAM, char **argv)
{
FILE *src_stream;
unsigned opts;
unsigned col = 76;
opts = getopt32(argv, "^" "dw:+" "\0" "?1"/* 1 arg max*/, &col);
opts = getopt32(argv, "^" "d" "\0" "?1"/* 1 arg max*/);
argv += optind;
if (!argv[0])
*--argv = (char*)"-";
src_stream = xfopen_stdin(argv[0]);
if (opts & 1) {
/* -d: decode */
int flags = (unsigned char)EOF;
if (ENABLE_BASE32 && (!ENABLE_BASE64 || applet_name[4] == '3'))
flags = ((unsigned char)EOF) | BASE64_32;
read_base64(src_stream, stdout, flags);
if (opts) {
read_base64(src_stream, stdout, /*flags:*/ (char)EOF);
} else {
enum {
SRC_BUF_SIZE = 3 * 5 * 32, /* this *MUST* be a multiple of 3 and 5 */
DST_BUF_SIZE = 8 * ((SRC_BUF_SIZE + 4) / 5), /* max growth on encode (base32 case) */
SRC_BUF_SIZE = 76/4*3, /* This *MUST* be a multiple of 3 */
DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3),
};
/* Use one buffer for both input and output:
* encoding reads input "left-to-right",
* it's safe to place source at the end of the buffer and
* overwrite it while encoding, just be careful to have a gap.
*/
char dst_buf[((DST_BUF_SIZE + /*gap:*/ 16) /*round up to 16:*/ | 0xf) + 1];
#define src_buf (dst_buf + sizeof(dst_buf) - SRC_BUF_SIZE)
int src_fd, rem;
src_fd = fileno(src_stream);
rem = 0;
char src_buf[SRC_BUF_SIZE];
char dst_buf[DST_BUF_SIZE + 1];
int src_fd = fileno(src_stream);
while (1) {
size_t size = full_read(src_fd, src_buf, SRC_BUF_SIZE);
if (!size)
break;
if ((ssize_t)size < 0)
bb_simple_perror_msg_and_die(bb_msg_read_error);
if (size == 0) {
if (rem != 0) bb_putchar('\n');
break;
}
/* Encode the buffer we just read in */
if (ENABLE_BASE32 && (!ENABLE_BASE64 || applet_name[4] == '3')) {
bb_b32encode(dst_buf, src_buf, size);
size = 8 * ((size + 4) / 5);
} else {
bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64);
size = 4 * ((size + 2) / 3);
}
if (col == 0) {
fputs(dst_buf, stdout);
} else {
char *result = dst_buf;
if (rem == 0)
rem = col;
while (1) {
int out = size < rem ? size : rem;
rem -= out;
printf(rem != 0 ? "%.*s" : "%.*s\n", out, result);
if (rem != 0)
break;
size -= out;
if (size == 0)
break;
result += out;
rem = col;
}
}
bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64);
xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3));
bb_putchar('\n');
fflush(stdout);
}
#undef src_buf
}
fflush_stdout_and_exit(EXIT_SUCCESS);
+6 -6
View File
@@ -131,13 +131,12 @@ static int bb_alphasort(const void *p1, const void *p2)
return (option_mask32 & OPT_r) ? -r : r;
}
static int FAST_FUNC act(struct recursive_state *state,
const char *file, struct stat *statbuf)
static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args UNUSED_PARAM, int depth)
{
if (state->depth == 0)
if (depth == 1)
return TRUE;
if (state->depth == 1
if (depth == 2
&& ( !(statbuf->st_mode & (S_IFREG | S_IFLNK))
|| invalid_name(file)
|| (!(option_mask32 & OPT_l) && access(file, X_OK) != 0))
@@ -200,8 +199,9 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
ACTION_RECURSE|ACTION_FOLLOWLINKS,
act, /* file action */
act, /* dir action */
NULL /* user data */
);
NULL, /* user data */
1 /* depth */
);
if (!names)
return 0;
+2 -2
View File
@@ -17,9 +17,9 @@
//kbuild:lib-$(CONFIG_WHICH) += which.o
//usage:#define which_trivial_usage
//usage: "COMMAND..."
//usage: "[COMMAND]..."
//usage:#define which_full_usage "\n\n"
//usage: "Locate COMMAND"
//usage: "Locate a COMMAND"
//usage:
//usage:#define which_example_usage
//usage: "$ which login\n"
+1 -1
View File
@@ -127,7 +127,7 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f
/* Print file attributes on an ext2 file system */
const uint32_t e2attr_flags_value[] ALIGN4 = {
const uint32_t e2attr_flags_value[] = {
#ifdef ENABLE_COMPRESSION
EXT2_COMPRBLK_FL,
EXT2_DIRTY_FL,
+1 -1
View File
@@ -480,7 +480,7 @@ static int wait_one(int flags)
* time to set up the signal handler
*/
if (inst2->start_time >= time(NULL) - 1)
sleep1();
sleep(1);
kill(inst2->pid, SIGUSR1);
inst2->flags |= FLAG_PROGRESS;
break;
+1
View File
@@ -12,6 +12,7 @@
//config:config LSATTR
//config: bool "lsattr (5.5 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: lsattr lists the file attributes on a second extended file system.
+15 -39
View File
@@ -405,7 +405,7 @@ static const char tokenlist[] ALIGN1 =
#define OC_B OC_BUILTIN
static const uint32_t tokeninfo[] ALIGN4 = {
static const uint32_t tokeninfo[] = {
0,
0,
OC_REGEXP,
@@ -1763,34 +1763,12 @@ static void fsrealloc(int size)
nfields = size;
}
static int regexec1_nonempty(const regex_t *preg, const char *s, regmatch_t pmatch[])
{
int r = regexec(preg, s, 1, pmatch, 0);
if (r == 0 && pmatch[0].rm_eo == 0) {
/* For example, happens when FS can match
* an empty string (awk -F ' *'). Logically,
* this should split into one-char fields.
* However, gawk 5.0.1 searches for first
* _non-empty_ separator string match:
*/
size_t ofs = 0;
do {
ofs++;
if (!s[ofs])
return REG_NOMATCH;
regexec(preg, s + ofs, 1, pmatch, 0);
} while (pmatch[0].rm_eo == 0);
pmatch[0].rm_so += ofs;
pmatch[0].rm_eo += ofs;
}
return r;
}
static int awk_split(const char *s, node *spl, char **slist)
{
int n;
int l, n;
char c[4];
char *s1;
regmatch_t pmatch[2]; // TODO: why [2]? [1] is enough...
/* in worst case, each char would be a separate field */
*slist = s1 = xzalloc(strlen(s) * 2 + 3);
@@ -1807,31 +1785,29 @@ static int awk_split(const char *s, node *spl, char **slist)
return n; /* "": zero fields */
n++; /* at least one field will be there */
do {
int l;
regmatch_t pmatch[2]; // TODO: why [2]? [1] is enough...
l = strcspn(s, c+2); /* len till next NUL or \n */
if (regexec1_nonempty(icase ? spl->r.ire : spl->l.re, s, pmatch) == 0
if (regexec(icase ? spl->r.ire : spl->l.re, s, 1, pmatch, 0) == 0
&& pmatch[0].rm_so <= l
) {
/* if (pmatch[0].rm_eo == 0) ... - impossible */
l = pmatch[0].rm_so;
if (pmatch[0].rm_eo == 0) {
l++;
pmatch[0].rm_eo++;
}
n++; /* we saw yet another delimiter */
} else {
pmatch[0].rm_eo = l;
if (s[l])
pmatch[0].rm_eo++;
}
s1 = mempcpy(s1, s, l);
*s1++ = '\0';
memcpy(s1, s, l);
/* make sure we remove *all* of the separator chars */
do {
s1[l] = '\0';
} while (++l < pmatch[0].rm_eo);
nextword(&s1);
s += pmatch[0].rm_eo;
} while (*s);
/* echo a-- | awk -F-- '{ print NF, length($NF), $NF }'
* should print "2 0 ":
*/
*s1 = '\0';
return n;
}
if (c[0] == '\0') { /* null split */
@@ -2035,7 +2011,7 @@ static int ptest(node *pattern)
static int awk_getline(rstream *rsm, var *v)
{
char *b;
regmatch_t pmatch[2]; // TODO: why [2]? [1] is enough...
regmatch_t pmatch[2];
int size, a, p, pp = 0;
int fd, so, eo, r, rp;
char c, *m, *s;
+11 -11
View File
@@ -803,11 +803,11 @@ struct dlist {
};
/* This function adds a filename to dl, the directory listing. */
static int FAST_FUNC add_to_dirlist(struct recursive_state *state,
const char *filename,
struct stat *sb UNUSED_PARAM)
static int FAST_FUNC add_to_dirlist(const char *filename,
struct stat *sb UNUSED_PARAM,
void *userdata, int depth UNUSED_PARAM)
{
struct dlist *const l = state->userData;
struct dlist *const l = userdata;
const char *file = filename + l->len;
while (*file == '/')
file++;
@@ -820,12 +820,12 @@ static int FAST_FUNC add_to_dirlist(struct recursive_state *state,
/* If recursion is not set, this function adds the directory
* to the list and prevents recursive_action from recursing into it.
*/
static int FAST_FUNC skip_dir(struct recursive_state *state,
const char *filename,
struct stat *sb)
static int FAST_FUNC skip_dir(const char *filename,
struct stat *sb, void *userdata,
int depth)
{
if (!(option_mask32 & FLAG(r)) && state->depth) {
add_to_dirlist(state, filename, sb);
if (!(option_mask32 & FLAG(r)) && depth) {
add_to_dirlist(filename, sb, userdata, depth);
return SKIP;
}
if (!(option_mask32 & FLAG(N))) {
@@ -833,7 +833,7 @@ static int FAST_FUNC skip_dir(struct recursive_state *state,
* which do not exist on the "other side".
* Testcase: diff -r /tmp /
* (it would recurse deep into /proc without this code) */
struct dlist *const l = state->userData;
struct dlist *const l = userdata;
filename += l->len;
if (filename[0]) {
struct stat osb;
@@ -868,7 +868,7 @@ static void diffdir(char *p[2], const char *s_start)
* add_to_dirlist will remove it. */
list[i].len = strlen(p[i]);
recursive_action(p[i], ACTION_RECURSE | ACTION_FOLLOWLINKS,
add_to_dirlist, skip_dir, &list[i]);
add_to_dirlist, skip_dir, &list[i], 0);
/* Sort dl alphabetically.
* GNU diff does this ignoring any number of trailing dots.
* We don't, so for us dotted files almost always are
+1 -1
View File
@@ -31,7 +31,7 @@
//kbuild:lib-$(CONFIG_PATCH) += patch.o
//usage:#define patch_trivial_usage
//usage: "[-RNE] [-p N] [-i DIFF] [ORIGFILE [PATCHFILE]]"
//usage: "[OPTIONS] [ORIGFILE [PATCHFILE]]"
//usage:#define patch_full_usage "\n\n"
//usage: " -p N Strip N leading components from file names"
//usage: "\n -i DIFF Read DIFF instead of stdin"
+1 -1
View File
@@ -166,7 +166,7 @@
//kbuild:lib-$(CONFIG_VI) += vi.o
//usage:#define vi_trivial_usage
//usage: IF_FEATURE_VI_COLON("[-c CMD] ")IF_FEATURE_VI_READONLY("[-R] ")"[FILE]..."
//usage: "[OPTIONS] [FILE]..."
//usage:#define vi_full_usage "\n\n"
//usage: "Edit FILE\n"
//usage: IF_FEATURE_VI_COLON(
+1 -1
View File
@@ -31,7 +31,7 @@ time dgram udp wait root internal
#ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd
#telnet stream tcp nowait root /sbin/telnetd /sbin/telnetd
#nntp stream tcp nowait root tcpd in.nntpd
#smtp stream tcp nowait root tcpd sendmail -v
#smtp stream tcp nowait root tcpd sendmail -v
#
# Shell, login, exec and talk are BSD protocols.
#
+4 -4
View File
@@ -6,12 +6,12 @@ RESOLV_CONF="/etc/udhcpc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
ifconfig $interface $ip $BROADCAST $NETMASK
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ]
then
echo "deleting routers"
while route del default gw 0.0.0.0 dev $interface
while /sbin/route del default gw 0.0.0.0 dev $interface
do :
done
@@ -23,9 +23,9 @@ then
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
ip route add $i dev $interface
/sbin/ip route add $i dev $interface
fi
route add default gw $i dev $interface metric $((metric++))
/sbin/route add default gw $i dev $interface metric $((metric++))
done
fi
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
# Sample udhcpc deconfig script
ifconfig $interface 0.0.0.0
/sbin/ifconfig $interface 0.0.0.0
+4 -4
View File
@@ -6,12 +6,12 @@ RESOLV_CONF="/etc/udhcpc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
ifconfig $interface $ip $BROADCAST $NETMASK
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ]
then
echo "deleting routers"
while route del default gw 0.0.0.0 dev $interface
while /sbin/route del default gw 0.0.0.0 dev $interface
do :
done
@@ -23,9 +23,9 @@ then
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
ip route add $i dev $interface
/sbin/ip route add $i dev $interface
fi
route add default gw $i dev $interface metric $((metric++))
/sbin/route add default gw $i dev $interface metric $((metric++))
done
fi
+11 -10
View File
@@ -889,10 +889,10 @@ ACTF(links)
}
#endif
static int FAST_FUNC fileAction(
struct recursive_state *state IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM),
const char *fileName,
struct stat *statbuf)
static int FAST_FUNC fileAction(const char *fileName,
struct stat *statbuf,
void *userData UNUSED_PARAM,
int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM))
{
int r;
int same_fs = 1;
@@ -911,12 +911,12 @@ static int FAST_FUNC fileAction(
#endif
#if ENABLE_FEATURE_FIND_MAXDEPTH
if (state->depth < G.minmaxdepth[0]) {
if (depth < G.minmaxdepth[0]) {
if (same_fs)
return TRUE; /* skip this, continue recursing */
return SKIP; /* stop recursing */
}
if (state->depth > G.minmaxdepth[1])
if (depth > G.minmaxdepth[1])
return SKIP; /* stop recursing */
#endif
@@ -927,7 +927,7 @@ static int FAST_FUNC fileAction(
#if ENABLE_FEATURE_FIND_MAXDEPTH
if (S_ISDIR(statbuf->st_mode)) {
if (state->depth == G.minmaxdepth[1])
if (depth == G.minmaxdepth[1])
return SKIP;
}
#endif
@@ -1441,7 +1441,7 @@ static action*** parse_params(char **argv)
#else
#define XATOU_SFX xatoul_sfx
#endif
static const struct suffix_mult find_suffixes[] ALIGN_SUFFIX = {
static const struct suffix_mult find_suffixes[] = {
{ "c", 1 },
{ "w", 2 },
{ "", 512 },
@@ -1522,7 +1522,7 @@ int find_main(int argc UNUSED_PARAM, char **argv)
}
*past_HLP = NULL;
/* "+": stop on first non-option */
i = getopt32(argv, "+""HLP");
i = getopt32(argv, "+HLP");
if (i & (1<<0))
G.recurse_flags |= ACTION_FOLLOWLINKS_L0 | ACTION_DANGLING_OK;
if (i & (1<<1))
@@ -1570,7 +1570,8 @@ int find_main(int argc UNUSED_PARAM, char **argv)
G.recurse_flags,/* flags */
fileAction, /* file action */
fileAction, /* dir action */
NULL) /* user data */
NULL, /* user data */
0) /* depth */
) {
G.exitstatus |= EXIT_FAILURE;
}
+26 -25
View File
@@ -167,11 +167,13 @@ enum {
OPT_z = IF_EXTRA_COMPAT( (1 << OPTBIT_z)) + 0,
};
#define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l)
#define PRINT_LINE_NUM (option_mask32 & OPT_n)
#define BE_QUIET (option_mask32 & OPT_q)
#define SUPPRESS_ERR_MSGS (option_mask32 & OPT_s)
#define PRINT_MATCH_COUNTS (option_mask32 & OPT_c)
#define FGREP_FLAG (option_mask32 & OPT_F)
#define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L)
#define NUL_DELIMITED (option_mask32 & OPT_z)
struct globals {
@@ -474,13 +476,13 @@ static int grep_file(FILE *file)
* even if errors were detected" */
exit(EXIT_SUCCESS);
}
/* -l "print filenames with matches": stop after the first match */
if (option_mask32 & OPT_l) {
/* if we're just printing filenames, we stop after the first match */
if (PRINT_FILES_WITH_MATCHES) {
puts(cur_file);
return 1;
/* fall through to "return 1" */
}
/* -L "print filenames without matches": return early too */
return 0; /* 0: we do not print fname, hence it's "not a match" */
/* OPT_L aka PRINT_FILES_WITHOUT_MATCHES: return early */
return 1; /* one match */
}
#if ENABLE_FEATURE_GREP_CONTEXT
@@ -600,16 +602,15 @@ static int grep_file(FILE *file)
printf("%d\n", nmatches);
}
/* grep -L: "print filenames without matches" */
if (option_mask32 & OPT_L) {
/* grep -L: print just the filename */
if (PRINT_FILES_WITHOUT_MATCHES) {
/* nmatches is zero, no need to check it:
* we return 0 early if -L and we detect a match
*/
* we return 1 early if we detected a match
* and PRINT_FILES_WITHOUT_MATCHES is set */
puts(cur_file);
return 1; /* 1: we printed fname, hence it's "a match" */
}
return nmatches != 0; /* we return not a count, but a boolean */
return nmatches;
}
#if ENABLE_FEATURE_CLEAN_UP
@@ -656,9 +657,10 @@ static void load_pattern_list(llist_t **lst, char *pattern)
llist_add_to(lst, new_grep_list_data(p, 0));
}
static int FAST_FUNC file_action_grep(struct recursive_state *state UNUSED_PARAM,
const char *filename,
struct stat *statbuf)
static int FAST_FUNC file_action_grep(const char *filename,
struct stat *statbuf,
void* matched,
int depth UNUSED_PARAM)
{
FILE *file;
@@ -685,7 +687,7 @@ static int FAST_FUNC file_action_grep(struct recursive_state *state UNUSED_PARAM
return 0;
}
cur_file = filename;
*(int*)state->userData |= grep_file(file);
*(int*)matched += grep_file(file);
fclose(file);
return 1;
}
@@ -693,16 +695,15 @@ static int FAST_FUNC file_action_grep(struct recursive_state *state UNUSED_PARAM
static int grep_dir(const char *dir)
{
int matched = 0;
recursive_action(dir, 0
| ACTION_RECURSE
| ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0)
| ACTION_FOLLOWLINKS_L0 /* grep -r ... SYMLINK follows it */
| ACTION_DEPTHFIRST
| 0,
recursive_action(dir,
/* recurse=yes */ ACTION_RECURSE |
/* followLinks=always */ ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0) |
/* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
/* depthFirst=yes */ ACTION_DEPTHFIRST,
/* fileAction= */ file_action_grep,
/* dirAction= */ NULL,
/* userData= */ &matched
);
/* userData= */ &matched,
/* depth= */ 0);
return matched;
}
@@ -843,7 +844,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) {
if (!(option_mask32 & OPT_h))
print_filename = 1;
matched |= grep_dir(cur_file);
matched += grep_dir(cur_file);
goto grep_done;
}
}
@@ -856,7 +857,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
continue;
}
}
matched |= grep_file(file);
matched += grep_file(file);
fclose_if_not_stdin(file);
grep_done: ;
} while (*argv && *++argv);
+5 -16
View File
@@ -80,11 +80,9 @@
/* This is a NOEXEC applet. Be very careful! */
#if 0
# define dbg_msg(...) bb_error_msg(__VA_ARGS__)
#else
# define dbg_msg(...) ((void)0)
#endif
//#define dbg_msg(...) bb_error_msg(__VA_ARGS__)
#define dbg_msg(...) ((void)0)
#ifdef TEST
# ifndef ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION
@@ -468,18 +466,9 @@ static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg
while (1) {
int c = getchar();
if (p == buf) {
if (c == EOF)
goto ret; /* last line is empty, return "" */
if (c == G.eol_ch)
continue; /* empty line, ignore */
/* Skip leading whitespace of each line: try
* echo -e ' \t\v1 2 3 ' | xargs -I% echo '[%]'
*/
if (ISSPACE(c))
continue;
}
if (c == EOF || c == G.eol_ch) {
if (p == buf)
goto ret; /* empty line */
c = '\0';
}
*p++ = c;
View File
File renamed without changes.
+14 -1
View File
@@ -2,6 +2,20 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
#define F_IGNORE 0x01 /* %_A */
#define F_SETREP 0x02 /* rep count set, not default */
#define F_ADDRESS 0x001 /* print offset */
#define F_BPAD 0x002 /* blank pad */
#define F_C 0x004 /* %_c */
#define F_CHAR 0x008 /* %c */
#define F_DBL 0x010 /* %[EefGf] */
#define F_INT 0x020 /* %[di] */
#define F_P 0x040 /* %_p */
#define F_STR 0x080 /* %s */
#define F_U 0x100 /* %_u */
#define F_UINT 0x200 /* %[ouXx] */
#define F_TEXT 0x400 /* no conversions */
enum dump_vflag_t { ALL, DUP, FIRST, WAIT }; /* -v values */
typedef struct PR {
@@ -32,7 +46,6 @@ typedef struct dumper_t {
off_t dump_skip; /* bytes to skip */
int dump_length; /* max bytes to read */
smallint dump_vflag; /*enum dump_vflag_t*/
const char *eofstring;
FS *fshead;
} dumper_t;
+26 -86
View File
@@ -339,13 +339,12 @@ struct BUG_off_t_size_is_misdetected {
#endif
#endif
#if defined(errno)
/* If errno is a define, assume it's "define errno (*__errno_location())"
* and we will cache it's result in this variable */
#if defined(__GLIBC__)
/* glibc uses __errno_location() to get a ptr to errno */
/* We can just memorize it once - no multithreading in busybox :) */
extern int *const bb_errno;
#undef errno
#define errno (*bb_errno)
#define bb_cached_errno_ptr 1
#endif
#if !(ULONG_MAX > 0xffffffff)
@@ -387,32 +386,6 @@ void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) F
char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
void *mmap_read(int fd, size_t size) FAST_FUNC;
void *mmap_anon(size_t size) FAST_FUNC;
void *xmmap_anon(size_t size) FAST_FUNC;
#if defined(__x86_64__) || defined(i386)
# define BB_ARCH_FIXED_PAGESIZE 4096
#elif defined(__arm__) /* only 32bit, 64bit ARM has variable page size */
# define BB_ARCH_FIXED_PAGESIZE 4096
#else /* if defined(ARCH) */
/* add you favorite arch today! */
//From Linux kernel inspection:
//xtenza,s390[x],riscv,nios2,csky,sparc32: fixed 4k pages
//sparc64,alpha,openrisc: fixed 8k pages
#endif
#if defined BB_ARCH_FIXED_PAGESIZE
# define IF_VARIABLE_ARCH_PAGESIZE(...) /*nothing*/
# define bb_getpagesize() BB_ARCH_FIXED_PAGESIZE
# define INIT_PAGESIZE(var) ((void)0)
# define cached_pagesize(var) BB_ARCH_FIXED_PAGESIZE
#else
# define IF_VARIABLE_ARCH_PAGESIZE(...) __VA_ARGS__
# define bb_getpagesize() getpagesize()
# define INIT_PAGESIZE(var) ((var) = getpagesize())
# define cached_pagesize(var) (var)
#endif
//TODO: supply a pointer to char[11] buffer (avoid statics)?
@@ -463,23 +436,15 @@ enum {
ACTION_FOLLOWLINKS = (1 << 1),
ACTION_FOLLOWLINKS_L0 = (1 << 2),
ACTION_DEPTHFIRST = (1 << 3),
ACTION_QUIET = (1 << 4),
ACTION_DANGLING_OK = (1 << 5),
/*ACTION_REVERSE = (1 << 4), - unused */
ACTION_QUIET = (1 << 5),
ACTION_DANGLING_OK = (1 << 6),
};
typedef uint8_t recurse_flags_t;
typedef struct recursive_state {
unsigned flags;
unsigned depth;
void *userData;
int FAST_FUNC (*fileAction)(struct recursive_state *state, const char *fileName, struct stat* statbuf);
int FAST_FUNC (*dirAction)(struct recursive_state *state, const char *fileName, struct stat* statbuf);
} recursive_state_t;
int recursive_action(const char *fileName, unsigned flags,
int FAST_FUNC (*fileAction)(struct recursive_state *state, const char *fileName, struct stat* statbuf),
int FAST_FUNC (*dirAction)(struct recursive_state *state, const char *fileName, struct stat* statbuf),
void *userData
) FAST_FUNC;
extern int recursive_action(const char *fileName, unsigned flags,
int FAST_FUNC (*fileAction)(const char *fileName, struct stat* statbuf, void* userData, int depth),
int FAST_FUNC (*dirAction)(const char *fileName, struct stat* statbuf, void* userData, int depth),
void* userData, unsigned depth) FAST_FUNC;
extern int device_open(const char *device, int mode) FAST_FUNC;
enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */
extern int xgetpty(char *line) FAST_FUNC;
@@ -657,8 +622,6 @@ void parse_datestr(const char *date_str, struct tm *ptm) FAST_FUNC;
time_t validate_tm_time(const char *date_str, struct tm *ptm) FAST_FUNC;
char *strftime_HHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
void xsettimeofday(const struct timeval *tv) FAST_FUNC;
int xsocket(int domain, int type, int protocol) FAST_FUNC;
void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC;
@@ -854,7 +817,7 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
struct sockaddr *to,
socklen_t sa_size) FAST_FUNC;
uint16_t inet_cksum(const void *addr, int len) FAST_FUNC;
uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
int parse_pasv_epsv(char *buf) FAST_FUNC;
/* 0 if argv[0] is NULL: */
@@ -1054,9 +1017,8 @@ void generate_uuid(uint8_t *buf) FAST_FUNC;
/* Last element is marked by mult == 0 */
struct suffix_mult {
char suffix[4];
uint32_t mult;
unsigned mult;
};
#define ALIGN_SUFFIX ALIGN4
extern const struct suffix_mult bkm_suffixes[];
#define km_suffixes (bkm_suffixes + 1)
extern const struct suffix_mult cwbkMG_suffixes[];
@@ -1168,6 +1130,7 @@ int BB_EXECVP(const char *file, char *const argv[]) FAST_FUNC;
#define BB_EXECLP(prog,cmd,...) execlp(prog,cmd,__VA_ARGS__)
#endif
void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
/* xvfork() can't be a _function_, return after vfork in child mangles stack
* in the parent. It must be a macro. */
@@ -1552,8 +1515,7 @@ int del_loop(const char *device) FAST_FUNC;
* malloc and return it in *devname.
* return value is the opened fd to the loop device, or < on error
*/
int set_loop(char **devname, const char *file, unsigned long long offset,
unsigned long long sizelimit, unsigned flags) FAST_FUNC;
int set_loop(char **devname, const char *file, unsigned long long offset, unsigned flags) FAST_FUNC;
/* These constants match linux/loop.h (without BB_ prefix): */
#define BB_LO_FLAGS_READ_ONLY 1
#define BB_LO_FLAGS_AUTOCLEAR 4
@@ -1629,14 +1591,12 @@ char *bb_simplify_path(const char *path) FAST_FUNC;
/* Returns ptr to NUL */
char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
void pause_after_failed_login(void) FAST_FUNC;
void bb_do_delay(unsigned seconds) FAST_FUNC;
void msleep(unsigned ms) FAST_FUNC;
void sleep1(void) FAST_FUNC;
void change_identity(const struct passwd *pw) FAST_FUNC;
void exec_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
void exec_login_shell(const char *shell) NORETURN FAST_FUNC;
void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
#ifndef LOGIN_FAIL_DELAY
#define LOGIN_FAIL_DELAY 3
#endif
extern void bb_do_delay(int seconds) FAST_FUNC;
extern void change_identity(const struct passwd *pw) FAST_FUNC;
extern void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
/* Returns $SHELL, getpwuid(getuid())->pw_shell, or DEFAULT_SHELL.
* Note that getpwuid result might need xstrdup'ing
@@ -1865,20 +1825,14 @@ typedef const char *get_exe_name_t(int i) FAST_FUNC;
typedef struct line_input_t {
int flags;
int timeout;
# if ENABLE_FEATURE_TAB_COMPLETION
# if ENABLE_SHELL_ASH
const char *path_lookup;
# define EDITING_HAS_path_lookup 1
# else
# define EDITING_HAS_path_lookup 0
# endif
# if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH
# if ENABLE_FEATURE_TAB_COMPLETION \
&& (ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH \
|| ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH \
)
/* function to fetch additional application-specific names to match */
get_exe_name_t *get_exe_name;
# define EDITING_HAS_get_exe_name 1
# else
# define EDITING_HAS_get_exe_name 0
# endif
# define EDITING_HAS_get_exe_name 1
# endif
# if MAX_HISTORY
int cnt_history;
@@ -1906,11 +1860,7 @@ enum {
FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
};
line_input_t *new_line_input_t(int flags) FAST_FUNC;
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
void free_line_input_t(line_input_t *n) FAST_FUNC;
#else
# define free_line_input_t(n) free(n)
#endif
/*
* maxsize must be >= 2.
* Returns:
@@ -2066,17 +2016,14 @@ char *percent_decode_in_place(char *str, int strict) FAST_FUNC;
extern const char bb_uuenc_tbl_base64[] ALIGN1;
extern const char bb_uuenc_tbl_base32[] ALIGN1;
extern const char bb_uuenc_tbl_std[] ALIGN1;
void bb_uuencode(char *store, const void *s, int length, const char *tbl) FAST_FUNC;
enum {
BASE64_FLAG_UU_STOP = 0x100,
BASE64_32 = 0x200, /* base32 */
/* Sign-extends to a value which never matches fgetc result: */
BASE64_FLAG_NO_STOP_CHAR = 0x80,
};
char *decode_base64(char *dst, const char **pp_src) FAST_FUNC;
char *decode_base32(char *dst, const char **pp_src) FAST_FUNC;
const char *decode_base64(char **pp_dst, const char *src) FAST_FUNC;
void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC;
typedef struct md5_ctx_t {
@@ -2116,13 +2063,6 @@ unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
typedef struct md5_ctx_t md5sha_ctx_t;
#define md5sha_hash md5_hash
#define sha_end sha1_end
enum {
MD5_OUTSIZE = 16,
SHA1_OUTSIZE = 20,
SHA256_OUTSIZE = 32,
SHA512_OUTSIZE = 64,
SHA3_OUTSIZE = 28,
};
extern uint32_t *global_crc32_table;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
-2
View File
@@ -342,8 +342,6 @@ typedef unsigned smalluint;
# define ALIGN2
# define ALIGN4
#endif
#define ALIGN8 __attribute__((aligned(8)))
#define ALIGN_PTR __attribute__((aligned(sizeof(void*))))
/*
* For 0.9.29 and svn, __ARCH_USE_MMU__ indicates no-mmu reliably.
-6
View File
@@ -11,12 +11,6 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
#if ENABLE_FEATURE_HWCLOCK_ADJTIME_FHS
# define ADJTIME_PATH "/var/lib/hwclock/adjtime"
#else
# define ADJTIME_PATH "/etc/adjtime"
#endif
int rtc_adjtime_is_utc(void) FAST_FUNC;
int rtc_xopen(const char **default_rtc, int flags) FAST_FUNC;
void rtc_read_tm(struct tm *ptm, int fd) FAST_FUNC;
-6
View File
@@ -25,12 +25,6 @@
" (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
#endif
#if ENABLE_FEATURE_HWCLOCK_ADJTIME_FHS
# define ADJTIME_PATH "/var/lib/hwclock/adjtime"
#else
# define ADJTIME_PATH "/etc/adjtime"
#endif
INSERT
#define busybox_notes_usage \
+5 -5
View File
@@ -65,7 +65,7 @@
//kbuild:lib-$(CONFIG_REBOOT) += halt.o
//usage:#define halt_trivial_usage
//usage: "[-d DELAY] [-nf"IF_FEATURE_WTMP("w")"]"
//usage: "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
//usage:#define halt_full_usage "\n\n"
//usage: "Halt the system\n"
//usage: "\n -d SEC Delay interval"
@@ -76,7 +76,7 @@
//usage: )
//usage:
//usage:#define poweroff_trivial_usage
//usage: "[-d DELAY] [-nf]"
//usage: "[-d DELAY] [-n] [-f]"
//usage:#define poweroff_full_usage "\n\n"
//usage: "Halt and shut off power\n"
//usage: "\n -d SEC Delay interval"
@@ -84,7 +84,7 @@
//usage: "\n -f Force (don't go through init)"
//usage:
//usage:#define reboot_trivial_usage
//usage: "[-d DELAY] [-nf]"
//usage: "[-d DELAY] [-n] [-f]"
//usage:#define reboot_full_usage "\n\n"
//usage: "Reboot the system\n"
//usage: "\n -d SEC Delay interval"
@@ -144,14 +144,14 @@ static int init_was_not_there(void)
*/
#if 0
while (kill(1, 0) != 0 && --cnt >= 0)
sleep1();
sleep(1);
#endif
/* ... so let's wait for some evidence a usual startup event,
* mounting of /proc, happened. By that time init should be ready
* for signals.
*/
while (access("/proc/meminfo", F_OK) != 0 && --cnt >= 0)
sleep1();
sleep(1);
/* Does it look like init wasn't there? */
return (cnt != initial - 1);
+6 -6
View File
@@ -736,7 +736,7 @@ static void pause_and_low_level_reboot(unsigned magic)
pid_t pid;
/* Allow time for last message to reach serial console, etc */
sleep1();
sleep(1);
/* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS)
* in linux/kernel/sys.c, which can cause the machine to panic when
@@ -751,7 +751,7 @@ static void pause_and_low_level_reboot(unsigned magic)
* we would eternally sleep here - not what we want.
*/
waitpid(pid, NULL, 0);
sleep1(); /* paranoia */
sleep(1); /* paranoia */
_exit(EXIT_SUCCESS);
}
@@ -768,12 +768,12 @@ static void run_shutdown_and_kill_processes(void)
kill(-1, SIGTERM);
message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
sync();
sleep1();
sleep(1);
kill(-1, SIGKILL);
message(L_CONSOLE, "Sent SIG%s to all processes", "KILL");
sync();
/*sleep1(); - callers take care about making a pause */
/*sleep(1); - callers take care about making a pause */
}
/* Signal handling by init:
@@ -904,7 +904,7 @@ static void stop_handler(int sig UNUSED_PARAM)
wpid = wait_any_nohang(NULL);
mark_terminated(wpid);
if (wpid <= 0) /* no processes exited? sleep a bit */
sleep1();
sleep(1);
}
signal(SIGCONT, SIG_DFL);
@@ -1209,7 +1209,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
}
/* Don't consume all CPU time - sleep a bit */
sleep1();
sleep(1);
} /* while (1) */
}
+1
View File
@@ -8,6 +8,7 @@
//config:config RUN_INIT
//config: bool "run-init (7.7 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: The run-init utility is used from initramfs to select a new
//config: root device. Under initramfs, you have to use this instead of
+2
View File
@@ -334,6 +334,7 @@ config FEATURE_VERBOSE_CP_MESSAGE
config FEATURE_USE_SENDFILE
bool "Use sendfile system call"
default y
select PLATFORM_LINUX
help
When enabled, busybox will use the kernel sendfile() function
instead of read/write loops to copy data between file descriptors
@@ -375,6 +376,7 @@ config FEATURE_SKIP_ROOTFS
config MONOTONIC_SYSCALL
bool "Use clock_gettime(CLOCK_MONOTONIC) syscall"
default y
select PLATFORM_LINUX
help
Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring
time intervals (time, ping, traceroute etc need this).
+1 -2
View File
@@ -112,8 +112,7 @@ lib-y += xgethostbyname.o
lib-y += xreadlink.o
lib-y += xrealloc_vector.o
lib-$(CONFIG_MOUNT) += match_fstype.o
lib-$(CONFIG_UMOUNT) += match_fstype.o
lib-$(CONFIG_PLATFORM_LINUX) += match_fstype.o
lib-$(CONFIG_FEATURE_UTMP) += utmp.o
+2 -7
View File
@@ -25,11 +25,6 @@
*
* FEATURE_INSTALLER or FEATURE_SUID will still link printf routines in. :(
*/
/* Define this accessor before we #define "errno" our way */
#include <errno.h>
static inline int *get_perrno(void) { return &errno; }
#include "busybox.h"
#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
@@ -308,8 +303,8 @@ void lbb_prepare(const char *applet
void lbb_prepare(const char *applet
IF_FEATURE_INDIVIDUAL(, char **argv))
{
#ifdef bb_cached_errno_ptr
(*(int **)not_const_pp(&bb_errno)) = get_perrno();
#ifdef __GLIBC__
(*(int **)not_const_pp(&bb_errno)) = __errno_location();
barrier();
#endif
applet_name = applet;
+6 -53
View File
@@ -8,60 +8,13 @@
*/
#include "libbb.h"
/* void FAST_FUNC bb_do_delay(unsigned seconds) { ... } - no users yet */
#ifndef LOGIN_FAIL_DELAY
#define LOGIN_FAIL_DELAY 3
#endif
void FAST_FUNC pause_after_failed_login(void)
void FAST_FUNC bb_do_delay(int seconds)
{
#if 0 /* over-engineered madness */
time_t end, diff;
time_t start, now;
end = time(NULL) + LOGIN_FAIL_DELAY;
diff = LOGIN_FAIL_DELAY;
start = time(NULL);
do {
sleep(diff);
diff = end - time(NULL);
} while (diff > 0);
#else
sleep(LOGIN_FAIL_DELAY);
#endif
}
void FAST_FUNC sleep1(void)
{
sleep(1);
}
void FAST_FUNC msleep(unsigned ms)
{
#if 0
/* 1. usleep(n) is not guaranteed by standards to accept n >= 1000000
* 2. multiplication in usleep(ms * 1000) can overflow if ms > 4294967
* (sleep of ~71.5 minutes)
* Let's play safe and loop:
*/
while (ms > 500) {
usleep(500000);
ms -= 500;
}
usleep(ms * 1000);
#else
//usleep is often implemented as a call to nanosleep.
//Simply do the same to implement msleep.
//it's marginally larger, but wakes your CPU less often:
//function old new delta
//msleep 45 52 +7
struct timespec ts;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000000;
/*
* If a signal has non-default handler, nanosleep returns early.
* Our version of msleep doesn't return early
* if interrupted by such signals:
*/
while (nanosleep(&ts, &ts) != 0)
continue;
#endif
sleep(seconds);
now = time(NULL);
} while ((now - start) < seconds);
}
+1 -1
View File
@@ -17,7 +17,7 @@ extern int capget(cap_user_header_t header, const cap_user_data_t data);
// This way, libcap needs not be installed in build environment.
#include "libbb.h"
static const char *const capabilities[] ALIGN_PTR = {
static const char *const capabilities[] = {
"chown",
"dac_override",
"dac_read_search",
+2 -5
View File
@@ -117,11 +117,8 @@ int FAST_FUNC index_in_substrings(const char *strings, const char *key)
const char* FAST_FUNC nth_string(const char *strings, int n)
{
while (n) {
if (*strings++ == '\0') {
if (*strings == '\0') /* reached end of strings */
break;
n--;
}
n--;
strings += strlen(strings) + 1;
}
return strings;
}
+4 -1
View File
@@ -75,7 +75,10 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
goto use_small_buf;
/* We want page-aligned buffer, just in case kernel is clever
* and can do page-aligned io more efficiently */
buffer = mmap_anon(CONFIG_FEATURE_COPYBUF_KB * 1024);
buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON,
/* ignored: */ -1, 0);
buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
if (buffer == MAP_FAILED) {
use_small_buf:
-4
View File
@@ -8,10 +8,6 @@
*/
#include "libbb.h"
#ifndef LOGIN_NAME_MAX
#define LOGIN_NAME_MAX 256
#endif
/* To avoid problems, the username should consist only of
* letters, digits, underscores, periods, at signs and dashes,
* and not start with a dash (as defined by IEEE Std 1003.1-2001).
+23 -47
View File
@@ -13,19 +13,13 @@
#include "libbb.h"
#include "dump.h"
#define F_IGNORE 0x01 /* %_A */
#define F_SETREP 0x02 /* rep count set, not default */
#define F_ADDRESS 0x001 /* print offset */
#define F_BPAD 0x002 /* blank pad */
#define F_C 0x004 /* %_c */
#define F_CHAR 0x008 /* %c */
#define F_DBL 0x010 /* %[EefGf] */
#define F_INT 0x020 /* %[di] */
#define F_P 0x040 /* %_p */
#define F_STR 0x080 /* %s */
#define F_U 0x100 /* %_u */
#define F_UINT 0x200 /* %[ouXx] */
#define F_TEXT 0x400 /* no conversions */
static const char dot_flags_width_chars[] ALIGN1 = ".#-+ 0123456789";
static const char size_conv_str[] ALIGN1 =
"\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG";
static const char int_convs[] ALIGN1 = "diouxX";
typedef struct priv_dumper_t {
dumper_t pub;
@@ -45,13 +39,6 @@ typedef struct priv_dumper_t {
unsigned char *get__savp;
} priv_dumper_t;
static const char dot_flags_width_chars[] ALIGN1 = ".#-+ 0123456789";
static const char size_conv_str[] ALIGN1 =
"\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG";
static const char int_convs[] ALIGN1 = "diouxX";
dumper_t* FAST_FUNC alloc_dumper(void)
{
priv_dumper_t *dumper = xzalloc(sizeof(*dumper));
@@ -61,6 +48,7 @@ dumper_t* FAST_FUNC alloc_dumper(void)
return &dumper->pub;
}
static NOINLINE int bb_dump_size(FS *fs)
{
FU *fu;
@@ -296,9 +284,7 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs)
* repeat it as necessary.
*
* if rep count is greater than 1, no trailing whitespace
* gets output from the last iteration of the format unit:
* 2/1 "%02x " prints "XX XX", not "XX XX "
* 2/1 "%02x\n" prints "XX\nXX", not "XX\nXX\n"
* gets output from the last iteration of the format unit.
*/
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
if (!fu->nextfu
@@ -408,6 +394,7 @@ static unsigned char *get(priv_dumper_t *dumper)
if (dumper->pub.dump_vflag != DUP) {
puts("*");
}
return NULL;
}
memset(dumper->get__curp + nread, 0, need);
dumper->eaddress = dumper->address + nread;
@@ -466,7 +453,7 @@ static void bpad(PR *pr)
for (p2 = ++p1; *p1 && strchr(" -0+#", *p1); ++p1)
if (pr->nospace)
pr->nospace--;
while ((*p2++ = *p1++) != '\0')
while ((*p2++ = *p1++) != 0)
continue;
}
@@ -533,43 +520,36 @@ static void conv_u(PR *pr, unsigned char *p)
static void display(priv_dumper_t* dumper)
{
unsigned char *bp;
FS *fs;
FU *fu;
PR *pr;
int cnt;
unsigned char *bp, *savebp;
off_t saveaddress;
unsigned char savech = '\0';
while ((bp = get(dumper)) != NULL) {
FS *fs;
unsigned char *savebp;
off_t saveaddress;
fs = dumper->pub.fshead;
savebp = bp;
saveaddress = dumper->address;
for (; fs; fs = fs->nextfs, bp = savebp, dumper->address = saveaddress) {
FU *fu;
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
int cnt;
if (fu->flags & F_IGNORE) {
break;
}
for (cnt = fu->reps; cnt; --cnt) {
PR *pr;
for (pr = fu->nextpr; pr; dumper->address += pr->bcnt,
bp += pr->bcnt, pr = pr->nextpr) {
if (dumper->eaddress
&& dumper->address >= dumper->eaddress
if (dumper->eaddress && dumper->address >= dumper->eaddress
&& !(pr->flags & (F_TEXT | F_BPAD))
) {
if (dumper->pub.eofstring) {
/* xxd support: requested to not pad incomplete blocks */
fputs(dumper->pub.eofstring, stdout);
return;
}
if (!(pr->flags & (F_TEXT | F_BPAD)))
bpad(pr);
bpad(pr);
}
if (cnt == 1 && pr->nospace) {
savech = *pr->nospace;
*pr->nospace = '\0';
}
/* PRINT; */
switch (pr->flags) {
case F_ADDRESS:
printf(pr->fmt, (unsigned) dumper->address);
@@ -658,9 +638,7 @@ static void display(priv_dumper_t* dumper)
}
}
}
if (dumper->endfu) {
PR *pr;
/*
* if eaddress not set, error or file size was multiple
* of blocksize, and no partial block ever found.
@@ -717,7 +695,8 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
{
const char *p;
FS *tfs;
FU **nextfupp;
FU *tfu, **nextfupp;
const char *savep;
/* start new linked list of format units */
tfs = xzalloc(sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */
@@ -734,9 +713,6 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
/* take the format string and break it up into format units */
p = fmt;
for (;;) {
FU *tfu;
const char *savep;
p = skip_whitespace(p);
if (*p == '\0') {
break;
+1 -1
View File
@@ -21,7 +21,7 @@
#include "libbb.h"
static const struct suffix_mult duration_suffixes[] ALIGN_SUFFIX = {
static const struct suffix_mult duration_suffixes[] = {
{ "s", 1 },
{ "m", 60 },
{ "h", 60*60 },
+9
View File
@@ -91,3 +91,12 @@ void FAST_FUNC BB_EXECVP_or_die(char **argv)
xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
bb_perror_msg_and_die("can't execute '%s'", argv[0]);
}
/* Typical idiom for applets which exec *optional* PROG [ARGS] */
void FAST_FUNC exec_prog_or_SHELL(char **argv)
{
if (argv[0]) {
BB_EXECVP_or_die(argv);
}
run_shell(getenv("SHELL"), /*login:*/ 1, NULL);
}
+58 -39
View File
@@ -38,6 +38,35 @@ static ALWAYS_INLINE uint64_t rotl64(uint64_t x, unsigned n)
return (x << n) | (x >> (64 - n));
}
/* Feed data through a temporary buffer.
* The internal buffer remembers previous data until it has 64
* bytes worth to pass on.
*/
static void FAST_FUNC common64_hash(md5_ctx_t *ctx, const void *buffer, size_t len)
{
unsigned bufpos = ctx->total64 & 63;
ctx->total64 += len;
while (1) {
unsigned remaining = 64 - bufpos;
if (remaining > len)
remaining = len;
/* Copy data into aligned buffer */
memcpy(ctx->wbuffer + bufpos, buffer, remaining);
len -= remaining;
buffer = (const char *)buffer + remaining;
bufpos += remaining;
/* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */
bufpos -= 64;
if (bufpos != 0)
break;
/* Buffer is filled up, process it */
ctx->process_block(ctx);
/*bufpos = 0; - already is */
}
}
/* Process the remaining bytes in the buffer */
static void FAST_FUNC common64_end(md5_ctx_t *ctx, int swap_needed)
{
@@ -111,7 +140,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx)
They are defined in RFC 1321 as
T[i] = (int)(2^32 * fabs(sin(i))), i=1..64
*/
static const uint32_t C_array[] ALIGN4 = {
static const uint32_t C_array[] = {
/* round 1 */
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
@@ -420,29 +449,7 @@ void FAST_FUNC md5_begin(md5_ctx_t *ctx)
/* Used also for sha1 and sha256 */
void FAST_FUNC md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len)
{
unsigned bufpos = ctx->total64 & 63;
ctx->total64 += len;
while (1) {
unsigned remaining = 64 - bufpos;
if (remaining > len)
remaining = len;
/* Copy data into aligned buffer */
memcpy(ctx->wbuffer + bufpos, buffer, remaining);
len -= remaining;
buffer = (const char *)buffer + remaining;
bufpos += remaining;
/* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */
bufpos -= 64;
if (bufpos != 0)
break;
/* Buffer is filled up, process it */
ctx->process_block(ctx);
/*bufpos = 0; - already is */
}
common64_hash(ctx, buffer, len);
}
/* Process the remaining bytes in the buffer and put result from CTX
@@ -492,7 +499,7 @@ unsigned FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf)
static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx)
{
static const uint32_t rconsts[] ALIGN4 = {
static const uint32_t rconsts[] = {
0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6
};
int i, j;
@@ -567,7 +574,7 @@ typedef uint64_t sha_K_int;
typedef uint32_t sha_K_int;
# define K(v) (uint32_t)(v >> 32)
#endif
static const sha_K_int sha_K[] ALIGN8 = {
static const sha_K_int sha_K[] = {
K(0x428a2f98d728ae22ULL), K(0x7137449123ef65cdULL),
K(0xb5c0fbcfec4d3b2fULL), K(0xe9b5dba58189dbbcULL),
K(0x3956c25bf348b538ULL), K(0x59f111f1b605d019ULL),
@@ -760,7 +767,7 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
ctx->process_block = sha1_process_block64;
}
static const uint32_t init256[] ALIGN4 = {
static const uint32_t init256[] = {
0,
0,
0x6a09e667,
@@ -773,7 +780,7 @@ static const uint32_t init256[] ALIGN4 = {
0x5be0cd19,
};
#if NEED_SHA512
static const uint32_t init512_lo[] ALIGN4 = {
static const uint32_t init512_lo[] = {
0,
0,
0xf3bcc908,
@@ -809,7 +816,7 @@ void FAST_FUNC sha512_begin(sha512_ctx_t *ctx)
int i;
/* Two extra iterations zero out ctx->total64[2] */
uint64_t *tp = ctx->total64;
for (i = 0; i < 8 + 2; i++)
for (i = 0; i < 2+8; i++)
tp[i] = ((uint64_t)(init256[i]) << 32) + init512_lo[i];
/*ctx->total64[0] = ctx->total64[1] = 0; - already done */
}
@@ -825,7 +832,22 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len)
ctx->total64[0] += len;
if (ctx->total64[0] < len)
ctx->total64[1]++;
# if 0
remaining = 128 - bufpos;
/* Hash whole blocks */
while (len >= remaining) {
memcpy(ctx->wbuffer + bufpos, buffer, remaining);
buffer = (const char *)buffer + remaining;
len -= remaining;
remaining = 128;
bufpos = 0;
sha512_process_block128(ctx);
}
/* Save last, partial blosk */
memcpy(ctx->wbuffer + bufpos, buffer, len);
# else
while (1) {
remaining = 128 - bufpos;
if (remaining > len)
@@ -835,16 +857,15 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len)
len -= remaining;
buffer = (const char *)buffer + remaining;
bufpos += remaining;
/* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */
bufpos -= 128;
if (bufpos != 0)
break;
/* Buffer is filled up, process it */
sha512_process_block128(ctx);
/*bufpos = 0; - already is */
}
# endif
}
#endif /* NEED_SHA512 */
@@ -1009,7 +1030,7 @@ static void sha3_process_block72(uint64_t *state)
#if OPTIMIZE_SHA3_FOR_32
/*
static const uint32_t IOTA_CONST_0[NROUNDS] ALIGN4 = {
static const uint32_t IOTA_CONST_0[NROUNDS] = {
0x00000001UL,
0x00000000UL,
0x00000000UL,
@@ -1038,7 +1059,7 @@ static void sha3_process_block72(uint64_t *state)
** bits are in lsb: 0101 0000 1111 0100 1111 0001
*/
uint32_t IOTA_CONST_0bits = (uint32_t)(0x0050f4f1);
static const uint32_t IOTA_CONST_1[NROUNDS] ALIGN4 = {
static const uint32_t IOTA_CONST_1[NROUNDS] = {
0x00000000UL,
0x00000089UL,
0x8000008bUL,
@@ -1174,7 +1195,7 @@ static void sha3_process_block72(uint64_t *state)
combine_halves(state);
#else
/* Native 64-bit algorithm */
static const uint16_t IOTA_CONST[NROUNDS] ALIGN2 = {
static const uint16_t IOTA_CONST[NROUNDS] = {
/* Elements should be 64-bit, but top half is always zero
* or 0x80000000. We encode 63rd bits in a separate word below.
* Same is true for 31th bits, which lets us use 16-bit table
@@ -1210,15 +1231,15 @@ static void sha3_process_block72(uint64_t *state)
/* bit for CONST[0] is in msb: 0001 0110 0011 1000 0001 1011 */
const uint32_t IOTA_CONST_bit31 = (uint32_t)(0x16381b00);
static const uint8_t ROT_CONST[24] ALIGN1 = {
static const uint8_t ROT_CONST[24] = {
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,
};
static const uint8_t PI_LANE[24] ALIGN1 = {
static const uint8_t PI_LANE[24] = {
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,
};
/*static const uint8_t MOD5[10] ALIGN1 = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, };*/
/*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, };*/
unsigned x;
unsigned round;
@@ -1377,12 +1398,10 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len)
bufpos++;
remaining--;
}
/* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */
bufpos -= ctx->input_block_bytes;
if (bufpos != 0)
break;
/* Buffer is filled up, process it */
sha3_process_block72(ctx->state);
/*bufpos = 0; - already is */
+1 -3
View File
@@ -6,10 +6,8 @@
#include "libbb.h"
uint16_t FAST_FUNC inet_cksum(const void *ptr, int nleft)
uint16_t FAST_FUNC inet_cksum(uint16_t *addr, int nleft)
{
const uint16_t *addr = ptr;
/*
* Our algorithm is simple, using a 32 bit accumulator,
* we add sequential 16 bit words to it, and at the end, fold
+9 -11
View File
@@ -19,17 +19,15 @@ int FAST_FUNC get_linux_version_code(void)
{
struct utsname name;
char *t;
int r;
int i, r;
uname(&name); /* never fails */
t = name.release - 1;
r = 1;
do {
r <<= 8;
if (t) {
r += atoi(++t);
t = strchr(t, '.');
}
} while (r < 0x1000000);
return r - 0x1000000;
t = name.release;
r = 0;
for (i = 0; i < 3; i++) {
t = strtok(t, ".");
r = r * 256 + (t ? atoi(t) : 0);
t = NULL;
}
return r;
}
Loaded 100 of 331 files, more files were not shown because too many files have changed in this diff. Show more