Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd75474639 | ||
|
|
ebc1c38a92 | ||
|
|
be11940911 | ||
|
|
49a8839638 | ||
|
|
3004510fdc | ||
|
|
d6a8784f27 | ||
|
|
a1c7a9e976 | ||
|
|
2f3352682e | ||
|
|
50ba92128b | ||
|
|
4699b93244 | ||
|
|
244c0ebb4f | ||
|
|
c88d3ec458 |
No files matched your search
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 34
|
||||
PATCHLEVEL = 31
|
||||
SUBLEVEL = 1
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
@@ -612,7 +612,6 @@ quiet_cmd_busybox__ ?= LINK $@
|
||||
"$(core-y)" \
|
||||
"$(libs-y)" \
|
||||
"$(LDLIBS)" \
|
||||
"$(CONFIG_EXTRA_LDLIBS)" \
|
||||
&& $(srctree)/scripts/generate_BUFSIZ.sh --post include/common_bufsiz.h
|
||||
|
||||
# Generate System.map
|
||||
|
||||
+13
-37
@@ -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,)
|
||||
@@ -145,20 +123,15 @@ CFLAGS += --sysroot=$(CONFIG_SYSROOT)
|
||||
export SYSROOT=$(CONFIG_SYSROOT)
|
||||
endif
|
||||
|
||||
# libm may be needed for dc, awk, ntpd
|
||||
LDLIBS += m
|
||||
# Android has no separate crypt library
|
||||
# gcc-4.2.1 fails if we try to feed C source on stdin:
|
||||
# echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
|
||||
# fall back to using a temp file:
|
||||
CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) -lcrypt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
|
||||
RT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) -lrt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
|
||||
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 += crypt
|
||||
endif
|
||||
# librt may be needed for clock_gettime()
|
||||
ifeq ($(RT_AVAILABLE),y)
|
||||
LDLIBS += rt
|
||||
LDLIBS += m crypt
|
||||
else
|
||||
LDLIBS += m
|
||||
endif
|
||||
|
||||
# libpam may use libpthread, libdl and/or libaudit.
|
||||
@@ -184,10 +157,8 @@ LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
|
||||
ifneq (,$(findstring linux,$(shell $(CC) $(CFLAGS) -dumpmachine)))
|
||||
LDLIBS += resolv
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EFENCE),y)
|
||||
LDLIBS += efence
|
||||
@@ -212,6 +183,11 @@ LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXTRA_LDLIBS),)
|
||||
LDLIBS += $(strip $(subst ",,$(CONFIG_EXTRA_LDLIBS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
# Busybox is a stack-fatty so make sure we increase default size
|
||||
# TODO: use "make stksizes" to find & fix big stack users
|
||||
# (we stole scripts/checkstack.pl from the kernel... thanks guys!)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -56,7 +52,7 @@ static int cmp_name(const void *a, const void *b)
|
||||
static int str_isalnum_(const char *s)
|
||||
{
|
||||
while (*s) {
|
||||
if (!isalnum((unsigned char)*s) && *s != '_')
|
||||
if (!isalnum(*s) && *s != '_')
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ int main(int argc, char **argv)
|
||||
|
||||
void bb_show_usage(void)
|
||||
{
|
||||
fputs_stdout(APPLET_full_usage "\n");
|
||||
fputs(APPLET_full_usage "\n", stdout);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
+1
-1
@@ -71,7 +71,7 @@ int main(void)
|
||||
} else {
|
||||
printf(", ");
|
||||
}
|
||||
printf("%s", usage_array[i].aname);
|
||||
printf(usage_array[i].aname);
|
||||
col += len2;
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
@@ -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 "$@"
|
||||
@@ -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,)
|
||||
@@ -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
@@ -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
|
||||
|
||||
|
||||
+8
-14
@@ -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"
|
||||
|
||||
@@ -284,7 +284,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage: "\n -t Test file integrity"
|
||||
//usage:
|
||||
//usage:#define gunzip_example_usage
|
||||
//usage: "$ ls -la /tmp/BusyBox*\n"
|
||||
@@ -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);
|
||||
@@ -407,8 +407,6 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//usage:#define bzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define bzcat_full_usage "\n\n"
|
||||
@@ -463,21 +461,19 @@ 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"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//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"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//usage:#define lzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
@@ -536,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 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 integrity"
|
||||
//usage:
|
||||
//usage:#define xzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
|
||||
+4
-6
@@ -50,19 +50,17 @@
|
||||
//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"
|
||||
//usage: IF_FEATURE_BZIP2_DECOMPRESS(
|
||||
//usage: "\n -d Decompress"
|
||||
//usage: "\n -t Test file integrity"
|
||||
//usage: )
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: IF_FEATURE_BZIP2_DECOMPRESS(
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
@@ -147,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;
|
||||
}
|
||||
}
|
||||
@@ -189,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;
|
||||
}
|
||||
|
||||
+2
-9
@@ -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"
|
||||
@@ -418,8 +418,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (argv[0] == NULL)
|
||||
bb_show_usage();
|
||||
if (opt & OPT_CREATE_LEADING_DIR)
|
||||
/* GNU cpio 2.13: "cpio -d -p a/b/c" works */
|
||||
bb_make_directory(argv[0], -1, FILEUTILS_RECUR);
|
||||
mkdir(argv[0], 0777);
|
||||
/* Crude existence check:
|
||||
* close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
|
||||
* We can also xopen, fstat, IS_DIR, later fchdir.
|
||||
@@ -429,11 +428,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
* a diffrerent problem earlier.
|
||||
* This is good enough for now.
|
||||
*/
|
||||
//FIXME: GNU cpio -d -p DIR does not immediately create DIR -
|
||||
//it just prepends "DIR/" to the names of files to be created.
|
||||
//The first file (fails to) be copied, and then the -d logic
|
||||
//triggers and creates all necessary directories.
|
||||
//IOW: bare "cpio -d -p DIR" + ^C shouldn't create anything.
|
||||
#if !BB_MMU
|
||||
pp.rd = 3;
|
||||
pp.wr = 4;
|
||||
@@ -522,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
@@ -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
@@ -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"
|
||||
|
||||
+62
-74
@@ -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
|
||||
@@ -77,13 +77,11 @@ aa: 85.1% -- replaced with aa.gz
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_GZIP_DECOMPRESS(
|
||||
//usage: "\n -d Decompress"
|
||||
//usage: "\n -t Test file integrity"
|
||||
//usage: )
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: IF_FEATURE_GZIP_DECOMPRESS(
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage: )
|
||||
//usage:
|
||||
//usage:#define gzip_example_usage
|
||||
//usage: "$ ls -la /tmp/busybox*\n"
|
||||
@@ -101,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; }
|
||||
@@ -261,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.
|
||||
@@ -279,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
|
||||
@@ -288,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.
|
||||
@@ -337,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
|
||||
|
||||
/* =========================================================================== */
|
||||
@@ -509,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*/);
|
||||
}
|
||||
@@ -612,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 */
|
||||
|
||||
@@ -792,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);
|
||||
@@ -1012,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.
|
||||
@@ -1124,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 */
|
||||
@@ -1158,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
|
||||
@@ -1174,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;
|
||||
@@ -1209,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);
|
||||
@@ -1226,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));
|
||||
@@ -1240,7 +1237,6 @@ static void gen_bitlen(const tree_desc *desc)
|
||||
n--;
|
||||
}
|
||||
}
|
||||
#undef tree
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -1251,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.
|
||||
@@ -1309,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;
|
||||
@@ -1387,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);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -1399,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 */
|
||||
@@ -1451,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 */
|
||||
@@ -1627,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) */
|
||||
@@ -1677,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 */
|
||||
@@ -1924,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;
|
||||
|
||||
@@ -1932,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()
|
||||
@@ -2079,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();
|
||||
@@ -2231,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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
@@ -159,10 +159,6 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
//TODO: this causes problems if tarball contains a r-xr-xr-x directory:
|
||||
// we create this directory, and then fail to create files inside it
|
||||
// (if tar xf isn't run as root).
|
||||
// GNU tar works around this by chmod-ing directories *after* all files are extracted.
|
||||
res = mkdir(dst_name, file_header->mode);
|
||||
if ((res != 0)
|
||||
&& (errno != EISDIR) /* btw, Linux doesn't return this */
|
||||
@@ -211,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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,19 +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)) // commented out, since bit clearing has effect only if condition is true
|
||||
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;
|
||||
@@ -284,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 */
|
||||
@@ -322,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;
|
||||
@@ -343,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 */
|
||||
@@ -360,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 */
|
||||
@@ -391,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 */
|
||||
@@ -458,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 */
|
||||
@@ -484,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -789,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);
|
||||
@@ -865,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 */
|
||||
@@ -930,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);
|
||||
}
|
||||
|
||||
@@ -1026,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;
|
||||
}
|
||||
@@ -1099,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;
|
||||
@@ -1225,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) {
|
||||
@@ -1247,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;
|
||||
}
|
||||
@@ -1260,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;
|
||||
}
|
||||
@@ -1268,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;
|
||||
}
|
||||
@@ -1276,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -20,7 +20,7 @@ typedef struct hardlinks_t {
|
||||
char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
char cpio_header[111];
|
||||
char cpio_header[110];
|
||||
int namesize;
|
||||
int major, minor, nlink, mode, inode;
|
||||
unsigned size, uid, gid, mtime;
|
||||
@@ -33,17 +33,16 @@ 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");
|
||||
}
|
||||
|
||||
cpio_header[110] = '\0'; /* sscanf may call strlen which may break without this */
|
||||
if (sscanf(cpio_header + 6,
|
||||
"%8x" "%8x" "%8x" "%8x"
|
||||
"%8x" "%8x" "%8x" /*maj,min:*/ "%*16c"
|
||||
@@ -51,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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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
-8
@@ -86,7 +86,6 @@
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -U Delete input files"
|
||||
///////: "\n -k Keep input files" (default, so why bother documenting?)
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage: "\n -v Verbose"
|
||||
//usage: "\n -F Don't verify checksum"
|
||||
|
||||
@@ -753,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");
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -786,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) {
|
||||
@@ -847,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 {
|
||||
@@ -914,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");
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -1050,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
@@ -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);
|
||||
|
||||
+59
-92
@@ -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;
|
||||
|
||||
@@ -507,9 +504,6 @@ static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
|
||||
if (header_name[0] == '\0')
|
||||
return TRUE;
|
||||
|
||||
if (exclude_file(tbInfo->excludeList, header_name))
|
||||
return SKIP; /* "do not recurse on this directory", no error message printed */
|
||||
|
||||
/* It is against the rules to archive a socket */
|
||||
if (S_ISSOCK(statbuf->st_mode)) {
|
||||
bb_error_msg("%s: socket ignored", fileName);
|
||||
@@ -543,9 +537,12 @@ static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (exclude_file(tbInfo->excludeList, header_name))
|
||||
return SKIP;
|
||||
|
||||
# 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
|
||||
@@ -555,13 +552,13 @@ static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
|
||||
/* open the file we want to archive, and make sure all is well */
|
||||
inputFileFd = open_or_warn(fileName, O_RDONLY);
|
||||
if (inputFileFd < 0) {
|
||||
return FALSE; /* make recursive_action() return FALSE */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add an entry to the tarball */
|
||||
if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) {
|
||||
return FALSE; /* make recursive_action() return FALSE */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If it was a regular file, write out the body */
|
||||
@@ -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("[LONGOPT]... "))
|
||||
//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 );
|
||||
@@ -1132,15 +1115,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
tar_handle->ah_flags &= ~ARCHIVE_RESTORE_DATE;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
/* Convert each -X EXCLFILE to list of to-be-rejected glob patterns */
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
# if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
/* Append --exclude=GLOBPATTERNs to reject */
|
||||
if (excludes) {
|
||||
llist_t **p2next = &tar_handle->reject;
|
||||
while (*p2next)
|
||||
p2next = &((*p2next)->link);
|
||||
*p2next = excludes;
|
||||
/* Append excludes to reject */
|
||||
while (excludes) {
|
||||
llist_t *next = excludes->link;
|
||||
excludes->link = tar_handle->reject;
|
||||
tar_handle->reject = excludes;
|
||||
excludes = next;
|
||||
}
|
||||
# endif
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
@@ -1168,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: */
|
||||
@@ -1196,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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-47
@@ -56,15 +56,14 @@
|
||||
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
|
||||
|
||||
//usage:#define unzip_trivial_usage
|
||||
//usage: "[-lnojpq] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]"
|
||||
//usage: "[-lnojpq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
|
||||
//usage:#define unzip_full_usage "\n\n"
|
||||
//usage: "Extract FILEs from ZIP archive\n"
|
||||
//usage: "\n -l List contents (with -q for short form)"
|
||||
//usage: "\n -n Never overwrite files (default: ask)"
|
||||
//usage: "\n -o Overwrite"
|
||||
//usage: "\n -j Do not restore paths"
|
||||
//usage: "\n -p Write to stdout"
|
||||
//usage: "\n -t Test"
|
||||
//usage: "\n -p Print to stdout"
|
||||
//usage: "\n -q Quiet"
|
||||
//usage: "\n -x FILE Exclude FILEs"
|
||||
//usage: "\n -d DIR Extract into DIR"
|
||||
@@ -83,13 +82,11 @@ enum {
|
||||
ZIP_FILEHEADER_MAGIC = 0x504b0304,
|
||||
ZIP_CDF_MAGIC = 0x504b0102, /* CDF item */
|
||||
ZIP_CDE_MAGIC = 0x504b0506, /* End of CDF */
|
||||
ZIP64_CDE_MAGIC = 0x504b0606, /* End of Zip64 CDF */
|
||||
ZIP_DD_MAGIC = 0x504b0708,
|
||||
#else
|
||||
ZIP_FILEHEADER_MAGIC = 0x04034b50,
|
||||
ZIP_CDF_MAGIC = 0x02014b50,
|
||||
ZIP_CDE_MAGIC = 0x06054b50,
|
||||
ZIP64_CDE_MAGIC = 0x06064b50,
|
||||
ZIP_DD_MAGIC = 0x08074b50,
|
||||
#endif
|
||||
};
|
||||
@@ -263,12 +260,6 @@ static uint32_t find_cdf_offset(void)
|
||||
continue;
|
||||
/* we found CDE! */
|
||||
memcpy(cde.raw, p + 1, CDE_LEN);
|
||||
dbg("cde.this_disk_no:%d", cde.fmt.this_disk_no );
|
||||
dbg("cde.disk_with_cdf_no:%d", cde.fmt.disk_with_cdf_no );
|
||||
dbg("cde.cdf_entries_on_this_disk:%d", cde.fmt.cdf_entries_on_this_disk);
|
||||
dbg("cde.cdf_entries_total:%d", cde.fmt.cdf_entries_total );
|
||||
dbg("cde.cdf_size:%d", cde.fmt.cdf_size );
|
||||
dbg("cde.cdf_offset:%x", cde.fmt.cdf_offset );
|
||||
FIX_ENDIANNESS_CDE(cde);
|
||||
/*
|
||||
* I've seen .ZIP files with seemingly valid CDEs
|
||||
@@ -311,27 +302,19 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
|
||||
dbg("got ZIP_CDE_MAGIC");
|
||||
return 0; /* EOF */
|
||||
}
|
||||
if (magic == ZIP64_CDE_MAGIC) { /* seen in .zip with >4GB files */
|
||||
dbg("got ZIP64_CDE_MAGIC");
|
||||
return 0; /* EOF */
|
||||
}
|
||||
xread(zip_fd, cdf->raw, CDF_HEADER_LEN);
|
||||
|
||||
FIX_ENDIANNESS_CDF(*cdf);
|
||||
dbg(" magic:%08x filename_len:%u extra_len:%u file_comment_length:%u",
|
||||
magic,
|
||||
dbg(" filename_len:%u extra_len:%u file_comment_length:%u",
|
||||
(unsigned)cdf->fmt.filename_len,
|
||||
(unsigned)cdf->fmt.extra_len,
|
||||
(unsigned)cdf->fmt.file_comment_length
|
||||
);
|
||||
//TODO: require that magic == ZIP_CDF_MAGIC?
|
||||
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf->fmt.filename_len
|
||||
+ cdf->fmt.extra_len
|
||||
+ cdf->fmt.file_comment_length;
|
||||
|
||||
dbg("Next cdf_offset 0x%x", cdf_offset);
|
||||
return cdf_offset;
|
||||
};
|
||||
#endif
|
||||
@@ -339,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)
|
||||
@@ -376,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);
|
||||
@@ -416,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
|
||||
@@ -429,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
|
||||
@@ -437,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
|
||||
@@ -445,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 {
|
||||
@@ -453,12 +436,10 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
}
|
||||
|
||||
/* Validate decompression - size */
|
||||
if (zip->fmt.ucmpsize != 0xffffffff /* seen on files with >4GB uncompressed data */
|
||||
&& zip->fmt.ucmpsize != xstate.bytes_out
|
||||
) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,7 +538,7 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
opts = 0;
|
||||
/* '-' makes getopt return 1 for non-options */
|
||||
while ((i = getopt(argc, argv, "-d:lnotpqxjv")) != -1) {
|
||||
while ((i = getopt(argc, argv, "-d:lnopqxjv")) != -1) {
|
||||
switch (i) {
|
||||
case 'd': /* Extract to base directory */
|
||||
base_dir = optarg;
|
||||
@@ -575,13 +556,8 @@ int unzip_main(int argc, char **argv)
|
||||
overwrite = O_ALWAYS;
|
||||
break;
|
||||
|
||||
case 't': /* Extract files to /dev/null */
|
||||
xmove_fd(xopen("/dev/null", O_WRONLY), STDOUT_FILENO);
|
||||
/*fallthrough*/
|
||||
|
||||
case 'p': /* Extract files to stdout */
|
||||
case 'p': /* Extract files to stdout and fall through to set verbosity */
|
||||
dst_fd = STDOUT_FILENO;
|
||||
/*fallthrough*/
|
||||
|
||||
case 'q': /* Be quiet */
|
||||
quiet++;
|
||||
@@ -670,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) {
|
||||
@@ -990,6 +960,7 @@ int unzip_main(int argc, char **argv)
|
||||
/* O_NOFOLLOW defends against symlink attacks */
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW);
|
||||
#endif
|
||||
do_extract:
|
||||
if (!quiet) {
|
||||
printf(/* zip.fmt.method == 0
|
||||
? " extracting: %s\n"
|
||||
@@ -997,7 +968,6 @@ int unzip_main(int argc, char **argv)
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
}
|
||||
do_extract:
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
if (S_ISLNK(file_mode)) {
|
||||
if (dst_fd != STDOUT_FILENO) /* not -p? */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
## Assorted header problems:
|
||||
## # CONFIG_HOSTID is not set
|
||||
## # CONFIG_FEATURE_SYNC_FANCY is not set - syncfs()
|
||||
## # CONFIG_FEATURE_TOUCH_NODEREF is not set - lutimes()
|
||||
## # CONFIG_LOGNAME is not set - getlogin_r()
|
||||
## # CONFIG_LOADFONT is not set
|
||||
## # CONFIG_SETFONT is not set
|
||||
@@ -86,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
|
||||
@@ -268,6 +270,7 @@ CONFIG_SYNC=y
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
# CONFIG_FEATURE_TOUCH_NODEREF is not set
|
||||
CONFIG_FEATURE_TOUCH_SUSV3=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -193,6 +194,7 @@ CONFIG_SYNC=y
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
# CONFIG_FEATURE_TOUCH_NODEREF is not set
|
||||
CONFIG_FEATURE_TOUCH_SUSV3=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
+13
-11
@@ -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;
|
||||
@@ -399,7 +401,7 @@ setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
|
||||
-V Version
|
||||
*/
|
||||
//usage:#define setfont_trivial_usage
|
||||
//usage: "[-m MAPFILE] [-C TTY] FILE"
|
||||
//usage: "FONT [-m MAPFILE] [-C TTY]"
|
||||
//usage:#define setfont_full_usage "\n\n"
|
||||
//usage: "Load a console font\n"
|
||||
//usage: "\n -m MAPFILE Load console screen map"
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ int showkey_main(int argc UNUSED_PARAM, char **argv)
|
||||
xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)((option_mask32 & OPT_k) ? K_MEDIUMRAW : K_RAW));
|
||||
|
||||
// we should exit on any signal; signals should interrupt read
|
||||
bb_signals_norestart(BB_FATAL_SIGS, record_signo);
|
||||
bb_signals_recursive_norestart(BB_FATAL_SIGS, record_signo);
|
||||
|
||||
// inform user that program ends after time of inactivity
|
||||
printf(press_keys, "10s after last keypress");
|
||||
|
||||
+2
-2
@@ -152,7 +152,7 @@ static int catv(unsigned opts, char **argv)
|
||||
eol_seen = (c == eol_char);
|
||||
#endif
|
||||
visible(c, buf, opts);
|
||||
fputs_stdout(buf);
|
||||
fputs(buf, stdout);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP && fd)
|
||||
@@ -201,7 +201,7 @@ int cat_main(int argc UNUSED_PARAM, char **argv)
|
||||
ns.start = 1;
|
||||
ns.inc = 1;
|
||||
ns.sep = "\t";
|
||||
ns.empty_str = NULL;
|
||||
ns.empty_str = "\n";
|
||||
ns.all = !(opts & CAT_OPT_b); /* -n without -b */
|
||||
ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */
|
||||
exitcode = EXIT_SUCCESS;
|
||||
|
||||
+3
-7
@@ -21,18 +21,14 @@
|
||||
/* 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 FILEs to GROUP"
|
||||
//usage: "\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: )
|
||||
//next 4 options are the same for chmod/chown/chgrp:
|
||||
//usage: "\n -R Recurse"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -c List changed files"
|
||||
//usage: "\n -v Verbose"
|
||||
|
||||
+9
-11
@@ -26,13 +26,12 @@
|
||||
//usage:#define chmod_trivial_usage
|
||||
//usage: "[-R"IF_DESKTOP("cvf")"] MODE[,MODE]... FILE..."
|
||||
//usage:#define chmod_full_usage "\n\n"
|
||||
//usage: "MODE is octal number (bit pattern sstrwxrwxrwx) or [ugoa]{+|-|=}[rwxXst]"
|
||||
//usage: "\n"
|
||||
//next 4 options are the same for chmod/chown/chgrp:
|
||||
//usage: "Each MODE is one or more of the letters ugoa, one of the\n"
|
||||
//usage: "symbols +-= and one or more of the letters rwxst\n"
|
||||
//usage: "\n -R Recurse"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -c List changed files"
|
||||
//usage: "\n -v Verbose"
|
||||
//usage: "\n -v List all files"
|
||||
//usage: "\n -f Hide errors"
|
||||
//usage: )
|
||||
//usage:
|
||||
@@ -66,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;
|
||||
@@ -82,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
|
||||
@@ -139,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;
|
||||
}
|
||||
|
||||
+8
-11
@@ -28,19 +28,15 @@
|
||||
//usage:#define chown_trivial_usage
|
||||
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... USER[:[GRP]] FILE..."
|
||||
//usage:#define chown_full_usage "\n\n"
|
||||
//usage: "Change the owner and/or group of FILEs to USER and/or GRP"
|
||||
//usage: "\n"
|
||||
//usage: "Change the owner and/or group of each FILE to USER and/or GRP\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: )
|
||||
//next 4 options are the same for chmod/chown/chgrp:
|
||||
//usage: "\n -R Recurse"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -c List changed files"
|
||||
//usage: "\n -v Verbose"
|
||||
//usage: "\n -v List all files"
|
||||
//usage: "\n -f Hide errors"
|
||||
//usage: )
|
||||
//usage:
|
||||
@@ -101,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;
|
||||
@@ -163,7 +159,8 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
flags, /* flags */
|
||||
fileAction, /* file action */
|
||||
fileAction, /* dir action */
|
||||
¶m) /* user data */
|
||||
¶m, /* user data */
|
||||
0) /* depth */
|
||||
) {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+16
-38
@@ -9,40 +9,32 @@
|
||||
//config:config CKSUM
|
||||
//config: bool "cksum (4.1 kb)"
|
||||
//config: default y
|
||||
//config:
|
||||
//config:config CRC32
|
||||
//config: bool "crc32 (4.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cksum is used to calculate the CRC32 checksum of a file.
|
||||
|
||||
// APPLET_NOEXEC:name main location suid_type help
|
||||
//applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
|
||||
//applet:IF_CRC32(APPLET_NOEXEC(crc32, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
|
||||
/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */
|
||||
|
||||
//kbuild:lib-$(CONFIG_CKSUM) += cksum.o
|
||||
//kbuild:lib-$(CONFIG_CRC32) += cksum.o
|
||||
|
||||
//usage:#define cksum_trivial_usage
|
||||
//usage: "FILE..."
|
||||
//usage:#define cksum_full_usage "\n\n"
|
||||
//usage: "Calculate CRC32 checksum of FILEs"
|
||||
//usage: "Calculate the CRC32 checksums of FILEs"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#define IS_CKSUM (ENABLE_CKSUM && (!ENABLE_CRC32 || applet_name[1] == 'k'))
|
||||
#define IS_CRC32 (ENABLE_CRC32 && (!ENABLE_CKSUM || applet_name[1] == 'r'))
|
||||
|
||||
int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
uint32_t *crc32_table = crc32_filltable(NULL, IS_CKSUM);
|
||||
uint32_t *crc32_table = crc32_filltable(NULL, 1);
|
||||
int exit_code = EXIT_SUCCESS;
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
getopt32(argv, ""); /* cksum coreutils 6.9 compat */
|
||||
getopt32(argv, ""); /* coreutils 6.9 compat */
|
||||
argv += optind;
|
||||
#else
|
||||
argv++;
|
||||
@@ -51,55 +43,41 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
setup_common_bufsiz();
|
||||
do {
|
||||
uint32_t crc;
|
||||
IF_CKSUM(off_t filesize;)
|
||||
const char *fname = *argv ? *argv : bb_msg_standard_input;
|
||||
int fd = open_or_warn_stdin(fname);
|
||||
off_t filesize;
|
||||
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
|
||||
|
||||
if (fd < 0) {
|
||||
exit_code = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
crc = IS_CKSUM ? 0 : 0xffffffff;
|
||||
IF_CKSUM(filesize = 0;)
|
||||
crc = 0;
|
||||
filesize = 0;
|
||||
#define read_buf bb_common_bufsiz1
|
||||
for (;;) {
|
||||
uoff_t t;
|
||||
int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE);
|
||||
if (bytes_read < 0)
|
||||
bb_simple_perror_msg_and_die(fname);
|
||||
if (bytes_read > 0) {
|
||||
IF_CKSUM(filesize += bytes_read;)
|
||||
filesize += bytes_read;
|
||||
} else {
|
||||
IF_CKSUM(uoff_t t;)
|
||||
|
||||
/* Checksum filesize bytes, LSB first, and exit */
|
||||
close(fd);
|
||||
if (IS_CRC32)
|
||||
break;
|
||||
#if ENABLE_CKSUM
|
||||
fd = -1; /* break flag */
|
||||
/* Checksum filesize bytes, LSB first */
|
||||
t = filesize;
|
||||
/*bytes_read = 0; - already is */
|
||||
bytes_read = 0;
|
||||
while (t != 0) {
|
||||
read_buf[bytes_read++] = (uint8_t)t;
|
||||
t >>= 8;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
crc = (IS_CKSUM ? crc32_block_endian1 : crc32_block_endian0)(crc, read_buf, bytes_read, crc32_table);
|
||||
if (ENABLE_CKSUM && fd < 0)
|
||||
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
|
||||
if (fd < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
crc = ~crc;
|
||||
#if ENABLE_CKSUM
|
||||
if (IS_CKSUM)
|
||||
printf((*argv ? "%u %"OFF_FMT"u %s\n" : "%u %"OFF_FMT"u\n"),
|
||||
printf((*argv ? "%u %"OFF_FMT"u %s\n" : "%u %"OFF_FMT"u\n"),
|
||||
(unsigned)crc, filesize, *argv);
|
||||
else
|
||||
#endif
|
||||
printf((*argv ? "%08x %s\n" : "%08x\n"),
|
||||
(unsigned)crc, *argv);
|
||||
} while (*argv && *++argv);
|
||||
|
||||
fflush_stdout_and_exit(exit_code);
|
||||
|
||||
+98
-111
@@ -37,57 +37,10 @@
|
||||
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */
|
||||
|
||||
// Options of cp from GNU coreutils 6.10:
|
||||
// -a, --archive
|
||||
// -f, --force
|
||||
// -i, --interactive
|
||||
// -l, --link
|
||||
// -L, --dereference
|
||||
// -P, --no-dereference
|
||||
// -R, -r, --recursive
|
||||
// -s, --symbolic-link
|
||||
// -v, --verbose
|
||||
// -H follow command-line symbolic links in SOURCE
|
||||
// -d same as --no-dereference --preserve=links
|
||||
// -p same as --preserve=mode,ownership,timestamps
|
||||
// -c same as --preserve=context
|
||||
// -u, --update
|
||||
// copy only when the SOURCE file is newer than the destination
|
||||
// file or when the destination file is missing
|
||||
// --remove-destination
|
||||
// remove each existing destination file before attempting to open
|
||||
// --parents
|
||||
// use full source file name under DIRECTORY
|
||||
// -T, --no-target-directory
|
||||
// treat DEST as a normal file
|
||||
// NOT SUPPORTED IN BBOX:
|
||||
// --backup[=CONTROL]
|
||||
// make a backup of each existing destination file
|
||||
// -b like --backup but does not accept an argument
|
||||
// --copy-contents
|
||||
// copy contents of special files when recursive
|
||||
// --preserve[=ATTR_LIST]
|
||||
// preserve attributes (default: mode,ownership,timestamps),
|
||||
// if possible additional attributes: security context,links,all
|
||||
// --no-preserve=ATTR_LIST
|
||||
// --sparse=WHEN
|
||||
// control creation of sparse files
|
||||
// --strip-trailing-slashes
|
||||
// remove any trailing slashes from each SOURCE argument
|
||||
// -S, --suffix=SUFFIX
|
||||
// override the usual backup suffix
|
||||
// -t, --target-directory=DIRECTORY
|
||||
// copy all SOURCE arguments into DIRECTORY
|
||||
// -x, --one-file-system
|
||||
// stay on this file system
|
||||
// -Z, --context=CONTEXT
|
||||
// (SELinux) set SELinux security context of copy to CONTEXT
|
||||
|
||||
//usage:#define cp_trivial_usage
|
||||
//usage: "[-arPLHpfinlsTu] SOURCE DEST\n"
|
||||
//usage: "or: cp [-arPLHpfinlsu] SOURCE... { -t DIRECTORY | DIRECTORY }"
|
||||
//usage: "[OPTIONS] SOURCE... DEST"
|
||||
//usage:#define cp_full_usage "\n\n"
|
||||
//usage: "Copy SOURCEs to DEST\n"
|
||||
//usage: "Copy SOURCE(s) to DEST\n"
|
||||
//usage: "\n -a Same as -dpR"
|
||||
//usage: IF_SELINUX(
|
||||
//usage: "\n -c Preserve security context"
|
||||
@@ -99,10 +52,8 @@
|
||||
//usage: "\n -p Preserve file attributes if possible"
|
||||
//usage: "\n -f Overwrite"
|
||||
//usage: "\n -i Prompt before overwrite"
|
||||
//usage: "\n -n Don't overwrite"
|
||||
//usage: "\n -l,-s Create (sym)links"
|
||||
//usage: "\n -T Refuse to copy if DEST is a directory"
|
||||
//usage: "\n -t DIR Copy all SOURCEs into DIR"
|
||||
//usage: "\n -T Treat DEST as a normal file"
|
||||
//usage: "\n -u Copy only newer files"
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -121,46 +72,44 @@ int cp_main(int argc, char **argv)
|
||||
int d_flags;
|
||||
int flags;
|
||||
int status;
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
enum {
|
||||
/*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTBITS */
|
||||
OPT_parents = 1 << (FILEUTILS_CP_OPTBITS+1),
|
||||
OPT_reflink = 1 << (FILEUTILS_CP_OPTBITS+2),
|
||||
FILEUTILS_CP_OPTNUM = sizeof(FILEUTILS_CP_OPTSTR)-1,
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
/*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */
|
||||
OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1),
|
||||
OPT_reflink = 1 << (FILEUTILS_CP_OPTNUM+2),
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
# if ENABLE_FEATURE_CP_REFLINK
|
||||
char *reflink = NULL;
|
||||
# endif
|
||||
flags = getopt32long(argv, "^"
|
||||
FILEUTILS_CP_OPTSTR
|
||||
"\0"
|
||||
// Need at least one argument. (Usually two+, but -t DIR can have only one)
|
||||
// Need at least two arguments
|
||||
// Soft- and hardlinking doesn't mix
|
||||
// -P and -d are the same (-P is POSIX, -d is GNU)
|
||||
// -r and -R are the same
|
||||
// -R (and therefore -r) turns on -d (coreutils does this)
|
||||
// -a = -pdR
|
||||
// -i overrides -n and vice versa (last wins)
|
||||
"-1:l--s:s--l:Pd:rRd:Rd:apdR:i-n:n-i",
|
||||
"-2:l--s:s--l:Pd:rRd:Rd:apdR",
|
||||
"archive\0" No_argument "a"
|
||||
"force\0" No_argument "f"
|
||||
"interactive\0" No_argument "i"
|
||||
"no-clobber\0" No_argument "n"
|
||||
"link\0" No_argument "l"
|
||||
"dereference\0" No_argument "L"
|
||||
"no-dereference\0" No_argument "P"
|
||||
"recursive\0" No_argument "R"
|
||||
"symbolic-link\0" No_argument "s"
|
||||
"no-target-directory\0" No_argument "T"
|
||||
"target-directory\0" Required_argument "t"
|
||||
"verbose\0" No_argument "v"
|
||||
"update\0" No_argument "u"
|
||||
"remove-destination\0" No_argument "\xff"
|
||||
"parents\0" No_argument "\xfe"
|
||||
# if ENABLE_FEATURE_CP_REFLINK
|
||||
"reflink\0" Optional_argument "\xfd"
|
||||
# endif
|
||||
, &last
|
||||
# if ENABLE_FEATURE_CP_REFLINK
|
||||
, &reflink
|
||||
# endif
|
||||
);
|
||||
@@ -179,10 +128,55 @@ int cp_main(int argc, char **argv)
|
||||
flags = getopt32(argv, "^"
|
||||
FILEUTILS_CP_OPTSTR
|
||||
"\0"
|
||||
"-1:l--s:s--l:Pd:rRd:Rd:apdR"
|
||||
, &last
|
||||
"-2:l--s:s--l:Pd:rRd:Rd:apdR"
|
||||
);
|
||||
#endif
|
||||
/* Options of cp from GNU coreutils 6.10:
|
||||
* -a, --archive
|
||||
* -f, --force
|
||||
* -i, --interactive
|
||||
* -l, --link
|
||||
* -L, --dereference
|
||||
* -P, --no-dereference
|
||||
* -R, -r, --recursive
|
||||
* -s, --symbolic-link
|
||||
* -v, --verbose
|
||||
* -H follow command-line symbolic links in SOURCE
|
||||
* -d same as --no-dereference --preserve=links
|
||||
* -p same as --preserve=mode,ownership,timestamps
|
||||
* -c same as --preserve=context
|
||||
* -u, --update
|
||||
* copy only when the SOURCE file is newer than the destination
|
||||
* file or when the destination file is missing
|
||||
* --remove-destination
|
||||
* remove each existing destination file before attempting to open
|
||||
* --parents
|
||||
* use full source file name under DIRECTORY
|
||||
* -T, --no-target-directory
|
||||
* treat DEST as a normal file
|
||||
* NOT SUPPORTED IN BBOX:
|
||||
* --backup[=CONTROL]
|
||||
* make a backup of each existing destination file
|
||||
* -b like --backup but does not accept an argument
|
||||
* --copy-contents
|
||||
* copy contents of special files when recursive
|
||||
* --preserve[=ATTR_LIST]
|
||||
* preserve attributes (default: mode,ownership,timestamps),
|
||||
* if possible additional attributes: security context,links,all
|
||||
* --no-preserve=ATTR_LIST
|
||||
* --sparse=WHEN
|
||||
* control creation of sparse files
|
||||
* --strip-trailing-slashes
|
||||
* remove any trailing slashes from each SOURCE argument
|
||||
* -S, --suffix=SUFFIX
|
||||
* override the usual backup suffix
|
||||
* -t, --target-directory=DIRECTORY
|
||||
* copy all SOURCE arguments into DIRECTORY
|
||||
* -x, --one-file-system
|
||||
* stay on this file system
|
||||
* -Z, --context=CONTEXT
|
||||
* (SELinux) set SELinux security context of copy to CONTEXT
|
||||
*/
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
/* Reverse this bit. If there is -d, bit is not set: */
|
||||
@@ -201,56 +195,49 @@ int cp_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
status = EXIT_SUCCESS;
|
||||
if (!(flags & FILEUTILS_TARGET_DIR)) {
|
||||
last = argv[argc - 1];
|
||||
if (argc < 2)
|
||||
bb_show_usage();
|
||||
if (argc != 2) {
|
||||
if (flags & FILEUTILS_NO_TARGET_DIR)
|
||||
bb_show_usage();
|
||||
/* "cp A B C... DIR" - target must be dir */
|
||||
} else /* argc == 2 */ {
|
||||
/* "cp A B" - only case where target can be not a dir */
|
||||
s_flags = cp_mv_stat2(*argv, &source_stat,
|
||||
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
||||
if (s_flags < 0) /* error other than ENOENT */
|
||||
return EXIT_FAILURE;
|
||||
d_flags = cp_mv_stat(last, &dest_stat);
|
||||
if (d_flags < 0) /* error other than ENOENT */
|
||||
return EXIT_FAILURE;
|
||||
last = argv[argc - 1];
|
||||
/* If there are only two arguments and... */
|
||||
if (argc == 2) {
|
||||
s_flags = cp_mv_stat2(*argv, &source_stat,
|
||||
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
||||
if (s_flags < 0)
|
||||
return EXIT_FAILURE;
|
||||
d_flags = cp_mv_stat(last, &dest_stat);
|
||||
if (d_flags < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
|
||||
if (!(s_flags & 2) && (d_flags & 2))
|
||||
/* cp -T NOTDIR DIR */
|
||||
bb_error_msg_and_die("'%s' is a directory", last);
|
||||
}
|
||||
if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
|
||||
if (!(s_flags & 2) && (d_flags & 2))
|
||||
/* cp -T NOTDIR DIR */
|
||||
bb_error_msg_and_die("'%s' is a directory", last);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
if (flags & FILEUTILS_RMDEST) {
|
||||
flags |= FILEUTILS_FORCE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ...if neither is a directory... */
|
||||
if (!((s_flags | d_flags) & 2)
|
||||
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|
||||
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|
||||
|| (flags & FILEUTILS_NO_TARGET_DIR)
|
||||
) {
|
||||
/* Do a simple copy */
|
||||
dest = last;
|
||||
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
|
||||
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
|
||||
// flags, FILEUTILS_RMDEST, OPT_parents);
|
||||
if (flags & OPT_parents) {
|
||||
if (!(d_flags & 2)) {
|
||||
bb_error_msg_and_die("with --parents, the destination must be a directory");
|
||||
}
|
||||
}
|
||||
if (flags & FILEUTILS_RMDEST) {
|
||||
flags |= FILEUTILS_FORCE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ...if neither is a directory... */
|
||||
if (!((s_flags | d_flags) & 2)
|
||||
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|
||||
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|
||||
|| (flags & FILEUTILS_NO_TARGET_DIR)
|
||||
) {
|
||||
/* Do a simple copy */
|
||||
dest = last;
|
||||
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
|
||||
}
|
||||
} else if (flags & FILEUTILS_NO_TARGET_DIR) {
|
||||
bb_error_msg_and_die("too many arguments");
|
||||
}
|
||||
/* else: last is DIR from "-t DIR" */
|
||||
|
||||
while (1) {
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
@@ -272,7 +259,7 @@ int cp_main(int argc, char **argv)
|
||||
if (copy_file(*argv, dest, flags) < 0) {
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
if (!*++argv || *argv == last) {
|
||||
if (*++argv == last) {
|
||||
/* possibly leaking dest... */
|
||||
break;
|
||||
}
|
||||
|
||||
+98
-112
@@ -14,13 +14,6 @@
|
||||
//config: help
|
||||
//config: cut is used to print selected parts of lines from
|
||||
//config: each file to stdout.
|
||||
//config:
|
||||
//config:config FEATURE_CUT_REGEX
|
||||
//config: bool "cut -F"
|
||||
//config: default y
|
||||
//config: depends on CUT
|
||||
//config: help
|
||||
//config: Allow regex based delimiters.
|
||||
|
||||
//applet:IF_CUT(APPLET_NOEXEC(cut, cut, BB_DIR_USR_BIN, BB_SUID_DROP, cut))
|
||||
|
||||
@@ -29,19 +22,13 @@
|
||||
//usage:#define cut_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define cut_full_usage "\n\n"
|
||||
//usage: "Print selected fields from FILEs to stdout\n"
|
||||
//usage: "Print selected fields from each input FILE to stdout\n"
|
||||
//usage: "\n -b LIST Output only bytes from LIST"
|
||||
//usage: "\n -c LIST Output only characters from LIST"
|
||||
//usage: "\n -d SEP Field delimiter for input (default -f TAB, -F run of whitespace)"
|
||||
//usage: "\n -O SEP Field delimeter for output (default = -d for -f, one space for -F)"
|
||||
//usage: "\n -D Don't sort/collate sections or match -fF lines without delimeter"
|
||||
//usage: "\n -f LIST Print only these fields (-d is single char)"
|
||||
//usage: IF_FEATURE_CUT_REGEX(
|
||||
//usage: "\n -F LIST Print only these fields (-d is regex)"
|
||||
//usage: )
|
||||
//usage: "\n -s Output only lines containing delimiter"
|
||||
//usage: "\n -d CHAR Use CHAR instead of tab as the field delimiter"
|
||||
//usage: "\n -s Output only the lines containing delimiter"
|
||||
//usage: "\n -f N Print only these fields"
|
||||
//usage: "\n -n Ignored"
|
||||
//(manpage:-n with -b: don't split multibyte characters)
|
||||
//usage:
|
||||
//usage:#define cut_example_usage
|
||||
//usage: "$ echo \"Hello world\" | cut -f 1 -d ' '\n"
|
||||
@@ -51,49 +38,38 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if ENABLE_FEATURE_CUT_REGEX
|
||||
#include "xregex.h"
|
||||
#else
|
||||
#define regex_t int
|
||||
typedef struct { int rm_eo, rm_so; } regmatch_t;
|
||||
#define xregcomp(x, ...) *(x) = 0
|
||||
#define regexec(...) 0
|
||||
#endif
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
/* option vars */
|
||||
#define OPT_STR "b:c:f:d:O:sD"IF_FEATURE_CUT_REGEX("F:")"n"
|
||||
#define OPT_STR "b:c:f:d:sn"
|
||||
#define CUT_OPT_BYTE_FLGS (1 << 0)
|
||||
#define CUT_OPT_CHAR_FLGS (1 << 1)
|
||||
#define CUT_OPT_FIELDS_FLGS (1 << 2)
|
||||
#define CUT_OPT_DELIM_FLGS (1 << 3)
|
||||
#define CUT_OPT_ODELIM_FLGS (1 << 4)
|
||||
#define CUT_OPT_SUPPRESS_FLGS (1 << 5)
|
||||
#define CUT_OPT_NOSORT_FLGS (1 << 6)
|
||||
#define CUT_OPT_REGEX_FLGS ((1 << 7) * ENABLE_FEATURE_CUT_REGEX)
|
||||
#define CUT_OPT_SUPPRESS_FLGS (1 << 4)
|
||||
|
||||
struct cut_list {
|
||||
int startpos;
|
||||
int endpos;
|
||||
};
|
||||
|
||||
enum {
|
||||
BOL = 0,
|
||||
EOL = INT_MAX,
|
||||
NON_RANGE = -1
|
||||
};
|
||||
|
||||
static int cmpfunc(const void *a, const void *b)
|
||||
{
|
||||
return (((struct cut_list *) a)->startpos -
|
||||
((struct cut_list *) b)->startpos);
|
||||
}
|
||||
|
||||
static void cut_file(FILE *file, const char *delim, const char *odelim,
|
||||
const struct cut_list *cut_lists, unsigned nlists)
|
||||
static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, unsigned nlists)
|
||||
{
|
||||
char *line;
|
||||
unsigned linenum = 0; /* keep these zero-based to be consistent */
|
||||
regex_t reg;
|
||||
int spos, shoe = option_mask32 & CUT_OPT_REGEX_FLGS;
|
||||
|
||||
if (shoe) xregcomp(®, delim, REG_EXTENDED);
|
||||
|
||||
/* go through every line in the file */
|
||||
while ((line = xmalloc_fgetline(file)) != NULL) {
|
||||
@@ -103,22 +79,29 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
|
||||
char *printed = xzalloc(linelen + 1);
|
||||
char *orig_line = line;
|
||||
unsigned cl_pos = 0;
|
||||
int spos;
|
||||
|
||||
/* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
|
||||
if (option_mask32 & (CUT_OPT_CHAR_FLGS | CUT_OPT_BYTE_FLGS)) {
|
||||
/* print the chars specified in each cut list */
|
||||
for (; cl_pos < nlists; cl_pos++) {
|
||||
for (spos = cut_lists[cl_pos].startpos; spos < linelen;) {
|
||||
spos = cut_lists[cl_pos].startpos;
|
||||
while (spos < linelen) {
|
||||
if (!printed[spos]) {
|
||||
printed[spos] = 'X';
|
||||
putchar(line[spos]);
|
||||
}
|
||||
if (++spos > cut_lists[cl_pos].endpos) {
|
||||
spos++;
|
||||
if (spos > cut_lists[cl_pos].endpos
|
||||
/* NON_RANGE is -1, so if below is true,
|
||||
* the above was true too (spos is >= 0) */
|
||||
/* || cut_lists[cl_pos].endpos == NON_RANGE */
|
||||
) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (*delim == '\n') { /* cut by lines */
|
||||
} else if (delim == '\n') { /* cut by lines */
|
||||
spos = cut_lists[cl_pos].startpos;
|
||||
|
||||
/* get out if we have no more lists to process or if the lines
|
||||
@@ -131,7 +114,9 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
|
||||
while (spos < (int)linenum) {
|
||||
spos++;
|
||||
/* go to the next list if we're at the end of this one */
|
||||
if (spos > cut_lists[cl_pos].endpos) {
|
||||
if (spos > cut_lists[cl_pos].endpos
|
||||
|| cut_lists[cl_pos].endpos == NON_RANGE
|
||||
) {
|
||||
cl_pos++;
|
||||
/* get out if there's no more lists to process */
|
||||
if (cl_pos >= nlists)
|
||||
@@ -149,56 +134,55 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
|
||||
puts(line);
|
||||
goto next_line;
|
||||
} else { /* cut by fields */
|
||||
unsigned uu = 0, start = 0, end = 0, out = 0;
|
||||
int dcount = 0;
|
||||
int ndelim = -1; /* zero-based / one-based problem */
|
||||
int nfields_printed = 0;
|
||||
char *field = NULL;
|
||||
char delimiter[2];
|
||||
|
||||
/* Loop through bytes, finding next delimiter */
|
||||
for (;;) {
|
||||
/* End of current range? */
|
||||
if (end == linelen || dcount > cut_lists[cl_pos].endpos) {
|
||||
if (++cl_pos >= nlists) break;
|
||||
if (option_mask32 & CUT_OPT_NOSORT_FLGS)
|
||||
start = dcount = uu = 0;
|
||||
end = 0;
|
||||
}
|
||||
/* End of current line? */
|
||||
if (uu == linelen) {
|
||||
/* If we've seen no delimiters, check -s */
|
||||
if (!cl_pos && !dcount && !shoe) {
|
||||
if (option_mask32 & CUT_OPT_SUPPRESS_FLGS)
|
||||
goto next_line;
|
||||
} else if (dcount<cut_lists[cl_pos].startpos)
|
||||
start = linelen;
|
||||
end = linelen;
|
||||
} else {
|
||||
/* Find next delimiter */
|
||||
if (shoe) {
|
||||
regmatch_t rr = {-1, -1};
|
||||
delimiter[0] = delim;
|
||||
delimiter[1] = 0;
|
||||
|
||||
if (!regexec(®, line+uu, 1, &rr, REG_NOTBOL|REG_NOTEOL)) {
|
||||
end = uu + rr.rm_so;
|
||||
uu += rr.rm_eo;
|
||||
} else {
|
||||
uu = linelen;
|
||||
continue;
|
||||
}
|
||||
} else if (line[end = uu++] != *delim)
|
||||
continue;
|
||||
/* does this line contain any delimiters? */
|
||||
if (strchr(line, delim) == NULL) {
|
||||
if (!(option_mask32 & CUT_OPT_SUPPRESS_FLGS))
|
||||
puts(line);
|
||||
goto next_line;
|
||||
}
|
||||
|
||||
/* Got delimiter. Loop if not yet within range. */
|
||||
if (dcount++ < cut_lists[cl_pos].startpos) {
|
||||
start = uu;
|
||||
continue;
|
||||
/* process each list on this line, for as long as we've got
|
||||
* a line to process */
|
||||
for (; cl_pos < nlists && line; cl_pos++) {
|
||||
spos = cut_lists[cl_pos].startpos;
|
||||
do {
|
||||
/* find the field we're looking for */
|
||||
while (line && ndelim < spos) {
|
||||
field = strsep(&line, delimiter);
|
||||
ndelim++;
|
||||
}
|
||||
}
|
||||
if (end != start || !shoe)
|
||||
printf("%s%.*s", out++ ? odelim : "", end-start, line + start);
|
||||
start = uu;
|
||||
if (!dcount)
|
||||
break;
|
||||
|
||||
/* we found it, and it hasn't been printed yet */
|
||||
if (field && ndelim == spos && !printed[ndelim]) {
|
||||
/* if this isn't our first time through, we need to
|
||||
* print the delimiter after the last field that was
|
||||
* printed */
|
||||
if (nfields_printed > 0)
|
||||
putchar(delim);
|
||||
fputs(field, stdout);
|
||||
printed[ndelim] = 'X';
|
||||
nfields_printed++; /* shouldn't overflow.. */
|
||||
}
|
||||
|
||||
spos++;
|
||||
|
||||
/* keep going as long as we have a line to work with,
|
||||
* this is a list, and we're not at the end of that
|
||||
* list */
|
||||
} while (spos <= cut_lists[cl_pos].endpos && line
|
||||
&& cut_lists[cl_pos].endpos != NON_RANGE);
|
||||
}
|
||||
}
|
||||
/* if we printed anything, finish with newline */
|
||||
/* if we printed anything at all, we need to finish it with a
|
||||
* newline cuz we were handed a chomped line */
|
||||
putchar('\n');
|
||||
next_line:
|
||||
linenum++;
|
||||
@@ -213,35 +197,37 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* growable array holding a series of lists */
|
||||
struct cut_list *cut_lists = NULL;
|
||||
unsigned nlists = 0; /* number of elements in above list */
|
||||
char delim = '\t'; /* delimiter, default is tab */
|
||||
char *sopt, *ltok;
|
||||
const char *delim = NULL;
|
||||
const char *odelim = NULL;
|
||||
unsigned opt;
|
||||
|
||||
#define ARG "bcf"IF_FEATURE_CUT_REGEX("F")
|
||||
opt = getopt32(argv, "^"
|
||||
OPT_STR // = "b:c:f:d:O:sD"IF_FEATURE_CUT_REGEX("F:")"n"
|
||||
"\0" "b--"ARG":c--"ARG":f--"ARG IF_FEATURE_CUT_REGEX("F--"ARG),
|
||||
&sopt, &sopt, &sopt, &delim, &odelim IF_FEATURE_CUT_REGEX(, &sopt)
|
||||
OPT_STR
|
||||
"\0" "b--bcf:c--bcf:f--bcf",
|
||||
&sopt, &sopt, &sopt, <ok
|
||||
);
|
||||
if (!delim || !*delim)
|
||||
delim = (opt & CUT_OPT_REGEX_FLGS) ? "[[:space:]]+" : "\t";
|
||||
if (!odelim) odelim = (opt & CUT_OPT_REGEX_FLGS) ? " " : delim;
|
||||
|
||||
// argc -= optind;
|
||||
argv += optind;
|
||||
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS | CUT_OPT_REGEX_FLGS)))
|
||||
bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields");
|
||||
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
|
||||
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_error_msg_and_die("the delimiter must be a single character");
|
||||
}
|
||||
delim = ltok[0];
|
||||
}
|
||||
|
||||
/* non-field (char or byte) cutting has some special handling */
|
||||
if (!(opt & (CUT_OPT_FIELDS_FLGS|CUT_OPT_REGEX_FLGS))) {
|
||||
if (!(opt & CUT_OPT_FIELDS_FLGS)) {
|
||||
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
|
||||
|
||||
if (opt & CUT_OPT_SUPPRESS_FLGS) {
|
||||
bb_error_msg_and_die
|
||||
("suppressing non-delimited lines makes sense%s", _op_on_field);
|
||||
("suppressing non-delimited lines makes sense%s",
|
||||
_op_on_field);
|
||||
}
|
||||
if (opt & CUT_OPT_DELIM_FLGS) {
|
||||
if (delim != '\t') {
|
||||
bb_error_msg_and_die
|
||||
("a delimiter may be specified%s", _op_on_field);
|
||||
}
|
||||
@@ -266,7 +252,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* get the start pos */
|
||||
ntok = strsep(<ok, "-");
|
||||
if (!ntok[0]) {
|
||||
s = 0;
|
||||
s = BOL;
|
||||
} else {
|
||||
s = xatoi_positive(ntok);
|
||||
/* account for the fact that arrays are zero based, while
|
||||
@@ -277,23 +263,24 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* get the end pos */
|
||||
if (ltok == NULL) {
|
||||
e = s;
|
||||
e = NON_RANGE;
|
||||
} else if (!ltok[0]) {
|
||||
e = INT_MAX;
|
||||
e = EOL;
|
||||
} else {
|
||||
e = xatoi_positive(ltok);
|
||||
/* if the user specified and end position of 0,
|
||||
* that means "til the end of the line" */
|
||||
if (!*ltok)
|
||||
e = INT_MAX;
|
||||
else if (e < s)
|
||||
bb_error_msg_and_die("%d<%d", e, s);
|
||||
if (e == 0)
|
||||
e = EOL;
|
||||
e--; /* again, arrays are zero based, lines are 1 based */
|
||||
if (e == s)
|
||||
e = NON_RANGE;
|
||||
}
|
||||
|
||||
/* add the new list */
|
||||
cut_lists = xrealloc_vector(cut_lists, 4, nlists);
|
||||
/* NB: startpos is always >= 0 */
|
||||
/* NB: startpos is always >= 0,
|
||||
* while endpos may be = NON_RANGE (-1) */
|
||||
cut_lists[nlists].startpos = s;
|
||||
cut_lists[nlists].endpos = e;
|
||||
nlists++;
|
||||
@@ -301,13 +288,12 @@ 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
|
||||
*/
|
||||
if (!(opt & CUT_OPT_NOSORT_FLGS))
|
||||
qsort(cut_lists, nlists, sizeof(cut_lists[0]), cmpfunc);
|
||||
qsort(cut_lists, nlists, sizeof(cut_lists[0]), cmpfunc);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -322,7 +308,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
|
||||
retval = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
cut_file(file, delim, odelim, cut_lists, nlists);
|
||||
cut_file(file, delim, cut_lists, nlists);
|
||||
fclose_if_not_stdin(file);
|
||||
} while (*++argv);
|
||||
|
||||
|
||||
+62
-52
@@ -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);
|
||||
}
|
||||
|
||||
+39
-102
@@ -56,10 +56,10 @@
|
||||
//kbuild:lib-$(CONFIG_DD) += dd.o
|
||||
|
||||
//usage:#define dd_trivial_usage
|
||||
//usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]"
|
||||
//usage: IF_FEATURE_DD_IBS_OBS("\n"
|
||||
//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|count_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,12 +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 iflag=count_bytes count=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"
|
||||
@@ -137,22 +134,19 @@ enum {
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of conv flags */
|
||||
/* start of input flags */
|
||||
FLAG_IFLAG_SHIFT = 5,
|
||||
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT_BYTES = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FULLBLOCK = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_IDIRECT = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_IFLAG_SHIFT = 5,
|
||||
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of input flags */
|
||||
/* start of output flags */
|
||||
FLAG_OFLAG_SHIFT = 9,
|
||||
FLAG_SEEK_BYTES = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_APPEND = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_ODIRECT = (1 << 11) * 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 << 12) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 13,
|
||||
FLAG_STATUS_NONE = 1 << 14,
|
||||
FLAG_STATUS_NOXFER = 1 << 15,
|
||||
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)
|
||||
@@ -177,9 +171,8 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
//So far we react to it (we print the stats),
|
||||
//status=none only suppresses final, non-USR1 generated status message.
|
||||
# endif
|
||||
fprintf(stderr, /*G.total_bytes < 1024
|
||||
? "%llu bytes copied, " : */ "%llu bytes (%sB) copied, "
|
||||
, G.total_bytes,
|
||||
fprintf(stderr, "%llu bytes (%sB) copied, ",
|
||||
G.total_bytes,
|
||||
/* show fractional digit, use suffixes */
|
||||
make_human_readable_str(G.total_bytes, 1, 0)
|
||||
);
|
||||
@@ -199,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;
|
||||
@@ -299,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)
|
||||
{
|
||||
@@ -320,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""count_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 =
|
||||
@@ -362,11 +309,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Partially implemented: */
|
||||
//swab swap every pair of input bytes: will abort on non-even reads
|
||||
OP_iflag_skip_bytes,
|
||||
OP_iflag_count_bytes,
|
||||
OP_iflag_fullblock,
|
||||
OP_iflag_direct,
|
||||
OP_oflag_seek_bytes,
|
||||
OP_oflag_direct,
|
||||
#endif
|
||||
};
|
||||
smallint exitcode = EXIT_FAILURE;
|
||||
@@ -482,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
|
||||
|
||||
@@ -499,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;
|
||||
}
|
||||
@@ -515,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)) {
|
||||
@@ -541,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)
|
||||
@@ -555,17 +498,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto die_outfile;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
ssize_t n = ibs;
|
||||
|
||||
if (G.flags & FLAG_COUNT) {
|
||||
if (count == 0)
|
||||
break;
|
||||
if ((G.flags & FLAG_COUNT_BYTES) && count < ibs)
|
||||
n = count;
|
||||
}
|
||||
|
||||
n = dd_read(ibuf, n);
|
||||
while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
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) {
|
||||
@@ -600,7 +540,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
p16++;
|
||||
}
|
||||
}
|
||||
count -= (G.flags & FLAG_COUNT_BYTES) ? n : 1;
|
||||
if ((size_t)n == ibs)
|
||||
G.in_full++;
|
||||
else {
|
||||
@@ -661,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;
|
||||
}
|
||||
+20
-27
@@ -45,7 +45,7 @@
|
||||
//usage: IF_FEATURE_HUMAN_READABLE("mh")
|
||||
//usage: "T"
|
||||
//usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE")
|
||||
//usage: "] [-t TYPE] [FILESYSTEM]..."
|
||||
//usage: "] [FILESYSTEM]..."
|
||||
//usage:#define df_full_usage "\n\n"
|
||||
//usage: "Print filesystem usage statistics\n"
|
||||
//usage: "\n -P POSIX output format"
|
||||
@@ -55,7 +55,6 @@
|
||||
//usage: "\n -h Human readable (e.g. 1K 243M 2G)"
|
||||
//usage: )
|
||||
//usage: "\n -T Print filesystem type"
|
||||
//usage: "\n -t TYPE Print only mounts of this type"
|
||||
//usage: IF_FEATURE_DF_FANCY(
|
||||
//usage: "\n -a Show all filesystems"
|
||||
//usage: "\n -i Inodes"
|
||||
@@ -98,31 +97,24 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
FILE *mount_table;
|
||||
struct mntent *mount_entry;
|
||||
struct statvfs s;
|
||||
|
||||
enum {
|
||||
OPT_KILO = (1 << 0),
|
||||
OPT_POSIX = (1 << 1),
|
||||
OPT_FSTYPE = (1 << 2),
|
||||
OPT_t = (1 << 3),
|
||||
OPT_ALL = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 6) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (5 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_KILO = (1 << 0),
|
||||
OPT_POSIX = (1 << 1),
|
||||
OPT_FSTYPE = (1 << 2),
|
||||
OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
};
|
||||
const char *disp_units_hdr = NULL;
|
||||
char *chp, *opt_t;
|
||||
char *chp;
|
||||
|
||||
init_unicode();
|
||||
|
||||
/* From the manpage of df from coreutils-6.10:
|
||||
* Disk space is shown in 1K blocks by default, unless the environment
|
||||
* variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
|
||||
*/
|
||||
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
|
||||
df_disp_hr = 512;
|
||||
|
||||
opt = getopt32(argv, "^"
|
||||
"kPTt:"
|
||||
"kPT"
|
||||
IF_FEATURE_DF_FANCY("aiB:")
|
||||
IF_FEATURE_HUMAN_READABLE("hm")
|
||||
"\0"
|
||||
@@ -131,7 +123,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
"k-m:m-k"
|
||||
#endif
|
||||
, &opt_t
|
||||
IF_FEATURE_DF_FANCY(, &chp)
|
||||
);
|
||||
if (opt & OPT_MEGA)
|
||||
@@ -151,6 +142,13 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
got_it: ;
|
||||
}
|
||||
|
||||
/* From the manpage of df from coreutils-6.10:
|
||||
* Disk space is shown in 1K blocks by default, unless the environment
|
||||
* variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
|
||||
*/
|
||||
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
|
||||
df_disp_hr = 512;
|
||||
|
||||
if (opt & OPT_HUMAN) {
|
||||
df_disp_hr = 0;
|
||||
disp_units_hdr = " Size";
|
||||
@@ -180,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) {
|
||||
@@ -216,11 +214,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
mount_point = mount_entry->mnt_dir;
|
||||
fs_type = mount_entry->mnt_type;
|
||||
|
||||
if (opt & OPT_t) {
|
||||
if (strcmp(fs_type, opt_t) != 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (statvfs(mount_point, &s) != 0) {
|
||||
bb_simple_perror_msg(mount_point);
|
||||
goto set_error;
|
||||
|
||||
+13
-22
@@ -40,9 +40,8 @@
|
||||
//usage:#define du_trivial_usage
|
||||
//usage: "[-aHLdclsx" IF_FEATURE_HUMAN_READABLE("hm") "k] [FILE]..."
|
||||
//usage:#define du_full_usage "\n\n"
|
||||
//usage: "Summarize disk space used for FILEs (or directories)\n"
|
||||
//usage: "Summarize disk space used for each FILE and/or directory\n"
|
||||
//usage: "\n -a Show file sizes too"
|
||||
//usage: "\n -b Apparent size (including holes)"
|
||||
//usage: "\n -L Follow all symlinks"
|
||||
//usage: "\n -H Follow symlinks on command line"
|
||||
//usage: "\n -d N Limit output to directories (and files with -a) of depth < N"
|
||||
@@ -85,9 +84,8 @@ enum {
|
||||
OPT_d_maxdepth = (1 << 6),
|
||||
OPT_l_hardlinks = (1 << 7),
|
||||
OPT_c_total = (1 << 8),
|
||||
OPT_b = (1 << 9),
|
||||
OPT_h_for_humans = (1 << 10),
|
||||
OPT_m_mbytes = (1 << 11),
|
||||
OPT_h_for_humans = (1 << 9),
|
||||
OPT_m_mbytes = (1 << 10),
|
||||
};
|
||||
|
||||
struct globals {
|
||||
@@ -111,7 +109,7 @@ static void print(unsigned long long size, const char *filename)
|
||||
/* TODO - May not want to defer error checking here. */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
# if ENABLE_DESKTOP
|
||||
/* ~30 bytes of code for extra compat:
|
||||
/* ~30 bytes of code for extra comtat:
|
||||
* coreutils' du rounds sizes up:
|
||||
* for example, 1025k file is shown as "2" by du -m.
|
||||
* We round to nearest if human-readable [too hard to fix],
|
||||
@@ -126,16 +124,12 @@ static void print(unsigned long long size, const char *filename)
|
||||
* If G.disp_unit == 0, show one fractional
|
||||
* and use suffixes
|
||||
*/
|
||||
make_human_readable_str(size, (option_mask32 & OPT_b) ? 1 : 512, G.disp_unit),
|
||||
make_human_readable_str(size, 512, G.disp_unit),
|
||||
filename);
|
||||
#else
|
||||
if (G.disp_k) {
|
||||
if (!(option_mask32 & OPT_b)) {
|
||||
size++;
|
||||
size >>= 1;
|
||||
} else {
|
||||
size >>= 10;
|
||||
}
|
||||
size++;
|
||||
size >>= 1;
|
||||
}
|
||||
printf("%llu\t%s\n", size, filename);
|
||||
#endif
|
||||
@@ -161,7 +155,7 @@ static unsigned long long du(const char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
sum = ((option_mask32 & OPT_b) ? statbuf.st_size : statbuf.st_blocks);
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
if (G.slink_depth > G.du_depth) { /* -H or -L */
|
||||
@@ -170,7 +164,7 @@ static unsigned long long du(const char *filename)
|
||||
G.status = EXIT_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
sum = ((option_mask32 & OPT_b) ? statbuf.st_size : statbuf.st_blocks);
|
||||
sum = statbuf.st_blocks;
|
||||
if (G.slink_depth == 1) {
|
||||
/* Convert -H to -L */
|
||||
G.slink_depth = INT_MAX;
|
||||
@@ -247,14 +241,11 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
*/
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt = getopt32(argv, "^"
|
||||
"aHkLsxd:+lcbhm"
|
||||
"aHkLsxd:+lchm"
|
||||
"\0" "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s",
|
||||
&G.max_print_depth
|
||||
);
|
||||
argv += optind;
|
||||
if (opt & OPT_b) {
|
||||
G.disp_unit = 1;
|
||||
}
|
||||
if (opt & OPT_h_for_humans) {
|
||||
G.disp_unit = 0;
|
||||
}
|
||||
@@ -266,16 +257,16 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
#else
|
||||
opt = getopt32(argv, "^"
|
||||
"aHkLsxd:+lcb"
|
||||
"aHkLsxd:+lc"
|
||||
"\0" "H-L:L-H:s-d:d-s",
|
||||
&G.max_print_depth
|
||||
);
|
||||
argv += optind;
|
||||
# if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if (opt & OPT_k_kbytes) {
|
||||
G.disp_k = 1;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
if (opt & OPT_H_follow_links) {
|
||||
G.slink_depth = 1;
|
||||
|
||||
+9
-9
@@ -43,10 +43,10 @@
|
||||
//usage:#define echo_trivial_usage
|
||||
//usage: IF_FEATURE_FANCY_ECHO("[-neE] ") "[ARG]..."
|
||||
//usage:#define echo_full_usage "\n\n"
|
||||
//usage: "Print ARGs to stdout"
|
||||
//usage: "Print the specified ARGs to stdout"
|
||||
//usage: IF_FEATURE_FANCY_ECHO( "\n"
|
||||
//usage: "\n -n No trailing newline"
|
||||
//usage: "\n -e Interpret backslash escapes (\\t=tab etc)"
|
||||
//usage: "\n -n Suppress trailing newline"
|
||||
//usage: "\n -e Interpret backslash escapes (i.e., \\t=tab)"
|
||||
//usage: "\n -E Don't interpret backslash escapes (default)"
|
||||
//usage: )
|
||||
//usage:
|
||||
@@ -87,7 +87,6 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *out;
|
||||
char *buffer;
|
||||
unsigned buflen;
|
||||
int err;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
enum {
|
||||
eflag = 0, /* 0 -- disable escape sequences */
|
||||
@@ -186,12 +185,13 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
|
||||
do_write:
|
||||
/* Careful to error out on partial writes too (think ENOSPC!) */
|
||||
errno = 0;
|
||||
err = full_write(STDOUT_FILENO, buffer, out - buffer) != out - buffer;
|
||||
if (err) {
|
||||
bb_simple_perror_msg(bb_msg_write_error);
|
||||
}
|
||||
/*r =*/ full_write(STDOUT_FILENO, buffer, out - buffer);
|
||||
free(buffer);
|
||||
return err;
|
||||
if (/*WRONG:r < 0*/ errno) {
|
||||
bb_perror_msg(bb_msg_write_error);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+8
-13
@@ -39,15 +39,12 @@
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/env.html */
|
||||
|
||||
//usage:#define env_trivial_usage
|
||||
//usage: "[-i0] [-u NAME]... [-] [NAME=VALUE]... [PROG ARGS]"
|
||||
// The "-" can occur only once (unlike, say, -i): it terminates option processing,
|
||||
// so if it is followed by another "-" arg (or any option-looking arg),
|
||||
// that arg will be taken as PROG (or even as NAME=VALUE, example: "-z=QWE").
|
||||
//usage: "[-iu] [-] [name=value]... [PROG ARGS]"
|
||||
//usage:#define env_full_usage "\n\n"
|
||||
//usage: "Print current environment or run PROG after setting up environment\n"
|
||||
//usage: "\n -, -i Start with empty environment"
|
||||
//usage: "\n -0 NUL terminated output"
|
||||
//usage: "\n -u NAME Remove variable from environment"
|
||||
//usage: "Print the current environment or run PROG after setting up\n"
|
||||
//usage: "the specified environment\n"
|
||||
//usage: "\n -, -i Start with an empty environment"
|
||||
//usage: "\n -u Remove variable from the environment"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -57,9 +54,8 @@ int env_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opts;
|
||||
llist_t *unset_env = NULL;
|
||||
|
||||
opts = getopt32long(argv, "+i0u:*",
|
||||
opts = getopt32long(argv, "+iu:*",
|
||||
"ignore-environment\0" No_argument "i"
|
||||
"null\0" No_argument "0"
|
||||
"unset\0" Required_argument "u"
|
||||
, &unset_env
|
||||
);
|
||||
@@ -83,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;
|
||||
}
|
||||
@@ -94,9 +90,8 @@ int env_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
if (environ) { /* clearenv() may set environ == NULL! */
|
||||
char **ep;
|
||||
opts = (opts & 2) ? 0 : '\n';
|
||||
for (ep = environ; *ep; ep++) {
|
||||
printf("%s%c", *ep, opts);
|
||||
puts(*ep);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -123,7 +123,7 @@ static void expand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
fputs_stdout(ptr_strbeg);
|
||||
fputs(ptr_strbeg, stdout);
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
+10
-10
@@ -45,7 +45,7 @@
|
||||
//usage:#define expr_trivial_usage
|
||||
//usage: "EXPRESSION"
|
||||
//usage:#define expr_full_usage "\n\n"
|
||||
//usage: "Print the value of EXPRESSION\n"
|
||||
//usage: "Print the value of EXPRESSION to stdout\n"
|
||||
//usage: "\n"
|
||||
//usage: "EXPRESSION may be:\n"
|
||||
//usage: " ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2\n"
|
||||
@@ -63,7 +63,7 @@
|
||||
//usage: " ARG1 % ARG2\n"
|
||||
//usage: " STRING : REGEXP Anchored pattern match of REGEXP in STRING\n"
|
||||
//usage: " match STRING REGEXP Same as STRING : REGEXP\n"
|
||||
//usage: " substr STRING POS LEN Substring of STRING, POS counts from 1\n"
|
||||
//usage: " substr STRING POS LENGTH Substring of STRING, POS counted from 1\n"
|
||||
//usage: " index STRING CHARS Index in STRING where any CHARS is found, or 0\n"
|
||||
//usage: " length STRING Length of STRING\n"
|
||||
//usage: " quote TOKEN Interpret TOKEN as a string, even if\n"
|
||||
@@ -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
@@ -19,7 +19,6 @@
|
||||
//usage: "Print prime factors"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
#if 0
|
||||
# define dbg(...) bb_error_msg(__VA_ARGS__)
|
||||
@@ -43,116 +42,9 @@ typedef unsigned long half_t;
|
||||
#error Cant find an integer type which is half as wide as ullong
|
||||
#endif
|
||||
|
||||
/* The trial divisor increment wheel. Use it to skip over divisors that
|
||||
* are composites of 2, 3, 5, 7, or 11.
|
||||
* Larger wheels improve sieving only slightly, but quickly grow in size
|
||||
* (adding just one prime, 13, results in 5766 element sieve).
|
||||
*/
|
||||
#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
|
||||
(((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \
|
||||
(((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31)
|
||||
#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
|
||||
R( (a/2),(b/2),(c/2),(d/2),(e/2),(f/2),(g/2),(h/2),(i/2),(j/2), \
|
||||
(A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2) )
|
||||
static const uint64_t packed_wheel[] = {
|
||||
/*1, 2, 2, 4, 2,*/
|
||||
P( 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4), //01
|
||||
P( 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2, 4), //02
|
||||
P( 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4), //03
|
||||
P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2), //04
|
||||
P( 6, 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4), //05
|
||||
P( 2, 6, 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2), //06
|
||||
P( 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6), //07
|
||||
P( 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6), //08
|
||||
P( 8, 6, 4, 2,10, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6), //09
|
||||
P( 4, 2, 4, 6, 6, 2, 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4), //10
|
||||
P( 6, 6, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2), //11
|
||||
P( 6, 4, 6, 2, 6, 4, 2, 4, 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2), //12
|
||||
P( 4, 8,10, 6, 2, 4, 8, 6, 6, 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2), //13
|
||||
P(10, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 6, 6, 4, 6, 8), //14
|
||||
P( 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6, 2, 6, 6, 4, 2, 4, 6, 8, 4), //15
|
||||
P( 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2,10, 2, 4, 6, 8, 6, 4, 2), //16
|
||||
P( 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 6), //17
|
||||
P( 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2,10, 6), //18
|
||||
P( 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4, 6, 2, 4, 6, 2), //19
|
||||
P(12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4, 6, 2, 6, 4), //20
|
||||
P( 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6, 4, 6, 2), //21
|
||||
P( 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4, 2,10), //22
|
||||
P( 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8, 6), //23
|
||||
P( 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12), //24
|
||||
};
|
||||
#undef P
|
||||
#undef R
|
||||
#define WHEEL_START 5
|
||||
#define WHEEL_SIZE (5 + 24 * 20)
|
||||
#define square_count (((uint8_t*)&bb_common_bufsiz1)[0])
|
||||
#define wheel_tab (((uint8_t*)&bb_common_bufsiz1) + 1)
|
||||
/*
|
||||
* Why, you ask?
|
||||
* plain byte array:
|
||||
* function old new delta
|
||||
* wheel_tab - 485 +485
|
||||
* 3-bit-packed insanity:
|
||||
* packed_wheel - 192 +192
|
||||
* factor_main 108 171 +63
|
||||
*/
|
||||
static void unpack_wheel(void)
|
||||
{
|
||||
int i;
|
||||
uint8_t *p;
|
||||
|
||||
setup_common_bufsiz();
|
||||
wheel_tab[0] = 1;
|
||||
wheel_tab[1] = 2;
|
||||
wheel_tab[2] = 2;
|
||||
wheel_tab[3] = 4;
|
||||
wheel_tab[4] = 2;
|
||||
p = &wheel_tab[5];
|
||||
for (i = 0; i < ARRAY_SIZE(packed_wheel); i++) {
|
||||
uint64_t v = packed_wheel[i];
|
||||
while ((v & 0xe) != 0) {
|
||||
*p = v & 0xe;
|
||||
//printf("%2u,", *p);
|
||||
p++;
|
||||
v >>= 3;
|
||||
}
|
||||
//printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* Prevent inlining, factorize() needs all help it can get with reducing register pressure */
|
||||
static NOINLINE void print_w(wide_t n)
|
||||
{
|
||||
unsigned rep = square_count;
|
||||
do
|
||||
printf(" %llu", n);
|
||||
while (--rep != 0);
|
||||
}
|
||||
static NOINLINE void print_h(half_t n)
|
||||
{
|
||||
print_w(n);
|
||||
}
|
||||
|
||||
static void factorize(wide_t N);
|
||||
|
||||
static half_t isqrt_odd(wide_t N)
|
||||
{
|
||||
half_t s = isqrt(N);
|
||||
/* s^2 is <= N, (s+1)^2 > N */
|
||||
|
||||
/* If s^2 in fact is EQUAL to N, it's very lucky.
|
||||
* Examples:
|
||||
* factor 18446743988964486098 = 2 * 3037000493 * 3037000493
|
||||
* factor 18446743902517389507 = 3 * 2479700513 * 2479700513
|
||||
*/
|
||||
if ((wide_t)s * s == N) {
|
||||
/* factorize sqrt(N), printing each factor twice */
|
||||
square_count *= 2;
|
||||
factorize(s);
|
||||
/* Let caller know we recursed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Subtract 1 from even s, odd s won't change: */
|
||||
/* (doesnt work for zero, but we know that s != 0 here) */
|
||||
s = (s - 1) | 1;
|
||||
@@ -161,20 +53,43 @@ static half_t isqrt_odd(wide_t N)
|
||||
|
||||
static NOINLINE void factorize(wide_t N)
|
||||
{
|
||||
unsigned w;
|
||||
half_t factor;
|
||||
half_t max_factor;
|
||||
// unsigned count3;
|
||||
// unsigned count5;
|
||||
// unsigned count7;
|
||||
// ^^^^^^^^^^^^^^^ commented-out simple sieving code (easier to grasp).
|
||||
// Faster sieving, using one word for potentially up to 6 counters:
|
||||
// count upwards in each mask, counter "triggers" when it sets its mask to "100[0]..."
|
||||
// 10987654321098765432109876543210 - bits 31-0 in 32-bit word
|
||||
// 17777713333311111777775555333 - bit masks for counters for primes 3,5,7,11,13,17
|
||||
// 100000100001000010001001 - value for adding 1 to each mask
|
||||
// 10000010000010000100001000100 - value for checking that any mask reached msb
|
||||
enum {
|
||||
SHIFT_3 = 1 << 0,
|
||||
SHIFT_5 = 1 << 3,
|
||||
SHIFT_7 = 1 << 7,
|
||||
INCREMENT_EACH = SHIFT_3 | SHIFT_5 | SHIFT_7,
|
||||
MULTIPLE_OF_3 = 1 << 2,
|
||||
MULTIPLE_OF_5 = 1 << 6,
|
||||
MULTIPLE_OF_7 = 1 << 11,
|
||||
MULTIPLE_DETECTED = MULTIPLE_OF_3 | MULTIPLE_OF_5 | MULTIPLE_OF_7,
|
||||
};
|
||||
unsigned sieve_word;
|
||||
|
||||
if (N < 4)
|
||||
goto end;
|
||||
|
||||
while (!(N & 1)) {
|
||||
printf(" 2");
|
||||
N >>= 1;
|
||||
}
|
||||
|
||||
/* The code needs to be optimized for the case where
|
||||
* there are large prime factors. For example,
|
||||
* this is not hard:
|
||||
* 8262075252869367027 = 3 7 17 23 47 101 113 127 131 137 823
|
||||
* (the largest divisor to test for largest factor 823
|
||||
* is only ~sqrt(823) = 28, the entire factorization needs
|
||||
* only ~33 trial divisions)
|
||||
* (the largest factor to test is only ~sqrt(823) = 28)
|
||||
* but this is:
|
||||
* 18446744073709551601 = 53 348051774975651917
|
||||
* the last factor requires testing up to
|
||||
@@ -183,37 +98,70 @@ static NOINLINE void factorize(wide_t N)
|
||||
* factor 18446744073709551557 (0xffffffffffffffc5).
|
||||
*/
|
||||
max_factor = isqrt_odd(N);
|
||||
if (!max_factor)
|
||||
return; /* square was detected and recursively factored */
|
||||
factor = 2;
|
||||
w = 0;
|
||||
// count3 = 3;
|
||||
// count5 = 6;
|
||||
// count7 = 9;
|
||||
sieve_word = 0
|
||||
/* initial count for SHIFT_n is (n-1)/2*3: */
|
||||
+ (MULTIPLE_OF_3 - 3 * SHIFT_3)
|
||||
+ (MULTIPLE_OF_5 - 6 * SHIFT_5)
|
||||
+ (MULTIPLE_OF_7 - 9 * SHIFT_7)
|
||||
//+ (MULTIPLE_OF_11 - 15 * SHIFT_11)
|
||||
//+ (MULTIPLE_OF_13 - 18 * SHIFT_13)
|
||||
//+ (MULTIPLE_OF_17 - 24 * SHIFT_17)
|
||||
;
|
||||
factor = 3;
|
||||
for (;;) {
|
||||
half_t fw;
|
||||
|
||||
/* The division is the most costly part of the loop.
|
||||
* On 64bit CPUs, takes at best 12 cycles, often ~20.
|
||||
*/
|
||||
while ((N % factor) == 0) { /* not likely */
|
||||
N = N / factor;
|
||||
print_h(factor);
|
||||
printf(" %"HALF_FMT"u", factor);
|
||||
max_factor = isqrt_odd(N);
|
||||
if (!max_factor)
|
||||
return; /* square was detected */
|
||||
}
|
||||
next_factor:
|
||||
if (factor >= max_factor)
|
||||
break;
|
||||
fw = factor + wheel_tab[w];
|
||||
if (fw < factor)
|
||||
break; /* overflow */
|
||||
factor = fw;
|
||||
w++;
|
||||
if (w < WHEEL_SIZE)
|
||||
factor += 2;
|
||||
/* Rudimentary wheel sieving: skip multiples of 3, 5 and 7:
|
||||
* Every third odd number is divisible by three and thus isn't a prime:
|
||||
* 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47...
|
||||
* ^ ^ ^ ^ ^ ^ ^ _ ^ ^ _ ^ ^ ^ ^
|
||||
* (^ = primes, _ = would-be-primes-if-not-divisible-by-5)
|
||||
* The numbers with space under them are excluded by sieve 3.
|
||||
*/
|
||||
// count7--;
|
||||
// count5--;
|
||||
// count3--;
|
||||
// if (count3 && count5 && count7)
|
||||
// continue;
|
||||
sieve_word += INCREMENT_EACH;
|
||||
if (!(sieve_word & MULTIPLE_DETECTED))
|
||||
continue;
|
||||
w = WHEEL_START;
|
||||
/*
|
||||
* "factor" is multiple of 3 33% of the time (count3 reached 0),
|
||||
* else, multiple of 5 13% of the time,
|
||||
* else, multiple of 7 7.6% of the time.
|
||||
* Cumulatively, with 3,5,7 sieving we are here 54.3% of the time.
|
||||
*/
|
||||
// if (count3 == 0)
|
||||
// count3 = 3;
|
||||
if (sieve_word & MULTIPLE_OF_3)
|
||||
sieve_word -= SHIFT_3 * 3;
|
||||
// if (count5 == 0)
|
||||
// count5 = 5;
|
||||
if (sieve_word & MULTIPLE_OF_5)
|
||||
sieve_word -= SHIFT_5 * 5;
|
||||
// if (count7 == 0)
|
||||
// count7 = 7;
|
||||
if (sieve_word & MULTIPLE_OF_7)
|
||||
sieve_word -= SHIFT_7 * 7;
|
||||
goto next_factor;
|
||||
}
|
||||
end:
|
||||
if (N > 1)
|
||||
print_w(N);
|
||||
printf(" %llu", N);
|
||||
bb_putchar('\n');
|
||||
}
|
||||
|
||||
@@ -228,15 +176,12 @@ static void factorize_numstr(const char *numstr)
|
||||
if (errno)
|
||||
bb_show_usage();
|
||||
printf("%llu:", N);
|
||||
square_count = 1;
|
||||
factorize(N);
|
||||
}
|
||||
|
||||
int factor_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int factor_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unpack_wheel();
|
||||
|
||||
//// coreutils has undocumented option ---debug (three dashes)
|
||||
//getopt32(argv, "");
|
||||
//argv += optind;
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
//usage:#define fold_trivial_usage
|
||||
//usage: "[-bs] [-w WIDTH] [FILE]..."
|
||||
//usage:#define fold_full_usage "\n\n"
|
||||
//usage: "Wrap input lines in FILEs (or stdin), writing to stdout\n"
|
||||
//usage: "Wrap input lines in each FILE (or stdin), writing to stdout\n"
|
||||
//usage: "\n -b Count bytes rather than columns"
|
||||
//usage: "\n -s Break at spaces"
|
||||
//usage: "\n -w Use WIDTH columns instead of 80"
|
||||
|
||||
+7
-8
@@ -29,18 +29,17 @@
|
||||
//usage:#define head_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define head_full_usage "\n\n"
|
||||
//usage: "Print first 10 lines of FILEs (or stdin).\n"
|
||||
//usage: "Print first 10 lines of each FILE (or stdin) to stdout.\n"
|
||||
//usage: "With more than one FILE, precede each with a filename header.\n"
|
||||
//usage: "\n -n N[bkm] Print first N lines"
|
||||
//usage: IF_FEATURE_FANCY_HEAD(
|
||||
//usage: "\n -n -N[bkm] Print all except N last lines"
|
||||
//usage: "\n -c [-]N[bkm] Print first N bytes"
|
||||
//usage: )
|
||||
//usage: "\n (b:*512 k:*1024 m:*1024^2)"
|
||||
//usage: "\n -n N[kbm] Print first N lines"
|
||||
//usage: IF_FEATURE_FANCY_HEAD(
|
||||
//usage: "\n -n -N[kbm] Print all except N last lines"
|
||||
//usage: "\n -c [-]N[kbm] Print first N bytes"
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
|
||||
//usage:
|
||||
//usage:#define head_example_usage
|
||||
//usage: "$ head -n 2 /etc/passwd\n"
|
||||
@@ -118,7 +117,7 @@ print_except_N_last_lines(FILE *fp, unsigned count)
|
||||
char *c;
|
||||
if (head == count)
|
||||
head = 0;
|
||||
fputs_stdout(circle[head]);
|
||||
fputs(circle[head], stdout);
|
||||
c = xmalloc_fgets(fp);
|
||||
if (!c)
|
||||
goto ret;
|
||||
|
||||
+4
-4
@@ -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(
|
||||
@@ -52,7 +52,7 @@
|
||||
//usage:#define groups_trivial_usage
|
||||
//usage: "[USER]"
|
||||
//usage:#define groups_full_usage "\n\n"
|
||||
//usage: "Print the groups USER is in"
|
||||
//usage: "Print the group memberships of USER or for the current process"
|
||||
//usage:
|
||||
//usage:#define groups_example_usage
|
||||
//usage: "$ groups\n"
|
||||
@@ -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)
|
||||
@@ -258,7 +258,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_error_msg_and_die("can't get process context%s",
|
||||
username ? " for a different user" : "");
|
||||
}
|
||||
fputs_stdout(scontext);
|
||||
fputs(scontext, stdout);
|
||||
}
|
||||
/* freecon(NULL) seems to be harmless */
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
|
||||
+1
-1
@@ -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
@@ -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
@@ -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");
|
||||
}
|
||||
+14
-18
@@ -109,11 +109,11 @@
|
||||
//usage:#define ls_full_usage "\n\n"
|
||||
//usage: "List directory contents\n"
|
||||
//usage: "\n -1 One column output"
|
||||
//usage: "\n -a Include names starting with ."
|
||||
//usage: "\n -a Include entries which start with ."
|
||||
//usage: "\n -A Like -a, but exclude . and .."
|
||||
////usage: "\n -C List by columns" - don't show, this is a default anyway
|
||||
//usage: "\n -x List by lines"
|
||||
//usage: "\n -d List directory names, not contents"
|
||||
//usage: "\n -d List directory entries instead of contents"
|
||||
//usage: IF_FEATURE_LS_FOLLOWLINKS(
|
||||
//usage: "\n -L Follow symlinks"
|
||||
//usage: "\n -H Follow symlinks on command line"
|
||||
@@ -122,10 +122,10 @@
|
||||
//usage: "\n -R Recurse"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_LS_FILETYPES(
|
||||
//usage: "\n -p Append / to directory names"
|
||||
//usage: "\n -F Append indicator (one of */=@|) to names"
|
||||
//usage: "\n -p Append / to dir entries"
|
||||
//usage: "\n -F Append indicator (one of */=@|) to entries"
|
||||
//usage: )
|
||||
//usage: "\n -l Long format"
|
||||
//usage: "\n -l Long listing format"
|
||||
//usage: "\n -i List inode numbers"
|
||||
//usage: "\n -n List numeric UIDs and GIDs instead of names"
|
||||
//usage: "\n -s List allocated blocks"
|
||||
@@ -134,7 +134,7 @@
|
||||
//usage: "\n -lu List atime"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(
|
||||
//usage: "\n --full-time List full date/time"
|
||||
//usage: "\n --full-time List full date and time"
|
||||
//usage: ))
|
||||
//usage: IF_FEATURE_HUMAN_READABLE(
|
||||
//usage: "\n -h Human readable sizes (1K 243M 2G)"
|
||||
@@ -160,7 +160,7 @@
|
||||
//usage: "\n -w N Format N columns wide"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_LS_COLOR(
|
||||
//usage: "\n --color[={always,never,auto}]"
|
||||
//usage: "\n --color[={always,never,auto}] Control coloring"
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -187,7 +187,7 @@
|
||||
|
||||
|
||||
enum {
|
||||
TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */
|
||||
TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */
|
||||
|
||||
SPLIT_FILE = 0,
|
||||
SPLIT_DIR = 1,
|
||||
@@ -298,7 +298,7 @@ struct dnode {
|
||||
// but there are invisible fields as well
|
||||
// (such as nanosecond-resolution timespamps)
|
||||
// and padding, which we also don't want to store.
|
||||
// We also pre-parse dev_t dn_rdev (in glibc, it's huge).
|
||||
// We also can pre-parse dev_t dn_rdev (in glibc, it's huge).
|
||||
// On 32-bit uclibc: dnode size went from 112 to 84 bytes.
|
||||
//
|
||||
/* Same names as in struct stat, but with dn_ instead of st_ pfx: */
|
||||
@@ -453,7 +453,7 @@ static unsigned print_name(const char *name)
|
||||
name = printable_string2(&uni_stat, name);
|
||||
|
||||
if (!(option_mask32 & OPT_Q)) {
|
||||
fputs_stdout(name);
|
||||
fputs(name, stdout);
|
||||
return uni_stat.unicode_width;
|
||||
}
|
||||
|
||||
@@ -1145,15 +1145,11 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
#if ENABLE_FEATURE_LS_COLOR
|
||||
/* set G_show_color = 1/0 */
|
||||
if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && !is_TERM_dumb()) {
|
||||
if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && isatty(STDOUT_FILENO)) {
|
||||
char *p = getenv("LS_COLORS");
|
||||
/* LS_COLORS is unset, or (not empty && not "none") ? */
|
||||
if (!p || (p[0] && strcmp(p, "none") != 0)) {
|
||||
if (isatty(STDOUT_FILENO)) {
|
||||
/* check isatty() last because it's expensive (syscall) */
|
||||
G_show_color = 1;
|
||||
}
|
||||
}
|
||||
if (!p || (p[0] && strcmp(p, "none") != 0))
|
||||
G_show_color = 1;
|
||||
}
|
||||
if (opt & OPT_color) {
|
||||
if (color_opt[0] == 'n')
|
||||
@@ -1162,7 +1158,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
if (!is_TERM_dumb() && isatty(STDOUT_FILENO)) {
|
||||
if (isatty(STDOUT_FILENO)) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
|
||||
@@ -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
@@ -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
-3
@@ -36,9 +36,7 @@
|
||||
//usage: "$ mknod /dev/fd0 b 2 0\n"
|
||||
//usage: "$ mknod -m 644 /tmp/pipe p\n"
|
||||
|
||||
#ifdef __linux__
|
||||
# include <sys/sysmacros.h> // For makedev
|
||||
#endif
|
||||
#include <sys/sysmacros.h> // For makedev
|
||||
|
||||
#include "libbb.h"
|
||||
#include "libcoreutils/coreutils.h"
|
||||
|
||||
+26
-52
@@ -23,15 +23,13 @@
|
||||
//kbuild:lib-$(CONFIG_MV) += mv.o
|
||||
|
||||
//usage:#define mv_trivial_usage
|
||||
//usage: "[-finT] SOURCE DEST\n"
|
||||
//usage: "or: mv [-fin] SOURCE... { -t DIRECTORY | DIRECTORY }"
|
||||
//usage: "[-fin] SOURCE DEST\n"
|
||||
//usage: "or: mv [-fin] SOURCE... DIRECTORY"
|
||||
//usage:#define mv_full_usage "\n\n"
|
||||
//usage: "Rename SOURCE to DEST, or move SOURCEs to DIRECTORY\n"
|
||||
//usage: "Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY\n"
|
||||
//usage: "\n -f Don't prompt before overwriting"
|
||||
//usage: "\n -i Interactive, prompt before overwrite"
|
||||
//usage: "\n -n Don't overwrite an existing file"
|
||||
//usage: "\n -T Refuse to move if DEST is a directory"
|
||||
//usage: "\n -t DIR Move all SOURCEs into DIR"
|
||||
//usage:
|
||||
//usage:#define mv_example_usage
|
||||
//usage: "$ mv /tmp/foo /bin/bar\n"
|
||||
@@ -42,7 +40,7 @@
|
||||
int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mv_main(int argc, char **argv)
|
||||
{
|
||||
struct stat statbuf;
|
||||
struct stat dest_stat;
|
||||
const char *last;
|
||||
const char *dest;
|
||||
unsigned flags;
|
||||
@@ -53,66 +51,41 @@ int mv_main(int argc, char **argv)
|
||||
#define OPT_FORCE (1 << 0)
|
||||
#define OPT_INTERACTIVE (1 << 1)
|
||||
#define OPT_NOCLOBBER (1 << 2)
|
||||
#define OPT_DESTNOTDIR (1 << 3)
|
||||
#define OPT_DESTDIR (1 << 4)
|
||||
#define OPT_VERBOSE ((1 << 5) * ENABLE_FEATURE_VERBOSE)
|
||||
#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
|
||||
/* Need at least two arguments.
|
||||
* If more than one of -f, -i, -n is specified , only the final one
|
||||
* takes effect (it unsets previous options).
|
||||
*/
|
||||
flags = getopt32long(argv, "^"
|
||||
"finTt:v"
|
||||
"finv"
|
||||
"\0"
|
||||
/* At least one argument. (Usually two+, but -t DIR can have only one) */
|
||||
"-1"
|
||||
/* only the final one of -f, -i, -n takes effect */
|
||||
":f-in:i-fn:n-fi"
|
||||
/* -t and -T don't mix */
|
||||
":t--T:T--t",
|
||||
"-2:f-in:i-fn:n-fi",
|
||||
"interactive\0" No_argument "i"
|
||||
"force\0" No_argument "f"
|
||||
"no-clobber\0" No_argument "n"
|
||||
"no-target-directory\0" No_argument "T"
|
||||
"target-directory\0" Required_argument "t"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v",
|
||||
&last
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
);
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
last = argv[argc - 1];
|
||||
|
||||
if (!(flags & OPT_DESTDIR)) {
|
||||
last = argv[argc - 1];
|
||||
if (argc < 2)
|
||||
bb_show_usage();
|
||||
if (argc != 2) {
|
||||
if (flags & OPT_DESTNOTDIR)
|
||||
bb_show_usage();
|
||||
/* "mv A B C... DIR" - target must be dir */
|
||||
} else /* argc == 2 */ {
|
||||
/* "mv A B" - only case where target can be not a dir */
|
||||
dest_exists = cp_mv_stat(last, &statbuf);
|
||||
if (dest_exists < 0) { /* error other than ENOENT */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!(dest_exists & 2)) {
|
||||
/* last is not a directory */
|
||||
dest = last;
|
||||
goto DO_MOVE;
|
||||
}
|
||||
/* last is a directory */
|
||||
if (flags & OPT_DESTNOTDIR) {
|
||||
if (stat(argv[0], &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
|
||||
bb_error_msg_and_die("'%s' is a directory", last);
|
||||
/* "mv -T DIR1 DIR2" is allowed (renames a dir) */
|
||||
dest = last;
|
||||
goto DO_MOVE;
|
||||
}
|
||||
/* else: fall through into "do { move SRC to DIR/SRC } while" loop */
|
||||
if (argc == 2) {
|
||||
dest_exists = cp_mv_stat(last, &dest_stat);
|
||||
if (dest_exists < 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!(dest_exists & 2)) { /* last is not a directory */
|
||||
dest = last;
|
||||
goto DO_MOVE;
|
||||
}
|
||||
}
|
||||
/* else: last is DIR from "-t DIR" */
|
||||
|
||||
do {
|
||||
dest = concat_path_file(last, bb_get_last_path_component_strip(*argv));
|
||||
dest_exists = cp_mv_stat(dest, &statbuf);
|
||||
dest_exists = cp_mv_stat(dest, &dest_stat);
|
||||
if (dest_exists < 0) {
|
||||
goto RET_1;
|
||||
}
|
||||
@@ -135,10 +108,11 @@ int mv_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (rename(*argv, dest) < 0) {
|
||||
struct stat source_stat;
|
||||
int source_exists;
|
||||
|
||||
if (errno != EXDEV
|
||||
|| (source_exists = cp_mv_stat2(*argv, &statbuf, lstat)) < 1
|
||||
|| (source_exists = cp_mv_stat2(*argv, &source_stat, lstat)) < 1
|
||||
) {
|
||||
bb_perror_msg("can't rename '%s'", *argv);
|
||||
} else {
|
||||
@@ -185,7 +159,7 @@ int mv_main(int argc, char **argv)
|
||||
if (dest != last) {
|
||||
free((void *) dest);
|
||||
}
|
||||
} while (*++argv && *argv != last);
|
||||
} while (*++argv != last);
|
||||
|
||||
return status;
|
||||
}
|
||||
+2
-2
@@ -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"
|
||||
@@ -68,7 +68,7 @@ int nl_main(int argc UNUSED_PARAM, char **argv)
|
||||
&ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b);
|
||||
ns.all = (opt_b[0] == 'a');
|
||||
ns.nonempty = (opt_b[0] == 't');
|
||||
ns.empty_str = xasprintf("%*s", ns.width + (int)strlen(ns.sep), "");
|
||||
ns.empty_str = xasprintf("%*s\n", ns.width + (int)strlen(ns.sep), "");
|
||||
|
||||
argv += optind;
|
||||
if (!*argv)
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@
|
||||
//kbuild:lib-$(CONFIG_NPROC) += nproc.o
|
||||
|
||||
//usage:#define nproc_trivial_usage
|
||||
//usage: ""IF_LONG_OPTS("[--all] [--ignore=N]")
|
||||
//usage: ""IF_LONG_OPTS("--all --ignore=N")
|
||||
//usage:#define nproc_full_usage "\n\n"
|
||||
//usage: "Print number of available CPUs"
|
||||
//usage: IF_LONG_OPTS(
|
||||
@@ -48,7 +48,7 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
if (cpuid && isdigit(cpuid[strlen(cpuid) - 1]))
|
||||
count++;
|
||||
}
|
||||
IF_FEATURE_CLEAN_UP(closedir(cpusd);)
|
||||
closedir(cpusd);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
|
||||
+21
-21
@@ -422,19 +422,19 @@ print_named_ascii(size_t n_bytes, const char *block,
|
||||
|
||||
masked_c &= 0x7f;
|
||||
if (masked_c == 0x7f) {
|
||||
fputs_stdout(" del");
|
||||
fputs(" del", stdout);
|
||||
continue;
|
||||
}
|
||||
if (masked_c > ' ') {
|
||||
buf[3] = masked_c;
|
||||
fputs_stdout(buf);
|
||||
fputs(buf, stdout);
|
||||
continue;
|
||||
}
|
||||
/* Why? Because printf(" %3.3s") is much slower... */
|
||||
buf[6] = charname[masked_c][0];
|
||||
buf[7] = charname[masked_c][1];
|
||||
buf[8] = charname[masked_c][2];
|
||||
fputs_stdout(buf+5);
|
||||
fputs(buf+5, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ print_ascii(size_t n_bytes, const char *block,
|
||||
|
||||
if (ISPRINT(c)) {
|
||||
buf[3] = c;
|
||||
fputs_stdout(buf);
|
||||
fputs(buf, stdout);
|
||||
continue;
|
||||
}
|
||||
switch (c) {
|
||||
@@ -485,7 +485,7 @@ print_ascii(size_t n_bytes, const char *block,
|
||||
buf[8] = (c & 7) + '0';
|
||||
s = buf + 5;
|
||||
}
|
||||
fputs_stdout(s);
|
||||
fputs(s, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -881,7 +881,7 @@ format_address_label(off_t address, char c)
|
||||
static void
|
||||
dump_hexl_mode_trailer(size_t n_bytes, const char *block)
|
||||
{
|
||||
fputs_stdout(" >");
|
||||
fputs(" >", stdout);
|
||||
while (n_bytes--) {
|
||||
unsigned c = *(unsigned char *) block++;
|
||||
c = (ISPRINT(c) ? c : '.');
|
||||
@@ -1121,13 +1121,13 @@ dump_strings(off_t address, off_t end_offset)
|
||||
|
||||
for (i = 0; (c = buf[i]); i++) {
|
||||
switch (c) {
|
||||
case '\007': fputs_stdout("\\a"); break;
|
||||
case '\b': fputs_stdout("\\b"); break;
|
||||
case '\f': fputs_stdout("\\f"); break;
|
||||
case '\n': fputs_stdout("\\n"); break;
|
||||
case '\r': fputs_stdout("\\r"); break;
|
||||
case '\t': fputs_stdout("\\t"); break;
|
||||
case '\v': fputs_stdout("\\v"); break;
|
||||
case '\007': fputs("\\a", stdout); break;
|
||||
case '\b': fputs("\\b", stdout); break;
|
||||
case '\f': fputs("\\f", stdout); break;
|
||||
case '\n': fputs("\\n", stdout); break;
|
||||
case '\r': fputs("\\r", stdout); break;
|
||||
case '\t': fputs("\\t", stdout); break;
|
||||
case '\v': fputs("\\v", stdout); break;
|
||||
default: putchar(c);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
+4
-4
@@ -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"
|
||||
@@ -53,7 +53,7 @@ static void paste_files(FILE** files, int file_cnt, char* delims, int del_cnt)
|
||||
--active_files;
|
||||
continue;
|
||||
}
|
||||
fputs_stdout(line);
|
||||
fputs(line, stdout);
|
||||
free(line);
|
||||
delim = '\n';
|
||||
if (i != file_cnt - 1) {
|
||||
@@ -79,7 +79,7 @@ static void paste_files_separate(FILE** files, char* delims, int del_cnt)
|
||||
line = NULL;
|
||||
while ((next_line = xmalloc_fgetline(files[i])) != NULL) {
|
||||
if (line) {
|
||||
fputs_stdout(line);
|
||||
fputs(line, stdout);
|
||||
free(line);
|
||||
delim = delims[del_idx++];
|
||||
if (del_idx == del_cnt)
|
||||
@@ -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
-2
@@ -122,7 +122,6 @@ static void FAST_FUNC conv_strtod(const char *arg, void *result)
|
||||
char *end;
|
||||
/* Well, this one allows leading whitespace... so what? */
|
||||
/* What I like much less is that "-" accepted too! :( */
|
||||
//TODO: needs setlocale(LC_NUMERIC, "C")?
|
||||
*(double*)result = strtod(arg, &end);
|
||||
if (end[0]) {
|
||||
errno = ERANGE;
|
||||
@@ -431,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();
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
//usage:#define realpath_trivial_usage
|
||||
//usage: "FILE..."
|
||||
//usage:#define realpath_full_usage "\n\n"
|
||||
//usage: "Print absolute pathnames of FILEs"
|
||||
//usage: "Return the absolute pathnames of given FILE"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
|
||||
+1
-1
@@ -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
@@ -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"
|
||||
|
||||
+11
-16
@@ -15,15 +15,14 @@
|
||||
//kbuild:lib-$(CONFIG_SHRED) += shred.o
|
||||
|
||||
//usage:#define shred_trivial_usage
|
||||
//usage: "[-fuz] [-n N] [-s SIZE] FILE..."
|
||||
//usage: "FILE..."
|
||||
//usage:#define shred_full_usage "\n\n"
|
||||
//usage: "Overwrite/delete FILEs\n"
|
||||
//usage: "\n -f Chmod to ensure writability"
|
||||
//usage: "\n -s SIZE Size to write"
|
||||
//usage: "\n -n N Overwrite N times (default 3)"
|
||||
//usage: "\n -z Final overwrite with zeros"
|
||||
//usage: "\n -u Remove file"
|
||||
//-x (exact: don't round up to 4k) and -v (verbose) are accepted but have no effect
|
||||
//-x and -v are accepted but have no effect
|
||||
|
||||
/* shred (GNU coreutils) 8.25:
|
||||
-f, --force change permissions to allow writing if necessary
|
||||
@@ -42,7 +41,6 @@
|
||||
int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int shred_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
char *opt_s;
|
||||
int rand_fd = rand_fd; /* for compiler */
|
||||
int zero_fd;
|
||||
unsigned num_iter = 3;
|
||||
@@ -54,16 +52,18 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
|
||||
OPT_n = (1 << 3),
|
||||
OPT_v = (1 << 4),
|
||||
OPT_x = (1 << 5),
|
||||
OPT_s = (1 << 6),
|
||||
};
|
||||
|
||||
opt = getopt32(argv, "^" "fuzn:+vxs:" "\0" "-1"/*min 1 arg*/, &num_iter, &opt_s);
|
||||
opt = getopt32(argv, "fuzn:+vx", &num_iter);
|
||||
argv += optind;
|
||||
|
||||
zero_fd = xopen("/dev/zero", O_RDONLY);
|
||||
if (num_iter != 0)
|
||||
rand_fd = xopen("/dev/urandom", O_RDONLY);
|
||||
|
||||
if (!*argv)
|
||||
bb_show_usage();
|
||||
|
||||
for (;;) {
|
||||
struct stat sb;
|
||||
const char *fname;
|
||||
@@ -85,11 +85,6 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
|
||||
off_t size = sb.st_size;
|
||||
|
||||
if (opt & OPT_s) {
|
||||
size = BB_STRTOOFF(opt_s, NULL, 0); /* accepts oct/hex */
|
||||
if (errno || size < 0) bb_show_usage();
|
||||
}
|
||||
|
||||
for (i = 0; i < num_iter; i++) {
|
||||
bb_copyfd_size(rand_fd, fd, size);
|
||||
fdatasync(fd);
|
||||
@@ -99,12 +94,12 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_copyfd_size(zero_fd, fd, size);
|
||||
fdatasync(fd);
|
||||
}
|
||||
if (opt & OPT_u) {
|
||||
ftruncate(fd, 0);
|
||||
xunlink(fname);
|
||||
}
|
||||
xclose(fd);
|
||||
}
|
||||
if (opt & OPT_u) {
|
||||
ftruncate(fd, 0);
|
||||
xunlink(fname);
|
||||
}
|
||||
xclose(fd);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -74,6 +74,10 @@ int sleep_main(int argc UNUSED_PARAM, char **argv)
|
||||
sleep(INT_MAX);
|
||||
|
||||
#if ENABLE_FEATURE_FANCY_SLEEP
|
||||
# if ENABLE_FLOAT_DURATION
|
||||
/* undo busybox.c setlocale */
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
# endif
|
||||
duration = 0;
|
||||
do {
|
||||
duration += parse_duration_str(*argv);
|
||||
|
||||
+8
-9
@@ -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"
|
||||
@@ -67,7 +67,7 @@
|
||||
//usage: "\n -r Reverse sort order"
|
||||
//usage: "\n -s Stable (don't sort ties alphabetically)"
|
||||
//usage: "\n -u Suppress duplicate lines"
|
||||
//usage: "\n -z NUL terminated input and output"
|
||||
//usage: "\n -z Lines are terminated by NUL, not newline"
|
||||
///////: "\n -m Ignored for GNU compatibility"
|
||||
///////: "\n -S BUFSZ Ignored for GNU compatibility"
|
||||
///////: "\n -T TMPDIR Ignored for GNU compatibility"
|
||||
@@ -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:
|
||||
@@ -295,7 +295,6 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
#if ENABLE_FEATURE_SORT_BIG
|
||||
case FLAG_g: {
|
||||
char *xx, *yy;
|
||||
//TODO: needs setlocale(LC_NUMERIC, "C")?
|
||||
double dx = strtod(x, &xx);
|
||||
double dy = strtod(y, &yy);
|
||||
/* not numbers < NaN < -infinity < numbers < +infinity) */
|
||||
@@ -399,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
|
||||
@@ -462,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,
|
||||
@@ -505,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
@@ -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;
|
||||
|
||||
+42
-38
@@ -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);
|
||||
@@ -439,7 +444,7 @@ static void print_it(const char *masterformat,
|
||||
|
||||
/* print preceding string */
|
||||
*p = '\0';
|
||||
fputs_stdout(b);
|
||||
fputs(b, stdout);
|
||||
|
||||
p += len;
|
||||
b = p + 1;
|
||||
@@ -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;
|
||||
|
||||
+6
-6
@@ -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 )
|
||||
@@ -855,7 +855,7 @@ static void wrapf(const char *message, ...)
|
||||
}
|
||||
}
|
||||
}
|
||||
fputs_stdout(buf);
|
||||
fputs(buf, stdout);
|
||||
G.current_col += buflen;
|
||||
if (buf[buflen-1] == '\n')
|
||||
G.current_col = 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 */
|
||||
|
||||
+29
-44
@@ -48,20 +48,19 @@
|
||||
//usage:#define tail_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define tail_full_usage "\n\n"
|
||||
//usage: "Print last 10 lines of FILEs (or stdin) to.\n"
|
||||
//usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n"
|
||||
//usage: "With more than one FILE, precede each with a filename header.\n"
|
||||
//usage: "\n -c [+]N[bkm] Print last N bytes"
|
||||
//usage: "\n -n N[bkm] Print last N lines"
|
||||
//usage: "\n -n +N[bkm] Start on Nth line and print the rest"
|
||||
//usage: "\n (b:*512 k:*1024 m:*1024^2)"
|
||||
//usage: "\n -f Print data as file grows"
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: "\n -n N[kbm] Print last N lines"
|
||||
//usage: "\n -n +N[kbm] Start on Nth line and print the rest"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: )
|
||||
//usage: "\n -f Print data as file grows"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -F Same as -f, but keep retrying"
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: "\n -F Same as -f, but keep retrying"
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
|
||||
//usage: )
|
||||
//usage:
|
||||
//usage:#define tail_example_usage
|
||||
@@ -90,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;
|
||||
}
|
||||
|
||||
@@ -119,7 +118,7 @@ int tail_main(int argc, char **argv)
|
||||
|
||||
char *tailbuf;
|
||||
size_t tailbufsize;
|
||||
unsigned header_threshold = 1;
|
||||
unsigned header_threshhold = 1;
|
||||
unsigned nfiles;
|
||||
int i, opt;
|
||||
|
||||
@@ -152,10 +151,10 @@ int tail_main(int argc, char **argv)
|
||||
if (opt & 0x2) count = eat_num(str_c); // -c
|
||||
if (opt & 0x4) count = eat_num(str_n); // -n
|
||||
#if ENABLE_FEATURE_FANCY_TAIL
|
||||
/* q: make it impossible for nfiles to be > header_threshold */
|
||||
if (opt & 0x8) header_threshold = UINT_MAX; // -q
|
||||
/* q: make it impossible for nfiles to be > header_threshhold */
|
||||
if (opt & 0x8) header_threshhold = UINT_MAX; // -q
|
||||
//if (opt & 0x10) // -s
|
||||
if (opt & 0x20) header_threshold = 0; // -v
|
||||
if (opt & 0x20) header_threshhold = 0; // -v
|
||||
# define FOLLOW_RETRY (opt & 0x40)
|
||||
#else
|
||||
# define FOLLOW_RETRY 0
|
||||
@@ -187,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;
|
||||
@@ -216,7 +215,7 @@ int tail_main(int argc, char **argv)
|
||||
if (ENABLE_FEATURE_FANCY_TAIL && fd < 0)
|
||||
continue; /* may happen with -F */
|
||||
|
||||
if (nfiles > header_threshold) {
|
||||
if (nfiles > header_threshhold) {
|
||||
tail_xprint_header(fmt, argv[i]);
|
||||
fmt = header_fmt_str;
|
||||
}
|
||||
@@ -346,11 +345,9 @@ int tail_main(int argc, char **argv)
|
||||
int nread;
|
||||
const char *filename = argv[i];
|
||||
int fd = fds[i];
|
||||
int new_fd = -1;
|
||||
struct stat sbuf;
|
||||
|
||||
if (FOLLOW_RETRY) {
|
||||
struct stat fsbuf;
|
||||
struct stat sbuf, fsbuf;
|
||||
|
||||
if (fd < 0
|
||||
|| fstat(fd, &fsbuf) < 0
|
||||
@@ -358,51 +355,39 @@ int tail_main(int argc, char **argv)
|
||||
|| fsbuf.st_dev != sbuf.st_dev
|
||||
|| fsbuf.st_ino != sbuf.st_ino
|
||||
) {
|
||||
/* Looks like file has been created/renamed/deleted */
|
||||
int new_fd;
|
||||
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
new_fd = open(filename, O_RDONLY);
|
||||
if (new_fd >= 0) {
|
||||
bb_error_msg("%s has %s; following end of new file",
|
||||
filename, (fd < 0) ? "appeared" : "been replaced"
|
||||
);
|
||||
if (fd < 0) {
|
||||
/* No previously open fd for this file,
|
||||
* start using new_fd immediately. */
|
||||
fds[i] = fd = new_fd;
|
||||
new_fd = -1;
|
||||
}
|
||||
} else if (fd >= 0) {
|
||||
bb_perror_msg("%s has been renamed or deleted", filename);
|
||||
bb_perror_msg("%s has become inaccessible", filename);
|
||||
}
|
||||
fds[i] = fd = new_fd;
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_FANCY_TAIL && fd < 0)
|
||||
continue;
|
||||
if (nfiles > header_threshold) {
|
||||
if (nfiles > header_threshhold) {
|
||||
fmt = header_fmt_str;
|
||||
}
|
||||
for (;;) {
|
||||
/* tail -f keeps following files even if they are truncated */
|
||||
struct stat sbuf;
|
||||
/* /proc files report zero st_size, don't lseek them */
|
||||
if (fstat(fd, &sbuf) == 0
|
||||
/* && S_ISREG(sbuf.st_mode) TODO? */
|
||||
&& sbuf.st_size > 0
|
||||
) {
|
||||
if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) {
|
||||
off_t current = lseek(fd, 0, SEEK_CUR);
|
||||
if (sbuf.st_size < current) {
|
||||
//bb_perror_msg("%s: file truncated", filename); - says coreutils 8.32
|
||||
if (sbuf.st_size < current)
|
||||
xlseek(fd, 0, SEEK_SET);
|
||||
}
|
||||
}
|
||||
|
||||
nread = tail_read(fd, tailbuf, BUFSIZ);
|
||||
if (nread <= 0) {
|
||||
if (new_fd < 0)
|
||||
break;
|
||||
/* Switch to "tail -F"ing the new file */
|
||||
xmove_fd(new_fd, fd);
|
||||
new_fd = -1;
|
||||
continue;
|
||||
}
|
||||
if (nread <= 0)
|
||||
break;
|
||||
if (fmt && (fd != prev_fd)) {
|
||||
tail_xprint_header(fmt, filename);
|
||||
fmt = NULL;
|
||||
|
||||
+4
-20
@@ -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
@@ -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
@@ -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)) {
|
||||
|
||||
+74
-69
@@ -19,8 +19,16 @@
|
||||
//config: touch is used to create or change the access and/or
|
||||
//config: modification timestamp of specified files.
|
||||
//config:
|
||||
//config:config FEATURE_TOUCH_NODEREF
|
||||
//config: bool "Add support for -h"
|
||||
//config: default y
|
||||
//config: depends on TOUCH
|
||||
//config: help
|
||||
//config: Enable touch to have the -h option.
|
||||
//config: This requires libc support for lutimes() function.
|
||||
//config:
|
||||
//config:config FEATURE_TOUCH_SUSV3
|
||||
//config: bool "Add support for SUSV3 features (-a -d -m -t -r)"
|
||||
//config: bool "Add support for SUSV3 features (-d -t -r)"
|
||||
//config: default y
|
||||
//config: depends on TOUCH
|
||||
//config: help
|
||||
@@ -30,17 +38,18 @@
|
||||
|
||||
//kbuild:lib-$(CONFIG_TOUCH) += touch.o
|
||||
|
||||
/* BB_AUDIT SUSv3 _NOT_ compliant -- options -a, -m not supported. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/touch.html */
|
||||
|
||||
//usage:#define touch_trivial_usage
|
||||
//usage: "[-ch" IF_FEATURE_TOUCH_SUSV3("am") "]"
|
||||
//usage: IF_FEATURE_TOUCH_SUSV3(" [-d DATE] [-t DATE] [-r FILE]")
|
||||
//usage: " FILE..."
|
||||
//usage: "[-c]" IF_FEATURE_TOUCH_SUSV3(" [-d DATE] [-t DATE] [-r FILE]") " FILE..."
|
||||
//usage:#define touch_full_usage "\n\n"
|
||||
//usage: "Update mtime of FILEs\n"
|
||||
//usage: "Update the last-modified date on the given FILE[s]\n"
|
||||
//usage: "\n -c Don't create files"
|
||||
//usage: IF_FEATURE_TOUCH_NODEREF(
|
||||
//usage: "\n -h Don't follow links"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_TOUCH_SUSV3(
|
||||
//usage: "\n -a Change only atime"
|
||||
//usage: "\n -m Change only mtime"
|
||||
//usage: "\n -d DT Date/time to use"
|
||||
//usage: "\n -t DT Date/time to use"
|
||||
//usage: "\n -r FILE Use FILE's date/time"
|
||||
@@ -76,68 +85,70 @@ int touch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int fd;
|
||||
int status = EXIT_SUCCESS;
|
||||
int opts;
|
||||
smalluint status = EXIT_SUCCESS;
|
||||
enum {
|
||||
OPT_c = (1 << 0),
|
||||
OPT_r = (1 << 1) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_d = (1 << 2) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_t = (1 << 3) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_h = (1 << 4) * ENABLE_FEATURE_TOUCH_NODEREF,
|
||||
};
|
||||
#if ENABLE_FEATURE_TOUCH_SUSV3
|
||||
char *reference_file;
|
||||
char *date_str;
|
||||
/* timebuf[0] is atime, timebuf[1] is mtime */
|
||||
struct timespec timebuf[2];
|
||||
# if ENABLE_LONG_OPTS
|
||||
static const char touch_longopts[] ALIGN1 =
|
||||
/* name, has_arg, val */
|
||||
"no-create\0" No_argument "c"
|
||||
"reference\0" Required_argument "r"
|
||||
"date\0" Required_argument "d"
|
||||
IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h")
|
||||
;
|
||||
# define GETOPT32 getopt32long
|
||||
# define LONGOPTS ,touch_longopts
|
||||
# else
|
||||
# define GETOPT32 getopt32
|
||||
# define LONGOPTS
|
||||
# endif
|
||||
char *reference_file = NULL;
|
||||
char *date_str = NULL;
|
||||
struct timeval timebuf[2];
|
||||
timebuf[1].tv_usec = timebuf[0].tv_usec = 0;
|
||||
#else
|
||||
# define reference_file NULL
|
||||
# define date_str NULL
|
||||
# define timebuf ((struct timespec*)NULL)
|
||||
# define timebuf ((struct timeval*)NULL)
|
||||
# define GETOPT32 getopt32
|
||||
# define LONGOPTS
|
||||
#endif
|
||||
|
||||
enum {
|
||||
OPT_c = (1 << 0),
|
||||
OPT_h = (1 << 1),
|
||||
OPT_r = (1 << 2) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_d = (1 << 3) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_t = (1 << 4) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_a = (1 << 5) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_m = (1 << 6) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
};
|
||||
#if ENABLE_LONG_OPTS
|
||||
static const char touch_longopts[] ALIGN1 =
|
||||
/* name, has_arg, val */
|
||||
"no-create\0" No_argument "c"
|
||||
"no-dereference\0" No_argument "h"
|
||||
IF_FEATURE_TOUCH_SUSV3("reference\0" Required_argument "r")
|
||||
IF_FEATURE_TOUCH_SUSV3("date\0" Required_argument "d")
|
||||
;
|
||||
#endif
|
||||
/* -d and -t both set time. In coreutils,
|
||||
* accepted data format differs a bit between -d and -t.
|
||||
* We accept the same formats for both
|
||||
*/
|
||||
opts = getopt32long(argv, "^"
|
||||
"ch"
|
||||
IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
|
||||
/*ignored:*/ "f" IF_NOT_FEATURE_TOUCH_SUSV3("am")
|
||||
"\0" /* opt_complementary: */
|
||||
/* at least one arg: */ "-1"
|
||||
/* coreutils forbids -r and -t at once: */ IF_FEATURE_TOUCH_SUSV3(":r--t:t--r")
|
||||
/* but allows these combinations: "r--d:d--r:t--d:d--t" */
|
||||
, touch_longopts
|
||||
#if ENABLE_FEATURE_TOUCH_SUSV3
|
||||
, &reference_file
|
||||
, &date_str
|
||||
, &date_str
|
||||
#endif
|
||||
* We accept the same formats for both */
|
||||
opts = GETOPT32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:")
|
||||
IF_FEATURE_TOUCH_NODEREF("h")
|
||||
/*ignored:*/ "fma"
|
||||
LONGOPTS
|
||||
IF_FEATURE_TOUCH_SUSV3(, &reference_file)
|
||||
IF_FEATURE_TOUCH_SUSV3(, &date_str)
|
||||
IF_FEATURE_TOUCH_SUSV3(, &date_str)
|
||||
);
|
||||
|
||||
#if ENABLE_FEATURE_TOUCH_SUSV3
|
||||
timebuf[0].tv_nsec = timebuf[1].tv_nsec = UTIME_NOW;
|
||||
if (opts & OPT_r) {
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (reference_file) {
|
||||
struct stat stbuf;
|
||||
xstat(reference_file, &stbuf);
|
||||
timebuf[0].tv_sec = stbuf.st_atime;
|
||||
timebuf[1].tv_sec = stbuf.st_mtime;
|
||||
timebuf[0].tv_nsec = stbuf.st_atim.tv_nsec;
|
||||
timebuf[1].tv_nsec = stbuf.st_mtim.tv_nsec;
|
||||
timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime;
|
||||
/* Can use .st_mtim.tv_nsec
|
||||
* (or is it .st_mtimensec?? see date.c)
|
||||
* to set microseconds too.
|
||||
*/
|
||||
}
|
||||
if (opts & (OPT_d|OPT_t)) {
|
||||
|
||||
if (date_str) {
|
||||
struct tm tm_time;
|
||||
time_t t;
|
||||
|
||||
@@ -152,21 +163,15 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
t = validate_tm_time(date_str, &tm_time);
|
||||
|
||||
timebuf[1].tv_sec = timebuf[0].tv_sec = t;
|
||||
timebuf[1].tv_nsec = timebuf[0].tv_nsec = 0;
|
||||
}
|
||||
/* If both -a and -m specified, both times should be set.
|
||||
* IOW: set OMIT only if one, not both, of them is given!
|
||||
*/
|
||||
if ((opts & (OPT_a|OPT_m)) == OPT_a)
|
||||
timebuf[1].tv_nsec = UTIME_OMIT;
|
||||
if ((opts & (OPT_a|OPT_m)) == OPT_m)
|
||||
timebuf[0].tv_nsec = UTIME_OMIT;
|
||||
#endif
|
||||
|
||||
argv += optind;
|
||||
do {
|
||||
int result = utimensat(AT_FDCWD, *argv, timebuf,
|
||||
(opts & OPT_h) ? AT_SYMLINK_NOFOLLOW : 0);
|
||||
int result;
|
||||
result = (
|
||||
#if ENABLE_FEATURE_TOUCH_NODEREF
|
||||
(opts & OPT_h) ? lutimes :
|
||||
#endif
|
||||
utimes)(*argv, (reference_file || date_str) ? timebuf : NULL);
|
||||
if (result != 0) {
|
||||
if (errno == ENOENT) { /* no such file? */
|
||||
if (opts & OPT_c) {
|
||||
@@ -176,9 +181,9 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Try to create the file */
|
||||
fd = open(*argv, O_RDWR | O_CREAT, 0666);
|
||||
if (fd >= 0) {
|
||||
if (opts & (OPT_r|OPT_d|OPT_t))
|
||||
futimens(fd, timebuf);
|
||||
xclose(fd);
|
||||
if (reference_file || date_str)
|
||||
utimes(*argv, timebuf);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
//usage:#define truncate_trivial_usage
|
||||
//usage: "[-c] -s SIZE FILE..."
|
||||
//usage:#define truncate_full_usage "\n\n"
|
||||
//usage: "Truncate FILEs to SIZE\n"
|
||||
//usage: "Truncate FILEs to the given size\n"
|
||||
//usage: "\n -c Do not create files"
|
||||
//usage: "\n -s SIZE"
|
||||
//usage: "\n -s SIZE Truncate to SIZE"
|
||||
//usage:
|
||||
//usage:#define truncate_example_usage
|
||||
//usage: "$ truncate -s 1G foo"
|
||||
|
||||
Loaded 100 of 627 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user