Compare commits

..
12 Commits
Author SHA1 Message Date
Denys Vlasenko bd75474639 Bump version to 1.31.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 10:45:05 +02:00
Denys Vlasenko ebc1c38a92 dpkg-deb: work around bogus error message when working with XZ compressed packages
function                                             old     new   delta
unpack_xz_stream                                    2309    2317      +8
bb_full_fd_action                                    464     472      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Denys Vlasenko be11940911 telnet: fix uninitialized variable bug
function                                             old     new   delta
telnet_main                                         1236    1238      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Denys Vlasenko 49a8839638 ash: fix BASE##nn bashism for bases 36..64
function                                             old     new   delta
evaluate_string                                      876     932     +56

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Denys Vlasenko 3004510fdc ash: fix BASE##nn bashism to accept letter 'digits' for bases > 9
function                                             old     new   delta
evaluate_string                                      873     876      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
David Demelier d6a8784f27 wget: increase redirections limit
Some hosting services like sourceforge perform a lot of relocations
before actually serving the file. Example of current limitation:

    busybox wget http://sourceforge.net/projects/fluxbox/files/fluxbox/1.3.7/fluxbox-1.3.7.tar.xz
    Connecting to sourceforge.net (216.105.38.13:80)
    Connecting to sourceforge.net (216.105.38.13:443)
    Connecting to sourceforge.net (216.105.38.13:443)
    Connecting to sourceforge.net (216.105.38.13:443)
    Connecting to downloads.sourceforge.net (216.105.38.13:443)
    wget: too many redirections

Signed-off-by: David Demelier <markand@malikania.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Denys Vlasenko a1c7a9e976 hush: fix "set -o INVALID" affecting -e flag state
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Brian Foley 2f3352682e dc: Parse error & fix out of bounds read in xc_program_printString
function                                             old     new   delta
xc_program_print                                     712     735     +23

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Brian Foley 50ba92128b dc: Fix segfault when executing strings generated using asciify
function                                             old     new   delta
zxc_vm_process                                      6884    6891      +7

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Brian Foley 4699b93244 dc: execute shouldn't pop if stack head is not a string
This matches the behaviour of both GNU dc (as specified in
its man page), and BSD dc (where stack_popstring() pops
only if the head is a string.)

Add a couple of tests to verify this behavior.

function                                             old     new   delta
zxc_vm_process                                      6882    6884      +2

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Denys Vlasenko 244c0ebb4f ash: fix set -o to not show "nameless" options
Patch by Martijn Dekker <martijn@inlv.org>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
Ron Yorston c88d3ec458 ash: only catch unexpected exceptions in PS1 expansion
Commit d1a2fa2a4 (ash: catch error in arithmetic expansion in PS1)
catches all exceptions raised by expandarg().  Some exceptions, such as
the EXEXIT raised when command expansion is used, are expected:

   export PS1='$(echo "$ ")'

These should be processed normally or the shell hangs at the prompt.

function                                             old     new   delta
expandstr                                            344     353      +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 9/0)                 Total: 9 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-21 16:54:40 +02:00
513 changed files with 5466 additions and 8833 deletions

No files matched your search

+14 -24
View File
@@ -156,13 +156,12 @@ config FEATURE_PIDFILE
config PID_FILE_PATH
string "Directory for pidfiles"
default "/var/run"
depends on FEATURE_PIDFILE || FEATURE_CROND_SPECIAL_TIMES
depends on FEATURE_PIDFILE
help
This is the default path where pidfiles are created. Applets which
allow you to set the pidfile path on the command line will override
this value. The option has no effect on applets that require you to
specify a pidfile path. When crond has the 'Support special times'
option enabled, the 'crond.reboot' file is also stored here.
specify a pidfile path.
config BUSYBOX
bool "Include busybox applet"
@@ -312,6 +311,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 +357,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 +540,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
@@ -658,19 +661,6 @@ config WERROR
Most people should answer N.
config WARN_SIMPLE_MSG
bool "Warn about single parameter bb_xx_msg calls"
default n
help
This will cause warnings to be shown for any instances of
bb_error_msg(), bb_error_msg_and_die(), bb_perror_msg(),
bb_perror_msg_and_die(), bb_herror_msg() or bb_herror_msg_and_die()
being called with a single parameter. In these cases the equivalent
bb_simple_xx_msg function should be used instead.
Note that use of STRERROR_FMT may give false positives.
If you aren't developing busybox, say N here.
choice
prompt "Additional debugging library"
default NO_DEBUG_LIB
+2 -2
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 33
SUBLEVEL = 2
PATCHLEVEL = 31
SUBLEVEL = 1
EXTRAVERSION =
NAME = Unnamed
+6 -30
View File
@@ -15,7 +15,7 @@ CPPFLAGS += \
-include include/autoconf.h \
-D_GNU_SOURCE -DNDEBUG \
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
-DBB_VER=$(squote)$(quote)$(BB_VER)$(quote)$(squote)
-D"BB_VER=KBUILD_STR($(BB_VER))"
CFLAGS += $(call cc-option,-Wall,)
CFLAGS += $(call cc-option,-Wshadow,)
@@ -47,29 +47,12 @@ endif
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
ifneq ($(CC),clang)
# "clang-9: warning: optimization flag '-finline-limit=0' is not supported
CFLAGS += $(call cc-option,-finline-limit=0,)
endif
CFLAGS += $(call cc-option,-fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections,)
CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
# -fno-guess-branch-probability: prohibit pseudo-random guessing
# of branch probabilities (hopefully makes bloatcheck more stable):
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
# "clang-9: warning: argument unused during compilation: '-static-libgcc'"
CFLAGS += $(call cc-option,-static-libgcc,)
endif
CFLAGS += $(call cc-option,-falign-functions=1,)
ifneq ($(CC),clang)
# "clang-9: warning: optimization flag '-falign-jumps=1' is not supported" (and same for other two)
CFLAGS += $(call cc-option,-falign-jumps=1 -falign-labels=1 -falign-loops=1,)
endif
CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary):
CFLAGS += $(call cc-option,-fno-unwind-tables,)
CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
@@ -77,11 +60,6 @@ CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
# (try disabling this and comparing assembly, it's instructive)
CFLAGS += $(call cc-option,-fno-builtin-printf,)
# clang-9 does not like "str" + N and "if (CONFIG_ITEM && cond)" constructs
ifeq ($(CC),clang)
CFLAGS += $(call cc-option,-Wno-string-plus-int -Wno-constant-logical-operand)
endif
# FIXME: These warnings are at least partially to be concerned about and should
# be fixed..
#CFLAGS += $(call cc-option,-Wconversion,)
@@ -151,12 +129,10 @@ endif
# fall back to using a temp file:
CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >crypttest.c; $(CC) $(CFLAGS) -lcrypt -o /dev/null crypttest.c >/dev/null 2>&1 && echo "y"; rm crypttest.c)
ifeq ($(CRYPT_AVAILABLE),y)
LDLIBS += m rt crypt
LDLIBS += m crypt
else
LDLIBS += m rt
LDLIBS += m
endif
# libm may be needed for dc, awk, ntpd
# librt may be needed for clock_gettime()
# libpam may use libpthread, libdl and/or libaudit.
# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
-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"
-39
View File
@@ -1,39 +0,0 @@
#!/bin/sh
MIMFILE="Mimfile"
if [ $# -ge 2 ] && [ "$1" = "-f" ]
then
MIMFILE="$2"
shift 2
fi
exec <"$MIMFILE" || exit 1
{
INCASE=false
while read -r REPLY
do
case $REPLY in
*:)
if ! $INCASE
then
printf '[ $# -eq 0 ] && set -- "%s"
TARGET="$1"
shift
case "$TARGET" in
' "${REPLY%:}"
else
printf ';;\n'
fi
printf '%s)\n' "${REPLY%:}"
INCASE=true
;;
"") ;;
*) printf '%s\n' "${REPLY##[ ]}";;
esac
done
$INCASE && printf ';;\n'
printf '*)
echo "Unknown command $TARGET"
exit 1
;;
esac
'
} | sh -s "$@"
-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
+7 -9
View File
@@ -114,7 +114,7 @@ int FAST_FUNC bbunpack(char **argv,
/* Check that the input is sane */
if (!(option_mask32 & BBUNPK_OPT_FORCE) && isatty(STDIN_FILENO)) {
bb_simple_error_msg_and_die("compressed data not read from terminal, "
bb_error_msg_and_die("compressed data not read from terminal, "
"use -f to force it");
}
@@ -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"
@@ -386,7 +386,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
* Normally, "zcat" is just "gunzip -c".
* But if seamless magic is enabled, then we are much more clever.
*/
if (ENABLE_ZCAT && applet_name[1] == 'c')
if (ENABLE_ZCAT && (!ENABLE_GUNZIP || applet_name[1] == 'c'))
option_mask32 |= BBUNPK_OPT_STDOUT | BBUNPK_SEAMLESS_MAGIC;
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
@@ -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,21 +532,19 @@ 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"
//usage: "\n -t Test file integrity"
//usage:
//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"
//usage: "\n -k Keep input files"
//usage: "\n -t Test file integrity"
//usage:
//usage:#define xzcat_trivial_usage
//usage: "[FILE]..."
+3 -3
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"
@@ -145,7 +145,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
if (n2 != n) {
if (n2 >= 0)
errno = 0; /* prevent bogus error message */
bb_simple_perror_msg(n2 >= 0 ? "short write" : bb_msg_write_error);
bb_perror_msg(n2 >= 0 ? "short write" : bb_msg_write_error);
return -1;
}
}
@@ -187,7 +187,7 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate U
while (1) {
count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
if (count < 0) {
bb_simple_perror_msg(bb_msg_read_error);
bb_perror_msg(bb_msg_read_error);
total = -1;
break;
}
+1 -2
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"
@@ -516,7 +516,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
if (archive_handle->cpio__blocks != (off_t)-1
&& !(opt & OPT_QUIET)
) {
fflush_all();
fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
}
+8 -31
View File
@@ -487,7 +487,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
} else if (strncmp(version, ">=", offset_ch) == 0) {
edge->operator = VER_MORE_EQUAL;
} else {
bb_simple_error_msg_and_die("illegal operator");
bb_error_msg_and_die("illegal operator");
}
}
/* skip to start of version numbers */
@@ -730,7 +730,7 @@ static void set_status(const unsigned status_node_num, const char *new_value, co
status = new_value_num;
break;
default:
bb_simple_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
}
new_status = xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
@@ -944,10 +944,10 @@ static void write_status_file(deb_file_t **deb_file)
/* Create a separate backfile to dpkg */
if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
if (errno != ENOENT)
bb_simple_error_msg_and_die("can't create backup status file");
bb_error_msg_and_die("can't create backup status file");
/* Its ok if renaming the status file fails because status
* file doesn't exist, maybe we are starting from scratch */
bb_simple_error_msg("no status file found, creating new one");
bb_error_msg("no status file found, creating new one");
}
xrename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status");
@@ -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"
@@ -1839,7 +1816,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
init_archive_deb_control(archive_handle);
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
if (deb_file[deb_count]->control_file == NULL) {
bb_simple_error_msg_and_die("can't extract control file");
bb_error_msg_and_die("can't extract control file");
}
deb_file[deb_count]->filename = xstrdup(argv[0]);
package_num = fill_package_struct(deb_file[deb_count]->control_file);
@@ -1902,13 +1879,13 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
argv++;
}
if (!deb_count)
bb_simple_error_msg_and_die("no package files specified");
bb_error_msg_and_die("no package files specified");
deb_file[deb_count] = NULL;
/* Check that the deb file arguments are installable */
if (!(opt & OPT_force_ignore_depends)) {
if (!check_deps(deb_file, 0 /*, deb_count*/)) {
bb_simple_error_msg_and_die("dependency check failed");
bb_error_msg_and_die("dependency check failed");
}
}
+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"
+61 -71
View File
@@ -52,7 +52,7 @@ aa: 85.1% -- replaced with aa.gz
//config: help
//config: Enable support for compression levels 4-9. The default level
//config: is 6. If levels 1-3 are specified, 4 is used.
//config: If this option is not selected, -N options are ignored and -6
//config: If this option is not selected, -N options are ignored and -9
//config: is used.
//config:
//config:config FEATURE_GZIP_DECOMPRESS
@@ -99,7 +99,7 @@ aa: 85.1% -- replaced with aa.gz
/* Diagnostic functions */
#ifdef DEBUG
static int verbose;
# define Assert(cond,msg) { if (!(cond)) bb_simple_error_msg(msg); }
# define Assert(cond,msg) { if (!(cond)) bb_error_msg(msg); }
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x; }
# define Tracevv(x) {if (verbose > 1) fprintf x; }
@@ -259,13 +259,12 @@ enum {
#if !ENABLE_FEATURE_GZIP_LEVELS
comp_level_minus4 = 6 - 4,
max_chain_length = 128,
max_chain_length = 4096,
/* To speed up deflation, hash chains are never searched beyond this length.
* A higher limit improves compression ratio but degrades the speed.
*/
max_lazy_match = 16,
max_lazy_match = 258,
/* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression
* levels >= 4.
@@ -277,7 +276,7 @@ enum {
* max_insert_length is used only for compression levels <= 3.
*/
good_match = 8,
good_match = 32,
/* Use a faster search when the previous match is longer than this */
/* Values for max_lazy_match, good_match and max_chain_length, depending on
@@ -286,7 +285,7 @@ enum {
* found for specific files.
*/
nice_match = 128, /* Stop searching when current match exceeds this */
nice_match = 258, /* Stop searching when current match exceeds this */
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
* meaning.
@@ -335,16 +334,14 @@ struct globals {
#define head (G1.prev + WSIZE) /* hash head (see deflate.c) */
#if ENABLE_FEATURE_GZIP_LEVELS
unsigned comp_level_minus4; /* can be a byte */
unsigned max_chain_length;
unsigned max_lazy_match;
unsigned good_match;
unsigned nice_match;
#define comp_level_minus4 (G1.comp_level_minus4)
#define max_chain_length (G1.max_chain_length)
#define max_lazy_match (G1.max_lazy_match)
#define good_match (G1.good_match)
#define nice_match (G1.nice_match)
#define max_chain_length (G1.max_chain_length)
#define max_lazy_match (G1.max_lazy_match)
#define good_match (G1.good_match)
#define nice_match (G1.nice_match)
#endif
/* =========================================================================== */
@@ -507,7 +504,7 @@ static ALWAYS_INLINE void flush_outbuf_if_32bit_optimized(void)
* pointer, then initialize the crc shift register contents instead.
* Return the current crc in either case.
*/
static void updcrc(uch *s, unsigned n)
static void updcrc(uch * s, unsigned n)
{
G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/);
}
@@ -610,7 +607,7 @@ static void bi_windup(void)
* Copy a stored block to the zip file, storing first the length and its
* one's complement if requested.
*/
static void copy_block(const char *buf, unsigned len, int header)
static void copy_block(char *buf, unsigned len, int header)
{
bi_windup(); /* align on byte boundary */
@@ -790,7 +787,7 @@ static void check_match(IPos start, IPos match, int length)
/* check that the match is indeed a match */
if (memcmp(G1.window + match, G1.window + start, length) != 0) {
bb_error_msg(" start %d, match %d, length %d", start, match, length);
bb_simple_error_msg("invalid match");
bb_error_msg("invalid match");
}
if (verbose > 1) {
bb_error_msg("\\[%d,%d]", start - match, length);
@@ -1010,8 +1007,7 @@ struct globals2 {
tree_desc d_desc;
tree_desc bl_desc;
/* was "ush", but "unsigned" results in smaller code */
unsigned bl_count[MAX_BITS + 1];
ush bl_count[MAX_BITS + 1];
/* The lengths of the bit length codes are sent in order of decreasing
* probability, to avoid transmitting the lengths for unused bit length codes.
@@ -1122,7 +1118,7 @@ static void init_block(void)
(tree[n].Freq < tree[m].Freq \
|| (tree[n].Freq == tree[m].Freq && G2.depth[n] <= G2.depth[m]))
static void pqdownheap(const ct_data *tree, int k)
static void pqdownheap(ct_data * tree, int k)
{
int v = G2.heap[k];
int j = k << 1; /* left son of k */
@@ -1156,15 +1152,22 @@ static void pqdownheap(const ct_data *tree, int k)
* The length opt_len is updated; static_len is also updated if stree is
* not null.
*/
static void gen_bitlen(const tree_desc *desc)
static void gen_bitlen(tree_desc * desc)
{
#define tree desc->dyn_tree
int h; /* heap index */
int n, m; /* iterate over the tree elements */
int bits; /* bit length */
int overflow; /* number of elements with bit length too large */
ct_data *tree = desc->dyn_tree;
const uint8_t *extra = desc->extra_bits;
int base = desc->extra_base;
int max_code = desc->max_code;
int max_length = desc->max_length;
ct_data *stree = desc->static_tree;
int h; /* heap index */
int n, m; /* iterate over the tree elements */
int bits; /* bit length */
int xbits; /* extra bits */
ush f; /* frequency */
int overflow = 0; /* number of elements with bit length too large */
for (bits = 0; bits < ARRAY_SIZE(G2.bl_count); bits++)
for (bits = 0; bits <= MAX_BITS; bits++)
G2.bl_count[bits] = 0;
/* In a first pass, compute the optimal bit lengths (which may
@@ -1172,32 +1175,28 @@ static void gen_bitlen(const tree_desc *desc)
*/
tree[G2.heap[G2.heap_max]].Len = 0; /* root of the heap */
overflow = 0;
for (h = G2.heap_max + 1; h < HEAP_SIZE; h++) {
ulg f; /* frequency */
int xbits; /* extra bits */
n = G2.heap[h];
bits = tree[tree[n].Dad].Len + 1;
if (bits > desc->max_length) {
bits = desc->max_length;
if (bits > max_length) {
bits = max_length;
overflow++;
}
tree[n].Len = (ush) bits;
/* We overwrite tree[n].Dad which is no longer needed */
if (n > desc->max_code)
if (n > max_code)
continue; /* not a leaf node */
G2.bl_count[bits]++;
xbits = 0;
if (n >= desc->extra_base)
xbits = desc->extra_bits[n - desc->extra_base];
if (n >= base)
xbits = extra[n - base];
f = tree[n].Freq;
G2.opt_len += f * (bits + xbits);
G2.opt_len += (ulg) f *(bits + xbits);
if (desc->static_tree)
G2.static_len += f * (desc->static_tree[n].Len + xbits);
if (stree)
G2.static_len += (ulg) f * (stree[n].Len + xbits);
}
if (overflow == 0)
return;
@@ -1207,14 +1206,14 @@ static void gen_bitlen(const tree_desc *desc)
/* Find the first bit length which could increase: */
do {
bits = desc->max_length - 1;
bits = max_length - 1;
while (G2.bl_count[bits] == 0)
bits--;
G2.bl_count[bits]--; /* move one leaf down the tree */
G2.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
G2.bl_count[desc->max_length]--;
G2.bl_count[max_length]--;
/* The brother of the overflow item also moves one step up,
* but this does not affect bl_count[desc->max_length]
* but this does not affect bl_count[max_length]
*/
overflow -= 2;
} while (overflow > 0);
@@ -1224,11 +1223,11 @@ static void gen_bitlen(const tree_desc *desc)
* lengths instead of fixing only the wrong ones. This idea is taken
* from 'ar' written by Haruhiko Okumura.)
*/
for (bits = desc->max_length; bits != 0; bits--) {
for (bits = max_length; bits != 0; bits--) {
n = G2.bl_count[bits];
while (n != 0) {
m = G2.heap[--h];
if (m > desc->max_code)
if (m > max_code)
continue;
if (tree[m].Len != (unsigned) bits) {
Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len, bits));
@@ -1238,7 +1237,6 @@ static void gen_bitlen(const tree_desc *desc)
n--;
}
}
#undef tree
}
/* ===========================================================================
@@ -1249,13 +1247,12 @@ static void gen_bitlen(const tree_desc *desc)
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
*/
static void gen_codes(ct_data *tree, int max_code)
static void gen_codes(ct_data * tree, int max_code)
{
/* next_code[] and code used to be "ush", but "unsigned" results in smaller code */
unsigned next_code[MAX_BITS + 1]; /* next code value for each bit length */
unsigned code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
ush next_code[MAX_BITS + 1]; /* next code value for each bit length */
ush code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
/* The distribution counts are first used to generate the code values
* without bit reversal.
@@ -1307,7 +1304,7 @@ do { \
pqdownheap(tree, SMALLEST); \
} while (0)
static void build_tree(tree_desc *desc)
static void build_tree(tree_desc * desc)
{
ct_data *tree = desc->dyn_tree;
ct_data *stree = desc->static_tree;
@@ -1385,10 +1382,10 @@ static void build_tree(tree_desc *desc)
/* At this point, the fields freq and dad are set. We can now
* generate the bit lengths.
*/
gen_bitlen(desc);
gen_bitlen((tree_desc *) desc);
/* The field len is now set, we can generate the bit codes */
gen_codes(tree, max_code);
gen_codes((ct_data *) tree, max_code);
}
/* ===========================================================================
@@ -1397,7 +1394,7 @@ static void build_tree(tree_desc *desc)
* counts. (The contribution of the bit length codes will be added later
* during the construction of bl_tree.)
*/
static void scan_tree(ct_data *tree, int max_code)
static void scan_tree(ct_data * tree, int max_code)
{
int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */
@@ -1449,7 +1446,7 @@ static void scan_tree(ct_data *tree, int max_code)
* Send a literal or distance tree in compressed form, using the codes in
* bl_tree.
*/
static void send_tree(const ct_data *tree, int max_code)
static void send_tree(ct_data * tree, int max_code)
{
int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */
@@ -1625,7 +1622,7 @@ static int ct_tally(int dist, int lc)
/* ===========================================================================
* Send the block data compressed using the given Huffman trees
*/
static void compress_block(const ct_data *ltree, const ct_data *dtree)
static void compress_block(ct_data * ltree, ct_data * dtree)
{
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
@@ -1675,7 +1672,7 @@ static void compress_block(const ct_data *ltree, const ct_data *dtree)
* trees or store, and output the encoded block to the zip file. This function
* returns the total compressed length for the file so far.
*/
static void flush_block(const char *buf, ulg stored_len, int eof)
static void flush_block(char *buf, ulg stored_len, int eof)
{
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex; /* index of last bit length code of non zero freq */
@@ -1922,7 +1919,7 @@ static void bi_init(void)
/* ===========================================================================
* Initialize the "longest match" routines for a new file
*/
static void lm_init(void)
static void lm_init(unsigned *flags16p)
{
unsigned j;
@@ -1930,6 +1927,8 @@ static void lm_init(void)
memset(head, 0, HASH_SIZE * sizeof(*head));
/* prev will be initialized on the fly */
/* speed options for the general purpose bit flag */
*flags16p |= 2; /* FAST 4, SLOW 2 */
/* ??? reduce max_chain_length for binary files */
//G1.strstart = 0; // globals are zeroed in pack_gzip()
@@ -2077,16 +2076,10 @@ static void zip(void)
bi_init();
ct_init();
lm_init();
deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
lm_init(&deflate_flags);
deflate_flags = 0x300; /* extra flags. OS id = 3 (Unix) */
#if ENABLE_FEATURE_GZIP_LEVELS
/* Note that comp_level < 4 do not exist in this version of gzip */
if (comp_level_minus4 == 9 - 4) {
deflate_flags |= 0x02; /* SLOW flag */
}
#endif
put_16bit(deflate_flags);
put_16bit(deflate_flags | 0x300); /* extra flags. OS id = 3 (Unix) */
/* The above 32-bit misaligns outbuf (10 bytes are stored), flush it */
flush_outbuf_if_32bit_optimized();
@@ -2229,11 +2222,8 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_GZIP_LEVELS
opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */
if (opt == 0)
opt = 1 << 5; /* default: 6 */
opt = 1 << 6; /* default: 6 */
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
comp_level_minus4 = opt;
max_chain_length = 1 << gzip_level_config[opt].chain_shift;
good_match = gzip_level_config[opt].good;
max_lazy_match = gzip_level_config[opt].lazy2 * 2;
+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
+2 -2
View File
@@ -103,7 +103,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
struct stat existing_sb;
if (lstat(dst_name, &existing_sb) == -1) {
if (errno != ENOENT) {
bb_simple_perror_msg_and_die("can't stat old file");
bb_perror_msg_and_die("can't stat old file");
}
}
else if (existing_sb.st_mtime >= file_header->mtime) {
@@ -207,7 +207,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
break;
default:
bb_simple_error_msg_and_die("unrecognized file type");
bb_error_msg_and_die("unrecognized file type");
}
if (!S_ISLNK(file_header->mode)) {
@@ -20,7 +20,7 @@ enum {
TAR_MAX,
};
static const char *const tar_var[] ALIGN_PTR = {
static const char *const tar_var[] = {
// "FILETYPE",
"MODE",
"FILENAME",
+1 -1
View File
@@ -817,7 +817,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
break;
}
if (bd->headerCRC != bd->totalCRC) {
bb_simple_error_msg("CRC error");
bb_error_msg("CRC error");
break;
}
+59 -74
View File
@@ -39,8 +39,7 @@ typedef struct huft_t {
unsigned char e; /* number of extra bits or operation */
unsigned char b; /* number of bits in this code or subcode */
union {
unsigned n; /* literal, length base, or distance base */
/* ^^^^^ was "unsigned short", but that results in larger code */
unsigned short n; /* literal, length base, or distance base */
struct huft_t *t; /* pointer to next level of table */
} v;
} huft_t;
@@ -185,26 +184,29 @@ static const uint16_t mask_bits[] ALIGN2 = {
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
/* Put lengths/offsets and extra bits in a struct of arrays
* to make calls to huft_build() have one fewer parameter.
*/
struct cp_ext {
uint16_t cp[31];
uint8_t ext[31];
/* Copy lengths for literal codes 257..285 */
static const uint16_t cplens[] ALIGN2 = {
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
};
/* 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 = {
/*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 */
/* Extra bits for literal codes 257..285 */
static const uint8_t cplext[] ALIGN1 = {
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 for distance codes 0..29 */
static const uint16_t cpdist[] ALIGN2 = {
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
};
/* Copy offsets and extra bits for distance codes 0..29 */
static const struct cp_ext dist ALIGN2 = {
/*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 }
/* Extra bits for distance codes */
static const uint8_t cpdext[] ALIGN1 = {
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
};
/* Tables for deflate from PKZIP's appnote.txt. */
@@ -220,20 +222,10 @@ static const uint8_t border[] ALIGN1 = {
* each table.
* t: table to free
*/
#define BAD_HUFT(p) ((uintptr_t)(p) & 1)
#define ERR_RET ((huft_t*)(uintptr_t)1)
static void huft_free(huft_t *p)
{
huft_t *q;
/*
* If 'p' has the error bit set we have to clear it, otherwise we might run
* into a segmentation fault or an invalid pointer to free(p)
*/
if (BAD_HUFT(p)) {
p = (huft_t*)((uintptr_t)(p) ^ (uintptr_t)(ERR_RET));
}
/* Go through linked list, freeing from the malloced (t[-1]) address. */
while (p) {
q = (--p)->v.t;
@@ -285,23 +277,22 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
/* Given a list of code lengths and a maximum table size, make a set of
* tables to decode that set of codes.
* tables to decode that set of codes. Return zero on success, one if
* the given code set is incomplete (the tables are still built in this
* case), two if the input is invalid (an oversubscribed set of lengths)
* - in this case stores NULL in *t.
*
* b: code lengths in bits (all assumed <= BMAX)
* n: number of codes (assumed <= N_MAX)
* s: number of simple-valued codes (0..s-1)
* cp_ext->cp,ext: list of base values/extra bits for non-simple codes
* d: list of base values for non-simple codes
* e: list of extra bits for non-simple codes
* t: result: starting table
* m: maximum lookup bits, returns actual
* result: starting table
*
* On error, returns a value with lowest-bit set on error.
* It can be just the value of 0x1,
* or a valid pointer to a Huffman table, ORed with 0x1 if incompete table
* is given: "fixed inflate" decoder feeds us such data.
*/
static huft_t* huft_build(const unsigned *b, const unsigned n,
const unsigned s, const struct cp_ext *cp_ext,
unsigned *m)
static int huft_build(const unsigned *b, const unsigned n,
const unsigned s, const unsigned short *d,
const unsigned char *e, huft_t **t, unsigned *m)
{
unsigned a; /* counter for codes of length k */
unsigned c[BMAX + 1]; /* bit length count table */
@@ -323,12 +314,12 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
unsigned *xp; /* pointer into x */
int y; /* number of dummy codes added */
unsigned z; /* number of entries in current table */
huft_t *result;
huft_t **t;
/* Length of EOB code, if any */
eob_len = n > 256 ? b[256] : BMAX;
*t = NULL;
/* Generate counts for each bit length */
memset(c, 0, sizeof(c));
p = b;
@@ -344,8 +335,9 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
q[1].b = 1;
q[2].e = 99; /* invalid code marker */
q[2].b = 1;
*t = q + 1;
*m = 1;
return q + 1;
return 0;
}
/* Find minimum and maximum length, bound *m by those */
@@ -361,11 +353,11 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
for (y = 1 << j; j < i; j++, y <<= 1) {
y -= c[j];
if (y < 0)
return ERR_RET; /* bad input: more codes than bits */
return 2; /* bad input: more codes than bits */
}
y -= c[i];
if (y < 0)
return ERR_RET;
return 2;
c[i] += y;
/* Generate starting offsets into the value table for each length */
@@ -392,8 +384,6 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
} while (++i < n);
/* Generate the Huffman codes and for each, make the table entries */
result = ERR_RET;
t = &result;
x[0] = i = 0; /* first Huffman code is zero */
p = v; /* grab values in bit order */
htl = -1; /* no tables yet--level -1 */
@@ -459,8 +449,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
r.v.n = (unsigned short) (*p++); /* simple code is just the value */
} else {
r.e = (unsigned char) cp_ext->ext[*p - s]; /* non-simple--look up in lists */
r.v.n = cp_ext->cp[*p++ - s];
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
r.v.n = d[*p++ - s];
}
/* fill code-like entries with r */
@@ -485,11 +475,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
/* return actual size of base table */
*m = ws[1];
if (y != 0 && g != 1) /* we were given an incomplete table */
/* return "result" ORed with 1 */
return (void*)((uintptr_t)result | 1);
return result;
/* Return 1 if we were given an incomplete table */
return y != 0 && g != 1;
}
@@ -790,17 +777,14 @@ static int inflate_block(STATE_PARAM smallint *e)
for (; i < 288; i++) /* make a complete, but wrong code set */
ll[i] = 8;
bl = 7;
inflate_codes_tl = huft_build(ll, 288, 257, &lit, &bl);
/* ^^^ never returns error here - we use known data */
huft_build(ll, 288, 257, cplens, cplext, &inflate_codes_tl, &bl);
/* huft_build() never return nonzero - we use known data */
/* set up distance table */
for (i = 0; i < 30; i++) /* make an incomplete code set */
ll[i] = 5;
bd = 5;
inflate_codes_td = huft_build(ll, 30, 0, &dist, &bd);
/* ^^^ does return error here! (lsb bit is set) - we gave it incomplete code set */
/* clearing error bit: */
inflate_codes_td = (void*)((uintptr_t)inflate_codes_td & ~(uintptr_t)1);
huft_build(ll, 30, 0, cpdist, cpdext, &inflate_codes_td, &bd);
/* set up data for inflate_codes() */
inflate_codes_setup(PASS_STATE bl, bd);
@@ -866,9 +850,9 @@ static int inflate_block(STATE_PARAM smallint *e)
/* build decoding table for trees - single level, 7 bit lookup */
bl = 7;
inflate_codes_tl = huft_build(ll, 19, 19, NULL, &bl);
if (BAD_HUFT(inflate_codes_tl)) {
abort_unzip(PASS_STATE_ONLY); /* incomplete code set */
i = huft_build(ll, 19, 19, NULL, NULL, &inflate_codes_tl, &bl);
if (i != 0) {
abort_unzip(PASS_STATE_ONLY); //return i; /* incomplete code set */
}
/* read in literal and distance code lengths */
@@ -931,13 +915,14 @@ static int inflate_block(STATE_PARAM smallint *e)
/* build the decoding tables for literal/length and distance codes */
bl = lbits;
inflate_codes_tl = huft_build(ll, nl, 257, &lit, &bl);
if (BAD_HUFT(inflate_codes_tl)) {
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
bd = dbits;
inflate_codes_td = huft_build(ll + nl, nd, 0, &dist, &bd);
if (BAD_HUFT(inflate_codes_td)) {
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
@@ -1027,7 +1012,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
error_msg = "corrupted data";
if (setjmp(error_jmp)) {
/* Error from deep inside zip machinery */
bb_simple_error_msg(error_msg);
bb_error_msg(error_msg);
n = -1;
goto ret;
}
@@ -1100,7 +1085,7 @@ static int top_up(STATE_PARAM unsigned n)
bytebuffer_offset = 0;
bytebuffer_size = full_read(gunzip_src_fd, &bytebuffer[count], bytebuffer_max - count);
if ((int)bytebuffer_size < 0) {
bb_simple_error_msg(bb_msg_read_error);
bb_error_msg(bb_msg_read_error);
return 0;
}
bytebuffer_size += count;
@@ -1226,7 +1211,7 @@ unpack_gz_stream(transformer_state_t *xstate)
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
bad_magic:
bb_simple_error_msg("invalid magic");
bb_error_msg("invalid magic");
return -1;
}
if (magic2 == COMPRESS_MAGIC) {
@@ -1248,7 +1233,7 @@ unpack_gz_stream(transformer_state_t *xstate)
again:
if (!check_header_gzip(PASS_STATE xstate)) {
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
total = -1;
goto ret;
}
@@ -1261,7 +1246,7 @@ unpack_gz_stream(transformer_state_t *xstate)
total += n;
if (!top_up(PASS_STATE 8)) {
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
total = -1;
goto ret;
}
@@ -1269,7 +1254,7 @@ unpack_gz_stream(transformer_state_t *xstate)
/* Validate decompression - crc */
v32 = buffer_read_le_u32(PASS_STATE_ONLY);
if ((~gunzip_crc) != v32) {
bb_simple_error_msg("crc error");
bb_error_msg("crc error");
total = -1;
goto ret;
}
@@ -1277,7 +1262,7 @@ unpack_gz_stream(transformer_state_t *xstate)
/* Validate decompression - size */
v32 = buffer_read_le_u32(PASS_STATE_ONLY);
if ((uint32_t)gunzip_bytes_out != v32) {
bb_simple_error_msg("incorrect length");
bb_error_msg("incorrect length");
total = -1;
}
+5 -5
View File
@@ -113,7 +113,7 @@ unpack_Z_stream(transformer_state_t *xstate)
/* xread isn't good here, we have to return - caller may want
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
bb_simple_error_msg("short read");
bb_error_msg("short read");
goto err;
}
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_state_t *xstate)
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
if (rsize < 0)
bb_simple_error_msg_and_die(bb_msg_read_error);
bb_error_msg_and_die(bb_msg_read_error);
insize += rsize;
}
@@ -200,7 +200,7 @@ unpack_Z_stream(transformer_state_t *xstate)
if (oldcode == -1) {
if (code >= 256)
bb_simple_error_msg_and_die("corrupted data"); /* %ld", code); */
bb_error_msg_and_die("corrupted data"); /* %ld", code); */
oldcode = code;
finchar = (int) oldcode;
outbuf[outpos++] = (unsigned char) finchar;
@@ -236,7 +236,7 @@ unpack_Z_stream(transformer_state_t *xstate)
insize, posbits, p[-1], p[0], p[1], p[2], p[3],
(posbits & 07));
*/
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
goto err;
}
@@ -247,7 +247,7 @@ unpack_Z_stream(transformer_state_t *xstate)
/* Generate output characters in reverse order */
while (code >= 256) {
if (stackp <= &htabof(0))
bb_simple_error_msg_and_die("corrupted data");
bb_error_msg_and_die("corrupted data");
*--stackp = tab_suffixof(code);
code = tab_prefixof(code);
}
+4 -7
View File
@@ -59,7 +59,7 @@ static void rc_read(rc_t *rc)
//TODO: return -1 instead
//This will make unlzma delete broken unpacked file on unpack errors
if (buffer_size <= 0)
bb_simple_error_msg_and_die("unexpected EOF");
bb_error_msg_and_die("unexpected EOF");
rc->buffer_end = RC_BUFFER + buffer_size;
rc->ptr = RC_BUFFER;
}
@@ -234,7 +234,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|| header.pos >= (9 * 5 * 5)
) {
bb_simple_error_msg("bad lzma header");
bb_error_msg("bad lzma header");
return -1;
}
@@ -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;
@@ -516,7 +513,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
* potentially more detailed information).
* Do not fail silently.
*/
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
total_written = -1; /* failure */
}
rc_free(rc);
+2 -2
View File
@@ -74,7 +74,7 @@ unpack_xz_stream(transformer_state_t *xstate)
if (iobuf.in_pos == iobuf.in_size) {
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
if (rd < 0) {
bb_simple_error_msg(bb_msg_read_error);
bb_error_msg(bb_msg_read_error);
total = -1;
break;
}
@@ -141,7 +141,7 @@ unpack_xz_stream(transformer_state_t *xstate)
continue;
}
if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
total = -1;
break;
}
+5 -5
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)
@@ -22,7 +22,7 @@ static unsigned read_num(char *str, int base, int len)
* on misformatted numbers bb_strtou returns all-ones */
err = bb_strtou(str, NULL, base);
if (err == -1)
bb_simple_error_msg_and_die("invalid ar header");
bb_error_msg_and_die("invalid ar header");
return err;
}
@@ -53,7 +53,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
archive_handle->offset += 60;
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
bb_simple_error_msg_and_die("invalid ar header");
bb_error_msg_and_die("invalid ar header");
/*
* Note that the fields MUST be read in reverse order as
@@ -86,7 +86,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
return get_header_ar(archive_handle);
}
#else
bb_simple_error_msg_and_die("long filenames not supported");
bb_error_msg_and_die("long filenames not supported");
#endif
}
/* Only size is always present, the rest may be missing in
@@ -107,7 +107,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
long_offset = read_num(&ar.formatted.name[1], 10,
sizeof(ar.formatted.name) - 1);
if (long_offset >= archive_handle->ar__long_name_size) {
bb_simple_error_msg_and_die("can't resolve long filename");
bb_error_msg_and_die("can't resolve long filename");
}
typed->name = xstrdup(archive_handle->ar__long_names + long_offset);
} else
+3 -3
View File
@@ -33,14 +33,14 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
goto create_hardlinks;
}
if (size != 110) {
bb_simple_error_msg_and_die("short read");
bb_error_msg_and_die("short read");
}
archive_handle->offset += 110;
if (!is_prefixed_with(&cpio_header[0], "07070")
|| (cpio_header[5] != '1' && cpio_header[5] != '2')
) {
bb_simple_error_msg_and_die("unsupported cpio format, use newc or crc");
bb_error_msg_and_die("unsupported cpio format, use newc or crc");
}
if (sscanf(cpio_header + 6,
@@ -50,7 +50,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
&inode, &mode, &uid, &gid,
&nlink, &mtime, &size,
&major, &minor, &namesize) != 10)
bb_simple_error_msg_and_die("damaged cpio file");
bb_error_msg_and_die("damaged cpio file");
file_header->mode = mode;
/* "cpio -R USER:GRP" support: */
if (archive_handle->cpio__owner.uid != (uid_t)-1L)
+8 -8
View File
@@ -32,7 +32,7 @@ static unsigned long long getOctal(char *str, int len)
if (*end != '\0' && *end != ' ') {
int8_t first = str[0];
if (!(first & 0x80))
bb_simple_error_msg_and_die("corrupted octal value in tar header");
bb_error_msg_and_die("corrupted octal value in tar header");
/*
* GNU tar uses "base-256 encoding" for very large numbers.
* Encoding is binary, with highest bit always set as a marker
@@ -100,7 +100,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|| errno != EINVAL
|| *end != ' '
) {
bb_simple_error_msg("malformed extended header, skipped");
bb_error_msg("malformed extended header, skipped");
// More verbose version:
//bb_error_msg("malformed extended header at %"OFF_FMT"d, skipped",
// archive_handle->offset - (sz + len));
@@ -194,13 +194,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* the very first read fails. Grrr.
*/
if (archive_handle->offset == 0)
bb_simple_error_msg("short read");
bb_error_msg("short read");
/* this merely signals end of archive, not exit(1): */
return EXIT_FAILURE;
}
if (i != 512) {
IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
bb_simple_error_msg_and_die("short read");
bb_error_msg_and_die("short read");
}
#else
@@ -243,11 +243,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
goto err;
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
err:
bb_simple_error_msg_and_die("invalid tar magic");
bb_error_msg_and_die("invalid tar magic");
archive_handle->offset = 0;
goto again_after_align;
#endif
bb_simple_error_msg_and_die("invalid tar magic");
bb_error_msg_and_die("invalid tar magic");
}
/* Do checksum on headers.
@@ -282,7 +282,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
if (sum_u != sum
IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)
) {
bb_simple_error_msg_and_die("invalid tar header checksum");
bb_error_msg_and_die("invalid tar header checksum");
}
/* GET_OCTAL trashes subsequent field, therefore we call it
@@ -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
+3 -3
View File
@@ -15,7 +15,7 @@ int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
if (!xstate->signature_skipped) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
bb_simple_error_msg("invalid magic");
bb_error_msg("invalid magic");
return -1;
}
xstate->signature_skipped = 2;
@@ -46,7 +46,7 @@ ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf
} else {
nwrote = full_write(xstate->dst_fd, buf, bufsize);
if (nwrote != (ssize_t)bufsize) {
bb_simple_perror_msg("write");
bb_perror_msg("write");
nwrote = -1;
goto ret;
}
@@ -205,7 +205,7 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
/* No known magic seen */
if (fail_if_not_compressed)
bb_simple_error_msg_and_die("no gzip"
bb_error_msg_and_die("no gzip"
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
IF_FEATURE_SEAMLESS_XZ("/xz")
" magic");
+1 -1
View File
@@ -13,6 +13,6 @@ void FAST_FUNC seek_by_jump(int fd, off_t amount)
if (errno == ESPIPE)
seek_by_read(fd, amount);
else
bb_simple_perror_msg_and_die("seek failure");
bb_perror_msg_and_die("seek failure");
}
}
+2 -2
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)
{
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
if (!is_prefixed_with(magic, AR_MAGIC)) {
bb_simple_error_msg_and_die("invalid ar magic");
bb_error_msg_and_die("invalid ar magic");
}
ar_archive->offset += AR_MAGIC_LEN;
+7 -7
View File
@@ -752,7 +752,7 @@ static FAST_FUNC void lzo_check(
*/
uint32_t c = fn(init, buf, len);
if (c != ref)
bb_simple_error_msg_and_die("checksum error");
bb_error_msg_and_die("checksum error");
}
/**********************************************************************/
@@ -785,15 +785,15 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
/* error if split file */
if (dst_len == 0xffffffffL)
/* should not happen - not yet implemented */
bb_simple_error_msg_and_die("this file is a split lzop file");
bb_error_msg_and_die("this file is a split lzop file");
if (dst_len > MAX_BLOCK_SIZE)
bb_simple_error_msg_and_die("corrupted data");
bb_error_msg_and_die("corrupted data");
/* read compressed block size */
src_len = read32();
if (src_len <= 0 || src_len > dst_len)
bb_simple_error_msg_and_die("corrupted data");
bb_error_msg_and_die("corrupted data");
if (dst_len > block_size) {
if (b2) {
@@ -846,7 +846,7 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
r = lzo1x_decompress_safe(b1, src_len, b2, &d /*, NULL*/);
if (r != 0 /*LZO_E_OK*/ || dst_len != d) {
bb_simple_error_msg_and_die("corrupted data");
bb_error_msg_and_die("corrupted data");
}
dst = b2;
} else {
@@ -913,7 +913,7 @@ static void check_magic(void)
unsigned char magic[sizeof(lzop_magic)];
xread(0, magic, sizeof(magic));
if (memcmp(magic, lzop_magic, sizeof(lzop_magic)) != 0)
bb_simple_error_msg_and_die("bad magic number");
bb_error_msg_and_die("bad magic number");
}
/**********************************************************************/
@@ -1049,7 +1049,7 @@ static void lzo_set_method(header_t *h)
else if (option_mask32 & OPT_8)
level = 8;
#else
bb_simple_error_msg_and_die("high compression not compiled in");
bb_error_msg_and_die("high compression not compiled in");
#endif
}
+6 -8
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]);
@@ -545,7 +543,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
}
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
bb_simple_error_msg_and_die("error unpacking");
bb_error_msg_and_die("error unpacking");
if (ENABLE_FEATURE_CLEAN_UP) {
close(rpm_fd);
+48 -80
View File
@@ -232,7 +232,7 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf
}
/* Put an octal string into the specified buffer.
* The number is zero padded and possibly NUL terminated.
* The number is zero padded and possibly null terminated.
* Stores low-order bits only if whole value does not fit. */
static void putOctal(char *cp, int len, off_t value)
{
@@ -283,33 +283,31 @@ static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static void writeLongname(int fd, int type, const char *name, int dir)
{
struct prefilled {
static const struct {
char mode[8]; /* 100-107 */
char uid[8]; /* 108-115 */
char gid[8]; /* 116-123 */
char size[12]; /* 124-135 */
char mtime[12]; /* 136-147 */
} prefilled = {
"0000000",
"0000000",
"0000000",
"00000000000",
"00000000000",
};
struct tar_header_t header;
int size;
memset(&header, 0, sizeof(header));
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));
header.mode [sizeof(header.mode ) - 1] = '\0';
header.uid [sizeof(header.uid ) - 1] = '\0';
header.gid [sizeof(header.gid ) - 1] = '\0';
/* header.size is filled by '0' now, will be corrected below */
header.mtime[sizeof(header.mtime) - 1] = '\0';
dir = !!dir; /* normalize: 0/1 */
size = strlen(name) + 1 + dir; /* GNU tar uses strlen+1 */
/* + dir: account for possible '/' */
memset(&header, 0, sizeof(header));
strcpy(header.name, "././@LongLink");
memcpy(header.mode, prefilled.mode, sizeof(prefilled));
PUT_OCTAL(header.size, size);
header.typeflag = type;
chksum_and_xwrite(fd, &header);
/* Write filename[/] and pad the block. */
@@ -371,7 +369,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
/* If it is larger than 100 bytes, bail out */
if (header.linkname[sizeof(header.linkname)-1]) {
free(lpath);
bb_simple_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return FALSE;
}
# endif
@@ -491,11 +489,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;
@@ -545,7 +542,7 @@ static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
# if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (strlen(header_name) >= NAME_SIZE) {
bb_simple_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return TRUE;
}
# endif
@@ -639,14 +636,8 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
}
xmove_fd(data.rd, 0);
xmove_fd(tfd, 1);
/* exec gzip/bzip2/... program */
//BB_EXECLP(gzip, gzip, "-f", (char *)0); - WRONG for "xz",
// if xz is an enabled applet, it'll be a version which
// can only decompress. We do need to execute external
// program, not applet.
execlp(gzip, gzip, "-f", (char *)0);
/* exec gzip/bzip2 program/applet */
BB_EXECLP(gzip, gzip, "-f", (char *)0);
vfork_exec_errno = errno;
_exit(EXIT_FAILURE);
}
@@ -701,7 +692,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;
}
@@ -724,13 +715,13 @@ static NOINLINE int writeTarFile(
freeHardLinkInfo(&tbInfo->hlInfoHead);
if (errorFlag)
bb_simple_error_msg("error exit delayed from previous errors");
bb_error_msg("error exit delayed from previous errors");
# if SEAMLESS_COMPRESSION
if (gzip) {
int status;
if (safe_waitpid(-1, &status, 0) == -1)
bb_simple_perror_msg("waitpid");
bb_perror_msg("waitpid");
else if (!WIFEXITED(status) || WEXITSTATUS(status))
/* gzip was killed or has exited with nonzero! */
errorFlag = TRUE;
@@ -770,12 +761,12 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_SEAMLESS_GZ("z")
//usage: IF_FEATURE_SEAMLESS_XZ("J")
//usage: IF_FEATURE_SEAMLESS_BZ2("j")
//usage: "a"
//usage: IF_FEATURE_SEAMLESS_LZMA("a")
//usage: IF_FEATURE_TAR_CREATE("h")
//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, ")
@@ -810,11 +801,8 @@ static llist_t *append_file_list_to_list(llist_t *list)
//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: "\n -a (De)compress using lzma"
//usage: )
//usage: )
//usage: "\n -a (De)compress based on extension"
//usage: IF_FEATURE_TAR_CREATE(
//usage: "\n -h Follow symlinks"
//usage: )
@@ -825,36 +813,34 @@ 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:
// 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 ,)
IF_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
IF_FEATURE_SEAMLESS_BZ2( OPTBIT_BZIP2 ,)
IF_FEATURE_SEAMLESS_LZMA(OPTBIT_LZMA ,)
IF_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
IF_FEATURE_SEAMLESS_XZ( OPTBIT_XZ ,)
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit
OPTBIT_AUTOCOMPRESS_BY_EXT,
IF_FEATURE_SEAMLESS_XZ( OPTBIT_XZ ,) // 16th bit
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
OPTBIT_STRIP_COMPONENTS,
IF_FEATURE_SEAMLESS_LZMA(OPTBIT_LZMA ,)
OPTBIT_NORECURSION,
IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,)
OPTBIT_NUMERIC_OWNER,
@@ -873,15 +859,14 @@ enum {
OPT_CREATE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_CREATE )) + 0, // c
OPT_DEREFERENCE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_DEREFERENCE )) + 0, // h
OPT_BZIP2 = IF_FEATURE_SEAMLESS_BZ2( (1 << OPTBIT_BZIP2 )) + 0, // j
OPT_LZMA = IF_FEATURE_SEAMLESS_LZMA((1 << OPTBIT_LZMA )) + 0, // a
OPT_INCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_INCLUDE_FROM)) + 0, // T
OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J
OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
OPT_AUTOCOMPRESS_BY_EXT = 1 << OPTBIT_AUTOCOMPRESS_BY_EXT, // a
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
OPT_STRIP_COMPONENTS = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_STRIP_COMPONENTS)) + 0, // strip-components
OPT_LZMA = IF_FEATURE_TAR_LONG_OPTIONS(IF_FEATURE_SEAMLESS_LZMA((1 << OPTBIT_LZMA))) + 0, // lzma
OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
@@ -911,6 +896,9 @@ static const char tar_longopts[] ALIGN1 =
# if ENABLE_FEATURE_SEAMLESS_BZ2
"bzip2\0" No_argument "j"
# endif
# if ENABLE_FEATURE_SEAMLESS_LZMA
"lzma\0" No_argument "a"
# endif
# if ENABLE_FEATURE_TAR_FROM
"files-from\0" Required_argument "T"
"exclude-from\0" Required_argument "X"
@@ -924,14 +912,10 @@ static const char tar_longopts[] ALIGN1 =
# if ENABLE_FEATURE_SEAMLESS_Z
"compress\0" No_argument "Z"
# endif
"auto-compress\0" No_argument "a"
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
"touch\0" No_argument "m"
# endif
"strip-components\0" Required_argument "\xf8"
# if ENABLE_FEATURE_SEAMLESS_LZMA
"lzma\0" No_argument "\xf9"
# endif
"strip-components\0" Required_argument "\xf9"
"no-recursion\0" No_argument "\xfa"
# if ENABLE_FEATURE_TAR_TO_COMMAND
"to-command\0" Required_argument "\xfb"
@@ -1020,13 +1004,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
"txC:f:Oopvk"
IF_FEATURE_TAR_CREATE( "ch" )
IF_FEATURE_SEAMLESS_BZ2( "j" )
IF_FEATURE_SEAMLESS_LZMA("a" )
IF_FEATURE_TAR_FROM( "T:*X:*")
IF_FEATURE_SEAMLESS_GZ( "z" )
IF_FEATURE_SEAMLESS_XZ( "J" )
IF_FEATURE_SEAMLESS_Z( "Z" )
"a"
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
IF_FEATURE_TAR_LONG_OPTIONS("\xf8:") // --strip-components
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
"\0"
"tt:vv:" // count -t,-v
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
@@ -1036,7 +1020,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
":\xf8+" // --strip-components=NUM
":\xf9+" // --strip-components=NUM
#endif
LONGOPTS
, &base_dir // -C dir
@@ -1055,7 +1039,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
);
#if DBG_OPTION_PARSING
bb_error_msg("opt: 0x%08x", opt);
# define showopt(o) bb_error_msg("opt & %s(%x):\t%x", #o, o, opt & o);
# define showopt(o) bb_error_msg("opt & %s(%x): %x", #o, o, opt & o);
showopt(OPT_TEST );
showopt(OPT_EXTRACT );
showopt(OPT_BASEDIR );
@@ -1068,15 +1052,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
showopt(OPT_CREATE );
showopt(OPT_DEREFERENCE );
showopt(OPT_BZIP2 );
showopt(OPT_LZMA );
showopt(OPT_INCLUDE_FROM );
showopt(OPT_EXCLUDE_FROM );
showopt(OPT_GZIP );
showopt(OPT_XZ );
showopt(OPT_COMPRESS );
showopt(OPT_AUTOCOMPRESS_BY_EXT);
showopt(OPT_NOPRESERVE_TIME );
showopt(OPT_STRIP_COMPONENTS);
showopt(OPT_LZMA );
showopt(OPT_NORECURSION );
showopt(OPT_2COMMAND );
showopt(OPT_NUMERIC_OWNER );
@@ -1167,7 +1150,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_CREATE) {
/* Make sure there is at least one file to tar up */
if (tar_handle->accept == NULL)
bb_simple_error_msg_and_die("empty archive");
bb_error_msg_and_die("empty archive");
tar_fd = STDOUT_FILENO;
/* Mimicking GNU tar 1.15.1: */
@@ -1195,21 +1178,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
bb_perror_msg_and_die("can't open '%s'", tar_filename);
} else {
tar_handle->src_fd = xopen(tar_filename, flags);
#if ENABLE_FEATURE_TAR_CREATE
if ((OPT_GZIP | OPT_BZIP2 | OPT_XZ | OPT_LZMA) != 0 /* at least one is config-enabled */
&& (opt & OPT_AUTOCOMPRESS_BY_EXT)
&& flags != O_RDONLY
) {
if (OPT_GZIP != 0 && is_suffixed_with(tar_filename, "gz"))
opt |= OPT_GZIP;
if (OPT_BZIP2 != 0 && is_suffixed_with(tar_filename, "bz2"))
opt |= OPT_BZIP2;
if (OPT_XZ != 0 && is_suffixed_with(tar_filename, "xz"))
opt |= OPT_XZ;
if (OPT_LZMA != 0 && is_suffixed_with(tar_filename, "lzma"))
opt |= OPT_LZMA;
}
#endif
}
}
+10 -16
View File
@@ -322,7 +322,7 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
static void die_if_bad_fnamesize(unsigned sz)
{
if (sz > 0xfff) /* more than 4k?! no funny business please */
bb_simple_error_msg_and_die("bad archive");
bb_error_msg_and_die("bad archive");
}
static void unzip_skip(off_t skip)
@@ -359,7 +359,7 @@ static void unzip_extract_symlink(llist_t **symlink_placeholders,
xread(zip_fd, target, zip->fmt.ucmpsize);
} else {
#if 1
bb_simple_error_msg_and_die("compressed symlink is not supported");
bb_error_msg_and_die("compressed symlink is not supported");
#else
transformer_state_t xstate;
init_transformer_state(&xstate);
@@ -399,10 +399,10 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
if (zip->fmt.method == 8) {
/* Method 8 - inflate */
if (inflate_unzip(&xstate) < 0)
bb_simple_error_msg_and_die("inflate error");
bb_error_msg_and_die("inflate error");
/* Validate decompression - crc */
if (zip->fmt.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
bb_simple_error_msg_and_die("crc error");
bb_error_msg_and_die("crc error");
}
}
#if ENABLE_FEATURE_UNZIP_BZIP2
@@ -412,7 +412,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
*/
xstate.bytes_out = unpack_bz2_stream(&xstate);
if (xstate.bytes_out < 0)
bb_simple_error_msg_and_die("inflate error");
bb_error_msg_and_die("inflate error");
}
#endif
#if ENABLE_FEATURE_UNZIP_LZMA
@@ -420,7 +420,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
/* Not tested yet */
xstate.bytes_out = unpack_lzma_stream(&xstate);
if (xstate.bytes_out < 0)
bb_simple_error_msg_and_die("inflate error");
bb_error_msg_and_die("inflate error");
}
#endif
#if ENABLE_FEATURE_UNZIP_XZ
@@ -428,7 +428,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
/* Not tested yet */
xstate.bytes_out = unpack_xz_stream(&xstate);
if (xstate.bytes_out < 0)
bb_simple_error_msg_and_die("inflate error");
bb_error_msg_and_die("inflate error");
}
#endif
else {
@@ -439,7 +439,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
if (zip->fmt.ucmpsize != xstate.bytes_out) {
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_simple_error_msg("bad length");
bb_error_msg("bad length");
}
}
@@ -447,7 +447,7 @@ static void my_fgets80(char *buf80)
{
fflush_all();
if (!fgets(buf80, 80, stdin)) {
bb_simple_perror_msg_and_die("can't read standard input");
bb_perror_msg_and_die("can't read standard input");
}
}
@@ -646,14 +646,8 @@ int unzip_main(int argc, char **argv)
}
/* Change dir if necessary */
if (base_dir) {
/* -p DIR: try to create, errors don't matter.
* UnZip 6.00 does no multi-level mkdir (-p DIR1/DIR2 syntax),
* not using bb_make_directory() here (yet?)
*/
mkdir(base_dir, 0777);
if (base_dir)
xchdir(base_dir);
}
if (quiet <= 1) { /* not -qq */
if (quiet == 0) {
+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.
+12 -10
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:
@@ -223,7 +225,7 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize,
if (unicode == PSF2_SEPARATOR) {
break;
} else if (unicode == PSF2_STARTSEQ) {
bb_simple_error_msg_and_die("unicode sequences not implemented");
bb_error_msg_and_die("unicode sequences not implemented");
} else if (unicode >= 0xC0) {
if (unicode >= 0xFC)
unicode &= 0x01, maxct = 5;
@@ -237,12 +239,12 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize,
unicode &= 0x1F, maxct = 1;
do {
if (tailsz <= 0 || *inbuf < 0x80 || *inbuf > 0xBF)
bb_simple_error_msg_and_die("illegal UTF-8 character");
bb_error_msg_and_die("illegal UTF-8 character");
--tailsz;
unicode = (unicode << 6) + (*inbuf++ & 0x3F);
} while (--maxct > 0);
} else if (unicode >= 0x80) {
bb_simple_error_msg_and_die("illegal UTF-8 character");
bb_error_msg_and_die("illegal UTF-8 character");
}
#else
return;
@@ -279,7 +281,7 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
if (len >= sizeof(struct psf1_header) && PSF1_MAGIC_OK(psf1h(buffer))) {
if (psf1h(buffer)->mode > PSF1_MAXMODE)
bb_simple_error_msg_and_die("unsupported psf file mode");
bb_error_msg_and_die("unsupported psf file mode");
if (psf1h(buffer)->mode & PSF1_MODE512)
fontsize = 512;
if (psf1h(buffer)->mode & PSF1_MODEHASTAB)
@@ -290,7 +292,7 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
#if ENABLE_FEATURE_LOADFONT_PSF2
if (len >= sizeof(struct psf2_header) && PSF2_MAGIC_OK(psf2h(buffer))) {
if (psf2h(buffer)->version > PSF2_MAXVERSION)
bb_simple_error_msg_and_die("unsupported psf file version");
bb_error_msg_and_die("unsupported psf file version");
fontsize = psf2h(buffer)->length;
if (psf2h(buffer)->flags & PSF2_HAS_UNICODE_TABLE)
has_table = 2;
@@ -309,19 +311,19 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
} else
#endif
{
bb_simple_error_msg_and_die("input file: bad length or unsupported font type");
bb_error_msg_and_die("input file: bad length or unsupported font type");
}
#if !defined(PIO_FONTX) || defined(__sparc__)
if (fontsize != 256)
bb_simple_error_msg_and_die("only fontsize 256 supported");
bb_error_msg_and_die("only fontsize 256 supported");
#endif
table = font + fontsize * charsize;
buffer += len;
if (table > buffer || (!has_table && table != buffer))
bb_simple_error_msg_and_die("input file: bad length");
bb_error_msg_and_die("input file: bad length");
do_loadfont(fd, font, height, width, charsize, fontsize);
@@ -359,7 +361,7 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
buffer = xmalloc_read(STDIN_FILENO, &len);
// xmalloc_open_zipped_read_close(filename, &len);
if (!buffer)
bb_simple_perror_msg_and_die("error reading input font");
bb_perror_msg_and_die("error reading input font");
do_load(get_console_fd_or_die(), buffer, len);
return EXIT_SUCCESS;
@@ -500,7 +502,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
if (a < 0 || a >= E_TABSZ
|| b < 0 || b > 65535
) {
bb_simple_error_msg_and_die("map format");
bb_error_msg_and_die("map format");
}
// patch map
unicodes[a] = b;
+2 -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.
@@ -68,7 +69,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
xread(STDIN_FILENO, flags, 7);
if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
bb_simple_error_msg_and_die("not a valid binary keymap");
bb_error_msg_and_die("not a valid binary keymap");
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
+3 -2
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.
@@ -86,7 +87,7 @@ static int get_vt_fd(void)
fd = open(DEV_CONSOLE, O_RDONLY | O_NONBLOCK);
if (fd >= 0 && !not_vt_fd(fd))
return fd;
bb_simple_error_msg_and_die("can't find open VT");
bb_error_msg_and_die("can't find open VT");
}
static int find_free_vtno(void)
@@ -97,7 +98,7 @@ static int find_free_vtno(void)
errno = 0;
/*xfunc_error_retval = 3; - do we need compat? */
if (ioctl(fd, VT_OPENQRY, &vtno) != 0 || vtno <= 0)
bb_simple_perror_msg_and_die("can't find open VT");
bb_perror_msg_and_die("can't find open VT");
// Not really needed, grep for DAEMON_CLOSE_EXTRA_FDS
// if (fd > 2)
// close(fd);
+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.
+2 -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.
@@ -55,7 +56,7 @@ static void xset1(struct termios *t)
{
int ret = tcsetattr(STDIN_FILENO, TCSAFLUSH, t);
if (ret) {
bb_simple_perror_msg("can't tcsetattr for stdin");
bb_perror_msg("can't tcsetattr for stdin");
}
}
+2 -2
View File
@@ -21,15 +21,15 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
//usage:#define chgrp_trivial_usage
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... GROUP FILE..."
//usage: "[-RhLHP"IF_DESKTOP("cvf")"]... GROUP FILE..."
//usage:#define chgrp_full_usage "\n\n"
//usage: "Change the group membership of each FILE to GROUP\n"
//usage: "\n -R Recurse"
//usage: "\n -h Affect symlinks instead of symlink targets"
//usage: IF_DESKTOP(
//usage: "\n -L Traverse all symlinks to directories"
//usage: "\n -H Traverse symlinks on command line only"
//usage: "\n -P Don't traverse symlinks (default)"
//usage: IF_DESKTOP(
//usage: "\n -c List changed files"
//usage: "\n -v Verbose"
//usage: "\n -f Hide errors"
+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;
}
+3 -3
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"
@@ -217,7 +217,7 @@ int cp_main(int argc, char **argv)
// flags, FILEUTILS_RMDEST, OPT_parents);
if (flags & OPT_parents) {
if (!(d_flags & 2)) {
bb_simple_error_msg_and_die("with --parents, the destination must be a directory");
bb_error_msg_and_die("with --parents, the destination must be a directory");
}
}
if (flags & FILEUTILS_RMDEST) {
@@ -236,7 +236,7 @@ int cp_main(int argc, char **argv)
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
}
} else if (flags & FILEUTILS_NO_TARGET_DIR) {
bb_simple_error_msg_and_die("too many arguments");
bb_error_msg_and_die("too many arguments");
}
while (1) {
+3 -3
View File
@@ -209,11 +209,11 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
// argc -= optind;
argv += optind;
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields");
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
if (opt & CUT_OPT_DELIM_FLGS) {
if (ltok[0] && ltok[1]) { /* more than 1 char? */
bb_simple_error_msg_and_die("the delimiter must be a single character");
bb_error_msg_and_die("the delimiter must be a single character");
}
delim = ltok[0];
}
@@ -288,7 +288,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
/* make sure we got some cut positions out of all that */
if (nlists == 0)
bb_simple_error_msg_and_die("missing list of positions");
bb_error_msg_and_die("missing list of positions");
/* now that the lists are parsed, we need to sort them to make life
* easier on us when it comes time to print the chars / fields / lines
+62 -52
View File
@@ -33,10 +33,12 @@
//config: Enable option (-I) to output an ISO-8601 compliant
//config: date/time string.
//config:
//config:# defaults to "no": stat's nanosecond field is a bit non-portable
//config:config FEATURE_DATE_NANO
//config: bool "Support %[num]N nanosecond format specifier"
//config: default n # stat's nanosecond field is a bit non-portable
//config: default n # syscall(__NR_clock_gettime)
//config: depends on DATE
//config: select PLATFORM_LINUX
//config: help
//config: Support %[num]N format specifier. Adds ~250 bytes of code.
//config:
@@ -93,25 +95,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 +149,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 +172,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 +185,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 +204,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 +222,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) {
@@ -254,14 +272,13 @@ int date_main(int argc UNUSED_PARAM, char **argv)
#endif
} else {
#if ENABLE_FEATURE_DATE_NANO
clock_gettime(CLOCK_REALTIME, &ts);
/* libc has incredibly messy way of doing this,
* typically requiring -lrt. We just skip all this mess */
syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
#else
time(&ts.tv_sec);
#endif
}
#if !ENABLE_FEATURE_DATE_NANO
ts.tv_nsec = 0;
#endif
localtime_r(&ts.tv_sec, &tm_time);
/* If date string is given, update tm_time, and maybe set date */
@@ -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 {
@@ -284,11 +301,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)
if (date_str[0] != '@')
tm_time.tm_isdst = -1;
ts.tv_sec = validate_tm_time(date_str, &tm_time);
ts.tv_nsec = 0;
/* if setting time, set it */
if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
bb_simple_perror_msg("can't set date");
if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
bb_perror_msg("can't set date");
}
}
@@ -298,34 +314,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 +383,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;
}
+1 -1
View File
@@ -178,7 +178,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
if (!argv[0]) {
mount_table = setmntent(bb_path_mtab_file, "r");
if (!mount_table)
bb_simple_perror_msg_and_die(bb_path_mtab_file);
bb_perror_msg_and_die(bb_path_mtab_file);
}
while (1) {
+1 -1
View File
@@ -188,7 +188,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
/*r =*/ full_write(STDOUT_FILENO, buffer, out - buffer);
free(buffer);
if (/*WRONG:r < 0*/ errno) {
bb_simple_perror_msg(bb_msg_write_error);
bb_perror_msg(bb_msg_write_error);
return 1;
}
return 0;
+1 -1
View File
@@ -79,7 +79,7 @@ int env_main(int argc UNUSED_PARAM, char **argv)
while (*argv && (strchr(*argv, '=') != NULL)) {
if (putenv(*argv) < 0) {
bb_simple_perror_msg_and_die("putenv");
bb_perror_msg_and_die("putenv");
}
++argv;
}
+5 -5
View File
@@ -160,7 +160,7 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
putchar('\t');
}
if (!(opt & OPT_ALL) && ptr != line) {
if ((opt & OPT_INITIAL) && ptr != line) {
printf("%*s%s", len, "", ptr);
break;
}
@@ -207,13 +207,13 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
"ft:a"
"\0"
"ta" /* -t NUM sets -a */,
"first-only\0" No_argument "f"
"first-only\0" No_argument "i"
"tabs\0" Required_argument "t"
"all\0" No_argument "a"
, &opt_t
);
/* -t implies -a, but an explicit -f overrides */
if (opt & OPT_INITIAL) opt &= ~OPT_ALL;
/* -f --first-only is the default */
if (!(opt & OPT_ALL)) opt |= OPT_INITIAL;
}
tab_size = xatou_range(opt_t, 1, UINT_MAX);
@@ -247,7 +247,7 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
/* Now close stdin also */
/* (if we didn't read from it, it's a no-op) */
if (fclose(stdin))
bb_simple_perror_msg_and_die(bb_msg_standard_input);
bb_perror_msg_and_die(bb_msg_standard_input);
fflush_stdout_and_exit(exit_status);
}
+8 -8
View File
@@ -249,7 +249,7 @@ static arith_t arithmetic_common(VALUE *l, VALUE *r, int op)
arith_t li, ri;
if (!toarith(l) || !toarith(r))
bb_simple_error_msg_and_die("non-numeric argument");
bb_error_msg_and_die("non-numeric argument");
li = l->u.i;
ri = r->u.i;
if (op == '+')
@@ -259,7 +259,7 @@ static arith_t arithmetic_common(VALUE *l, VALUE *r, int op)
if (op == '*')
return li * ri;
if (ri == 0)
bb_simple_error_msg_and_die("division by zero");
bb_error_msg_and_die("division by zero");
if (op == '/')
return li / ri;
return li % ri;
@@ -319,19 +319,19 @@ static VALUE *eval7(void)
VALUE *v;
if (!*G.args)
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
if (nextarg("(")) {
G.args++;
v = eval();
if (!nextarg(")"))
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
G.args++;
return v;
}
if (nextarg(")"))
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
return str_value(*G.args++);
}
@@ -353,7 +353,7 @@ static VALUE *eval6(void)
G.args++; /* We have a valid token, so get the next argument. */
if (key == 1) { /* quote */
if (!*G.args)
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
return str_value(*G.args++);
}
if (key == 2) { /* length */
@@ -546,11 +546,11 @@ int expr_main(int argc UNUSED_PARAM, char **argv)
xfunc_error_retval = 2; /* coreutils compat */
G.args = argv + 1;
if (*G.args == NULL) {
bb_simple_error_msg_and_die("too few arguments");
bb_error_msg_and_die("too few arguments");
}
v = eval();
if (*G.args)
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
if (v->type == INTEGER)
printf("%" PF_REZ "d\n", PF_REZ_TYPE v->u.i);
else
+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;
+2 -2
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(
@@ -231,7 +231,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
}
} else if (n < 0) { /* error in get_groups() */
if (ENABLE_DESKTOP)
bb_simple_error_msg_and_die("can't get groups");
bb_error_msg_and_die("can't get groups");
return EXIT_FAILURE;
}
if (ENABLE_FEATURE_CLEAN_UP)
+1 -1
View File
@@ -238,7 +238,7 @@ int install_main(int argc, char **argv)
args[2] = dest;
args[3] = NULL;
if (spawn_and_wait(args)) {
bb_simple_perror_msg("strip");
bb_perror_msg("strip");
ret = EXIT_FAILURE;
}
}
+7 -24
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:
@@ -41,6 +41,7 @@
/* This is a NOEXEC applet. Be very careful! */
#define LN_SYMLINK (1 << 0)
#define LN_FORCE (1 << 1)
#define LN_NODEREFERENCE (1 << 2)
@@ -62,28 +63,13 @@ int ln_main(int argc, char **argv)
int (*link_func)(const char *, const char *);
opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix);
/*
-s, --symbolic make symbolic links instead of hard links
-f, --force remove existing destination files
-n, --no-dereference treat LINK_NAME as a normal file if it is a symbolic link to a directory
-b like --backup but does not accept an argument
--backup[=CONTROL] make a backup of each existing destination file
-S, --suffix=SUFFIX override the usual backup suffix
-v, --verbose
-T, --no-target-directory
-d, -F, --directory allow the superuser to attempt to hard link directories
-i, --interactive prompt whether to remove destinations
-L, --logical dereference TARGETs that are symbolic links
-P, --physical make hard links directly to symbolic links
-r, --relative create symbolic links relative to link location
-t, --target-directory=DIRECTORY specify the DIRECTORY in which to create the links
*/
last = argv[argc - 1];
argv += optind;
argc -= optind;
if ((opts & LN_LINKFILE) && argc > 2) {
bb_simple_error_msg_and_die("-T accepts 2 args max");
bb_error_msg_and_die("-T accepts 2 args max");
}
if (!argv[1]) {
@@ -100,11 +86,8 @@ int ln_main(int argc, char **argv)
src = last;
if (is_directory(src,
/*followlinks:*/ !(opts & (LN_NODEREFERENCE|LN_LINKFILE))
/* Why LN_LINKFILE does not follow links:
* -T/--no-target-directory implies -n/--no-dereference
*/
)
(opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE
)
) {
if (opts & LN_LINKFILE) {
bb_error_msg_and_die("'%s' is a directory", src);
+1 -1
View File
@@ -56,5 +56,5 @@ int logname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
return fflush_all();
}
bb_simple_perror_msg_and_die("getlogin");
bb_perror_msg_and_die("getlogin");
}
+2 -2
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
@@ -300,7 +300,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
}
if (filename_ptr == NULL) {
if (flags & FLAG_WARN) {
bb_simple_error_msg("invalid format");
bb_error_msg("invalid format");
}
count_failed++;
return_value = EXIT_FAILURE;
+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"
+8 -8
View File
@@ -536,7 +536,7 @@ check_and_close(void)
}
if (ferror(stdout)) {
bb_simple_error_msg_and_die(bb_msg_write_error);
bb_error_msg_and_die(bb_msg_write_error);
}
}
@@ -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",
@@ -841,7 +841,7 @@ skip(off_t n_skip)
}
if (n_skip)
bb_simple_error_msg_and_die("can't skip past end of combined input");
bb_error_msg_and_die("can't skip past end of combined input");
}
@@ -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 }
@@ -1308,10 +1308,10 @@ int od_main(int argc UNUSED_PARAM, char **argv)
pseudo_start = o2;
argv[1] = NULL;
} else {
bb_simple_error_msg_and_die("the last two arguments must be offsets");
bb_error_msg_and_die("the last two arguments must be offsets");
}
} else { /* >3 args */
bb_simple_error_msg_and_die("too many arguments");
bb_error_msg_and_die("too many arguments");
}
if (pseudo_start >= 0) {
@@ -1332,7 +1332,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
if (option_mask32 & OPT_N) {
end_offset = n_bytes_to_skip + max_bytes_to_format;
if (end_offset < n_bytes_to_skip)
bb_simple_error_msg_and_die("SKIP + SIZE is too large");
bb_error_msg_and_die("SKIP + SIZE is too large");
}
if (G.n_specs == 0) {
@@ -1389,7 +1389,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
dump(n_bytes_to_skip, end_offset);
if (fclose(stdin))
bb_simple_perror_msg_and_die(bb_msg_standard_input);
bb_perror_msg_and_die(bb_msg_standard_input);
return G.exit_code;
}
+2 -2
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"
@@ -116,7 +116,7 @@ int paste_main(int argc UNUSED_PARAM, char **argv)
if (opt & PASTE_OPT_DELIMITERS) {
if (!delims[0])
bb_simple_error_msg_and_die("-d '' is not supported");
bb_error_msg_and_die("-d '' is not supported");
/* unknown mappings are not changed: "\z" -> '\\' 'z' */
/* trailing backslash, if any, is preserved */
del_cnt = strcpy_and_process_escape_sequences(delims, delims) - delims;
+1 -1
View File
@@ -430,7 +430,7 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
if (ENABLE_ASH_PRINTF
&& applet_name[0] != 'p'
) {
bb_simple_error_msg("usage: printf FORMAT [ARGUMENT...]");
bb_error_msg("usage: printf FORMAT [ARGUMENT...]");
return 2; /* bash compat */
}
bb_show_usage();
+1 -1
View File
@@ -62,7 +62,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
const char *base = bb_get_last_path_component_strip(*argv);
if (DOT_OR_DOTDOT(base)) {
bb_simple_error_msg("can't remove '.' or '..'");
bb_error_msg("can't remove '.' or '..'");
} else if (remove_file(*argv, flags) >= 0) {
continue;
}
+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"
+7 -7
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"
@@ -277,7 +277,7 @@ static int compare_keys(const void *xarg, const void *yarg)
/* Perform actual comparison */
switch (flags & (FLAG_n | FLAG_g | FLAG_M | FLAG_V)) {
default:
bb_simple_error_msg_and_die("unknown sort type");
bb_error_msg_and_die("unknown sort type");
break;
#if defined(HAVE_STRVERSCMP) && HAVE_STRVERSCMP == 1
case FLAG_V:
@@ -398,10 +398,10 @@ static unsigned str2u(char **str)
{
unsigned long lu;
if (!isdigit((*str)[0]))
bb_simple_error_msg_and_die("bad field specification");
bb_error_msg_and_die("bad field specification");
lu = strtoul(*str, str, 10);
if ((sizeof(long) > sizeof(int) && lu > INT_MAX) || !lu)
bb_simple_error_msg_and_die("bad field specification");
bb_error_msg_and_die("bad field specification");
return lu;
}
#endif
@@ -461,7 +461,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_SORT_BIG
if (opts & FLAG_t) {
if (!str_t[0] || str_t[1])
bb_simple_error_msg_and_die("bad -t parameter");
bb_error_msg_and_die("bad -t parameter");
key_separator = str_t[0];
}
/* note: below this point we use option_mask32, not opts,
@@ -504,10 +504,10 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
because comma isn't in OPT_STR */
idx = strchr(OPT_STR, *str_k);
if (!idx)
bb_simple_error_msg_and_die("unknown key option");
bb_error_msg_and_die("unknown key option");
flag = 1 << (idx - OPT_STR);
if (flag & ~FLAG_allowed_for_k)
bb_simple_error_msg_and_die("unknown sort type");
bb_error_msg_and_die("unknown sort type");
/* b after ',' means strip _trailing_ space */
if (i && flag == FLAG_b)
flag = FLAG_bb;
+3 -3
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 },
@@ -127,7 +127,7 @@ int split_main(int argc UNUSED_PARAM, char **argv)
}
if (NAME_MAX < strlen(sfx) + suffix_len)
bb_simple_error_msg_and_die("suffix too long");
bb_error_msg_and_die("suffix too long");
{
char *char_p = xzalloc(suffix_len + 1);
@@ -147,7 +147,7 @@ int split_main(int argc UNUSED_PARAM, char **argv)
do {
if (!remaining) {
if (!pfx)
bb_simple_error_msg_and_die("suffixes exhausted");
bb_error_msg_and_die("suffixes exhausted");
xmove_fd(xopen(pfx, O_WRONLY | O_CREAT | O_TRUNC), 1);
pfx = next_file(pfx, suffix_len);
remaining = cnt;
+41 -37
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")
@@ -149,16 +150,20 @@ static const char *file_type(const struct stat *st)
return "weird file";
}
static const char *human_time(struct timespec *ts)
static const char *human_time(time_t t)
{
char fmt[sizeof("%Y-%m-%d %H:%M:%S.123456789 %z") + /*paranoia*/ 8];
/* Old
static char *str;
str = ctime(&t);
str[strlen(str)-1] = '\0';
return str;
*/
/* coreutils 6.3 compat: */
/* coreutils 6.3 compat */
/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
#define buf bb_common_bufsiz1
setup_common_bufsiz();
sprintf(stpcpy(fmt, "%Y-%m-%d %H:%M:%S"), ".%09u %%z", (unsigned)ts->tv_nsec);
strftime(buf, COMMON_BUFSIZE, fmt, localtime(&ts->tv_sec));
strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000");
return buf;
#undef buf
}
@@ -208,7 +213,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
@@ -379,19 +384,19 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
strcat(pformat, "lu");
printf(pformat, (unsigned long) statbuf->st_blksize);
} else if (m == 'x') {
printfs(pformat, human_time(&statbuf->st_atim));
printfs(pformat, human_time(statbuf->st_atime));
} else if (m == 'X') {
strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
/* note: (unsigned long) would be wrong:
* imagine (unsigned long64)int32 */
printf(pformat, (long) statbuf->st_atime);
} else if (m == 'y') {
printfs(pformat, human_time(&statbuf->st_mtim));
printfs(pformat, human_time(statbuf->st_mtime));
} else if (m == 'Y') {
strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
printf(pformat, (long) statbuf->st_mtime);
} else if (m == 'z') {
printfs(pformat, human_time(&statbuf->st_ctim));
printfs(pformat, human_time(statbuf->st_ctime));
} else if (m == 'Z') {
strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
printf(pformat, (long) statbuf->st_ctime);
@@ -496,7 +501,7 @@ static bool do_statfs(const char *filename, const char *format)
if (format == NULL) {
# if !ENABLE_SELINUX
format = (option_mask32 & OPT_TERSE
? "%n %i %l %t %s %b %f %a %c %d"
? "%n %i %l %t %s %b %f %a %c %d\n"
: " File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
@@ -504,26 +509,25 @@ static bool do_statfs(const char *filename, const char *format)
"Inodes: Total: %-10c Free: %d");
# else
format = (option_mask32 & OPT_TERSE
? (option_mask32 & OPT_SELINUX
? "%n %i %l %t %s %b %f %a %c %d %C"
: "%n %i %l %t %s %b %f %a %c %d")
: (option_mask32 & OPT_SELINUX
? " File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
"Inodes: Total: %-10c Free: %d"
" S_context: %C"
: " File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
"Inodes: Total: %-10c Free: %d")
? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n":
"%n %i %l %t %s %b %f %a %c %d\n")
: (option_mask32 & OPT_SELINUX ?
" File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
"Inodes: Total: %-10c Free: %d"
" S_context: %C\n":
" File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
"Inodes: Total: %-10c Free: %d\n")
);
# endif /* SELINUX */
}
print_it(format, filename, print_statfs, &statfsbuf IF_SELINUX(, scontext));
#else /* !FEATURE_STAT_FORMAT */
#else /* FEATURE_STAT_FORMAT */
format = (option_mask32 & OPT_TERSE
? "%s %llx %lu "
: " File: \"%s\"\n"
@@ -620,14 +624,14 @@ static bool do_stat(const char *filename, const char *format)
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
" Device type: %t,%T\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"Access: %x\n" "Modify: %y\n" "Change: %z";
"Access: %x\n" "Modify: %y\n" "Change: %z\n";
} else {
format =
" File: %N\n"
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"Access: %x\n" "Modify: %y\n" "Change: %z";
"Access: %x\n" "Modify: %y\n" "Change: %z\n";
}
}
# else
@@ -646,14 +650,14 @@ static bool do_stat(const char *filename, const char *format)
" Device type: %t,%T\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
" S_Context: %C\n"
"Access: %x\n" "Modify: %y\n" "Change: %z"
"Access: %x\n" "Modify: %y\n" "Change: %z\n"
:
" File: %N\n"
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
" Device type: %t,%T\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"Access: %x\n" "Modify: %y\n" "Change: %z"
"Access: %x\n" "Modify: %y\n" "Change: %z\n"
);
} else {
format = (option_mask32 & OPT_SELINUX ?
@@ -662,13 +666,13 @@ static bool do_stat(const char *filename, const char *format)
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"S_Context: %C\n"
"Access: %x\n" "Modify: %y\n" "Change: %z"
"Access: %x\n" "Modify: %y\n" "Change: %z\n"
:
" File: %N\n"
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"Access: %x\n" "Modify: %y\n" "Change: %z"
"Access: %x\n" "Modify: %y\n" "Change: %z\n"
);
}
}
@@ -745,9 +749,9 @@ static bool do_stat(const char *filename, const char *format)
if (option_mask32 & OPT_SELINUX)
printf(" S_Context: %s\n", scontext);
# endif
printf("Access: %s\n", human_time(&statbuf.st_atim));
printf("Modify: %s\n", human_time(&statbuf.st_mtim));
printf("Change: %s\n", human_time(&statbuf.st_ctim));
printf("Access: %s\n", human_time(statbuf.st_atime));
printf("Modify: %s\n", human_time(statbuf.st_mtime));
printf("Change: %s\n", human_time(statbuf.st_ctime));
}
#endif /* FEATURE_STAT_FORMAT */
return 1;
+5 -5
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 },
@@ -1320,7 +1320,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
break;
case 'F':
if (file_name)
bb_simple_error_msg_and_die("only one device may be specified");
bb_error_msg_and_die("only one device may be specified");
file_name = &arg[i+1]; /* "-Fdevice" ? */
if (!file_name[0]) { /* nope, "-F device" */
int p = k+1; /* argv[p] is argnext */
@@ -1405,13 +1405,13 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) ==
(STTY_verbose_output | STTY_recoverable_output)
) {
bb_simple_error_msg_and_die("-a and -g are mutually exclusive");
bb_error_msg_and_die("-a and -g are mutually exclusive");
}
/* Specifying -a or -g with non-options is an error */
if ((stty_state & (STTY_verbose_output | STTY_recoverable_output))
&& !(stty_state & STTY_noargs)
) {
bb_simple_error_msg_and_die("modes may not be set when -a or -g is used");
bb_error_msg_and_die("modes may not be set when -a or -g is used");
}
/* Now it is safe to start doing things */
+2 -2
View File
@@ -89,7 +89,7 @@ static ssize_t tail_read(int fd, char *buf, size_t count)
r = full_read(fd, buf, count);
if (r < 0) {
bb_simple_perror_msg(bb_msg_read_error);
bb_perror_msg(bb_msg_read_error);
G.exitcode = EXIT_FAILURE;
}
@@ -186,7 +186,7 @@ int tail_main(int argc, char **argv)
} while (++i < argc);
if (!nfiles)
bb_simple_error_msg_and_die("no files");
bb_error_msg_and_die("no files");
/* prepare the buffer */
tailbufsize = BUFSIZ;
+4 -20
View File
@@ -39,19 +39,6 @@
//usage: "$ cat /tmp/foo\n"
//usage: "Hello\n"
// Bare "tee" with no below options does not install SIGPIPE handler - just dies on it.
// TODO:
// --output-error[=MODE]
// 'warn' diagnose errors writing to any output
// 'warn-nopipe' diagnose errors writing to any output not a pipe
// 'exit' exit on error writing to any output
// 'exit-nopipe' exit on error writing to any output not a pipe
// ^^^ all of these should set SIGPIPE to SIG_IGN.
// Because "exit" mode should print error message and exit1(1) - not die on SIGPIPE.
// "exit-nopipe" does not exit on EPIPE and does not set exitcode to 1 too.
// -p diagnose errors writing to non pipes
// ^^^^ this should set SIGPIPE to SIG_IGN. EPIPE is ignored (same as "warn-nopipe")
#include "libbb.h"
#include "common_bufsiz.h"
@@ -79,12 +66,12 @@ int tee_main(int argc, char **argv)
mode += (retval & 2); /* Since 'a' is the 2nd option... */
if (retval & 1) {
signal(SIGINT, SIG_IGN);
signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */
}
retval = EXIT_SUCCESS;
/* if (opt_p || opt_output_error)
signal(SIGPIPE, SIG_IGN);
*/
/* gnu tee ignores SIGPIPE in case one of the output files is a pipe
* that doesn't consume all its input. Good idea... */
signal(SIGPIPE, SIG_IGN);
/* Allocate an array of FILE *'s, with one extra for a sentinel. */
fp = files = xzalloc(sizeof(FILE *) * (argc + 2));
@@ -92,7 +79,6 @@ int tee_main(int argc, char **argv)
files[0] = stdout;
goto GOT_NEW_FILE;
do {
*fp = stdout;
if (NOT_LONE_DASH(*argv)) {
@@ -116,7 +102,6 @@ int tee_main(int argc, char **argv)
fp = files;
do
fwrite(buf, 1, c, *fp);
/* if (opt_p && fwrite() != c && !EPIPE) bb_error_msg("..."); */
while (*++fp);
}
if (c < 0) { /* Make sure read errors are signaled. */
@@ -128,7 +113,6 @@ int tee_main(int argc, char **argv)
fp = files;
do
putc(c, *fp);
/* if (opt_p && putc() == EOF && !EPIPE) bb_error_msg("..."); */
while (*++fp);
}
#endif
+4 -86
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,11 +408,10 @@ 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 { \
(*(struct test_statics**)not_const_pp(&test_ptr_to_statics)) = xzalloc(sizeof(S)); \
(*(struct test_statics**)&test_ptr_to_statics) = xzalloc(sizeof(S)); \
barrier(); \
} while (0)
#define DEINIT_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)
@@ -907,17 +832,14 @@ int test_main(int argc, char **argv)
--argc;
if (!arg0[1]) { /* "[" ? */
if (NOT_LONE_CHAR(argv[argc], ']')) {
bb_simple_error_msg("missing ]");
bb_error_msg("missing ]");
return 2;
}
} else { /* assuming "[[" */
if (strcmp(argv[argc], "]]") != 0) {
bb_simple_error_msg("missing ]]");
bb_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)) {
+2 -2
View File
@@ -308,7 +308,7 @@ int tr_main(int argc UNUSED_PARAM, char **argv)
str1_length = complement(str1, str1_length);
if (*argv) {
if (argv[0][0] == '\0')
bb_simple_error_msg_and_die("STRING2 cannot be empty");
bb_error_msg_and_die("STRING2 cannot be empty");
str2_length = expand(*argv, &str2);
map(vector, str1, str1_length,
str2, str2_length);
@@ -333,7 +333,7 @@ int tr_main(int argc UNUSED_PARAM, char **argv)
read_chars = safe_read(STDIN_FILENO, str1, TR_BUFSIZ);
if (read_chars <= 0) {
if (read_chars < 0)
bb_simple_perror_msg_and_die(bb_msg_read_error);
bb_perror_msg_and_die(bb_msg_read_error);
break;
}
in_index = 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"
+28 -144
View File
@@ -82,7 +82,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
continue;
}
if (encoded_len > 60) {
bb_simple_error_msg_and_die("line too long");
bb_error_msg_and_die("line too long");
}
dst = line;
@@ -108,9 +108,11 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
fwrite(line, 1, dst - line, dst_stream);
free(line);
}
bb_simple_error_msg_and_die("short file");
bb_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)
{
@@ -164,15 +166,13 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
/* fclose_if_not_stdin(src_stream); - redundant */
return EXIT_SUCCESS;
}
bb_simple_error_msg_and_die("no 'begin' line");
bb_error_msg_and_die("no 'begin' line");
}
#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 ((ssize_t)size < 0)
bb_simple_perror_msg_and_die(bb_msg_read_error);
if (size == 0) {
if (rem != 0) bb_putchar('\n');
if (!size)
break;
}
if ((ssize_t)size < 0)
bb_perror_msg_and_die(bb_msg_read_error);
/* 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);
+1 -1
View File
@@ -66,7 +66,7 @@ int uuencode_main(int argc UNUSED_PARAM, char **argv)
if (!size)
break;
if ((ssize_t)size < 0)
bb_simple_perror_msg_and_die(bb_msg_read_error);
bb_perror_msg_and_die(bb_msg_read_error);
/* Encode the buffer we just read in */
bb_uuencode(dst_buf, src_buf, size, tbl);
bb_putchar('\n');
+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
@@ -317,7 +317,7 @@ static void do_procinit(void)
}
closedir(procdir);
if (!pid)
bb_simple_error_msg_and_die("nothing in /proc - not mounted?");
bb_error_msg_and_die("nothing in /proc - not mounted?");
}
static int do_stop(void)
@@ -337,7 +337,7 @@ static int do_stop(void)
} else if (userspec) {
what = xasprintf("process(es) owned by '%s'", userspec);
} else {
bb_simple_error_msg_and_die("internal error, please report");
bb_error_msg_and_die("internal error, please report");
}
if (!G.found_procs) {
+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"
+3 -3
View File
@@ -196,11 +196,11 @@ int chattr_main(int argc UNUSED_PARAM, char **argv)
/* run sanity checks on all the arguments given us */
if ((g.flags & OPT_SET) && (g.flags & (OPT_ADD|OPT_REM)))
bb_simple_error_msg_and_die("= is incompatible with - and +");
bb_error_msg_and_die("= is incompatible with - and +");
if (g.rf & g.af)
bb_simple_error_msg_and_die("can't set and unset a flag");
bb_error_msg_and_die("can't set and unset a flag");
if (!g.flags)
bb_simple_error_msg_and_die("must use '-v', =, - or +");
bb_error_msg_and_die("must use '-v', =, - or +");
/* now run chattr on all the files passed to us */
do change_attributes(*argv, &g); while (*++argv);
+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,
+4 -4
View File
@@ -431,10 +431,10 @@ static int wait_one(int flags)
if (errno == EINTR)
continue;
if (errno == ECHILD) { /* paranoia */
bb_simple_error_msg("wait: no more children");
bb_error_msg("wait: no more children");
return -1;
}
bb_simple_perror_msg("wait");
bb_perror_msg("wait");
continue;
}
prev = NULL;
@@ -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;
@@ -919,7 +919,7 @@ static void compile_fs_type(char *fs_type)
if (G.fs_type_negated == -1)
G.fs_type_negated = negate;
if (G.fs_type_negated != negate)
bb_simple_error_msg_and_die(
bb_error_msg_and_die(
"either all or none of the filesystem types passed to -t must be prefixed "
"with 'no' or '!'");
}
+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.
+22 -62
View File
@@ -272,8 +272,7 @@ typedef struct tsplitter_s {
/* if previous token class is CONCAT1 and next is CONCAT2, concatenation */
/* operator is inserted between them */
#define TC_CONCAT1 (TC_VARIABLE | TC_ARRTERM | TC_SEQTERM \
| TC_STRING | TC_NUMBER | TC_UOPPOST \
| TC_LENGTH)
| TC_STRING | TC_NUMBER | TC_UOPPOST)
#define TC_CONCAT2 (TC_OPERAND | TC_UOPPRE)
#define OF_RES1 0x010000
@@ -405,7 +404,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,
@@ -1071,10 +1070,8 @@ static uint32_t next_token(uint32_t expected)
const uint32_t *ti;
if (t_rollback) {
debug_printf_parse("%s: using rolled-back token\n", __func__);
t_rollback = FALSE;
} else if (concat_inserted) {
debug_printf_parse("%s: using concat-inserted token\n", __func__);
concat_inserted = FALSE;
t_tclass = save_tclass;
t_info = save_info;
@@ -1203,11 +1200,7 @@ static uint32_t next_token(uint32_t expected)
goto readnext;
/* insert concatenation operator when needed */
debug_printf_parse("%s: %x %x %x concat_inserted?\n", __func__,
(ltclass & TC_CONCAT1), (tc & TC_CONCAT2), (expected & TC_BINOP));
if ((ltclass & TC_CONCAT1) && (tc & TC_CONCAT2) && (expected & TC_BINOP)
&& !(ltclass == TC_LENGTH && tc == TC_SEQSTART) /* but not for "length(..." */
) {
if ((ltclass & TC_CONCAT1) && (tc & TC_CONCAT2) && (expected & TC_BINOP)) {
concat_inserted = TRUE;
save_tclass = tc;
save_info = t_info;
@@ -1215,7 +1208,6 @@ static uint32_t next_token(uint32_t expected)
t_info = OC_CONCAT | SS | P(35);
}
debug_printf_parse("%s: t_tclass=tc=%x\n", __func__, t_tclass);
t_tclass = tc;
}
ltclass = t_tclass;
@@ -1226,7 +1218,6 @@ static uint32_t next_token(uint32_t expected)
EMSG_UNEXP_EOS : EMSG_UNEXP_TOKEN);
}
debug_printf_parse("%s: returning, ltclass:%x t_double:%f\n", __func__, ltclass, t_double);
return ltclass;
#undef concat_inserted
#undef save_tclass
@@ -1291,7 +1282,7 @@ static node *parse_expr(uint32_t iexp)
glptr = NULL;
} else if (tc & (TC_BINOP | TC_UOPPOST)) {
debug_printf_parse("%s: TC_BINOP | TC_UOPPOST tc:%x\n", __func__, tc);
debug_printf_parse("%s: TC_BINOP | TC_UOPPOST\n", __func__);
/* for binary and postfix-unary operators, jump back over
* previous operators with higher priority */
vn = cn;
@@ -1359,10 +1350,8 @@ static node *parse_expr(uint32_t iexp)
v = cn->l.v = xzalloc(sizeof(var));
if (tc & TC_NUMBER)
setvar_i(v, t_double);
else {
else
setvar_s(v, t_string);
xtc &= ~TC_UOPPOST; /* "str"++ is not allowed */
}
break;
case TC_REGEXP:
@@ -1398,12 +1387,7 @@ static node *parse_expr(uint32_t iexp)
case TC_LENGTH:
debug_printf_parse("%s: TC_LENGTH\n", __func__);
next_token(TC_SEQSTART /* length(...) */
| TC_OPTERM /* length; (or newline)*/
| TC_GRPTERM /* length } */
| TC_BINOPX /* length <op> NUM */
| TC_COMMA /* print length, 1 */
);
next_token(TC_SEQSTART | TC_OPTERM | TC_GRPTERM);
rollback_token();
if (t_tclass & TC_SEQSTART) {
/* It was a "(" token. Handle just like TC_BUILTIN */
@@ -1763,34 +1747,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 +1769,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 +1995,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;
@@ -2673,7 +2633,7 @@ static var *evaluate(node *op, var *res)
if (opn == '|') {
rsm->F = popen(R.s, "w");
if (rsm->F == NULL)
bb_simple_perror_msg_and_die("popen");
bb_perror_msg_and_die("popen");
rsm->is_pipe = 1;
} else {
rsm->F = xfopen(R.s, opn=='w' ? "w" : "a");
@@ -3286,7 +3246,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
//argc -= optind;
if (opt & OPT_W)
bb_simple_error_msg("warning: option -W is ignored");
bb_error_msg("warning: option -W is ignored");
if (opt & OPT_F) {
unescape_string_in_place(opt_F);
setvar_s(intvar[FS], opt_F);
+13 -13
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
@@ -1006,7 +1006,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
xfunc_error_retval = 1;
if (gotstdin && (S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode)))
bb_simple_error_msg_and_die("can't compare stdin to a directory");
bb_error_msg_and_die("can't compare stdin to a directory");
/* Compare metadata to check if the files are the same physical file.
*
@@ -1037,7 +1037,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_DIFF_DIR
diffdir(file, s_start);
#else
bb_simple_error_msg_and_die("no support for directory comparison");
bb_error_msg_and_die("no support for directory comparison");
#endif
} else {
bool dirfile = S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode);
+17 -17
View File
@@ -165,7 +165,7 @@ static NOINLINE int searchLines(const char *str, int num1, int num2)
if (*str == '\0') {
if (searchString[0] == '\0') {
bb_simple_error_msg("no previous search string");
bb_error_msg("no previous search string");
return 0;
}
str = searchString;
@@ -228,7 +228,7 @@ static const char* getNum(const char *cp, smallint *retHaveNum, int *retNum)
case '\'':
cp++;
if ((unsigned)(*cp - 'a') >= 26) {
bb_simple_error_msg("bad mark name");
bb_error_msg("bad mark name");
return NULL;
}
haveNum = TRUE;
@@ -314,7 +314,7 @@ static int insertLine(int num, const char *data, int len)
LINE *newLp, *lp;
if ((num < 1) || (num > lastNum + 1)) {
bb_simple_error_msg("inserting at bad line number");
bb_error_msg("inserting at bad line number");
return FALSE;
}
@@ -384,7 +384,7 @@ static int readLines(const char *file, int num)
char *cp;
if ((num < 1) || (num > lastNum + 1)) {
bb_simple_error_msg("bad line for read");
bb_error_msg("bad line for read");
return FALSE;
}
@@ -629,7 +629,7 @@ static void subCommand(const char *cmd, int num1, int num2)
cp = buf;
if (isblank(*cp) || (*cp == '\0')) {
bb_simple_error_msg("bad delimiter for substitute");
bb_error_msg("bad delimiter for substitute");
return;
}
@@ -638,7 +638,7 @@ static void subCommand(const char *cmd, int num1, int num2)
cp = strchr(cp, delim);
if (cp == NULL) {
bb_simple_error_msg("missing 2nd delimiter for substitute");
bb_error_msg("missing 2nd delimiter for substitute");
return;
}
@@ -660,13 +660,13 @@ static void subCommand(const char *cmd, int num1, int num2)
printFlag = TRUE;
break;
default:
bb_simple_error_msg("unknown option for substitute");
bb_error_msg("unknown option for substitute");
return;
}
if (*oldStr == '\0') {
if (searchString[0] == '\0') {
bb_simple_error_msg("no previous search string");
bb_error_msg("no previous search string");
return;
}
oldStr = searchString;
@@ -846,7 +846,7 @@ static void doCommands(void)
case 'f':
if (*cp != '\0' && *cp != ' ') {
bb_simple_error_msg("bad file command");
bb_error_msg("bad file command");
break;
}
cp = skip_whitespace(cp);
@@ -870,7 +870,7 @@ static void doCommands(void)
case 'k':
cp = skip_whitespace(cp);
if ((unsigned)(*cp - 'a') >= 26 || cp[1]) {
bb_simple_error_msg("bad mark name");
bb_error_msg("bad mark name");
break;
}
marks[(unsigned)(*cp - 'a')] = num2;
@@ -887,7 +887,7 @@ static void doCommands(void)
case 'q':
cp = skip_whitespace(cp);
if (have1 || *cp) {
bb_simple_error_msg("bad quit command");
bb_error_msg("bad quit command");
break;
}
if (!dirty)
@@ -903,12 +903,12 @@ static void doCommands(void)
case 'r':
if (*cp != '\0' && *cp != ' ') {
bb_simple_error_msg("bad read command");
bb_error_msg("bad read command");
break;
}
cp = skip_whitespace(cp);
if (*cp == '\0') {
bb_simple_error_msg("no file name");
bb_error_msg("no file name");
break;
}
if (!have1)
@@ -925,14 +925,14 @@ static void doCommands(void)
case 'w':
if (*cp != '\0' && *cp != ' ') {
bb_simple_error_msg("bad write command");
bb_error_msg("bad write command");
break;
}
cp = skip_whitespace(cp);
if (*cp == '\0') {
cp = fileName;
if (!cp) {
bb_simple_error_msg("no file name specified");
bb_error_msg("no file name specified");
break;
}
}
@@ -960,7 +960,7 @@ static void doCommands(void)
case '.':
if (have1) {
bb_simple_error_msg("no arguments allowed");
bb_error_msg("no arguments allowed");
break;
}
printLines(curNum, curNum, FALSE);
@@ -984,7 +984,7 @@ static void doCommands(void)
break;
default:
bb_simple_error_msg("unimplemented command");
bb_error_msg("unimplemented command");
break;
}
}
+2 -3
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"
@@ -264,7 +264,7 @@ static int apply_one_hunk(void)
if (!plist && matcheof) break;
if (backwarn)
fdprintf(2, "Possibly reversed hunk %d at %ld\n",
fdprintf(2,"Possibly reversed hunk %d at %ld\n",
TT.hunknum, TT.linenum);
// File ended before we found a place for this hunk.
@@ -593,7 +593,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
TT.linenum = 0;
TT.hunknum = 0;
}
fflush_all(); // make "patching file F" visible
}
TT.hunknum++;
+3 -3
View File
@@ -30,7 +30,7 @@ static unsigned copy_lines(FILE *src_stream, FILE *dst_stream, unsigned lines_co
break;
}
if (fputs(line, dst_stream) == EOF) {
bb_simple_perror_msg_and_die("error writing to new file");
bb_perror_msg_and_die("error writing to new file");
}
free(line);
lines_count--;
@@ -148,7 +148,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
new_filename = extract_filename(patch_line, patch_level, "+++ ");
if (!new_filename) {
bb_simple_error_msg_and_die("invalid patch");
bb_error_msg_and_die("invalid patch");
}
/* Get access rights from the file to be patched */
@@ -209,7 +209,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
/* src_beg_line will be 0 if it's a new file */
count = src_beg_line - src_cur_line;
if (copy_lines(src_stream, dst_stream, count)) {
bb_simple_error_msg_and_die("bad src file");
bb_error_msg_and_die("bad src file");
}
src_cur_line += count;
dst_cur_line += count;
+1 -1
View File
@@ -200,7 +200,7 @@ int copy_tempfile(int fdin, char *name, char **tempname)
*tempname = xasprintf("%sXXXXXX", name);
fd = mkstemp(*tempname);
if(-1 == fd) bb_simple_perror_msg_and_die("no temp file");
if(-1 == fd) bb_perror_msg_and_die("no temp file");
// Set permissions of output file
fstat(fdin, &statbuf);
Loaded 100 of 513 files, more files were not shown because too many files have changed in this diff. Show more