Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbd3b883a8 | ||
|
|
30ffa2bb15 | ||
|
|
d811a8cd01 | ||
|
|
71afe6c513 | ||
|
|
0f668aad7f | ||
|
|
06f7cf1487 | ||
|
|
58cbf385e0 | ||
|
|
e7629ffbf5 | ||
|
|
e4c7cf3f8c | ||
|
|
4ac4f60942 | ||
|
|
94f6d1ece0 |
No files matched your search
@@ -312,6 +312,7 @@ config BUSYBOX_EXEC_PATH
|
||||
config SELINUX
|
||||
bool "Support NSA Security Enhanced Linux"
|
||||
default n
|
||||
select PLATFORM_LINUX
|
||||
help
|
||||
Enable support for SELinux in applets ls, ps, and id. Also provide
|
||||
the option of compiling in SELinux applets.
|
||||
@@ -357,6 +358,17 @@ config FEATURE_SYSLOG
|
||||
#This option is auto-selected when you select any applet which may
|
||||
#send its output to syslog. You do not need to select it manually.
|
||||
|
||||
config PLATFORM_LINUX
|
||||
bool #No description makes it a hidden option
|
||||
default n
|
||||
#help
|
||||
#For the most part, busybox requires only POSIX compatibility
|
||||
#from the target system, but some applets and features use
|
||||
#Linux-specific interfaces.
|
||||
#
|
||||
#This is automatically selected if any applet or feature requires
|
||||
#Linux-specific interfaces. You do not need to select it manually.
|
||||
|
||||
comment 'Build Options'
|
||||
|
||||
config STATIC
|
||||
@@ -529,14 +541,6 @@ config STACK_OPTIMIZATION_386
|
||||
do not work with it (they use SSE instructions without
|
||||
ensuring stack alignment).
|
||||
|
||||
config STATIC_LIBGCC
|
||||
bool "Use -static-libgcc"
|
||||
default y
|
||||
help
|
||||
This option instructs gcc to link in a static version of its
|
||||
support library, libgcc. This means that the binary will require
|
||||
one fewer dynamic library at run time.
|
||||
|
||||
comment 'Installation Options ("make install" behavior)'
|
||||
|
||||
choice
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 35
|
||||
SUBLEVEL = 0
|
||||
PATCHLEVEL = 32
|
||||
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
|
||||
|
||||
+11
-12
@@ -58,8 +58,7 @@ CFLAGS += $(call cc-option,-fno-builtin-strlen -fomit-frame-pointer -ffunction-s
|
||||
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
|
||||
CFLAGS += $(call cc-option,-funsigned-char,)
|
||||
|
||||
ifeq ($(CONFIG_STATIC_LIBGCC),y)
|
||||
# Disable it, for example, if you get
|
||||
ifneq ($(CC),clang)
|
||||
# "clang-9: warning: argument unused during compilation: '-static-libgcc'"
|
||||
CFLAGS += $(call cc-option,-static-libgcc,)
|
||||
endif
|
||||
@@ -145,21 +144,18 @@ 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) $(CFLAGS_busybox) -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) $(CFLAGS_busybox) -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
|
||||
LDLIBS += m rt crypt
|
||||
else
|
||||
LDLIBS += m rt
|
||||
endif
|
||||
# libm may be needed for dc, awk, ntpd
|
||||
# librt may be needed for clock_gettime()
|
||||
ifeq ($(RT_AVAILABLE),y)
|
||||
LDLIBS += rt
|
||||
endif
|
||||
|
||||
# libpam may use libpthread, libdl and/or libaudit.
|
||||
# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
|
||||
@@ -184,10 +180,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 +206,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");
|
||||
|
||||
@@ -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,)
|
||||
+30
-34
@@ -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 */
|
||||
@@ -196,10 +206,9 @@ static int write_ar_archive(archive_handle_t *handle)
|
||||
|
||||
static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
|
||||
{
|
||||
char mode[12];
|
||||
const char *mode = bb_mode_string(file_header->mode);
|
||||
char *mtime;
|
||||
|
||||
bb_mode_string(mode, file_header->mode);
|
||||
mtime = ctime(&file_header->mtime);
|
||||
mtime[16] = ' ';
|
||||
memmove(&mtime[17], &mtime[20], 4);
|
||||
@@ -211,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();
|
||||
|
||||
@@ -260,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
|
||||
);
|
||||
@@ -291,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
-12
@@ -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"
|
||||
@@ -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,21 @@ 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: "\n -t Test file integrity"
|
||||
//usage:
|
||||
//usage:#define xz_trivial_usage
|
||||
//usage: "-d [-cfk] [FILE]..."
|
||||
//usage:#define xz_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "Decompress FILE (or stdin)\n"
|
||||
//usage: "\n -d Decompress"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage: "\n -t Test file integrity"
|
||||
//usage:
|
||||
//usage:#define xzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
|
||||
+2
-4
@@ -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"
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
//kbuild:lib-$(CONFIG_FEATURE_TAR_CREATE) += chksum_and_xwrite_tar_header.o
|
||||
//kbuild:lib-$(CONFIG_SMEMCAP) += chksum_and_xwrite_tar_header.o
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC chksum_and_xwrite_tar_header(int fd, struct tar_header_t *hp)
|
||||
{
|
||||
/* POSIX says that checksum is done on unsigned bytes
|
||||
* (Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source) */
|
||||
const unsigned char *cp;
|
||||
unsigned int chksum, size;
|
||||
|
||||
strcpy(hp->magic, "ustar ");
|
||||
|
||||
/* Calculate and store the checksum (the sum of all of the bytes of
|
||||
* the header). The checksum field must be filled with blanks for the
|
||||
* calculation. The checksum field is formatted differently from the
|
||||
* other fields: it has 6 digits, a NUL, then a space -- rather than
|
||||
* digits, followed by a NUL like the other fields... */
|
||||
memset(hp->chksum, ' ', sizeof(hp->chksum));
|
||||
cp = (const unsigned char *) hp;
|
||||
chksum = 0;
|
||||
size = sizeof(*hp);
|
||||
do { chksum += *cp++; } while (--size);
|
||||
sprintf(hp->chksum, "%06o", chksum);
|
||||
|
||||
xwrite(fd, hp, sizeof(*hp));
|
||||
}
|
||||
+3
-61
@@ -38,20 +38,6 @@
|
||||
//config: depends on FEATURE_CPIO_O
|
||||
//config: help
|
||||
//config: Passthrough mode. Rarely used.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_IGNORE_DEVNO
|
||||
//config: bool "Support --ignore-devno like GNU cpio"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CPIO_O && LONG_OPTS
|
||||
//config: help
|
||||
//config: Optionally ignore device numbers when creating archives.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_RENUMBER_INODES
|
||||
//config: bool "Support --renumber-inodes like GNU cpio"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CPIO_O && LONG_OPTS
|
||||
//config: help
|
||||
//config: Optionally renumber inodes when creating archives.
|
||||
|
||||
//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
@@ -82,19 +68,13 @@
|
||||
//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"
|
||||
//usage: "\n -R USER[:GRP] Set owner of created files"
|
||||
//usage: "\n -L Dereference symlinks"
|
||||
//usage: "\n -0 NUL terminated input"
|
||||
//usage: IF_FEATURE_CPIO_IGNORE_DEVNO(
|
||||
//usage: "\n --ignore-devno"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_CPIO_RENUMBER_INODES(
|
||||
//usage: "\n --renumber-inodes"
|
||||
//usage: )
|
||||
//usage: "\n -0 Input is separated by NULs"
|
||||
|
||||
/* GNU cpio 2.9 --help (abridged):
|
||||
|
||||
@@ -182,22 +162,17 @@ enum {
|
||||
IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
|
||||
IF_LONG_OPTS( OPTBIT_QUIET ,)
|
||||
IF_LONG_OPTS( OPTBIT_2STDOUT ,)
|
||||
IF_FEATURE_CPIO_IGNORE_DEVNO(OPTBIT_IGNORE_DEVNO,)
|
||||
IF_FEATURE_CPIO_RENUMBER_INODES(OPTBIT_RENUMBER_INODES,)
|
||||
OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
|
||||
OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
|
||||
OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
|
||||
OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
|
||||
OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
|
||||
OPT_IGNORE_DEVNO = IF_FEATURE_CPIO_IGNORE_DEVNO((1 << OPTBIT_IGNORE_DEVNO)) + 0,
|
||||
OPT_RENUMBER_INODES = IF_FEATURE_CPIO_RENUMBER_INODES((1 << OPTBIT_RENUMBER_INODES)) + 0,
|
||||
};
|
||||
|
||||
#define OPTION_STR "it0uvdmLF:R:"
|
||||
|
||||
struct globals {
|
||||
struct bb_uidgid_t owner_ugid;
|
||||
ino_t next_inode;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
void BUG_cpio_globals_too_big(void);
|
||||
@@ -231,9 +206,6 @@ static NOINLINE int cpio_o(void)
|
||||
struct inodes_s *next;
|
||||
struct name_s *names;
|
||||
struct stat st;
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
ino_t mapped_inode;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct inodes_s *links = NULL;
|
||||
@@ -288,10 +260,6 @@ static NOINLINE int cpio_o(void)
|
||||
l = xzalloc(sizeof(*l));
|
||||
l->st = st;
|
||||
l->next = links;
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
if (option_mask32 & OPT_RENUMBER_INODES)
|
||||
l->mapped_inode = ++G.next_inode;
|
||||
#endif
|
||||
links = l;
|
||||
break;
|
||||
}
|
||||
@@ -310,11 +278,6 @@ static NOINLINE int cpio_o(void)
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
else if (option_mask32 & OPT_RENUMBER_INODES) {
|
||||
st.st_ino = ++G.next_inode;
|
||||
}
|
||||
#endif
|
||||
} else { /* line == NULL: EOF */
|
||||
next_link:
|
||||
if (links) {
|
||||
@@ -322,10 +285,6 @@ static NOINLINE int cpio_o(void)
|
||||
st = links->st;
|
||||
name = links->names->name;
|
||||
links->names = links->names->next;
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
if (links->mapped_inode)
|
||||
st.st_ino = links->mapped_inode;
|
||||
#endif
|
||||
/* GNU cpio is reported to emit file data
|
||||
* only for the last instance. Mimic that. */
|
||||
if (links->names == NULL)
|
||||
@@ -345,11 +304,6 @@ static NOINLINE int cpio_o(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
|
||||
if (option_mask32 & OPT_IGNORE_DEVNO)
|
||||
st.st_dev = st.st_rdev = 0;
|
||||
#endif
|
||||
|
||||
bytes += printf("070701"
|
||||
"%08X%08X%08X%08X%08X%08X%08X"
|
||||
"%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
|
||||
@@ -425,12 +379,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
"null\0" No_argument "0"
|
||||
"quiet\0" No_argument "\xff"
|
||||
"to-stdout\0" No_argument "\xfe"
|
||||
#if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
|
||||
"ignore-devno\0" No_argument "\xfd"
|
||||
#endif
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
"renumber-inodes\0" No_argument "\xfc"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
|
||||
@@ -470,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.
|
||||
@@ -481,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;
|
||||
|
||||
+1
-24
@@ -1204,27 +1204,6 @@ static char **create_list(const char *filename)
|
||||
return file_list;
|
||||
}
|
||||
|
||||
/** This tests if the filename is an "important" directory, which might be symlinked.
|
||||
* Debians dpkg test if directories are used by other packages, this
|
||||
* implementation doesn't and would remove for ex. an lib -> usr/lib symlink.
|
||||
*/
|
||||
static int is_builtin_exclude(const char *name)
|
||||
{
|
||||
if (*name++ != '/')
|
||||
return 0;
|
||||
if (index_in_strings(".\0" "etc\0" "opt\0" "srv\0" "var\0" "var/lib\0",
|
||||
name) >= 0)
|
||||
return 1;
|
||||
if (is_prefixed_with(name, "usr/")) {
|
||||
name += sizeof("usr/") - 1;
|
||||
if (is_prefixed_with(name, "local/"))
|
||||
name += sizeof("local/") - 1;
|
||||
}
|
||||
|
||||
return index_in_strings("bin\0" "lib\0" "lib32\0" "lib64\0" "sbin\0",
|
||||
name) >= 0;
|
||||
}
|
||||
|
||||
/* maybe i should try and hook this into remove_file.c somehow */
|
||||
static int remove_file_array(char **remove_names, char **exclude_names)
|
||||
{
|
||||
@@ -1236,8 +1215,6 @@ static int remove_file_array(char **remove_names, char **exclude_names)
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; remove_names[i] != NULL; i++) {
|
||||
if (is_builtin_exclude(remove_names[i]))
|
||||
continue;
|
||||
if (exclude_names != NULL) {
|
||||
for (j = 0; exclude_names[j] != NULL; j++) {
|
||||
if (strcmp(remove_names[i], exclude_names[j]) == 0) {
|
||||
@@ -1304,7 +1281,7 @@ postrm abort-install <old_version>
|
||||
postrm abort-upgrade <old_version>
|
||||
postrm disappear <overwriter> <version>
|
||||
*/
|
||||
static const char *const all_control_files[] ALIGN_PTR = {
|
||||
static const char *const all_control_files[] = {
|
||||
"preinst", "postinst", "prerm", "postrm",
|
||||
"list", "md5sums", "shlibs", "conffiles",
|
||||
"config", "templates"
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
//usage: "\n -f Print control fields"
|
||||
//usage: "\n -e Extract control files to DIR (default: ./DEBIAN)"
|
||||
//usage: "\n -x Extract files to DIR (no default)"
|
||||
//usage: "\n -X Verbose extract"
|
||||
//usage: "\n -X Verbose -x"
|
||||
//usage:
|
||||
//usage:#define dpkg_deb_example_usage
|
||||
//usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
|
||||
|
||||
+1
-3
@@ -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"
|
||||
|
||||
@@ -107,7 +107,7 @@ void fallbackSimpleSort(uint32_t* fmap,
|
||||
#define FALLBACK_QSORT_SMALL_THRESH 10
|
||||
#define FALLBACK_QSORT_STACK_SIZE 100
|
||||
|
||||
static NOINLINE
|
||||
static
|
||||
void fallbackQSort3(uint32_t* fmap,
|
||||
uint32_t* eclass,
|
||||
int32_t loSt,
|
||||
@@ -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
|
||||
|
||||
@@ -99,8 +99,9 @@ void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
|
||||
s->ptr = (uint32_t*)s->arr1;
|
||||
s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
|
||||
s->block = (uint8_t*)s->arr2;
|
||||
s->ftab = xmalloc(65537 * sizeof(uint32_t));
|
||||
|
||||
crc32_filltable(s->crc32table, 1);
|
||||
s->crc32table = crc32_filltable(NULL, 1);
|
||||
|
||||
s->state = BZ_S_INPUT;
|
||||
s->mode = BZ_M_RUNNING;
|
||||
@@ -368,8 +369,8 @@ void BZ2_bzCompressEnd(bz_stream *strm)
|
||||
s = strm->state;
|
||||
free(s->arr1);
|
||||
free(s->arr2);
|
||||
//free(s->ftab); // made it array member of s
|
||||
//free(s->crc32table); // ditto
|
||||
free(s->ftab);
|
||||
free(s->crc32table);
|
||||
free(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ typedef struct EState {
|
||||
/* for doing the block sorting */
|
||||
uint32_t *arr1;
|
||||
uint32_t *arr2;
|
||||
//uint32_t *ftab; //moved into this struct, see below
|
||||
uint32_t *ftab;
|
||||
|
||||
uint16_t *quadrant;
|
||||
int32_t budget;
|
||||
@@ -160,6 +160,9 @@ typedef struct EState {
|
||||
uint32_t bsBuff;
|
||||
int32_t bsLive;
|
||||
|
||||
/* guess what */
|
||||
uint32_t *crc32table;
|
||||
|
||||
/* block and combined CRCs */
|
||||
uint32_t blockCRC;
|
||||
uint32_t combinedCRC;
|
||||
@@ -182,12 +185,6 @@ typedef struct EState {
|
||||
|
||||
uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
|
||||
/* guess what */
|
||||
uint32_t crc32table[256];
|
||||
|
||||
/* for doing the block sorting */
|
||||
uint32_t ftab[65537];
|
||||
|
||||
/* stack-saving measures: these can be local, but they are too big */
|
||||
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -20,7 +20,7 @@ enum {
|
||||
TAR_MAX,
|
||||
};
|
||||
|
||||
static const char *const tar_var[] ALIGN_PTR = {
|
||||
static const char *const tar_var[] = {
|
||||
// "FILETYPE",
|
||||
"MODE",
|
||||
"FILENAME",
|
||||
|
||||
@@ -194,14 +194,14 @@ struct cp_ext {
|
||||
};
|
||||
/* Copy lengths and extra bits for literal codes 257..285 */
|
||||
/* note: see note #13 above about the 258 in this list. */
|
||||
static const struct cp_ext lit ALIGN2 = {
|
||||
static const struct cp_ext lit = {
|
||||
/*257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 */
|
||||
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 */
|
||||
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 } /* 99 == invalid */
|
||||
};
|
||||
/* Copy offsets and extra bits for distance codes 0..29 */
|
||||
static const struct cp_ext dist ALIGN2 = {
|
||||
static const struct cp_ext dist = {
|
||||
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 */
|
||||
{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 },
|
||||
{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }
|
||||
@@ -230,8 +230,9 @@ static void huft_free(huft_t *p)
|
||||
* 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);
|
||||
if (BAD_HUFT(p)) {
|
||||
p = (huft_t*)((uintptr_t)(p) ^ (uintptr_t)(ERR_RET));
|
||||
}
|
||||
|
||||
/* Go through linked list, freeing from the malloced (t[-1]) address. */
|
||||
while (p) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
@@ -92,12 +92,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
/* Only size is always present, the rest may be missing in
|
||||
* long filename pseudo file. Thus we decode the rest
|
||||
* after dealing with long filename pseudo file.
|
||||
*
|
||||
* GNU binutils in deterministic mode hard codes mode to 0644 (NOT
|
||||
* 0100644). AR archives can only contain files, so force file
|
||||
* mode.
|
||||
*/
|
||||
typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)) | S_IFREG;
|
||||
typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode));
|
||||
typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid));
|
||||
typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid));
|
||||
typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date));
|
||||
|
||||
@@ -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;
|
||||
@@ -43,7 +43,6 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
bb_simple_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"
|
||||
|
||||
@@ -147,12 +147,6 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
#endif
|
||||
}
|
||||
|
||||
static void die_if_bad_fnamesize(off_t sz)
|
||||
{
|
||||
if ((uoff_t)sz > 0xfff) /* more than 4k?! no funny business please */
|
||||
bb_simple_error_msg_and_die("bad archive");
|
||||
}
|
||||
|
||||
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
@@ -337,6 +331,8 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
file_header->name = xstrdup(tar.name);
|
||||
}
|
||||
|
||||
/* Set bits 12-15 of the files mode */
|
||||
/* (typeflag was not trashed because chksum does not use getOctal) */
|
||||
switch (tar_typeflag) {
|
||||
case '1': /* hardlink */
|
||||
/* we mark hardlinks as regular files with zero size and a link name */
|
||||
@@ -345,7 +341,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* ... For tar archives written by pre POSIX.1-1988
|
||||
* implementations, the size field usually contains the size of
|
||||
* the file and needs to be ignored as no data may follow this
|
||||
* header type. For POSIX.1-1988 compliant archives, the size
|
||||
* header type. For POSIX.1- 1988 compliant archives, the size
|
||||
* field needs to be 0. For POSIX.1-2001 compliant archives,
|
||||
* the size field may be non zero, indicating that file data is
|
||||
* included in the archive.
|
||||
@@ -356,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
|
||||
@@ -394,7 +390,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
/* free: paranoia: tar with several consecutive longnames */
|
||||
free(p_longname);
|
||||
/* For paranoia reasons we allocate extra NUL char */
|
||||
die_if_bad_fnamesize(file_header->size);
|
||||
p_longname = xzalloc(file_header->size + 1);
|
||||
/* We read ASCIZ string, including NUL */
|
||||
xread(archive_handle->src_fd, p_longname, file_header->size);
|
||||
@@ -405,7 +400,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
goto again;
|
||||
case 'K':
|
||||
free(p_linkname);
|
||||
die_if_bad_fnamesize(file_header->size);
|
||||
p_linkname = xzalloc(file_header->size + 1);
|
||||
xread(archive_handle->src_fd, p_linkname, file_header->size);
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
@@ -9,7 +9,6 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
|
||||
{
|
||||
struct tm tm_time;
|
||||
struct tm *ptm = &tm_time; //localtime(&file_header->mtime);
|
||||
char modestr[12];
|
||||
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
char uid[sizeof(int)*3 + 2];
|
||||
@@ -30,7 +29,7 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
|
||||
group = utoa(file_header->gid);
|
||||
}
|
||||
printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(modestr, file_header->mode),
|
||||
bb_mode_string(file_header->mode),
|
||||
user,
|
||||
group,
|
||||
file_header->size,
|
||||
@@ -47,7 +46,7 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
|
||||
localtime_r(&file_header->mtime, ptm);
|
||||
|
||||
printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(modestr, file_header->mode),
|
||||
bb_mode_string(file_header->mode),
|
||||
(unsigned)file_header->uid,
|
||||
(unsigned)file_header->gid,
|
||||
file_header->size,
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -545,7 +545,7 @@ static enum xz_ret XZ_FUNC dec_block_header(struct xz_dec *s)
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
static NOINLINE enum xz_ret XZ_FUNC dec_main(struct xz_dec *s, struct xz_buf *b)
|
||||
static enum xz_ret XZ_FUNC dec_main(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
enum xz_ret ret;
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
+5
-7
@@ -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]);
|
||||
|
||||
|
||||
+56
-37
@@ -254,6 +254,32 @@ static void putOctal(char *cp, int len, off_t value)
|
||||
}
|
||||
#define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b))
|
||||
|
||||
static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
|
||||
{
|
||||
/* POSIX says that checksum is done on unsigned bytes
|
||||
* (Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source) */
|
||||
const unsigned char *cp;
|
||||
int chksum, size;
|
||||
|
||||
strcpy(hp->magic, "ustar ");
|
||||
|
||||
/* Calculate and store the checksum (i.e., the sum of all of the bytes of
|
||||
* the header). The checksum field must be filled with blanks for the
|
||||
* calculation. The checksum field is formatted differently from the
|
||||
* other fields: it has 6 digits, a null, then a space -- rather than
|
||||
* digits, followed by a null like the other fields... */
|
||||
memset(hp->chksum, ' ', sizeof(hp->chksum));
|
||||
cp = (const unsigned char *) hp;
|
||||
chksum = 0;
|
||||
size = sizeof(*hp);
|
||||
do { chksum += *cp++; } while (--size);
|
||||
putOctal(hp->chksum, sizeof(hp->chksum)-1, chksum);
|
||||
|
||||
/* Now write the header out to disk */
|
||||
xwrite(fd, hp, sizeof(*hp));
|
||||
}
|
||||
|
||||
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
static void writeLongname(int fd, int type, const char *name, int dir)
|
||||
{
|
||||
@@ -271,8 +297,7 @@ static void writeLongname(int fd, int type, const char *name, int dir)
|
||||
header.typeflag = type;
|
||||
strcpy(header.name, "././@LongLink");
|
||||
/* This sets mode/uid/gid/mtime to "00...00<NUL>" strings */
|
||||
memset((char*)&header + offsetof(struct tar_header_t, mode), /* make gcc-9.x happy */
|
||||
'0', sizeof(struct prefilled));
|
||||
memset(header.mode, '0', sizeof(struct prefilled));
|
||||
header.mode [sizeof(header.mode ) - 1] = '\0';
|
||||
header.uid [sizeof(header.uid ) - 1] = '\0';
|
||||
header.gid [sizeof(header.gid ) - 1] = '\0';
|
||||
@@ -284,7 +309,7 @@ static void writeLongname(int fd, int type, const char *name, int dir)
|
||||
/* + dir: account for possible '/' */
|
||||
|
||||
PUT_OCTAL(header.size, size);
|
||||
chksum_and_xwrite_tar_header(fd, &header);
|
||||
chksum_and_xwrite(fd, &header);
|
||||
|
||||
/* Write filename[/] and pad the block. */
|
||||
/* dir=0: writes 'name<NUL>', pads */
|
||||
@@ -415,7 +440,8 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
header_name, S_ISDIR(statbuf->st_mode));
|
||||
# endif
|
||||
|
||||
chksum_and_xwrite_tar_header(tbInfo->tarFd, &header);
|
||||
/* Now write the header out to disk */
|
||||
chksum_and_xwrite(tbInfo->tarFd, &header);
|
||||
|
||||
/* Now do the verbose thing (or not) */
|
||||
if (tbInfo->verboseFlag) {
|
||||
@@ -464,11 +490,10 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
# define exclude_file(excluded_files, file) 0
|
||||
# endif
|
||||
|
||||
static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
|
||||
const char *fileName,
|
||||
struct stat *statbuf)
|
||||
static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
void *userData, int depth UNUSED_PARAM)
|
||||
{
|
||||
struct TarBallInfo *tbInfo = (struct TarBallInfo *) state->userData;
|
||||
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
|
||||
const char *header_name;
|
||||
int inputFileFd = -1;
|
||||
|
||||
@@ -480,9 +505,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);
|
||||
@@ -516,6 +538,9 @@ 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");
|
||||
@@ -528,13 +553,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 */
|
||||
@@ -674,7 +699,7 @@ static NOINLINE int writeTarFile(
|
||||
/* Read the directory/files and iterate over them one at a time */
|
||||
while (filelist) {
|
||||
if (!recursive_action(filelist->data, recurseFlags,
|
||||
writeFileToTarball, writeFileToTarball, tbInfo)
|
||||
writeFileToTarball, writeFileToTarball, tbInfo, 0)
|
||||
) {
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
@@ -748,7 +773,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
|
||||
//usage: "vokO] "
|
||||
//usage: "[-f TARFILE] [-C DIR] "
|
||||
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[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, ")
|
||||
@@ -782,11 +807,6 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
//usage: IF_FEATURE_SEAMLESS_BZ2(
|
||||
//usage: "\n -j (De)compress using bzip2"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_SEAMLESS_LZMA(
|
||||
//usage: IF_FEATURE_TAR_LONG_OPTIONS(
|
||||
//usage: "\n --lzma (De)compress using lzma"
|
||||
//usage: )
|
||||
//usage: )
|
||||
//usage: "\n -a (De)compress based on extension"
|
||||
//usage: IF_FEATURE_TAR_CREATE(
|
||||
//usage: "\n -h Follow symlinks"
|
||||
@@ -798,21 +818,21 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
//usage: "\n --exclude PATTERN Glob pattern to exclude"
|
||||
//usage: )
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_TAR_LONG_OPTIONS(
|
||||
//usage: "\n --overwrite Replace existing files"
|
||||
//usage: "\n --strip-components NUM NUM of leading components to strip"
|
||||
//usage: "\n --no-recursion Don't descend in directories"
|
||||
//usage: "\n --numeric-owner Use numeric user:group"
|
||||
//usage: "\n --no-same-permissions Don't restore access permissions"
|
||||
//usage: IF_FEATURE_TAR_TO_COMMAND(
|
||||
//usage: "\n --to-command COMMAND Pipe files to COMMAND"
|
||||
//usage: )
|
||||
//usage: )
|
||||
//usage:
|
||||
//usage:#define tar_example_usage
|
||||
//usage: "$ zcat /tmp/tarball.tar.gz | tar -xf -\n"
|
||||
//usage: "$ tar -cf /tmp/tarball.tar /usr/local\n"
|
||||
|
||||
// Supported but aren't in --help:
|
||||
// lzma
|
||||
// no-recursion
|
||||
// numeric-owner
|
||||
// no-same-permissions
|
||||
// overwrite
|
||||
//IF_FEATURE_TAR_TO_COMMAND(
|
||||
// to-command
|
||||
//)
|
||||
|
||||
enum {
|
||||
OPTBIT_KEEP_OLD = 8,
|
||||
IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
|
||||
@@ -1105,15 +1125,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);
|
||||
|
||||
+7
-31
@@ -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
|
||||
@@ -453,9 +436,7 @@ 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");
|
||||
@@ -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++;
|
||||
@@ -990,6 +966,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 +974,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.
|
||||
|
||||
|
||||
@@ -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:
|
||||
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
//config:config OPENVT
|
||||
//config: bool "openvt (7.2 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This program is used to start a command on an unused
|
||||
//config: virtual terminal.
|
||||
|
||||
+1
-13
@@ -74,19 +74,7 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
+ (1 << SIGTERM)
|
||||
+ (1 << SIGALRM)
|
||||
, onintr);
|
||||
/* Users report:
|
||||
* The resize command messes up the terminal.
|
||||
* In my case it looks like it is hanging and
|
||||
* I need to press ctrl-c to get a prompt.
|
||||
* Actually the program does not hang but just
|
||||
* the terminal is messed up.
|
||||
* Replaced TCSANOW with TCSAFLUSH:
|
||||
* "the change occurs after all output written to fd
|
||||
* has been transmitted, and all input that has been
|
||||
* received but not read will be discarded before
|
||||
* the change is made.
|
||||
*/
|
||||
tcsetattr(STDERR_FILENO, TCSAFLUSH, &new);
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &new);
|
||||
|
||||
/* save_cursor_pos 7
|
||||
* scroll_whole_screen [r
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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");
|
||||
|
||||
+4
-15
@@ -5,6 +5,10 @@
|
||||
|
||||
menu "Coreutils"
|
||||
|
||||
INSERT
|
||||
|
||||
comment "Common options"
|
||||
|
||||
config FEATURE_VERBOSE
|
||||
bool "Support verbose options (usually -v) for various applets"
|
||||
default y
|
||||
@@ -13,19 +17,6 @@ config FEATURE_VERBOSE
|
||||
Also enables long option (--verbose) if it exists.
|
||||
Without this option, -v is accepted but ignored.
|
||||
|
||||
comment "Common options for date and touch"
|
||||
|
||||
config FEATURE_TIMEZONE
|
||||
bool "Allow timezone in dates"
|
||||
default y
|
||||
depends on DESKTOP
|
||||
help
|
||||
Permit the use of timezones when parsing user-provided data
|
||||
strings, e.g. '1996-04-09 12:45:00 -0500'.
|
||||
|
||||
This requires support for the '%z' extension to strptime() which
|
||||
may not be available in all implementations.
|
||||
|
||||
comment "Common options for cp and mv"
|
||||
depends on CP || MV
|
||||
|
||||
@@ -46,6 +37,4 @@ config FEATURE_HUMAN_READABLE
|
||||
help
|
||||
Allow df, du, and ls to have human readable output.
|
||||
|
||||
INSERT
|
||||
|
||||
endmenu
|
||||
+24
-38
@@ -29,11 +29,9 @@
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */
|
||||
|
||||
//usage:#define basename_trivial_usage
|
||||
//usage: "FILE [SUFFIX] | -a FILE... | -s SUFFIX FILE..."
|
||||
//usage: "FILE [SUFFIX]"
|
||||
//usage:#define basename_full_usage "\n\n"
|
||||
//usage: "Strip directory path and SUFFIX from FILE\n"
|
||||
//usage: "\n -a All arguments are FILEs"
|
||||
//usage: "\n -s SUFFIX Remove SUFFIX (implies -a)"
|
||||
//usage: "Strip directory path and .SUFFIX from FILE"
|
||||
//usage:
|
||||
//usage:#define basename_example_usage
|
||||
//usage: "$ basename /usr/local/bin/foo\n"
|
||||
@@ -50,43 +48,31 @@
|
||||
int basename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int basename_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
const char *suffix = NULL;
|
||||
size_t m, n;
|
||||
char *s;
|
||||
|
||||
/* '+': stop at first non-option */
|
||||
opts = getopt32(argv, "^+" "as:"
|
||||
"\0" "-1" /* At least one argument */
|
||||
, &suffix
|
||||
);
|
||||
argv += optind;
|
||||
if (argv[1] && strcmp(argv[1], "--") == 0) {
|
||||
argv++;
|
||||
}
|
||||
if (!argv[1])
|
||||
bb_show_usage();
|
||||
|
||||
do {
|
||||
char *s;
|
||||
size_t m;
|
||||
/* It should strip slash: /abc/def/ -> def */
|
||||
s = bb_get_last_path_component_strip(*++argv);
|
||||
|
||||
/* It should strip slash: /abc/def/ -> def */
|
||||
s = bb_get_last_path_component_strip(*argv++);
|
||||
m = strlen(s);
|
||||
if (!opts) {
|
||||
if (*argv) {
|
||||
suffix = *argv;
|
||||
if (argv[1])
|
||||
bb_show_usage();
|
||||
}
|
||||
m = strlen(s);
|
||||
if (*++argv) {
|
||||
if (argv[1])
|
||||
bb_show_usage();
|
||||
n = strlen(*argv);
|
||||
if ((m > n) && (strcmp(s+m-n, *argv) == 0)) {
|
||||
m -= n;
|
||||
/*s[m] = '\0'; - redundant */
|
||||
}
|
||||
if (suffix) {
|
||||
size_t n = strlen(suffix);
|
||||
if ((m > n) && (strcmp(s + m - n, suffix) == 0)) {
|
||||
m -= n;
|
||||
/*s[m] = '\0'; - redundant */
|
||||
}
|
||||
}
|
||||
/* puts(s) will do, but we can do without stdio this way: */
|
||||
s[m++] = '\n';
|
||||
/* NB: != is correct here: */
|
||||
if (full_write(STDOUT_FILENO, s, m) != (ssize_t)m)
|
||||
return EXIT_FAILURE;
|
||||
} while (opts && *argv);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
/* puts(s) will do, but we can do without stdio this way: */
|
||||
s[m++] = '\n';
|
||||
/* NB: != is correct here: */
|
||||
return full_write(STDOUT_FILENO, s, m) != (ssize_t)m;
|
||||
}
|
||||
+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;
|
||||
|
||||
+2
-6
@@ -23,17 +23,13 @@
|
||||
//usage:#define chgrp_trivial_usage
|
||||
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... 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"
|
||||
//usage: "\n -f Hide errors"
|
||||
|
||||
+11
-15
@@ -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,18 +79,16 @@ 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
|
||||
|| (OPT_CHANGED
|
||||
&& (statbuf->st_mode & 07777) != (newmode & 07777))
|
||||
|| (OPT_CHANGED && statbuf->st_mode != newmode)
|
||||
) {
|
||||
char modestr[12];
|
||||
printf("mode of '%s' changed to %04o (%s)\n", fileName,
|
||||
newmode & 07777, bb_mode_string(modestr, newmode)+1);
|
||||
newmode & 07777, bb_mode_string(newmode)+1);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -141,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_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 */
|
||||
}
|
||||
} else if (flags & FILEUTILS_NO_TARGET_DIR) {
|
||||
bb_simple_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;
|
||||
}
|
||||
|
||||
+96
-110
@@ -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)))
|
||||
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
|
||||
bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields");
|
||||
|
||||
if (opt & CUT_OPT_DELIM_FLGS) {
|
||||
if (ltok[0] && ltok[1]) { /* more than 1 char? */
|
||||
bb_simple_error_msg_and_die("the delimiter must be a single character");
|
||||
}
|
||||
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++;
|
||||
@@ -306,8 +293,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* 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);
|
||||
|
||||
|
||||
+58
-48
@@ -37,6 +37,7 @@
|
||||
//config: bool "Support %[num]N nanosecond format specifier"
|
||||
//config: default n # stat's nanosecond field is a bit non-portable
|
||||
//config: depends on DATE
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Support %[num]N format specifier. Adds ~250 bytes of code.
|
||||
//config:
|
||||
@@ -93,25 +94,36 @@
|
||||
*/
|
||||
|
||||
//usage:#define date_trivial_usage
|
||||
//usage: "[OPTIONS] [+FMT] [[-s] TIME]"
|
||||
//usage: "[OPTIONS] [+FMT] [TIME]"
|
||||
//usage:#define date_full_usage "\n\n"
|
||||
//usage: "Display time (using +FMT), or set time\n"
|
||||
//usage: "\n -u Work in UTC (don't convert to local time)"
|
||||
//usage: IF_NOT_LONG_OPTS(
|
||||
//usage: "\n [-s] TIME Set time to TIME"
|
||||
//usage: "\n -d TIME Display TIME, not 'now'"
|
||||
//usage: IF_FEATURE_DATE_ISOFMT(
|
||||
//usage: "\n -D FMT FMT (strptime format) for -s/-d TIME conversion"
|
||||
////////^^^^^^^^^^^^^^^^^^^^^^ busybox invention, not compat
|
||||
//usage: "\n -u Work in UTC (don't convert to local time)"
|
||||
//usage: "\n -R Output RFC-2822 compliant date string"
|
||||
//usage: ) IF_LONG_OPTS(
|
||||
//usage: "\n [-s,--set] TIME Set time to TIME"
|
||||
//usage: "\n -u,--utc Work in UTC (don't convert to local time)"
|
||||
//usage: "\n -R,--rfc-2822 Output RFC-2822 compliant date string"
|
||||
//usage: )
|
||||
//usage: "\n -r FILE Display last modification time of FILE"
|
||||
//usage: "\n -R Output RFC-2822 date"
|
||||
//usage: IF_FEATURE_DATE_ISOFMT(
|
||||
//usage: "\n -I[SPEC] Output ISO-8601 date"
|
||||
//usage: "\n SPEC=date (default), hours, minutes, seconds or ns"
|
||||
//usage: "\n -I[SPEC] Output ISO-8601 compliant date string"
|
||||
//usage: "\n SPEC='date' (default) for date only,"
|
||||
//usage: "\n 'hours', 'minutes', or 'seconds' for date and"
|
||||
//usage: "\n time to the indicated precision"
|
||||
//usage: )
|
||||
//usage: IF_NOT_LONG_OPTS(
|
||||
//usage: "\n -r FILE Display last modification time of FILE"
|
||||
//usage: "\n -d TIME Display TIME, not 'now'"
|
||||
//usage: ) IF_LONG_OPTS(
|
||||
//usage: "\n -r,--reference FILE Display last modification time of FILE"
|
||||
//usage: "\n -d,--date TIME Display TIME, not 'now'"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_DATE_ISOFMT(
|
||||
//usage: "\n -D FMT Use FMT (strptime format) for -d TIME conversion"
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nRecognized TIME formats:"
|
||||
//usage: "\n @seconds_since_1970"
|
||||
//usage: "\n hh:mm[:ss]"
|
||||
//usage: "\n [YYYY.]MM.DD-hh:mm[:ss]"
|
||||
//usage: "\n YYYY-MM-DD hh:mm[:ss]"
|
||||
@@ -136,8 +148,8 @@ enum {
|
||||
OPT_UTC = (1 << 2), /* u */
|
||||
OPT_DATE = (1 << 3), /* d */
|
||||
OPT_REFERENCE = (1 << 4), /* r */
|
||||
OPT_ISO8601 = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
|
||||
OPT_STR2DT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
|
||||
OPT_TIMESPEC = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
|
||||
OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
|
||||
};
|
||||
|
||||
#if ENABLE_LONG_OPTS
|
||||
@@ -159,6 +171,12 @@ static const char date_longopts[] ALIGN1 =
|
||||
* - after xasprintf we use other xfuncs
|
||||
*/
|
||||
|
||||
static void maybe_set_utc(int opt)
|
||||
{
|
||||
if (opt & OPT_UTC)
|
||||
putenv((char*)"TZ=UTC0");
|
||||
}
|
||||
|
||||
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -166,7 +184,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct tm tm_time;
|
||||
char buf_fmt_dt2str[64];
|
||||
unsigned opt;
|
||||
int isofmt = -1;
|
||||
int ifmt = -1;
|
||||
char *date_str;
|
||||
char *fmt_dt2str;
|
||||
char *fmt_str2dt;
|
||||
@@ -185,16 +203,15 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
if (opt & OPT_UTC)
|
||||
putenv((char*)"TZ=UTC0");
|
||||
maybe_set_utc(opt);
|
||||
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_ISO8601)) {
|
||||
isofmt = 0; /* default is date */
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_TIMESPEC)) {
|
||||
ifmt = 0; /* default is date */
|
||||
if (isofmt_arg) {
|
||||
static const char isoformats[] ALIGN1 =
|
||||
"date\0""hours\0""minutes\0""seconds\0ns\0";
|
||||
isofmt = index_in_substrings(isoformats, isofmt_arg);
|
||||
if (isofmt < 0)
|
||||
"date\0""hours\0""minutes\0""seconds\0"; /* ns? */
|
||||
ifmt = index_in_substrings(isoformats, isofmt_arg);
|
||||
if (ifmt < 0)
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
@@ -204,7 +221,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
fmt_dt2str = &argv[0][1]; /* skip over the '+' */
|
||||
argv++;
|
||||
}
|
||||
if (!(opt & (OPT_SET | OPT_DATE))) { /* neither -s TIME nor -d TIME? */
|
||||
if (!(opt & (OPT_SET | OPT_DATE))) {
|
||||
opt |= OPT_SET;
|
||||
date_str = argv[0]; /* can be NULL */
|
||||
if (date_str) {
|
||||
@@ -266,23 +283,22 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* If date string is given, update tm_time, and maybe set date */
|
||||
if (date_str != NULL) {
|
||||
int check_dst = 1;
|
||||
/* Zero out fields - take her back to midnight! */
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
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 {
|
||||
check_dst = parse_datestr(date_str, &tm_time);
|
||||
parse_datestr(date_str, &tm_time);
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc. fields */
|
||||
/* Be sure to recheck dst (but not if date is UTC) */
|
||||
if (check_dst)
|
||||
/* Be sure to recheck dst (but not if date is time_t format) */
|
||||
if (date_str[0] != '@')
|
||||
tm_time.tm_isdst = -1;
|
||||
ts.tv_sec = validate_tm_time(date_str, &tm_time);
|
||||
ts.tv_nsec = 0;
|
||||
@@ -299,34 +315,24 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (fmt_dt2str == NULL) {
|
||||
int i;
|
||||
fmt_dt2str = buf_fmt_dt2str;
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && isofmt >= 0) {
|
||||
/* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds 4:ns*/
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
|
||||
/* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds */
|
||||
strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S");
|
||||
i = 8 + 3 * isofmt;
|
||||
if (isofmt != 0) {
|
||||
int n;
|
||||
if (isofmt == 4) {
|
||||
i -= 3;
|
||||
i += sprintf(&fmt_dt2str[i], ",%09u", (unsigned)ts.tv_nsec);
|
||||
}
|
||||
/* %z prints "+hhmm" timezone, but coreutils-8.30 prints "+hh:mm"! */
|
||||
/* ...therefore this atrocity: */
|
||||
n = strftime(&fmt_dt2str[i], 8, "%z", &tm_time);
|
||||
i += n;
|
||||
if (n == 5 && (fmt_dt2str[i-5] == '+' || fmt_dt2str[i-5] == '-')) {
|
||||
/* "mm" -> ":mm" */
|
||||
fmt_dt2str[i ] = fmt_dt2str[i - 1];
|
||||
fmt_dt2str[i - 1] = fmt_dt2str[i - 2];
|
||||
fmt_dt2str[i - 2] = ':';
|
||||
i++;
|
||||
}
|
||||
i = 8 + 3 * ifmt;
|
||||
if (ifmt != 0) {
|
||||
/* TODO: if (ifmt==4) i += sprintf(&fmt_dt2str[i], ",%09u", nanoseconds); */
|
||||
format_utc:
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = (opt & OPT_UTC) ? 'Z' : 'z';
|
||||
}
|
||||
fmt_dt2str[i] = '\0';
|
||||
} else if (opt & OPT_RFC2822) {
|
||||
/* -R. undo busybox.c setlocale */
|
||||
if (ENABLE_LOCALE_SUPPORT)
|
||||
setlocale(LC_TIME, "C");
|
||||
fmt_dt2str = (char*)"%a, %d %b %Y %H:%M:%S %z";
|
||||
strcpy(fmt_dt2str, "%a, %d %b %Y %H:%M:%S ");
|
||||
i = sizeof("%a, %d %b %Y %H:%M:%S ")-1;
|
||||
goto format_utc;
|
||||
} else { /* default case */
|
||||
fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
@@ -378,6 +384,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* With no format string, just print a blank line */
|
||||
date_buf[0] = '\0';
|
||||
} else {
|
||||
/* Handle special conversions */
|
||||
if (is_prefixed_with(fmt_dt2str, "%f")) {
|
||||
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
/* Generate output string */
|
||||
strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time);
|
||||
}
|
||||
|
||||
+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;
|
||||
}
|
||||
+21
-52
@@ -32,26 +32,6 @@
|
||||
//config: -a Show all filesystems
|
||||
//config: -i Inodes
|
||||
//config: -B <SIZE> Blocksize
|
||||
//config:
|
||||
//config:config FEATURE_SKIP_ROOTFS
|
||||
//config: bool "Skip rootfs in mount table"
|
||||
//config: default y
|
||||
//config: depends on DF
|
||||
//config: help
|
||||
//config: Ignore rootfs entry in mount table.
|
||||
//config:
|
||||
//config: In Linux, kernel has a special filesystem, rootfs, which is initially
|
||||
//config: mounted on /. It contains initramfs data, if kernel is configured
|
||||
//config: to have one. Usually, another file system is mounted over / early
|
||||
//config: in boot process, and therefore most tools which manipulate
|
||||
//config: mount table, such as df, will skip rootfs entry.
|
||||
//config:
|
||||
//config: However, some systems do not mount anything on /.
|
||||
//config: If you need to configure busybox for one of these systems,
|
||||
//config: you may find it useful to turn this option off to make df show
|
||||
//config: initramfs statistics.
|
||||
//config:
|
||||
//config: Otherwise, choose Y.
|
||||
|
||||
//applet:IF_DF(APPLET_NOEXEC(df, df, BB_DIR_BIN, BB_SUID_DROP, df))
|
||||
|
||||
@@ -65,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"
|
||||
@@ -75,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"
|
||||
@@ -118,41 +97,32 @@ 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_HUMANDEC = (1 << (5 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (6 + 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("hHm")
|
||||
IF_FEATURE_HUMAN_READABLE("hm")
|
||||
"\0"
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
|
||||
"k-mB:m-Bk:B-km"
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
"k-m:m-k"
|
||||
#endif
|
||||
, &opt_t
|
||||
IF_FEATURE_DF_FANCY(, &chp)
|
||||
);
|
||||
if (opt & OPT_MEGA)
|
||||
@@ -172,11 +142,15 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
got_it: ;
|
||||
}
|
||||
|
||||
if (opt & (OPT_HUMAN|OPT_HUMANDEC)) {
|
||||
/* 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;
|
||||
//TODO: need to add support in make_human_readable_str() for "decimal human readable"
|
||||
//if (opt & OPT_HUMANDEC)
|
||||
// df_disp_hr--;
|
||||
disp_units_hdr = " Size";
|
||||
}
|
||||
if (opt & OPT_INODE)
|
||||
@@ -240,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_simple_perror_msg(bb_msg_write_error);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+7
-12
@@ -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
|
||||
);
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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"
|
||||
|
||||
+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;
|
||||
|
||||
+3
-3
@@ -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"
|
||||
@@ -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)
|
||||
|
||||
+2
-2
@@ -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:
|
||||
|
||||
+15
-20
@@ -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;
|
||||
}
|
||||
|
||||
@@ -503,8 +503,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
|
||||
if (opt & OPT_l) {
|
||||
/* long listing: show mode */
|
||||
char modestr[12];
|
||||
column += printf("%-10s ", bb_mode_string(modestr, dn->dn_mode));
|
||||
column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode));
|
||||
/* long listing: show number of links */
|
||||
column += printf("%4lu ", (long) dn->dn_nlink);
|
||||
/* long listing: show user/group */
|
||||
@@ -1146,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')
|
||||
@@ -1163,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
|
||||
|
||||
+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"
|
||||
|
||||
+1
-15
@@ -72,27 +72,13 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
|
||||
OPT_t = 1 << 2,
|
||||
OPT_p = 1 << 3,
|
||||
OPT_u = 1 << 4,
|
||||
OPT_tmpdir = (1 << 5) * ENABLE_LONG_OPTS,
|
||||
};
|
||||
|
||||
path = getenv("TMPDIR");
|
||||
if (!path || path[0] == '\0')
|
||||
path = "/tmp";
|
||||
|
||||
#if ENABLE_LONG_OPTS
|
||||
opts = getopt32long(argv, "^"
|
||||
"dqtp:u"
|
||||
"\0"
|
||||
"?1" /* 1 arg max */,
|
||||
"directory\0" No_argument "d"
|
||||
"quiet\0" No_argument "q"
|
||||
"dry-run\0" No_argument "u"
|
||||
"tmpdir\0" Optional_argument "\xff"
|
||||
, &path, &path
|
||||
);
|
||||
#else
|
||||
opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path);
|
||||
#endif
|
||||
|
||||
chp = argv[optind];
|
||||
if (!chp) {
|
||||
@@ -109,7 +95,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
if (opts & (OPT_t|OPT_p|OPT_tmpdir))
|
||||
if (opts & (OPT_t|OPT_p))
|
||||
chp = concat_path_file(path, chp);
|
||||
|
||||
if (opts & OPT_u) {
|
||||
|
||||
+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
|
||||
|
||||
+15
-15
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
@@ -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 }
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
+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;
|
||||
@@ -313,7 +312,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
|
||||
}
|
||||
break;
|
||||
}
|
||||
while (*f && strchr("-+ #0", *f)) {
|
||||
if (*f && strchr("-+ #", *f)) {
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
+39
-58
@@ -17,14 +17,14 @@
|
||||
//kbuild:lib-$(CONFIG_SHUF) += shuf.o
|
||||
|
||||
//usage:#define shuf_trivial_usage
|
||||
//usage: "[-n NUM] [-o FILE] [-z] [FILE | -e [ARG...] | -i L-H]"
|
||||
//usage: "[-e|-i L-H] [-n NUM] [-o FILE] [-z] [FILE|ARG...]"
|
||||
//usage:#define shuf_full_usage "\n\n"
|
||||
//usage: "Randomly permute lines\n"
|
||||
//usage: "\n -n NUM Output at most NUM lines"
|
||||
//usage: "\n -o FILE Write to FILE, not standard output"
|
||||
//usage: "\n -z NUL terminated output"
|
||||
//usage: "\n -e Treat ARGs as lines"
|
||||
//usage: "\n -i L-H Treat numbers L-H as lines"
|
||||
//usage: "\n -n NUM Output at most NUM lines"
|
||||
//usage: "\n -o FILE Write to FILE, not standard output"
|
||||
//usage: "\n -z End lines with zero byte, not newline"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -39,30 +39,24 @@
|
||||
|
||||
/*
|
||||
* Use the Fisher-Yates shuffle algorithm on an array of lines.
|
||||
* If the required number of output lines is less than the total
|
||||
* we can stop shuffling early.
|
||||
*/
|
||||
static void shuffle_lines(char **lines, unsigned numlines, unsigned outlines)
|
||||
static void shuffle_lines(char **lines, unsigned numlines)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned r;
|
||||
char *tmp;
|
||||
|
||||
srand(monotonic_us());
|
||||
|
||||
while (outlines != 0) {
|
||||
char *tmp;
|
||||
unsigned r = rand();
|
||||
for (i = numlines-1; i > 0; i--) {
|
||||
r = rand();
|
||||
/* RAND_MAX can be as small as 32767 */
|
||||
if (numlines > RAND_MAX)
|
||||
if (i > RAND_MAX)
|
||||
r ^= rand() << 15;
|
||||
r %= numlines;
|
||||
//TODO: the above method is seriously non-uniform when numlines is very large.
|
||||
//For example, with numlines of 0xf0000000,
|
||||
//values of (r % numlines) in [0, 0x0fffffff] range
|
||||
//are more likely: e.g. r=1 and r=0xf0000001 both map to 1,
|
||||
//whereas only one value, r=0xefffffff, maps to 0xefffffff.
|
||||
numlines--;
|
||||
tmp = lines[numlines];
|
||||
lines[numlines] = lines[r];
|
||||
r %= i + 1;
|
||||
tmp = lines[i];
|
||||
lines[i] = lines[r];
|
||||
lines[r] = tmp;
|
||||
outlines--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,10 +65,9 @@ int shuf_main(int argc, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
char *opt_i_str, *opt_n_str, *opt_o_str;
|
||||
char **lines;
|
||||
unsigned long long lo = lo;
|
||||
unsigned numlines, outlines;
|
||||
unsigned i;
|
||||
char **lines;
|
||||
unsigned numlines;
|
||||
char eol;
|
||||
|
||||
opts = getopt32(argv, "^"
|
||||
@@ -94,48 +87,35 @@ int shuf_main(int argc, char **argv)
|
||||
} else
|
||||
if (opts & OPT_i) {
|
||||
/* create a range of numbers */
|
||||
unsigned long long hi;
|
||||
char *dash;
|
||||
|
||||
if (argv[0])
|
||||
bb_show_usage();
|
||||
unsigned lo, hi;
|
||||
|
||||
dash = strchr(opt_i_str, '-');
|
||||
if (!dash) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
*dash = '\0';
|
||||
lo = xatoull(opt_i_str);
|
||||
hi = xatoull(dash + 1);
|
||||
lo = xatou(opt_i_str);
|
||||
hi = xatou(dash + 1);
|
||||
*dash = '-';
|
||||
if (hi < lo)
|
||||
if (hi < lo) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
hi -= lo;
|
||||
if (sizeof(size_t) > sizeof(numlines)) {
|
||||
if (hi >= UINT_MAX)
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
} else {
|
||||
if (hi >= UINT_MAX / sizeof(lines[0]))
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
|
||||
numlines = hi + 1;
|
||||
lines = xmalloc((size_t)numlines * sizeof(lines[0]));
|
||||
numlines = (hi+1) - lo;
|
||||
lines = xmalloc(numlines * sizeof(lines[0]));
|
||||
for (i = 0; i < numlines; i++) {
|
||||
lines[i] = (char*)(uintptr_t)i;
|
||||
lines[i] = (char*)(uintptr_t)lo;
|
||||
lo++;
|
||||
}
|
||||
} else {
|
||||
/* default - read lines from stdin or the input file */
|
||||
FILE *fp;
|
||||
const char *fname = "-";
|
||||
|
||||
if (argv[0]) {
|
||||
if (argv[1])
|
||||
bb_show_usage();
|
||||
fname = argv[0];
|
||||
}
|
||||
if (argc > 1)
|
||||
bb_show_usage();
|
||||
|
||||
fp = xfopen_stdin(fname);
|
||||
fp = xfopen_stdin(argv[0] ? argv[0] : "-");
|
||||
lines = NULL;
|
||||
numlines = 0;
|
||||
for (;;) {
|
||||
@@ -148,25 +128,26 @@ int shuf_main(int argc, char **argv)
|
||||
fclose_if_not_stdin(fp);
|
||||
}
|
||||
|
||||
outlines = numlines;
|
||||
if (opts & OPT_n) {
|
||||
outlines = xatou(opt_n_str);
|
||||
if (outlines > numlines)
|
||||
outlines = numlines;
|
||||
}
|
||||
|
||||
shuffle_lines(lines, numlines, outlines);
|
||||
if (numlines != 0)
|
||||
shuffle_lines(lines, numlines);
|
||||
|
||||
if (opts & OPT_o)
|
||||
xmove_fd(xopen(opt_o_str, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
|
||||
|
||||
if (opts & OPT_n) {
|
||||
unsigned maxlines;
|
||||
maxlines = xatou(opt_n_str);
|
||||
if (numlines > maxlines)
|
||||
numlines = maxlines;
|
||||
}
|
||||
|
||||
eol = '\n';
|
||||
if (opts & OPT_z)
|
||||
eol = '\0';
|
||||
|
||||
for (i = numlines - outlines; i < numlines; i++) {
|
||||
for (i = 0; i < numlines; i++) {
|
||||
if (opts & OPT_i)
|
||||
printf("%llu%c", lo + (uintptr_t)lines[i], eol);
|
||||
printf("%u%c", (unsigned)(uintptr_t)lines[i], eol);
|
||||
else
|
||||
printf("%s%c", lines[i], eol);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
+2
-3
@@ -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"
|
||||
@@ -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) */
|
||||
|
||||
+1
-1
@@ -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 },
|
||||
|
||||
+6
-7
@@ -31,6 +31,7 @@
|
||||
//config: bool "Enable display of filesystem status (-f)"
|
||||
//config: default y
|
||||
//config: depends on STAT
|
||||
//config: select PLATFORM_LINUX # statfs()
|
||||
//config: help
|
||||
//config: Without this, stat will not support the '-f' option to display
|
||||
//config: information about filesystem status.
|
||||
@@ -40,7 +41,7 @@
|
||||
//kbuild:lib-$(CONFIG_STAT) += stat.o
|
||||
|
||||
//usage:#define stat_trivial_usage
|
||||
//usage: "[-lt"IF_FEATURE_STAT_FILESYSTEM("f")"] "IF_FEATURE_STAT_FORMAT("[-c FMT] ")"FILE..."
|
||||
//usage: "[OPTIONS] FILE..."
|
||||
//usage:#define stat_full_usage "\n\n"
|
||||
//usage: "Display file"
|
||||
//usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem")
|
||||
@@ -208,7 +209,7 @@ FS_TYPE(0x62656572, "sysfs")
|
||||
static const char *human_fstype(uint32_t f_type)
|
||||
{
|
||||
# define FS_TYPE(type, name) type,
|
||||
static const uint32_t fstype[] ALIGN4 = {
|
||||
static const uint32_t fstype[] = {
|
||||
FS_TYPE_LIST
|
||||
};
|
||||
# undef FS_TYPE
|
||||
@@ -339,8 +340,7 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
|
||||
strcat(pformat, "lo");
|
||||
printf(pformat, (unsigned long) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)));
|
||||
} else if (m == 'A') {
|
||||
char modestr[12];
|
||||
printfs(pformat, bb_mode_string(modestr, statbuf->st_mode));
|
||||
printfs(pformat, bb_mode_string(statbuf->st_mode));
|
||||
} else if (m == 'f') {
|
||||
strcat(pformat, "lx");
|
||||
printf(pformat, (unsigned long) statbuf->st_mode);
|
||||
@@ -440,7 +440,7 @@ static void print_it(const char *masterformat,
|
||||
|
||||
/* print preceding string */
|
||||
*p = '\0';
|
||||
fputs_stdout(b);
|
||||
fputs(b, stdout);
|
||||
|
||||
p += len;
|
||||
b = p + 1;
|
||||
@@ -703,7 +703,6 @@ static bool do_stat(const char *filename, const char *format)
|
||||
bb_putchar('\n');
|
||||
# endif
|
||||
} else {
|
||||
char modestr[12];
|
||||
char *linkname = NULL;
|
||||
struct passwd *pw_ent;
|
||||
struct group *gw_ent;
|
||||
@@ -738,7 +737,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
bb_putchar('\n');
|
||||
printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n",
|
||||
(unsigned long) (statbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)),
|
||||
bb_mode_string(modestr, statbuf.st_mode),
|
||||
bb_mode_string(statbuf.st_mode),
|
||||
(unsigned long) statbuf.st_uid,
|
||||
(pw_ent != NULL) ? pw_ent->pw_name : "UNKNOWN",
|
||||
(unsigned long) statbuf.st_gid,
|
||||
|
||||
+3
-3
@@ -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 },
|
||||
|
||||
+27
-42
@@ -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
|
||||
@@ -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
|
||||
@@ -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
-85
@@ -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,25 +397,22 @@ 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;
|
||||
};
|
||||
|
||||
/* See test_ptr_hack.c */
|
||||
extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics;
|
||||
extern struct test_statics *const test_ptr_to_statics;
|
||||
|
||||
#define S (*test_ptr_to_statics)
|
||||
#define args (S.args )
|
||||
#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 { \
|
||||
XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \
|
||||
(*(struct test_statics**)not_const_pp(&test_ptr_to_statics)) = xzalloc(sizeof(S)); \
|
||||
barrier(); \
|
||||
} while (0)
|
||||
#define DEINIT_S() do { \
|
||||
free(group_array); \
|
||||
@@ -535,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;
|
||||
}
|
||||
@@ -584,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)
|
||||
@@ -895,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)
|
||||
@@ -914,9 +840,6 @@ int test_main(int argc, char **argv)
|
||||
bb_simple_error_msg("missing ]]");
|
||||
return 2;
|
||||
}
|
||||
#if BASH_TEST2
|
||||
bt2 = 1;
|
||||
#endif
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
@@ -925,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;
|
||||
|
||||
+12
-33
@@ -39,29 +39,13 @@
|
||||
//kbuild:lib-$(CONFIG_TIMEOUT) += timeout.o
|
||||
|
||||
//usage:#define timeout_trivial_usage
|
||||
//usage: "[-s SIG] [-k KILL_SECS] SECS PROG ARGS"
|
||||
//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."
|
||||
//usage: "If it still exists in KILL_SECS seconds, send KILL.\n"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static NOINLINE int timeout_wait(int timeout, pid_t pid)
|
||||
{
|
||||
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
|
||||
while (1) {
|
||||
sleep1();
|
||||
if (--timeout <= 0)
|
||||
break;
|
||||
if (kill(pid, 0)) {
|
||||
/* process is gone */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int timeout_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -69,29 +53,23 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
|
||||
int status;
|
||||
int parent = 0;
|
||||
int timeout;
|
||||
int kill_timeout;
|
||||
pid_t pid;
|
||||
#if !BB_MMU
|
||||
char *sv1, *sv2;
|
||||
#endif
|
||||
const char *opt_s = "TERM";
|
||||
char *opt_k = NULL;
|
||||
|
||||
/* -p option is not documented, it is needed to support NOMMU. */
|
||||
|
||||
/* -t SECONDS; -p PARENT_PID */
|
||||
/* '+': stop at first non-option */
|
||||
getopt32(argv, "+s:k:" USE_FOR_NOMMU("p:+"), &opt_s, &opt_k, &parent);
|
||||
getopt32(argv, "+s:" USE_FOR_NOMMU("p:+"), &opt_s, &parent);
|
||||
/*argv += optind; - no, wait for bb_daemonize_or_rexec! */
|
||||
|
||||
signo = get_signum(opt_s);
|
||||
if (signo < 0)
|
||||
bb_error_msg_and_die("unknown signal '%s'", opt_s);
|
||||
|
||||
kill_timeout = 0;
|
||||
if (opt_k)
|
||||
kill_timeout = parse_duration_str(opt_k);
|
||||
|
||||
if (!argv[optind])
|
||||
bb_show_usage();
|
||||
timeout = parse_duration_str(argv[optind++]);
|
||||
@@ -125,16 +103,17 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_daemonize_or_rexec(0, argv);
|
||||
/* Here we are grandchild. Sleep, then kill grandparent */
|
||||
grandchild:
|
||||
if (timeout_wait(timeout, parent) == EXIT_SUCCESS)
|
||||
return EXIT_SUCCESS;
|
||||
kill(parent, signo);
|
||||
|
||||
if (kill_timeout > 0) {
|
||||
if (timeout_wait(kill_timeout, parent) == EXIT_SUCCESS)
|
||||
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
|
||||
while (1) {
|
||||
sleep(1);
|
||||
if (--timeout <= 0)
|
||||
break;
|
||||
if (kill(parent, 0)) {
|
||||
/* process is gone */
|
||||
return EXIT_SUCCESS;
|
||||
kill(parent, SIGKILL);
|
||||
}
|
||||
}
|
||||
|
||||
kill(parent, signo);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
+76
-73
@@ -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,99 +85,93 @@ 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;
|
||||
int check_dst;
|
||||
|
||||
//memset(&tm_time, 0, sizeof(tm_time));
|
||||
/* Better than memset: makes "HH:MM" dates meaningful */
|
||||
time(&t);
|
||||
localtime_r(&t, &tm_time);
|
||||
check_dst = parse_datestr(date_str, &tm_time);
|
||||
parse_datestr(date_str, &tm_time);
|
||||
|
||||
/* Correct any day of week and day of year etc. fields */
|
||||
if (check_dst)
|
||||
tm_time.tm_isdst = -1; /* recheck dst unless date is UTC */
|
||||
tm_time.tm_isdst = -1; /* Be sure to recheck dst */
|
||||
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) {
|
||||
@@ -178,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
/* http://www.opengroup.org/onlinepubs/9699919799/utilities/tty.html */
|
||||
|
||||
//usage:#define tty_trivial_usage
|
||||
//usage: "" IF_INCLUDE_SUSv2("[-s]")
|
||||
//usage: ""
|
||||
//usage:#define tty_full_usage "\n\n"
|
||||
//usage: "Print file name of stdin's terminal"
|
||||
//usage: IF_INCLUDE_SUSv2( "\n"
|
||||
|
||||
Loaded 100 of 563 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user