summaryrefslogtreecommitdiffstats
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Makefile.am30
-rw-r--r--libbb/Makefile.in649
-rw-r--r--libbb/all_read.c83
-rw-r--r--libbb/ask_confirmation.c49
-rw-r--r--libbb/concat_path_file.c45
-rw-r--r--libbb/copy_file.c237
-rw-r--r--libbb/copy_file_chunk.c70
-rw-r--r--libbb/error_msg.c46
-rw-r--r--libbb/error_msg_and_die.c47
-rw-r--r--libbb/gz_open.c58
-rw-r--r--libbb/last_char_is.c40
-rw-r--r--libbb/libbb.h352
-rw-r--r--libbb/make_directory.c71
-rw-r--r--libbb/messages.c67
-rw-r--r--libbb/mode_string.c78
-rw-r--r--libbb/parse_mode.c134
-rw-r--r--libbb/perror_msg.c45
-rw-r--r--libbb/perror_msg_and_die.c46
-rw-r--r--libbb/safe_strncpy.c42
-rw-r--r--libbb/time_string.c62
-rw-r--r--libbb/unarchive.c811
-rw-r--r--libbb/unzip.c1040
-rw-r--r--libbb/verror_msg.c43
-rw-r--r--libbb/vperror_msg.c45
-rw-r--r--libbb/wfopen.c44
-rw-r--r--libbb/xfuncs.c102
-rw-r--r--libbb/xreadlink.c37
27 files changed, 4373 insertions, 0 deletions
diff --git a/libbb/Makefile.am b/libbb/Makefile.am
new file mode 100644
index 0000000..1f2dd12
--- /dev/null
+++ b/libbb/Makefile.am
@@ -0,0 +1,30 @@
+HOST_CPU=@host_cpu@
+BUILD_CPU=@build_cpu@
+ALL_CFLAGS=-g -O -Wall -DHOST_CPU_STR=\"@host_cpu@\" -DBUILD_CPU=@build_cpu@
+
+noinst_LTLIBRARIES = libbb.la
+
+libbb_la_SOURCES = gz_open.c \
+ libbb.h \
+ unzip.c \
+ wfopen.c \
+ unarchive.c \
+ copy_file.c \
+ copy_file_chunk.c \
+ error_msg.c error_msg_and_die.c \
+ perror_msg.c perror_msg_and_die.c \
+ xreadlink.c \
+ concat_path_file.c \
+ ask_confirmation.c \
+ verror_msg.c vperror_msg.c \
+ xfuncs.c messages.c \
+ last_char_is.c \
+ make_directory.c \
+ safe_strncpy.c \
+ parse_mode.c \
+ time_string.c \
+ all_read.c \
+ mode_string.c
+
+libbb_la_CFLAGS = $(ALL_CFLAGS)
+#libbb_la_LDFLAGS = -static
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
new file mode 100644
index 0000000..29f4a91
--- /dev/null
+++ b/libbb/Makefile.in
@@ -0,0 +1,649 @@
+# Makefile.in generated by automake 1.9.5 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+SOURCES = $(libbb_la_SOURCES)
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = libbb
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+libbb_la_LIBADD =
+am_libbb_la_OBJECTS = libbb_la-gz_open.lo libbb_la-unzip.lo \
+ libbb_la-wfopen.lo libbb_la-unarchive.lo libbb_la-copy_file.lo \
+ libbb_la-copy_file_chunk.lo libbb_la-error_msg.lo \
+ libbb_la-error_msg_and_die.lo libbb_la-perror_msg.lo \
+ libbb_la-perror_msg_and_die.lo libbb_la-xreadlink.lo \
+ libbb_la-concat_path_file.lo libbb_la-ask_confirmation.lo \
+ libbb_la-verror_msg.lo libbb_la-vperror_msg.lo \
+ libbb_la-xfuncs.lo libbb_la-messages.lo \
+ libbb_la-last_char_is.lo libbb_la-make_directory.lo \
+ libbb_la-safe_strncpy.lo libbb_la-parse_mode.lo \
+ libbb_la-time_string.lo libbb_la-all_read.lo \
+ libbb_la-mode_string.lo
+libbb_la_OBJECTS = $(am_libbb_la_OBJECTS)
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(libbb_la_SOURCES)
+DIST_SOURCES = $(libbb_la_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+ac_ct_RANLIB = @ac_ct_RANLIB@
+ac_ct_STRIP = @ac_ct_STRIP@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+ipkglibdir = @ipkglibdir@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+HOST_CPU = @host_cpu@
+BUILD_CPU = @build_cpu@
+ALL_CFLAGS = -g -O -Wall -DHOST_CPU_STR=\"@host_cpu@\" -DBUILD_CPU=@build_cpu@
+noinst_LTLIBRARIES = libbb.la
+libbb_la_SOURCES = gz_open.c \
+ libbb.h \
+ unzip.c \
+ wfopen.c \
+ unarchive.c \
+ copy_file.c \
+ copy_file_chunk.c \
+ error_msg.c error_msg_and_die.c \
+ perror_msg.c perror_msg_and_die.c \
+ xreadlink.c \
+ concat_path_file.c \
+ ask_confirmation.c \
+ verror_msg.c vperror_msg.c \
+ xfuncs.c messages.c \
+ last_char_is.c \
+ make_directory.c \
+ safe_strncpy.c \
+ parse_mode.c \
+ time_string.c \
+ all_read.c \
+ mode_string.c
+
+libbb_la_CFLAGS = $(ALL_CFLAGS)
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu libbb/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu libbb/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+clean-noinstLTLIBRARIES:
+ -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+ @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+libbb.la: $(libbb_la_OBJECTS) $(libbb_la_DEPENDENCIES)
+ $(LINK) $(libbb_la_LDFLAGS) $(libbb_la_OBJECTS) $(libbb_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-all_read.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-ask_confirmation.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-concat_path_file.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-copy_file.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-copy_file_chunk.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-error_msg.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-error_msg_and_die.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-gz_open.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-last_char_is.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-make_directory.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-messages.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-mode_string.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-parse_mode.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-perror_msg.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-perror_msg_and_die.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-safe_strncpy.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-time_string.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-unarchive.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-unzip.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-verror_msg.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-vperror_msg.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-wfopen.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-xfuncs.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbb_la-xreadlink.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+libbb_la-gz_open.lo: gz_open.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-gz_open.lo -MD -MP -MF "$(DEPDIR)/libbb_la-gz_open.Tpo" -c -o libbb_la-gz_open.lo `test -f 'gz_open.c' || echo '$(srcdir)/'`gz_open.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-gz_open.Tpo" "$(DEPDIR)/libbb_la-gz_open.Plo"; else rm -f "$(DEPDIR)/libbb_la-gz_open.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='gz_open.c' object='libbb_la-gz_open.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-gz_open.lo `test -f 'gz_open.c' || echo '$(srcdir)/'`gz_open.c
+
+libbb_la-unzip.lo: unzip.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-unzip.lo -MD -MP -MF "$(DEPDIR)/libbb_la-unzip.Tpo" -c -o libbb_la-unzip.lo `test -f 'unzip.c' || echo '$(srcdir)/'`unzip.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-unzip.Tpo" "$(DEPDIR)/libbb_la-unzip.Plo"; else rm -f "$(DEPDIR)/libbb_la-unzip.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='unzip.c' object='libbb_la-unzip.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-unzip.lo `test -f 'unzip.c' || echo '$(srcdir)/'`unzip.c
+
+libbb_la-wfopen.lo: wfopen.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-wfopen.lo -MD -MP -MF "$(DEPDIR)/libbb_la-wfopen.Tpo" -c -o libbb_la-wfopen.lo `test -f 'wfopen.c' || echo '$(srcdir)/'`wfopen.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-wfopen.Tpo" "$(DEPDIR)/libbb_la-wfopen.Plo"; else rm -f "$(DEPDIR)/libbb_la-wfopen.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='wfopen.c' object='libbb_la-wfopen.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-wfopen.lo `test -f 'wfopen.c' || echo '$(srcdir)/'`wfopen.c
+
+libbb_la-unarchive.lo: unarchive.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-unarchive.lo -MD -MP -MF "$(DEPDIR)/libbb_la-unarchive.Tpo" -c -o libbb_la-unarchive.lo `test -f 'unarchive.c' || echo '$(srcdir)/'`unarchive.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-unarchive.Tpo" "$(DEPDIR)/libbb_la-unarchive.Plo"; else rm -f "$(DEPDIR)/libbb_la-unarchive.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='unarchive.c' object='libbb_la-unarchive.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-unarchive.lo `test -f 'unarchive.c' || echo '$(srcdir)/'`unarchive.c
+
+libbb_la-copy_file.lo: copy_file.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-copy_file.lo -MD -MP -MF "$(DEPDIR)/libbb_la-copy_file.Tpo" -c -o libbb_la-copy_file.lo `test -f 'copy_file.c' || echo '$(srcdir)/'`copy_file.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-copy_file.Tpo" "$(DEPDIR)/libbb_la-copy_file.Plo"; else rm -f "$(DEPDIR)/libbb_la-copy_file.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='copy_file.c' object='libbb_la-copy_file.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-copy_file.lo `test -f 'copy_file.c' || echo '$(srcdir)/'`copy_file.c
+
+libbb_la-copy_file_chunk.lo: copy_file_chunk.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-copy_file_chunk.lo -MD -MP -MF "$(DEPDIR)/libbb_la-copy_file_chunk.Tpo" -c -o libbb_la-copy_file_chunk.lo `test -f 'copy_file_chunk.c' || echo '$(srcdir)/'`copy_file_chunk.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-copy_file_chunk.Tpo" "$(DEPDIR)/libbb_la-copy_file_chunk.Plo"; else rm -f "$(DEPDIR)/libbb_la-copy_file_chunk.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='copy_file_chunk.c' object='libbb_la-copy_file_chunk.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-copy_file_chunk.lo `test -f 'copy_file_chunk.c' || echo '$(srcdir)/'`copy_file_chunk.c
+
+libbb_la-error_msg.lo: error_msg.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-error_msg.lo -MD -MP -MF "$(DEPDIR)/libbb_la-error_msg.Tpo" -c -o libbb_la-error_msg.lo `test -f 'error_msg.c' || echo '$(srcdir)/'`error_msg.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-error_msg.Tpo" "$(DEPDIR)/libbb_la-error_msg.Plo"; else rm -f "$(DEPDIR)/libbb_la-error_msg.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='error_msg.c' object='libbb_la-error_msg.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-error_msg.lo `test -f 'error_msg.c' || echo '$(srcdir)/'`error_msg.c
+
+libbb_la-error_msg_and_die.lo: error_msg_and_die.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-error_msg_and_die.lo -MD -MP -MF "$(DEPDIR)/libbb_la-error_msg_and_die.Tpo" -c -o libbb_la-error_msg_and_die.lo `test -f 'error_msg_and_die.c' || echo '$(srcdir)/'`error_msg_and_die.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-error_msg_and_die.Tpo" "$(DEPDIR)/libbb_la-error_msg_and_die.Plo"; else rm -f "$(DEPDIR)/libbb_la-error_msg_and_die.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='error_msg_and_die.c' object='libbb_la-error_msg_and_die.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-error_msg_and_die.lo `test -f 'error_msg_and_die.c' || echo '$(srcdir)/'`error_msg_and_die.c
+
+libbb_la-perror_msg.lo: perror_msg.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-perror_msg.lo -MD -MP -MF "$(DEPDIR)/libbb_la-perror_msg.Tpo" -c -o libbb_la-perror_msg.lo `test -f 'perror_msg.c' || echo '$(srcdir)/'`perror_msg.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-perror_msg.Tpo" "$(DEPDIR)/libbb_la-perror_msg.Plo"; else rm -f "$(DEPDIR)/libbb_la-perror_msg.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='perror_msg.c' object='libbb_la-perror_msg.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-perror_msg.lo `test -f 'perror_msg.c' || echo '$(srcdir)/'`perror_msg.c
+
+libbb_la-perror_msg_and_die.lo: perror_msg_and_die.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-perror_msg_and_die.lo -MD -MP -MF "$(DEPDIR)/libbb_la-perror_msg_and_die.Tpo" -c -o libbb_la-perror_msg_and_die.lo `test -f 'perror_msg_and_die.c' || echo '$(srcdir)/'`perror_msg_and_die.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-perror_msg_and_die.Tpo" "$(DEPDIR)/libbb_la-perror_msg_and_die.Plo"; else rm -f "$(DEPDIR)/libbb_la-perror_msg_and_die.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='perror_msg_and_die.c' object='libbb_la-perror_msg_and_die.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-perror_msg_and_die.lo `test -f 'perror_msg_and_die.c' || echo '$(srcdir)/'`perror_msg_and_die.c
+
+libbb_la-xreadlink.lo: xreadlink.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-xreadlink.lo -MD -MP -MF "$(DEPDIR)/libbb_la-xreadlink.Tpo" -c -o libbb_la-xreadlink.lo `test -f 'xreadlink.c' || echo '$(srcdir)/'`xreadlink.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-xreadlink.Tpo" "$(DEPDIR)/libbb_la-xreadlink.Plo"; else rm -f "$(DEPDIR)/libbb_la-xreadlink.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='xreadlink.c' object='libbb_la-xreadlink.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-xreadlink.lo `test -f 'xreadlink.c' || echo '$(srcdir)/'`xreadlink.c
+
+libbb_la-concat_path_file.lo: concat_path_file.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-concat_path_file.lo -MD -MP -MF "$(DEPDIR)/libbb_la-concat_path_file.Tpo" -c -o libbb_la-concat_path_file.lo `test -f 'concat_path_file.c' || echo '$(srcdir)/'`concat_path_file.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-concat_path_file.Tpo" "$(DEPDIR)/libbb_la-concat_path_file.Plo"; else rm -f "$(DEPDIR)/libbb_la-concat_path_file.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='concat_path_file.c' object='libbb_la-concat_path_file.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-concat_path_file.lo `test -f 'concat_path_file.c' || echo '$(srcdir)/'`concat_path_file.c
+
+libbb_la-ask_confirmation.lo: ask_confirmation.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-ask_confirmation.lo -MD -MP -MF "$(DEPDIR)/libbb_la-ask_confirmation.Tpo" -c -o libbb_la-ask_confirmation.lo `test -f 'ask_confirmation.c' || echo '$(srcdir)/'`ask_confirmation.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-ask_confirmation.Tpo" "$(DEPDIR)/libbb_la-ask_confirmation.Plo"; else rm -f "$(DEPDIR)/libbb_la-ask_confirmation.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='ask_confirmation.c' object='libbb_la-ask_confirmation.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-ask_confirmation.lo `test -f 'ask_confirmation.c' || echo '$(srcdir)/'`ask_confirmation.c
+
+libbb_la-verror_msg.lo: verror_msg.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-verror_msg.lo -MD -MP -MF "$(DEPDIR)/libbb_la-verror_msg.Tpo" -c -o libbb_la-verror_msg.lo `test -f 'verror_msg.c' || echo '$(srcdir)/'`verror_msg.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-verror_msg.Tpo" "$(DEPDIR)/libbb_la-verror_msg.Plo"; else rm -f "$(DEPDIR)/libbb_la-verror_msg.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='verror_msg.c' object='libbb_la-verror_msg.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-verror_msg.lo `test -f 'verror_msg.c' || echo '$(srcdir)/'`verror_msg.c
+
+libbb_la-vperror_msg.lo: vperror_msg.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-vperror_msg.lo -MD -MP -MF "$(DEPDIR)/libbb_la-vperror_msg.Tpo" -c -o libbb_la-vperror_msg.lo `test -f 'vperror_msg.c' || echo '$(srcdir)/'`vperror_msg.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-vperror_msg.Tpo" "$(DEPDIR)/libbb_la-vperror_msg.Plo"; else rm -f "$(DEPDIR)/libbb_la-vperror_msg.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='vperror_msg.c' object='libbb_la-vperror_msg.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-vperror_msg.lo `test -f 'vperror_msg.c' || echo '$(srcdir)/'`vperror_msg.c
+
+libbb_la-xfuncs.lo: xfuncs.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-xfuncs.lo -MD -MP -MF "$(DEPDIR)/libbb_la-xfuncs.Tpo" -c -o libbb_la-xfuncs.lo `test -f 'xfuncs.c' || echo '$(srcdir)/'`xfuncs.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-xfuncs.Tpo" "$(DEPDIR)/libbb_la-xfuncs.Plo"; else rm -f "$(DEPDIR)/libbb_la-xfuncs.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='xfuncs.c' object='libbb_la-xfuncs.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-xfuncs.lo `test -f 'xfuncs.c' || echo '$(srcdir)/'`xfuncs.c
+
+libbb_la-messages.lo: messages.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-messages.lo -MD -MP -MF "$(DEPDIR)/libbb_la-messages.Tpo" -c -o libbb_la-messages.lo `test -f 'messages.c' || echo '$(srcdir)/'`messages.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-messages.Tpo" "$(DEPDIR)/libbb_la-messages.Plo"; else rm -f "$(DEPDIR)/libbb_la-messages.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='messages.c' object='libbb_la-messages.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-messages.lo `test -f 'messages.c' || echo '$(srcdir)/'`messages.c
+
+libbb_la-last_char_is.lo: last_char_is.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-last_char_is.lo -MD -MP -MF "$(DEPDIR)/libbb_la-last_char_is.Tpo" -c -o libbb_la-last_char_is.lo `test -f 'last_char_is.c' || echo '$(srcdir)/'`last_char_is.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-last_char_is.Tpo" "$(DEPDIR)/libbb_la-last_char_is.Plo"; else rm -f "$(DEPDIR)/libbb_la-last_char_is.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='last_char_is.c' object='libbb_la-last_char_is.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-last_char_is.lo `test -f 'last_char_is.c' || echo '$(srcdir)/'`last_char_is.c
+
+libbb_la-make_directory.lo: make_directory.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-make_directory.lo -MD -MP -MF "$(DEPDIR)/libbb_la-make_directory.Tpo" -c -o libbb_la-make_directory.lo `test -f 'make_directory.c' || echo '$(srcdir)/'`make_directory.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-make_directory.Tpo" "$(DEPDIR)/libbb_la-make_directory.Plo"; else rm -f "$(DEPDIR)/libbb_la-make_directory.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='make_directory.c' object='libbb_la-make_directory.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-make_directory.lo `test -f 'make_directory.c' || echo '$(srcdir)/'`make_directory.c
+
+libbb_la-safe_strncpy.lo: safe_strncpy.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-safe_strncpy.lo -MD -MP -MF "$(DEPDIR)/libbb_la-safe_strncpy.Tpo" -c -o libbb_la-safe_strncpy.lo `test -f 'safe_strncpy.c' || echo '$(srcdir)/'`safe_strncpy.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-safe_strncpy.Tpo" "$(DEPDIR)/libbb_la-safe_strncpy.Plo"; else rm -f "$(DEPDIR)/libbb_la-safe_strncpy.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='safe_strncpy.c' object='libbb_la-safe_strncpy.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-safe_strncpy.lo `test -f 'safe_strncpy.c' || echo '$(srcdir)/'`safe_strncpy.c
+
+libbb_la-parse_mode.lo: parse_mode.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-parse_mode.lo -MD -MP -MF "$(DEPDIR)/libbb_la-parse_mode.Tpo" -c -o libbb_la-parse_mode.lo `test -f 'parse_mode.c' || echo '$(srcdir)/'`parse_mode.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-parse_mode.Tpo" "$(DEPDIR)/libbb_la-parse_mode.Plo"; else rm -f "$(DEPDIR)/libbb_la-parse_mode.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='parse_mode.c' object='libbb_la-parse_mode.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-parse_mode.lo `test -f 'parse_mode.c' || echo '$(srcdir)/'`parse_mode.c
+
+libbb_la-time_string.lo: time_string.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-time_string.lo -MD -MP -MF "$(DEPDIR)/libbb_la-time_string.Tpo" -c -o libbb_la-time_string.lo `test -f 'time_string.c' || echo '$(srcdir)/'`time_string.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-time_string.Tpo" "$(DEPDIR)/libbb_la-time_string.Plo"; else rm -f "$(DEPDIR)/libbb_la-time_string.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='time_string.c' object='libbb_la-time_string.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-time_string.lo `test -f 'time_string.c' || echo '$(srcdir)/'`time_string.c
+
+libbb_la-all_read.lo: all_read.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-all_read.lo -MD -MP -MF "$(DEPDIR)/libbb_la-all_read.Tpo" -c -o libbb_la-all_read.lo `test -f 'all_read.c' || echo '$(srcdir)/'`all_read.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-all_read.Tpo" "$(DEPDIR)/libbb_la-all_read.Plo"; else rm -f "$(DEPDIR)/libbb_la-all_read.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='all_read.c' object='libbb_la-all_read.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-all_read.lo `test -f 'all_read.c' || echo '$(srcdir)/'`all_read.c
+
+libbb_la-mode_string.lo: mode_string.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -MT libbb_la-mode_string.lo -MD -MP -MF "$(DEPDIR)/libbb_la-mode_string.Tpo" -c -o libbb_la-mode_string.lo `test -f 'mode_string.c' || echo '$(srcdir)/'`mode_string.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libbb_la-mode_string.Tpo" "$(DEPDIR)/libbb_la-mode_string.Plo"; else rm -f "$(DEPDIR)/libbb_la-mode_string.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mode_string.c' object='libbb_la-mode_string.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbb_la_CFLAGS) $(CFLAGS) -c -o libbb_la-mode_string.lo `test -f 'mode_string.c' || echo '$(srcdir)/'`mode_string.c
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+uninstall-info-am:
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+ list='$(DISTFILES)'; for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+ esac; \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-libtool distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-info-am
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-noinstLTLIBRARIES ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-exec \
+ install-exec-am install-info install-info-am install-man \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+ pdf pdf-am ps ps-am tags uninstall uninstall-am \
+ uninstall-info-am
+
+#libbb_la_LDFLAGS = -static
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/libbb/all_read.c b/libbb/all_read.c
new file mode 100644
index 0000000..6ec731a
--- /dev/null
+++ b/libbb/all_read.c
@@ -0,0 +1,83 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include "libbb.h"
+
+extern void archive_xread_all(int fd , char *buf, size_t count)
+{
+ ssize_t size;
+
+ size = full_read(fd, buf, count);
+ if (size != count) {
+ perror_msg_and_die("Short read");
+ }
+ return;
+}
+
+/*
+ * Read all of the supplied buffer from a file.
+ * This does multiple reads as necessary.
+ * Returns the amount read, or -1 on an error.
+ * A short read is returned on an end of file.
+ */
+ssize_t full_read(int fd, char *buf, int len)
+{
+ ssize_t cc;
+ ssize_t total;
+
+ total = 0;
+
+ while (len > 0) {
+ cc = safe_read(fd, buf, len);
+
+ if (cc < 0)
+ return cc; /* read() returns -1 on failure. */
+
+ if (cc == 0)
+ break;
+
+ buf = ((char *)buf) + cc;
+ total += cc;
+ len -= cc;
+ }
+
+ return total;
+}
+
+
+ssize_t safe_read(int fd, void *buf, size_t count)
+{
+ ssize_t n;
+
+ do {
+ n = read(fd, buf, count);
+ } while (n < 0 && errno == EINTR);
+
+ return n;
+}
+
+
+
+/* END CODE */
+
diff --git a/libbb/ask_confirmation.c b/libbb/ask_confirmation.c
new file mode 100644
index 0000000..d4d943a
--- /dev/null
+++ b/libbb/ask_confirmation.c
@@ -0,0 +1,49 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) many different people. If you wrote this, please
+ * acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <stdio.h>
+#include "libbb.h"
+
+
+int ask_confirmation()
+{
+ int c = '\0';
+ int ret = 0;
+
+ while (c != '\n') {
+ c = getchar();
+ if ( c != '\n' ) {
+ ret = ((c=='y')||(c=='Y')) ? 1 : 0;
+ }
+ }
+ return ret;
+}
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c
new file mode 100644
index 0000000..e62b99e
--- /dev/null
+++ b/libbb/concat_path_file.c
@@ -0,0 +1,45 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) many different people. If you wrote this, please
+ * acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+/* concatenate path and file name to new allocation buffer,
+ * not addition '/' if path name already have '/'
+*/
+
+#include <string.h>
+#include "libbb.h"
+
+extern char *concat_path_file(const char *path, const char *filename)
+{
+ char *outbuf;
+ char *lc;
+
+ if (!path)
+ path="";
+ lc = last_char_is(path, '/');
+ while (*filename == '/')
+ filename++;
+ outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
+ sprintf(outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename);
+
+ return outbuf;
+}
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
new file mode 100644
index 0000000..c79fbeb
--- /dev/null
+++ b/libbb/copy_file.c
@@ -0,0 +1,237 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini copy_file implementation for busybox
+ *
+ *
+ * Copyright (C) 2001 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <utime.h>
+#include <errno.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "libbb.h"
+
+int copy_file(const char *source, const char *dest, int flags)
+{
+ struct stat source_stat;
+ struct stat dest_stat;
+ int dest_exists = 1;
+ int status = 0;
+
+ if (((flags & FILEUTILS_PRESERVE_SYMLINKS) &&
+ lstat(source, &source_stat) < 0) ||
+ (!(flags & FILEUTILS_PRESERVE_SYMLINKS) &&
+ stat(source, &source_stat) < 0)) {
+ perror_msg("%s", source);
+ return -1;
+ }
+
+ if (stat(dest, &dest_stat) < 0) {
+ if (errno != ENOENT) {
+ perror_msg("unable to stat `%s'", dest);
+ return -1;
+ }
+ dest_exists = 0;
+ }
+
+ if (dest_exists && source_stat.st_rdev == dest_stat.st_rdev &&
+ source_stat.st_ino == dest_stat.st_ino) {
+ error_msg("`%s' and `%s' are the same file", source, dest);
+ return -1;
+ }
+
+ if (S_ISDIR(source_stat.st_mode)) {
+ DIR *dp;
+ struct dirent *d;
+ mode_t saved_umask = 0;
+
+ if (!(flags & FILEUTILS_RECUR)) {
+ error_msg("%s: omitting directory", source);
+ return -1;
+ }
+
+ /* Create DEST. */
+ if (dest_exists) {
+ if (!S_ISDIR(dest_stat.st_mode)) {
+ error_msg("`%s' is not a directory", dest);
+ return -1;
+ }
+ } else {
+ mode_t mode;
+ saved_umask = umask(0);
+
+ mode = source_stat.st_mode;
+ if (!(flags & FILEUTILS_PRESERVE_STATUS))
+ mode = source_stat.st_mode & ~saved_umask;
+ mode |= S_IRWXU;
+
+ if (mkdir(dest, mode) < 0) {
+ umask(saved_umask);
+ perror_msg("cannot create directory `%s'", dest);
+ return -1;
+ }
+
+ umask(saved_umask);
+ }
+
+ /* Recursively copy files in SOURCE. */
+ if ((dp = opendir(source)) == NULL) {
+ perror_msg("unable to open directory `%s'", source);
+ status = -1;
+ goto end;
+ }
+
+ while ((d = readdir(dp)) != NULL) {
+ char *new_source, *new_dest;
+
+ if (strcmp(d->d_name, ".") == 0 ||
+ strcmp(d->d_name, "..") == 0)
+ continue;
+
+ new_source = concat_path_file(source, d->d_name);
+ new_dest = concat_path_file(dest, d->d_name);
+ if (copy_file(new_source, new_dest, flags) < 0)
+ status = -1;
+ free(new_source);
+ free(new_dest);
+ }
+
+ /* ??? What if an error occurs in readdir? */
+
+ if (closedir(dp) < 0) {
+ perror_msg("unable to close directory `%s'", source);
+ status = -1;
+ }
+
+ if (!dest_exists &&
+ chmod(dest, source_stat.st_mode & ~saved_umask) < 0) {
+ perror_msg("unable to change permissions of `%s'", dest);
+ status = -1;
+ }
+ } else if (S_ISREG(source_stat.st_mode)) {
+ FILE *sfp, *dfp;
+
+ if (dest_exists) {
+ if (flags & FILEUTILS_INTERACTIVE) {
+ fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest);
+ if (!ask_confirmation())
+ return 0;
+ }
+
+ if ((dfp = fopen(dest, "w")) == NULL) {
+ if (!(flags & FILEUTILS_FORCE)) {
+ perror_msg("unable to open `%s'", dest);
+ return -1;
+ }
+
+ if (unlink(dest) < 0) {
+ perror_msg("unable to remove `%s'", dest);
+ return -1;
+ }
+
+ dest_exists = 0;
+ }
+ }
+
+ if (!dest_exists) {
+ int fd;
+
+ if ((fd = open(dest, O_WRONLY|O_CREAT, source_stat.st_mode)) < 0 ||
+ (dfp = fdopen(fd, "w")) == NULL) {
+ if (fd >= 0)
+ close(fd);
+ perror_msg("unable to open `%s'", dest);
+ return -1;
+ }
+ }
+
+ if ((sfp = fopen(source, "r")) == NULL) {
+ fclose(dfp);
+ perror_msg("unable to open `%s'", source);
+ status = -1;
+ goto end;
+ }
+
+ if (copy_file_chunk(sfp, dfp, -1) < 0)
+ status = -1;
+
+ if (fclose(dfp) < 0) {
+ perror_msg("unable to close `%s'", dest);
+ status = -1;
+ }
+
+ if (fclose(sfp) < 0) {
+ perror_msg("unable to close `%s'", source);
+ status = -1;
+ }
+ } else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) ||
+ S_ISSOCK(source_stat.st_mode)) {
+ if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) {
+ perror_msg("unable to create `%s'", dest);
+ return -1;
+ }
+ } else if (S_ISFIFO(source_stat.st_mode)) {
+ if (mkfifo(dest, source_stat.st_mode) < 0) {
+ perror_msg("cannot create fifo `%s'", dest);
+ return -1;
+ }
+ } else if (S_ISLNK(source_stat.st_mode)) {
+ char *lpath = xreadlink(source);
+ if (symlink(lpath, dest) < 0) {
+ perror_msg("cannot create symlink `%s'", dest);
+ return -1;
+ }
+ free(lpath);
+
+#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
+ if (flags & FILEUTILS_PRESERVE_STATUS)
+ if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)
+ perror_msg("unable to preserve ownership of `%s'", dest);
+#endif
+ return 0;
+ } else {
+ error_msg("internal error: unrecognized file type");
+ return -1;
+ }
+
+end:
+
+ if (flags & FILEUTILS_PRESERVE_STATUS) {
+ struct utimbuf times;
+
+ times.actime = source_stat.st_atime;
+ times.modtime = source_stat.st_mtime;
+ if (utime(dest, &times) < 0)
+ perror_msg("unable to preserve times of `%s'", dest);
+ if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) {
+ source_stat.st_mode &= ~(S_ISUID | S_ISGID);
+ perror_msg("unable to preserve ownership of `%s'", dest);
+ }
+ if (chmod(dest, source_stat.st_mode) < 0)
+ perror_msg("unable to preserve permissions of `%s'", dest);
+ }
+
+ return status;
+}
diff --git a/libbb/copy_file_chunk.c b/libbb/copy_file_chunk.c
new file mode 100644
index 0000000..63d2ab1
--- /dev/null
+++ b/libbb/copy_file_chunk.c
@@ -0,0 +1,70 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) many different people. If you wrote this, please
+ * acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include "libbb.h"
+
+/* Copy CHUNKSIZE bytes (or until EOF if CHUNKSIZE equals -1) from SRC_FILE
+ * to DST_FILE. */
+extern int copy_file_chunk(FILE *src_file, FILE *dst_file, unsigned long long chunksize)
+{
+ size_t nread, nwritten, size;
+ char buffer[BUFSIZ];
+
+ while (chunksize != 0) {
+ if (chunksize > BUFSIZ)
+ size = BUFSIZ;
+ else
+ size = chunksize;
+
+ nread = fread (buffer, 1, size, src_file);
+
+ if (nread != size && ferror (src_file)) {
+ perror_msg ("read");
+ return -1;
+ } else if (nread == 0) {
+ if (chunksize != -1) {
+ error_msg ("Unable to read all data");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ nwritten = fwrite (buffer, 1, nread, dst_file);
+
+ if (nwritten != nread) {
+ if (ferror (dst_file))
+ perror_msg ("write");
+ else
+ error_msg ("Unable to write all data");
+ return -1;
+ }
+
+ if (chunksize != -1)
+ chunksize -= nwritten;
+ }
+
+ return 0;
+}
diff --git a/libbb/error_msg.c b/libbb/error_msg.c
new file mode 100644
index 0000000..58308b6
--- /dev/null
+++ b/libbb/error_msg.c
@@ -0,0 +1,46 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void error_msg(const char *s, ...)
+{
+ va_list p;
+
+ va_start(p, s);
+ verror_msg(s, p);
+ va_end(p);
+ putc('\n', stderr);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c
new file mode 100644
index 0000000..67a79c3
--- /dev/null
+++ b/libbb/error_msg_and_die.c
@@ -0,0 +1,47 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void error_msg_and_die(const char *s, ...)
+{
+ va_list p;
+
+ va_start(p, s);
+ verror_msg(s, p);
+ va_end(p);
+ putc('\n', stderr);
+ exit(EXIT_FAILURE);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/gz_open.c b/libbb/gz_open.c
new file mode 100644
index 0000000..dbaf3bb
--- /dev/null
+++ b/libbb/gz_open.c
@@ -0,0 +1,58 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) many different people. If you wrote this, please
+ * acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "libbb.h"
+
+extern FILE *gz_open(FILE *compressed_file, int *pid)
+{
+ int unzip_pipe[2];
+
+ if (pipe(unzip_pipe)!=0) {
+ error_msg("pipe error");
+ return(NULL);
+ }
+ if ((*pid = fork()) == -1) {
+ error_msg("fork failed");
+ return(NULL);
+ }
+ if (*pid==0) {
+ /* child process */
+ close(unzip_pipe[0]);
+ unzip(compressed_file, fdopen(unzip_pipe[1], "w"));
+ fflush(NULL);
+ fclose(compressed_file);
+ close(unzip_pipe[1]);
+ exit(EXIT_SUCCESS);
+ }
+ close(unzip_pipe[1]);
+ if (unzip_pipe[0] == -1) {
+ error_msg("gzip stream init failed");
+ }
+ return(fdopen(unzip_pipe[0], "r"));
+}
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c
new file mode 100644
index 0000000..4e2ee92
--- /dev/null
+++ b/libbb/last_char_is.c
@@ -0,0 +1,40 @@
+/*
+ * busybox library eXtended function
+ *
+ * Copyright (C) 2001 Larry Doolittle, <ldoolitt@recycle.lbl.gov>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <string.h>
+#include "libbb.h"
+
+/* Find out if the last character of a string matches the one given Don't
+ * underrun the buffer if the string length is 0. Also avoids a possible
+ * space-hogging inline of strlen() per usage.
+ */
+char * last_char_is(const char *s, int c)
+{
+ char *sret;
+ if (!s)
+ return NULL;
+ sret = (char *)s+strlen(s)-1;
+ if (sret>=s && *sret == c) {
+ return sret;
+ } else {
+ return NULL;
+ }
+}
diff --git a/libbb/libbb.h b/libbb/libbb.h
new file mode 100644
index 0000000..c54038d
--- /dev/null
+++ b/libbb/libbb.h
@@ -0,0 +1,352 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Busybox main internal header file
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __LIBBB_H__
+#define __LIBBB_H__ 1
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <netdb.h>
+
+// Include because of single use with ipkg
+#define _BB_INTERNAL_H_
+#define L_archive_offset
+#define L_get_header_ar
+#define L_free_header_tar
+#define L_get_header_tar
+#define L_unarchive
+#define L_seek_sub_file
+#define L_memory_exhausted
+#define L_deb_extract
+#define L_extract_archive
+#define L_parse_mode
+#define L_time_string
+#define L_mode_string
+
+#ifndef _BB_INTERNAL_H_
+#include "../busybox.h"
+#endif
+
+#ifdef DMALLOC
+#include "dmalloc.h"
+#endif
+
+#include <features.h>
+
+#if (__GNU_LIBRARY__ < 5) && (!defined __dietlibc__)
+/* libc5 doesn't define socklen_t */
+typedef unsigned int socklen_t;
+/* libc5 doesn't implement BSD 4.4 daemon() */
+extern int daemon (int nochdir, int noclose);
+/* libc5 doesn't implement strtok_r */
+char *strtok_r(char *s, const char *delim, char **ptrptr);
+#endif
+
+/* Some useful definitions */
+#define FALSE ((int) 0)
+#define TRUE ((int) 1)
+#define SKIP ((int) 2)
+
+/* for mtab.c */
+#define MTAB_GETMOUNTPT '1'
+#define MTAB_GETDEVICE '2'
+
+#define BUF_SIZE 8192
+#define EXPAND_ALLOC 1024
+
+static inline int is_decimal(int ch) { return ((ch >= '0') && (ch <= '9')); }
+static inline int is_octal(int ch) { return ((ch >= '0') && (ch <= '7')); }
+
+/* Macros for min/max. */
+#ifndef MIN
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#endif
+
+#ifndef MAX
+#define MAX(a,b) (((a)>(b))?(a):(b))
+#endif
+
+
+
+extern void show_usage(void) __attribute__ ((noreturn));
+extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
+extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
+extern void perror_msg(const char *s, ...);
+extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
+extern void vherror_msg(const char *s, va_list p);
+extern void herror_msg(const char *s, ...);
+extern void herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
+extern void archive_xread_all(int fd, char *buf, size_t count);
+
+/* These two are used internally -- you shouldn't need to use them */
+extern void verror_msg(const char *s, va_list p);
+extern void vperror_msg(const char *s, va_list p);
+
+const char *mode_string(int mode);
+const char *time_string(time_t timeVal);
+int is_directory(const char *name, int followLinks, struct stat *statBuf);
+int isDevice(const char *name);
+
+int remove_file(const char *path, int flags);
+int copy_file(const char *source, const char *dest, int flags);
+int copy_file_chunk(FILE *src_file, FILE *dst_file, unsigned long long chunksize);
+char *buildName(const char *dirName, const char *fileName);
+int makeString(int argc, const char **argv, char *buf, int bufLen);
+char *getChunk(int size);
+char *chunkstrdup(const char *str);
+void freeChunks(void);
+ssize_t safe_read(int fd, void *buf, size_t count);
+ssize_t full_write(int fd, const char *buf, int len);
+ssize_t full_read(int fd, char *buf, int len);
+int recursive_action(const char *fileName, int recurse, int followLinks, int depthFirst,
+ int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
+ int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
+ void* userData);
+
+extern int parse_mode( const char* s, mode_t* theMode);
+
+extern int get_kernel_revision(void);
+
+extern int get_console_fd(char* tty_name);
+extern struct mntent *find_mount_point(const char *name, const char *table);
+extern void write_mtab(char* blockDevice, char* directory,
+ char* filesystemType, long flags, char* string_flags);
+extern void erase_mtab(const char * name);
+extern long atoi_w_units (const char *cp);
+extern long* find_pid_by_name( char* pidName);
+extern char *find_real_root_device_name(const char* name);
+extern char *get_line_from_file(FILE *file);
+extern void print_file(FILE *file);
+extern int copyfd(int fd1, int fd2);
+extern int print_file_by_name(char *filename);
+extern char process_escape_sequence(const char **ptr);
+extern char *get_last_path_component(char *path);
+extern FILE *wfopen(const char *path, const char *mode);
+extern FILE *xfopen(const char *path, const char *mode);
+extern void chomp(char *s);
+extern struct BB_applet *find_applet_by_name(const char *name);
+void run_applet_by_name(const char *name, int argc, char **argv);
+
+#ifndef DMALLOC
+extern void *xmalloc (size_t size);
+extern void *xrealloc(void *old, size_t size);
+extern void *xcalloc(size_t nmemb, size_t size);
+extern char *xstrdup (const char *s);
+#endif
+extern char *xstrndup (const char *s, int n);
+extern char * safe_strncpy(char *dst, const char *src, size_t size);
+
+struct suffix_mult {
+ const char *suffix;
+ int mult;
+};
+
+extern unsigned long parse_number(const char *numstr,
+ const struct suffix_mult *suffixes);
+
+
+/* These parse entries in /etc/passwd and /etc/group. This is desirable
+ * for BusyBox since we want to avoid using the glibc NSS stuff, which
+ * increases target size and is often not needed embedded systems. */
+extern long my_getpwnam(const char *name);
+extern long my_getgrnam(const char *name);
+extern void my_getpwuid(char *name, long uid);
+extern void my_getgrgid(char *group, long gid);
+extern long my_getpwnamegid(const char *name);
+
+extern int device_open(char *device, int mode);
+
+extern int del_loop(const char *device);
+extern int set_loop(const char *device, const char *file, int offset, int *loopro);
+extern char *find_unused_loop_device (void);
+
+
+#if (__GLIBC__ < 2)
+extern int vdprintf(int d, const char *format, va_list ap);
+#endif
+
+int nfsmount(const char *spec, const char *node, int *flags,
+ char **extra_opts, char **mount_opts, int running_bg);
+
+void syslog_msg_with_name(const char *name, int facility, int pri, const char *msg);
+void syslog_msg(int facility, int pri, const char *msg);
+
+/* Include our own copy of struct sysinfo to avoid binary compatability
+ * problems with Linux 2.4, which changed things. Grumble, grumble. */
+struct sysinfo {
+ long uptime; /* Seconds since boot */
+ unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
+ unsigned long totalram; /* Total usable main memory size */
+ unsigned long freeram; /* Available memory size */
+ unsigned long sharedram; /* Amount of shared memory */
+ unsigned long bufferram; /* Memory used by buffers */
+ unsigned long totalswap; /* Total swap space size */
+ unsigned long freeswap; /* swap space still available */
+ unsigned short procs; /* Number of current processes */
+ unsigned short pad; /* Padding needed for m68k */
+ unsigned long totalhigh; /* Total high memory size */
+ unsigned long freehigh; /* Available high memory size */
+ unsigned int mem_unit; /* Memory unit size in bytes */
+ char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
+};
+extern int sysinfo (struct sysinfo* info);
+
+enum {
+ KILOBYTE = 1024,
+ MEGABYTE = (KILOBYTE*1024),
+ GIGABYTE = (MEGABYTE*1024)
+};
+const char *make_human_readable_str(unsigned long size, unsigned long block_size, unsigned long display_unit);
+
+int ask_confirmation(void);
+int klogctl(int type, char * b, int len);
+
+char *xgetcwd(char *cwd);
+char *xreadlink(const char *path);
+char *concat_path_file(const char *path, const char *filename);
+char *last_char_is(const char *s, int c);
+
+extern long arith (const char *startbuf, int *errcode);
+
+typedef struct file_headers_s {
+ char *name;
+ char *link_name;
+ off_t size;
+ uid_t uid;
+ gid_t gid;
+ mode_t mode;
+ time_t mtime;
+ dev_t device;
+} file_header_t;
+file_header_t *get_header_ar(FILE *in_file);
+void free_header_ar(file_header_t *ar_entry);
+file_header_t *get_header_cpio(FILE *src_stream);
+file_header_t *get_header_tar(FILE *tar_stream);
+void free_header_tar(file_header_t *tar_entry);
+
+enum extract_functions_e {
+ extract_verbose_list = 1,
+ extract_list = 2,
+ extract_one_to_buffer = 4,
+ extract_to_stdout = 8,
+ extract_all_to_fs = 16,
+ extract_preserve_date = 32,
+ extract_data_tar_gz = 64,
+ extract_control_tar_gz = 128,
+ extract_unzip_only = 256,
+ extract_unconditional = 512,
+ extract_create_leading_dirs = 1024,
+ extract_quiet = 2048,
+ extract_exclude_list = 4096
+};
+char *unarchive(FILE *src_stream, FILE *out_stream,
+ file_header_t *(*get_header)(FILE *),
+ void (*free_headers)(file_header_t *),
+ const int extract_function, const char *prefix, char **extract_names);
+char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function,
+ const char *prefix, const char *filename);
+int read_package_field(const char *package_buffer, char **field_name, char **field_value);
+char *fgets_str(FILE *file, const char *terminating_string);
+
+extern int unzip(FILE *l_in_file, FILE *l_out_file);
+extern void gz_close(int gunzip_pid);
+extern FILE *gz_open(FILE *compressed_file, int *pid);
+
+extern struct hostent *xgethostbyname(const char *name);
+extern int create_icmp_socket(void);
+
+char *dirname (char *path);
+
+int make_directory (const char *path, long mode, int flags);
+
+const char *u_signal_names(const char *str_sig, int *signo, int startnum);
+char *simplify_path(const char *path);
+
+#define CT_AUTO 0
+#define CT_UNIX2DOS 1
+#define CT_DOS2UNIX 2
+/* extern int convert(char *fn, int ConvType); */
+
+enum {
+ FILEUTILS_PRESERVE_STATUS = 1,
+ FILEUTILS_PRESERVE_SYMLINKS = 2,
+ FILEUTILS_RECUR = 4,
+ FILEUTILS_FORCE = 8,
+ FILEUTILS_INTERACTIVE = 16
+};
+
+extern const char *applet_name;
+extern const char * const full_version;
+extern const char * const name_too_long;
+extern const char * const omitting_directory;
+extern const char * const not_a_directory;
+extern const char * const memory_exhausted;
+extern const char * const invalid_date;
+extern const char * const invalid_option;
+extern const char * const io_error;
+extern const char * const dash_dash_help;
+extern const char * const write_error;
+extern const char * const too_few_args;
+extern const char * const name_longer_than_foo;
+extern const char * const unknown;
+extern const char * const can_not_create_raw_socket;
+
+#ifdef BB_FEATURE_DEVFS
+# define CURRENT_VC "/dev/vc/0"
+# define VC_1 "/dev/vc/1"
+# define VC_2 "/dev/vc/2"
+# define VC_3 "/dev/vc/3"
+# define VC_4 "/dev/vc/4"
+# define VC_5 "/dev/vc/5"
+# define SC_0 "/dev/tts/0"
+# define SC_1 "/dev/tts/1"
+# define VC_FORMAT "/dev/vc/%d"
+# define SC_FORMAT "/dev/tts/%d"
+# define LOOP_FORMAT "/dev/loop/%d"
+#else
+# define CURRENT_VC "/dev/tty0"
+# define VC_1 "/dev/tty1"
+# define VC_2 "/dev/tty2"
+# define VC_3 "/dev/tty3"
+# define VC_4 "/dev/tty4"
+# define VC_5 "/dev/tty5"
+# define SC_0 "/dev/ttyS0"
+# define SC_1 "/dev/ttyS1"
+# define VC_FORMAT "/dev/tty%d"
+# define SC_FORMAT "/dev/ttyS%d"
+# define LOOP_FORMAT "/dev/loop%d"
+#endif
+
+/* The following devices are the same on devfs and non-devfs systems. */
+#define CURRENT_TTY "/dev/tty"
+#define CONSOLE_DEV "/dev/console"
+
+/* Cope with mmu-less systems somewhat gracefully */
+#if defined(__UCLIBC__) && !defined(__ARCH_HAS_MMU__)
+#define fork vfork
+#endif
+
+/* Stupid gcc always includes its own builtin strlen()... */
+extern size_t xstrlen(const char *string);
+#define strlen(x) xstrlen(x)
+
+#endif /* __LIBBB_H__ */
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
new file mode 100644
index 0000000..797ce27
--- /dev/null
+++ b/libbb/make_directory.c
@@ -0,0 +1,71 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini make_directory implementation for busybox
+ *
+ * Copyright (C) 2001 Matt Kraai.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "libbb.h"
+
+/* Create the directory PATH with mode MODE, or the default if MODE is -1.
+ * Also create parent directories as necessary if flags contains
+ * FILEUTILS_RECUR. */
+
+int make_directory (const char *path, long mode, int flags)
+{
+ if (!(flags & FILEUTILS_RECUR)) {
+ if (mkdir (path, 0777) < 0) {
+ perror_msg ("Cannot create directory `%s'", path);
+ return -1;
+ }
+
+ if (mode != -1 && chmod (path, mode) < 0) {
+ perror_msg ("Cannot set permissions of directory `%s'", path);
+ return -1;
+ }
+ } else {
+ struct stat st;
+
+ if (stat (path, &st) < 0 && errno == ENOENT) {
+ int status;
+ char *buf, *parent;
+ mode_t mask;
+
+ mask = umask (0);
+ umask (mask);
+
+ buf = xstrdup (path);
+ parent = dirname (buf);
+ status = make_directory (parent, (0777 & ~mask) | 0300,
+ FILEUTILS_RECUR);
+ free (buf);
+
+ if (status < 0 || make_directory (path, mode, 0) < 0)
+ return -1;
+ }
+ }
+
+ return 0;
+}
diff --git a/libbb/messages.c b/libbb/messages.c
new file mode 100644
index 0000000..47b5526
--- /dev/null
+++ b/libbb/messages.c
@@ -0,0 +1,67 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "libbb.h"
+
+#ifdef L_full_version
+ const char * const full_version = BB_BANNER " multi-call binary";
+#endif
+#ifdef L_name_too_long
+ const char * const name_too_long = "file name too long";
+#endif
+
+#ifdef L_omitting_directory
+ const char * const omitting_directory = "%s: omitting directory";
+#endif
+#ifdef L_not_a_directory
+ const char * const not_a_directory = "%s: not a directory";
+#endif
+#ifdef L_memory_exhausted
+ const char * const memory_exhausted = "memory exhausted";
+#endif
+#ifdef L_invalid_date
+ const char * const invalid_date = "invalid date `%s'";
+#endif
+#ifdef L_invalid_option
+ const char * const invalid_option = "invalid option -- %c";
+#endif
+#ifdef L_io_error
+ const char * const io_error = "%s: input/output error -- %s";
+#endif
+#ifdef L_dash_dash_help
+ const char * const dash_dash_help = "--help";
+#endif
+#ifdef L_write_error
+ const char * const write_error = "Write Error";
+#endif
+#ifdef L_too_few_args
+ const char * const too_few_args = "too few arguments";
+#endif
+#ifdef L_name_longer_than_foo
+ const char * const name_longer_than_foo = "Names longer than %d chars not supported.";
+#endif
+#ifdef L_unknown
+ const char * const unknown = "(unknown)";
+#endif
+
+#ifdef L_can_not_create_raw_socket
+ const char * const can_not_create_raw_socket = "can`t create raw socket";
+#endif
diff --git a/libbb/mode_string.c b/libbb/mode_string.c
new file mode 100644
index 0000000..12dc179
--- /dev/null
+++ b/libbb/mode_string.c
@@ -0,0 +1,78 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) many different people. If you wrote this, please
+ * acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <stdio.h>
+#include "libbb.h"
+
+
+
+#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
+#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
+
+/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
+static const mode_t SBIT[] = {
+ 0, 0, S_ISUID,
+ 0, 0, S_ISGID,
+ 0, 0, S_ISVTX
+};
+
+/* The 9 mode bits to test */
+static const mode_t MBIT[] = {
+ S_IRUSR, S_IWUSR, S_IXUSR,
+ S_IRGRP, S_IWGRP, S_IXGRP,
+ S_IROTH, S_IWOTH, S_IXOTH
+};
+
+static const char MODE1[] = "rwxrwxrwx";
+static const char MODE0[] = "---------";
+static const char SMODE1[] = "..s..s..t";
+static const char SMODE0[] = "..S..S..T";
+
+/*
+ * Return the standard ls-like mode string from a file mode.
+ * This is static and so is overwritten on each call.
+ */
+const char *mode_string(int mode)
+{
+ static char buf[12];
+
+ int i;
+
+ buf[0] = TYPECHAR(mode);
+ for (i = 0; i < 9; i++) {
+ if (mode & SBIT[i])
+ buf[i + 1] = (mode & MBIT[i]) ? SMODE1[i] : SMODE0[i];
+ else
+ buf[i + 1] = (mode & MBIT[i]) ? MODE1[i] : MODE0[i];
+ }
+ return buf;
+}
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/parse_mode.c b/libbb/parse_mode.c
new file mode 100644
index 0000000..ba34ea9
--- /dev/null
+++ b/libbb/parse_mode.c
@@ -0,0 +1,134 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) many different people. If you wrote this, please
+ * acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+
+/* This function parses the sort of string you might pass
+ * to chmod (i.e., [ugoa]{+|-|=}[rwxst] ) and returns the
+ * correct mode described by the string. */
+extern int parse_mode(const char *s, mode_t * theMode)
+{
+ static const mode_t group_set[] = {
+ S_ISUID | S_IRWXU, /* u */
+ S_ISGID | S_IRWXG, /* g */
+ S_IRWXO, /* o */
+ S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO /* a */
+ };
+
+ static const mode_t mode_set[] = {
+ S_IRUSR | S_IRGRP | S_IROTH, /* r */
+ S_IWUSR | S_IWGRP | S_IWOTH, /* w */
+ S_IXUSR | S_IXGRP | S_IXOTH, /* x */
+ S_ISUID | S_ISGID, /* s */
+ S_ISVTX /* t */
+ };
+
+ static const char group_chars[] = "ugoa";
+ static const char mode_chars[] = "rwxst";
+
+ const char *p;
+
+ mode_t andMode =
+ S_ISVTX | S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
+ mode_t orMode = 0;
+ mode_t mode;
+ mode_t groups;
+ char type;
+ char c;
+
+ if (s==NULL) {
+ return (FALSE);
+ }
+
+ do {
+ mode = 0;
+ groups = 0;
+ NEXT_GROUP:
+ if ((c = *s++) == '\0') {
+ return -1;
+ }
+ for (p=group_chars ; *p ; p++) {
+ if (*p == c) {
+ groups |= group_set[(int)(p-group_chars)];
+ goto NEXT_GROUP;
+ }
+ }
+ switch (c) {
+ case '=':
+ case '+':
+ case '-':
+ type = c;
+ if (groups == 0) { /* The default is "all" */
+ groups |= S_ISUID | S_ISGID | S_ISVTX
+ | S_IRWXU | S_IRWXG | S_IRWXO;
+ }
+ break;
+ default:
+ if ((c < '0') || (c > '7') || (mode | groups)) {
+ return (FALSE);
+ } else {
+ *theMode = strtol(--s, NULL, 8);
+ return (TRUE);
+ }
+ }
+
+ NEXT_MODE:
+ if (((c = *s++) != '\0') && (c != ',')) {
+ for (p=mode_chars ; *p ; p++) {
+ if (*p == c) {
+ mode |= mode_set[(int)(p-mode_chars)];
+ goto NEXT_MODE;
+ }
+ }
+ break; /* We're done so break out of loop.*/
+ }
+ switch (type) {
+ case '=':
+ andMode &= ~(groups); /* Now fall through. */
+ case '+':
+ orMode |= mode & groups;
+ break;
+ case '-':
+ andMode &= ~(mode & groups);
+ orMode &= ~(mode & groups);
+ break;
+ }
+ } while (c == ',');
+
+ *theMode &= andMode;
+ *theMode |= orMode;
+
+ return TRUE;
+}
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/perror_msg.c b/libbb/perror_msg.c
new file mode 100644
index 0000000..8c57b0d
--- /dev/null
+++ b/libbb/perror_msg.c
@@ -0,0 +1,45 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void perror_msg(const char *s, ...)
+{
+ va_list p;
+
+ va_start(p, s);
+ vperror_msg(s, p);
+ va_end(p);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/perror_msg_and_die.c b/libbb/perror_msg_and_die.c
new file mode 100644
index 0000000..9004925
--- /dev/null
+++ b/libbb/perror_msg_and_die.c
@@ -0,0 +1,46 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void perror_msg_and_die(const char *s, ...)
+{
+ va_list p;
+
+ va_start(p, s);
+ vperror_msg(s, p);
+ va_end(p);
+ exit(EXIT_FAILURE);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/safe_strncpy.c b/libbb/safe_strncpy.c
new file mode 100644
index 0000000..0c5cf12
--- /dev/null
+++ b/libbb/safe_strncpy.c
@@ -0,0 +1,42 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+#include "libbb.h"
+
+
+
+/* Like strncpy but make sure the resulting string is always 0 terminated. */
+extern char * safe_strncpy(char *dst, const char *src, size_t size)
+{
+ dst[size-1] = '\0';
+ return strncpy(dst, src, size-1);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/time_string.c b/libbb/time_string.c
new file mode 100644
index 0000000..d103a02
--- /dev/null
+++ b/libbb/time_string.c
@@ -0,0 +1,62 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <utime.h>
+#include "libbb.h"
+
+
+/*
+ * Return the standard ls-like time string from a time_t
+ * This is static and so is overwritten on each call.
+ */
+const char *time_string(time_t timeVal)
+{
+ time_t now;
+ char *str;
+ static char buf[26];
+
+ time(&now);
+
+ str = ctime(&timeVal);
+
+ strcpy(buf, &str[4]);
+ buf[12] = '\0';
+
+ if ((timeVal > now) || (timeVal < now - 365 * 24 * 60 * 60L)) {
+ strcpy(&buf[7], &str[20]);
+ buf[11] = '\0';
+ }
+
+ return buf;
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/unarchive.c b/libbb/unarchive.c
new file mode 100644
index 0000000..0946ded
--- /dev/null
+++ b/libbb/unarchive.c
@@ -0,0 +1,811 @@
+/*
+ * Copyright (C) 2000 by Glenn McGrath
+ * Copyright (C) 2001 by Laurence Anderson
+ *
+ * Based on previous work by busybox developers and others.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <utime.h>
+#include "libbb.h"
+
+#define CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY 1
+#define CONFIG_FEATURE_TAR_GNU_EXTENSIONS
+
+#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
+static char *longname = NULL;
+static char *linkname = NULL;
+#endif
+
+extern void seek_sub_file(FILE *src_stream, const int count);
+extern char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *file_entry,
+ const int function, const char *prefix);
+
+
+#ifdef L_archive_offset
+off_t archive_offset;
+#else
+extern off_t archive_offset;
+#endif
+
+#ifdef L_seek_sub_file
+void seek_sub_file(FILE *src_stream, const int count)
+{
+ int i;
+ /* Try to fseek as faster */
+ archive_offset += count;
+ if (fseek(src_stream, count, SEEK_CUR) != 0 && errno == ESPIPE) {
+ for (i = 0; i < count; i++) {
+ fgetc(src_stream);
+ }
+ }
+ return;
+}
+#endif
+
+
+
+#ifdef L_extract_archive
+/* Extract the data postioned at src_stream to either filesystem, stdout or
+ * buffer depending on the value of 'function' which is defined in libbb.h
+ *
+ * prefix doesnt have to be just a directory, it may prefix the filename as well.
+ *
+ * e.g. '/var/lib/dpkg/info/dpkg.' will extract all files to the base bath
+ * '/var/lib/dpkg/info/' and all files/dirs created in that dir will have
+ * 'dpkg.' as their prefix
+ *
+ * For this reason if prefix does point to a dir then it must end with a
+ * trailing '/' or else the last dir will be assumed to be the file prefix
+ */
+char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *file_entry,
+ const int function, const char *prefix)
+{
+ FILE *dst_stream = NULL;
+ char *full_name = NULL;
+ char *full_link_name = NULL;
+ char *buffer = NULL;
+ struct utimbuf t;
+ int res;
+
+
+ /* prefix doesnt have to be a proper path it may prepend
+ * the filename as well */
+ if (prefix != NULL) {
+ /* strip leading '/' in filename to extract as prefix may not be dir */
+ /* Cant use concat_path_file here as prefix might not be a directory */
+ char *path = file_entry->name;
+ if (strncmp("./", path, 2) == 0) {
+ path += 2;
+ if (strlen(path) == 0) {
+ return(NULL);
+ }
+ }
+ full_name = xmalloc(strlen(prefix) + strlen(path) + 1);
+ strcpy(full_name, prefix);
+ strcat(full_name, path);
+ if ( file_entry->link_name ){
+ full_link_name = xmalloc(strlen(prefix) + strlen(file_entry->link_name) + 1);
+ strcpy(full_link_name, prefix);
+ strcat(full_link_name, file_entry->link_name);
+ }
+ } else {
+ full_name = strdup(file_entry->name);
+ if ( file_entry->link_name )
+ full_link_name = strdup(file_entry->link_name);
+ }
+
+
+ if (function & extract_to_stdout) {
+ if (S_ISREG(file_entry->mode)) {
+ copy_file_chunk(src_stream, out_stream, file_entry->size);
+ archive_offset += file_entry->size;
+ }
+ }
+ else if (function & extract_one_to_buffer) {
+ if (S_ISREG(file_entry->mode)) {
+ buffer = (char *) xmalloc(file_entry->size + 1);
+ fread(buffer, 1, file_entry->size, src_stream);
+ buffer[file_entry->size] = '\0';
+ archive_offset += file_entry->size;
+ return(buffer);
+ }
+ }
+ else if (function & extract_all_to_fs) {
+ struct stat oldfile;
+ int stat_res;
+ stat_res = lstat (full_name, &oldfile);
+ if (stat_res == 0) { /* The file already exists */
+ if ((function & extract_unconditional) || (oldfile.st_mtime < file_entry->mtime)) {
+ if (!S_ISDIR(oldfile.st_mode)) {
+ unlink(full_name); /* Directories might not be empty etc */
+ }
+ } else {
+ if ((function & extract_quiet) != extract_quiet) {
+ error_msg("%s not created: newer or same age file exists", file_entry->name);
+ }
+ seek_sub_file(src_stream, file_entry->size);
+ return (NULL);
+ }
+ }
+ if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
+ char *buf, *parent;
+ buf = xstrdup(full_name);
+ parent = dirname(buf);
+ if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
+ if ((function & extract_quiet) != extract_quiet) {
+ error_msg("couldn't create leading directories");
+ }
+ }
+ free (buf);
+ }
+ switch(file_entry->mode & S_IFMT) {
+ case S_IFREG:
+ if (file_entry->link_name) { /* Found a cpio hard link */
+ if (link(full_link_name, full_name) != 0) {
+ if ((function & extract_quiet) != extract_quiet) {
+ perror_msg("Cannot link from %s to '%s'",
+ file_entry->name, file_entry->link_name);
+ }
+ }
+ } else {
+ if ((dst_stream = wfopen(full_name, "w")) == NULL) {
+ seek_sub_file(src_stream, file_entry->size);
+ return NULL;
+ }
+ archive_offset += file_entry->size;
+ copy_file_chunk(src_stream, dst_stream, file_entry->size);
+ fclose(dst_stream);
+ }
+ break;
+ case S_IFDIR:
+ if (stat_res != 0) {
+ if (mkdir(full_name, file_entry->mode) < 0) {
+ if ((function & extract_quiet) != extract_quiet) {
+ perror_msg("extract_archive: %s", full_name);
+ }
+ }
+ }
+ break;
+ case S_IFLNK:
+ if (symlink(file_entry->link_name, full_name) < 0) {
+ if ((function & extract_quiet) != extract_quiet) {
+ perror_msg("Cannot create symlink from %s to '%s'", file_entry->name, file_entry->link_name);
+ }
+ return NULL;
+ }
+ break;
+ case S_IFSOCK:
+ case S_IFBLK:
+ case S_IFCHR:
+ case S_IFIFO:
+ if (mknod(full_name, file_entry->mode, file_entry->device) == -1) {
+ if ((function & extract_quiet) != extract_quiet) {
+ perror_msg("Cannot create node %s", file_entry->name);
+ }
+ return NULL;
+ }
+ break;
+ default:
+ perror_msg("Don't know how to handle %s", full_name);
+
+ }
+
+ /* Changing a symlink's properties normally changes the properties of the
+ * file pointed to, so dont try and change the date or mode, lchown does
+ * does the right thing, but isnt available in older versions of libc */
+ if (S_ISLNK(file_entry->mode)) {
+#if (__GLIBC__ > 2) && (__GLIBC_MINOR__ > 1)
+ lchown(full_name, file_entry->uid, file_entry->gid);
+#endif
+ } else {
+ if (function & extract_preserve_date) {
+ t.actime = file_entry->mtime;
+ t.modtime = file_entry->mtime;
+ utime(full_name, &t);
+ }
+ chown(full_name, file_entry->uid, file_entry->gid);
+ chmod(full_name, file_entry->mode);
+ }
+ } else {
+ /* If we arent extracting data we have to skip it,
+ * if data size is 0 then then just do it anyway
+ * (saves testing for it) */
+ seek_sub_file(src_stream, file_entry->size);
+ }
+
+ /* extract_list and extract_verbose_list can be used in conjunction
+ * with one of the above four extraction functions, so do this seperately */
+ if (function & extract_verbose_list) {
+ fprintf(out_stream, "%s %d/%d %8d %s ", mode_string(file_entry->mode),
+ file_entry->uid, file_entry->gid,
+ (int) file_entry->size, time_string(file_entry->mtime));
+ }
+ if ((function & extract_list) || (function & extract_verbose_list)){
+ /* fputs doesnt add a trailing \n, so use fprintf */
+ fprintf(out_stream, "%s\n", file_entry->name);
+ }
+
+ free(full_name);
+ if ( full_link_name )
+ free(full_link_name);
+
+ return(NULL); /* Maybe we should say if failed */
+}
+#endif
+
+#ifdef L_unarchive
+char *unarchive(FILE *src_stream, FILE *out_stream,
+ file_header_t *(*get_headers)(FILE *),
+ void (*free_headers)(file_header_t *),
+ const int extract_function, const char *prefix, char **extract_names)
+{
+ file_header_t *file_entry;
+ int extract_flag;
+ int i;
+ char *buffer = NULL;
+
+ archive_offset = 0;
+ while ((file_entry = get_headers(src_stream)) != NULL) {
+ extract_flag = TRUE;
+ /* fprintf(stderr, __FUNCTION__ " getting headers\n"); */
+ if (extract_names != NULL) {
+ int found_flag = FALSE;
+ for(i = 0; extract_names[i] != 0; i++) {
+ if (strcmp(extract_names[i], file_entry->name) == 0) {
+ found_flag = TRUE;
+ break;
+ }
+ }
+ if (extract_function & extract_exclude_list) {
+ if (found_flag == TRUE) {
+ extract_flag = FALSE;
+ }
+ } else {
+ /* If its not found in the include list dont extract it */
+ if (found_flag == FALSE) {
+ extract_flag = FALSE;
+ }
+ }
+
+ }
+
+ if (extract_flag == TRUE) {
+ /* fprintf(stderr, __FUNCTION__ " extract?\n"); */
+ buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix);
+ /* fprintf(stderr, __FUNCTION__ " extracted\n"); */
+ } else {
+ /* seek past the data entry */
+ seek_sub_file(src_stream, file_entry->size);
+ }
+ free_headers(file_entry);
+ }
+ /*fprintf(stderr, __FUNCTION__ " goin home\n");*/
+
+ return(buffer);
+}
+#endif
+
+#ifdef L_get_header_ar
+file_header_t *get_header_ar(FILE *src_stream)
+{
+ file_header_t *typed;
+ union {
+ char raw[60];
+ struct {
+ char name[16];
+ char date[12];
+ char uid[6];
+ char gid[6];
+ char mode[8];
+ char size[10];
+ char magic[2];
+ } formated;
+ } ar;
+ static char *ar_long_names;
+
+ if (fread(ar.raw, 1, 60, src_stream) != 60) {
+ return(NULL);
+ }
+ archive_offset += 60;
+ /* align the headers based on the header magic */
+ if ((ar.formated.magic[0] != '`') || (ar.formated.magic[1] != '\n')) {
+ /* some version of ar, have an extra '\n' after each data entry,
+ * this puts the next header out by 1 */
+ if (ar.formated.magic[1] != '`') {
+ error_msg("Invalid magic");
+ return(NULL);
+ }
+ /* read the next char out of what would be the data section,
+ * if its a '\n' then it is a valid header offset by 1*/
+ archive_offset++;
+ if (fgetc(src_stream) != '\n') {
+ error_msg("Invalid magic");
+ return(NULL);
+ }
+ /* fix up the header, we started reading 1 byte too early */
+ /* raw_header[60] wont be '\n' as it should, but it doesnt matter */
+ memmove(ar.raw, &ar.raw[1], 59);
+ }
+
+ typed = (file_header_t *) xcalloc(1, sizeof(file_header_t));
+
+ typed->size = (size_t) atoi(ar.formated.size);
+ /* long filenames have '/' as the first character */
+ if (ar.formated.name[0] == '/') {
+ if (ar.formated.name[1] == '/') {
+ /* If the second char is a '/' then this entries data section
+ * stores long filename for multiple entries, they are stored
+ * in static variable long_names for use in future entries */
+ ar_long_names = (char *) xrealloc(ar_long_names, typed->size);
+ fread(ar_long_names, 1, typed->size, src_stream);
+ archive_offset += typed->size;
+ /* This ar entries data section only contained filenames for other records
+ * they are stored in the static ar_long_names for future reference */
+ return (get_header_ar(src_stream)); /* Return next header */
+ } else if (ar.formated.name[1] == ' ') {
+ /* This is the index of symbols in the file for compilers */
+ seek_sub_file(src_stream, typed->size);
+ return (get_header_ar(src_stream)); /* Return next header */
+ } else {
+ /* The number after the '/' indicates the offset in the ar data section
+ (saved in variable long_name) that conatains the real filename */
+ if (!ar_long_names) {
+ error_msg("Cannot resolve long file name");
+ return (NULL);
+ }
+ typed->name = xstrdup(ar_long_names + atoi(&ar.formated.name[1]));
+ }
+ } else {
+ /* short filenames */
+ typed->name = xcalloc(1, 16);
+ strncpy(typed->name, ar.formated.name, 16);
+ }
+ typed->name[strcspn(typed->name, " /")]='\0';
+
+ /* convert the rest of the now valid char header to its typed struct */
+ parse_mode(ar.formated.mode, &typed->mode);
+ typed->mtime = atoi(ar.formated.date);
+ typed->uid = atoi(ar.formated.uid);
+ typed->gid = atoi(ar.formated.gid);
+
+ return(typed);
+}
+
+void free_header_ar(file_header_t *ar_entry)
+{
+ if (ar_entry == NULL) {
+ return;
+ }
+
+ free(ar_entry->name);
+ free(ar_entry->link_name);
+
+ free(ar_entry);
+}
+#endif
+
+#ifdef L_get_header_cpio
+struct hardlinks {
+ file_header_t *entry;
+ int inode;
+ struct hardlinks *next;
+};
+
+file_header_t *get_header_cpio(FILE *src_stream)
+{
+ file_header_t *cpio_entry = NULL;
+ char cpio_header[110];
+ int namesize;
+ char dummy[16];
+ int major, minor, nlink, inode;
+ static struct hardlinks *saved_hardlinks = NULL;
+ static int pending_hardlinks = 0;
+
+
+ if (pending_hardlinks) { /* Deal with any pending hardlinks */
+ struct hardlinks *tmp = saved_hardlinks, *oldtmp = NULL;
+ while (tmp) {
+ if (tmp->entry->link_name) { /* Found a hardlink ready to be extracted */
+ cpio_entry = tmp->entry;
+ if (oldtmp) oldtmp->next = tmp->next; /* Remove item from linked list */
+ else saved_hardlinks = tmp->next;
+ free(tmp);
+ return (cpio_entry);
+ }
+ oldtmp = tmp;
+ tmp = tmp->next;
+ }
+ pending_hardlinks = 0; /* No more pending hardlinks, read next file entry */
+ }
+
+ /* There can be padding before archive header */
+ seek_sub_file(src_stream, (4 - (archive_offset % 4)) % 4);
+ if (fread(cpio_header, 1, 110, src_stream) == 110) {
+ archive_offset += 110;
+ if (strncmp(cpio_header, "07070", 5) != 0) {
+ error_msg("Unsupported format or invalid magic");
+ return(NULL);
+ }
+ switch (cpio_header[5]) {
+ case '2': /* "crc" header format */
+ /* Doesnt do the crc check yet */
+ case '1': /* "newc" header format */
+ cpio_entry = (file_header_t *) xcalloc(1, sizeof(file_header_t));
+ sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
+ dummy, &inode, (unsigned int*)&cpio_entry->mode,
+ (unsigned int*)&cpio_entry->uid, (unsigned int*)&cpio_entry->gid,
+ &nlink, &cpio_entry->mtime, (unsigned long*)&cpio_entry->size,
+ dummy, &major, &minor, &namesize, dummy);
+
+ cpio_entry->name = (char *) xcalloc(1, namesize);
+ fread(cpio_entry->name, 1, namesize, src_stream); /* Read in filename */
+ archive_offset += namesize;
+ /* Skip padding before file contents */
+ seek_sub_file(src_stream, (4 - (archive_offset % 4)) % 4);
+ if (strcmp(cpio_entry->name, "TRAILER!!!") == 0) {
+ printf("%d blocks\n", (int) (archive_offset % 512 ? (archive_offset / 512) + 1 : archive_offset / 512)); /* Always round up */
+ if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
+ struct hardlinks *tmp = saved_hardlinks, *oldtmp = NULL;
+ while (tmp) {
+ error_msg("%s not created: cannot resolve hardlink", tmp->entry->name);
+ oldtmp = tmp;
+ tmp = tmp->next;
+ free (oldtmp->entry->name);
+ free (oldtmp->entry);
+ free (oldtmp);
+ }
+ saved_hardlinks = NULL;
+ pending_hardlinks = 0;
+ }
+ return(NULL);
+ }
+
+ if (S_ISLNK(cpio_entry->mode)) {
+ cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1);
+ fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream);
+ archive_offset += cpio_entry->size;
+ cpio_entry->size = 0; /* Stop possiable seeks in future */
+ }
+ if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) {
+ if (cpio_entry->size == 0) { /* Put file on a linked list for later */
+ struct hardlinks *new = xmalloc(sizeof(struct hardlinks));
+ new->next = saved_hardlinks;
+ new->inode = inode;
+ new->entry = cpio_entry;
+ saved_hardlinks = new;
+ return(get_header_cpio(src_stream)); /* Recurse to next file */
+ } else { /* Found the file with data in */
+ struct hardlinks *tmp = saved_hardlinks;
+ pending_hardlinks = 1;
+ while (tmp) {
+ if (tmp->inode == inode) {
+ tmp->entry->link_name = xstrdup(cpio_entry->name);
+ nlink--;
+ }
+ tmp = tmp->next;
+ }
+ if (nlink > 1) error_msg("error resolving hardlink: did you create the archive with GNU cpio 2.0-2.2?");
+ }
+ }
+ cpio_entry->device = (major << 8) | minor;
+ break;
+ default:
+ error_msg("Unsupported format");
+ return(NULL);
+ }
+ if (ferror(src_stream) || feof(src_stream)) {
+ perror_msg("Stream error");
+ return(NULL);
+ }
+ }
+ return(cpio_entry);
+}
+#endif
+
+#ifdef L_get_header_tar
+file_header_t *get_header_tar(FILE *tar_stream)
+{
+
+ union {
+ unsigned char raw[512];
+ struct {
+ char name[100]; /* 0-99 */
+ char mode[8]; /* 100-107 */
+ char uid[8]; /* 108-115 */
+ char gid[8]; /* 116-123 */
+ char size[12]; /* 124-135 */
+ char mtime[12]; /* 136-147 */
+ char chksum[8]; /* 148-155 */
+ char typeflag; /* 156-156 */
+ char linkname[100]; /* 157-256 */
+ char magic[6]; /* 257-262 */
+ char version[2]; /* 263-264 */
+ char uname[32]; /* 265-296 */
+ char gname[32]; /* 297-328 */
+ char devmajor[8]; /* 329-336 */
+ char devminor[8]; /* 337-344 */
+ char prefix[155]; /* 345-499 */
+ char padding[12]; /* 500-512 */
+ } formated;
+ } tar;
+ file_header_t *tar_entry = NULL;
+ long i;
+ long sum = 0;
+
+ if (archive_offset % 512 != 0) {
+ seek_sub_file(tar_stream, 512 - (archive_offset % 512));
+ }
+
+ if (fread(tar.raw, 1, 512, tar_stream) != 512) {
+ /* Unfortunatly its common for tar files to have all sorts of
+ * trailing garbage, fail silently */
+// error_msg("Couldnt read header");
+ return(NULL);
+ }
+ archive_offset += 512;
+
+ /* Check header has valid magic, unfortunately some tar files
+ * have empty (0'ed) tar entries at the end, which will
+ * cause this to fail, so fail silently for now
+ */
+ if (strncmp(tar.formated.magic, "ustar", 5) != 0) {
+#ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
+ if (strncmp(tar.formated.magic, "\0\0\0\0\0", 5) != 0)
+#endif
+ return(NULL);
+ }
+
+ /* Do checksum on headers */
+ for (i = 0; i < 148 ; i++) {
+ sum += tar.raw[i];
+ }
+ sum += ' ' * 8;
+ for (i = 156; i < 512 ; i++) {
+ sum += tar.raw[i];
+ }
+ if (sum != strtol(tar.formated.chksum, NULL, 8)) {
+ if ( strtol(tar.formated.chksum,NULL,8) != 0 )
+ error_msg("Invalid tar header checksum");
+ return(NULL);
+ }
+
+ /* convert to type'ed variables */
+ tar_entry = xcalloc(1, sizeof(file_header_t));
+
+#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
+ if (longname) {
+ tar_entry->name = longname;
+ longname = NULL;
+ }
+ else if (linkname) {
+ tar_entry->name = linkname;
+ linkname = NULL;
+ } else
+#endif
+ if (tar.formated.prefix[0] == 0) {
+ tar_entry->name = strdup(tar.formated.name);
+ } else {
+ tar_entry->name = concat_path_file(tar.formated.prefix, tar.formated.name);
+ }
+
+ // tar_entry->name = xstrdup(tar.formated.name);
+
+/*
+ parse_mode(tar.formated.mode, &tar_entry->mode);
+*/
+ tar_entry->mode = 07777 & strtol(tar.formated.mode, NULL, 8);
+
+ tar_entry->uid = strtol(tar.formated.uid, NULL, 8);
+ tar_entry->gid = strtol(tar.formated.gid, NULL, 8);
+ tar_entry->size = strtol(tar.formated.size, NULL, 8);
+ tar_entry->mtime = strtol(tar.formated.mtime, NULL, 8);
+ tar_entry->link_name = strlen(tar.formated.linkname) ?
+ xstrdup(tar.formated.linkname) : NULL;
+ tar_entry->device = (strtol(tar.formated.devmajor, NULL, 8) << 8) +
+ strtol(tar.formated.devminor, NULL, 8);
+
+ /* Fix mode, used by the old format */
+ switch (tar.formated.typeflag) {
+ /* hard links are detected as regular files with 0 size and a link name */
+ case '1':
+ tar_entry->mode |= S_IFREG ;
+ break;
+ case 0:
+ case '0':
+
+# ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
+ if (last_char_is(tar_entry->name, '/')) {
+ tar_entry->mode |= S_IFDIR;
+ } else
+# endif
+ tar_entry->mode |= S_IFREG;
+ break;
+ case '2':
+ tar_entry->mode |= S_IFLNK;
+ break;
+ case '3':
+ tar_entry->mode |= S_IFCHR;
+ break;
+ case '4':
+ tar_entry->mode |= S_IFBLK;
+ break;
+ case '5':
+ tar_entry->mode |= S_IFDIR;
+ break;
+ case '6':
+ tar_entry->mode |= S_IFIFO;
+ break;
+# ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
+ case 'L': {
+ longname = xmalloc(tar_entry->size + 1);
+ if(fread(longname, tar_entry->size, 1, tar_stream) != 1)
+ return NULL;
+ longname[tar_entry->size] = '\0';
+ archive_offset += tar_entry->size;
+
+ return(get_header_tar(tar_stream));
+ }
+ case 'K': {
+ linkname = xmalloc(tar_entry->size + 1);
+ if(fread(linkname, tar_entry->size, 1, tar_stream) != 1)
+ return NULL;
+ linkname[tar_entry->size] = '\0';
+ archive_offset += tar_entry->size;
+
+ tar_entry->name = linkname;
+ return(get_header_tar(tar_stream));
+ }
+ case 'D':
+ case 'M':
+ case 'N':
+ case 'S':
+ case 'V':
+ perror_msg("Ignoring GNU extension type %c", tar.formated.typeflag);
+# endif
+ default:
+ perror_msg("Unknown typeflag: 0x%x", tar.formated.typeflag);
+ break;
+
+ }
+
+ return(tar_entry);
+}
+
+void free_header_tar(file_header_t *tar_entry)
+{
+ if (tar_entry == NULL) {
+ return;
+ }
+
+ free(tar_entry->name);
+ free(tar_entry->link_name);
+
+ free(tar_entry);
+}
+
+#endif
+
+#ifdef L_deb_extract
+char *deb_extract(const char *package_filename, FILE *out_stream,
+ const int extract_function, const char *prefix, const char *filename)
+{
+ FILE *deb_stream;
+ FILE *uncompressed_stream = NULL;
+ file_header_t *ar_header = NULL;
+ char **file_list = NULL;
+ char *output_buffer = NULL;
+ char *ared_file = NULL;
+ char ar_magic[8];
+ int gunzip_pid;
+
+ if (filename != NULL) {
+ file_list = xmalloc(sizeof(char *) * 2);
+ file_list[0] = xstrdup(filename);
+ file_list[1] = NULL;
+ }
+
+ if (extract_function & extract_control_tar_gz) {
+ ared_file = xstrdup("control.tar.gz");
+ }
+ else if (extract_function & extract_data_tar_gz) {
+ ared_file = xstrdup("data.tar.gz");
+ } else {
+ fprintf(stderr, "no file specified to extract -- extract_function=%x\n", extract_function);
+ return NULL;
+ }
+
+ /* open the debian package to be worked on */
+ deb_stream = wfopen(package_filename, "r");
+ if (deb_stream == NULL) {
+ return(NULL);
+ }
+ /* set the buffer size */
+ setvbuf(deb_stream, NULL, _IOFBF, 0x8000);
+
+ /* check ar magic */
+ fread(ar_magic, 1, 8, deb_stream);
+ /*fprintf(stderr, "deb_extract ar_magic=%08x\n", *(long *)ar_magic);*/
+ if (strncmp(ar_magic,"!<arch>",7) == 0) {
+ archive_offset = 8;
+
+ while ((ar_header = get_header_ar(deb_stream)) != NULL) {
+ if (strcmp(ared_file, ar_header->name) == 0) {
+ /* open a stream of decompressed data */
+ uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
+ archive_offset = 0;
+ output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, free_header_tar, extract_function, prefix, file_list);
+ }
+ seek_sub_file(deb_stream, ar_header->size);
+ }
+ gz_close(gunzip_pid);
+ fclose(deb_stream);
+ fclose(uncompressed_stream);
+ free(ared_file);
+ return(output_buffer);
+ } else if (strncmp(ar_magic, "\037\213", 2) == 0) {
+ /* it's a gz file, let's assume it's an ipkg */
+ int unzipped_ipkg_pid;
+ FILE *unzipped_ipkg_stream;
+ file_header_t *tar_header;
+ archive_offset = 0;
+ fseek(deb_stream, 0, SEEK_SET);
+ unzipped_ipkg_stream = gz_open(deb_stream, &unzipped_ipkg_pid);
+
+ /*fprintf(stderr, __FUNCTION__ ": processing ipkg %s -- ared_file=%s\n", package_filename, ared_file);*/
+ /* walk through outer tar file to find ared_file */
+ while ((tar_header = get_header_tar(unzipped_ipkg_stream)) != NULL) {
+ int name_offset = 0;
+ if (strncmp(tar_header->name, "./", 2) == 0)
+ name_offset = 2;
+ if (strcmp(ared_file, tar_header->name+name_offset) == 0) {
+ /* open a stream of decompressed data */
+ uncompressed_stream = gz_open(unzipped_ipkg_stream, &gunzip_pid);
+ archive_offset = 0;
+ /*fprintf(stderr, __FUNCTION__ ":%d: here -- found file\n", __LINE__);*/
+ output_buffer = unarchive(uncompressed_stream,
+ out_stream,
+ get_header_tar,
+ free_header_tar,
+ extract_function,
+ prefix,
+ file_list);
+ /*fprintf(stderr, __FUNCTION__ ":%d: unarchive complete\n", __LINE__);*/
+ free_header_tar(tar_header);
+ gz_close(gunzip_pid);
+ fclose(uncompressed_stream);
+ break;
+ }
+ seek_sub_file(unzipped_ipkg_stream, tar_header->size);
+ free_header_tar(tar_header);
+ }
+ gz_close(unzipped_ipkg_pid);
+ fclose(unzipped_ipkg_stream);
+ fclose(deb_stream);
+ free(ared_file);
+ /*fprintf(stderr, __FUNCTION__ ":%d: done\n", __LINE__);*/
+ return output_buffer;
+ } else {
+ error_msg_and_die("invalid magic");
+ }
+
+}
+#endif
diff --git a/libbb/unzip.c b/libbb/unzip.c
new file mode 100644
index 0000000..3826316
--- /dev/null
+++ b/libbb/unzip.c
@@ -0,0 +1,1040 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * gunzip implementation for busybox
+ *
+ * Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
+ *
+ * Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
+ * based on gzip sources
+ *
+ * Adjusted further by Erik Andersen <andersee@debian.org> to support
+ * files as well as stdin/stdout, and to generally behave itself wrt
+ * command line handling.
+ *
+ * General cleanup to better adhere to the style guide and make use of
+ * standard busybox functions by Glenn McGrath <bug1@optushome.com.au>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
+ * Copyright (C) 1992-1993 Jean-loup Gailly
+ * The unzip code was written and put in the public domain by Mark Adler.
+ * Portions of the lzw code are derived from the public domain 'compress'
+ * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
+ * Ken Turkowski, Dave Mack and Peter Jannesen.
+ *
+ * See the license_msg below and the file COPYING for the software license.
+ * See the file algorithm.doc for the compression algorithms and file formats.
+ */
+
+#if 0
+static char *license_msg[] = {
+ " Copyright (C) 1992-1993 Jean-loup Gailly",
+ " This program is free software; you can redistribute it and/or modify",
+ " it under the terms of the GNU General Public License as published by",
+ " the Free Software Foundation; either version 2, or (at your option)",
+ " any later version.",
+ "",
+ " This program is distributed in the hope that it will be useful,",
+ " but WITHOUT ANY WARRANTY; without even the implied warranty of",
+ " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
+ " GNU General Public License for more details.",
+ "",
+ " You should have received a copy of the GNU General Public License",
+ " along with this program; if not, write to the Free Software",
+ " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.",
+ 0
+};
+#endif
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include "libbb.h"
+
+static FILE *in_file, *out_file;
+
+/* these are freed by gz_close */
+static unsigned char *window;
+static unsigned long *crc_table;
+
+static unsigned long crc; /* shift register contents */
+
+/* Return codes from gzip */
+static const int ERROR = 1;
+
+/*
+ * window size--must be a power of two, and
+ * at least 32K for zip's deflate method
+ */
+static const int WSIZE = 0x8000;
+
+/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
+static const int BMAX = 16; /* maximum bit length of any code (16 for explode) */
+static const int N_MAX = 288; /* maximum number of codes in any set */
+
+static long bytes_out; /* number of output bytes */
+static unsigned long outcnt; /* bytes in output buffer */
+
+static unsigned hufts; /* track memory usage */
+static unsigned long bb; /* bit buffer */
+static unsigned bk; /* bits in bit buffer */
+
+typedef struct huft_s {
+ unsigned char e; /* number of extra bits or operation */
+ unsigned char b; /* number of bits in this code or subcode */
+ union {
+ unsigned short n; /* literal, length base, or distance base */
+ struct huft_s *t; /* pointer to next level of table */
+ } v;
+} huft_t;
+
+static const unsigned short mask_bits[] = {
+ 0x0000,
+ 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
+ 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
+};
+
+//static int error_number = 0;
+/* ========================================================================
+ * Signal and error handler.
+ */
+
+static void abort_gzip()
+{
+ error_msg("gzip aborted\n");
+ exit(ERROR);
+}
+
+static void make_crc_table()
+{
+ unsigned long table_entry; /* crc shift register */
+ unsigned long poly = 0; /* polynomial exclusive-or pattern */
+ int i; /* counter for all possible eight bit values */
+ int k; /* byte being shifted into crc apparatus */
+
+ /* terms of polynomial defining this crc (except x^32): */
+ static int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
+
+ /* initial shift register value */
+ crc = 0xffffffffL;
+ crc_table = (unsigned long *) malloc(256 * sizeof(unsigned long));
+
+ /* Make exclusive-or pattern from polynomial (0xedb88320) */
+ for (i = 0; i < sizeof(p)/sizeof(int); i++)
+ poly |= 1L << (31 - p[i]);
+
+ /* Compute and print table of CRC's, five per line */
+ for (i = 0; i < 256; i++) {
+ table_entry = i;
+ /* The idea to initialize the register with the byte instead of
+ * zero was stolen from Haruhiko Okumura's ar002
+ */
+ for (k = 8; k; k--) {
+ table_entry = table_entry & 1 ? (table_entry >> 1) ^ poly : table_entry >> 1;
+ }
+ crc_table[i]=table_entry;
+ }
+}
+
+/* ===========================================================================
+ * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * (Used for the decompressed data only.)
+ */
+static void flush_window(void)
+{
+ int n;
+
+ if (outcnt == 0)
+ return;
+
+ for (n = 0; n < outcnt; n++) {
+ crc = crc_table[((int) crc ^ (window[n])) & 0xff] ^ (crc >> 8);
+ }
+
+ if (fwrite(window, 1, outcnt, out_file) != outcnt) {
+ error_msg_and_die("Couldnt write");
+ }
+ bytes_out += (unsigned long) outcnt;
+ outcnt = 0;
+}
+
+/*
+ * Free the malloc'ed tables built by huft_build(), which makes a linked
+ * list of the tables it made, with the links in a dummy first entry of
+ * each table.
+ * t: table to free
+ */
+static int huft_free(huft_t *t)
+{
+ huft_t *p, *q;
+
+ /* Go through linked list, freeing from the malloced (t[-1]) address. */
+ p = t;
+ while (p != (huft_t *) NULL) {
+ q = (--p)->v.t;
+ free((char *) p);
+ p = q;
+ }
+ return 0;
+}
+
+/* Given a list of code lengths and a maximum table size, make a set of
+ * tables to decode that set of codes. Return zero on success, one if
+ * the given code set is incomplete (the tables are still built in this
+ * case), two if the input is invalid (all zero length codes or an
+ * oversubscribed set of lengths), and three if not enough memory.
+ *
+ * b: code lengths in bits (all assumed <= BMAX)
+ * n: number of codes (assumed <= N_MAX)
+ * s: number of simple-valued codes (0..s-1)
+ * d: list of base values for non-simple codes
+ * e: list of extra bits for non-simple codes
+ * t: result: starting table
+ * m: maximum lookup bits, returns actual
+ */
+static int huft_build(unsigned int *b, const unsigned int n, const unsigned int s,
+ const unsigned short *d, const unsigned short *e, huft_t **t, int *m)
+{
+ unsigned a; /* counter for codes of length k */
+ unsigned c[BMAX + 1]; /* bit length count table */
+ unsigned f; /* i repeats in table every f entries */
+ int g; /* maximum code length */
+ int h; /* table level */
+ register unsigned i; /* counter, current code */
+ register unsigned j; /* counter */
+ register int k; /* number of bits in current code */
+ int l; /* bits per table (returned in m) */
+ register unsigned *p; /* pointer into c[], b[], or v[] */
+ register huft_t *q; /* points to current table */
+ huft_t r; /* table entry for structure assignment */
+ huft_t *u[BMAX]; /* table stack */
+ unsigned v[N_MAX]; /* values in order of bit length */
+ register int w; /* bits before this table == (l * h) */
+ unsigned x[BMAX + 1]; /* bit offsets, then code stack */
+ unsigned *xp; /* pointer into x */
+ int y; /* number of dummy codes added */
+ unsigned z; /* number of entries in current table */
+
+ /* Generate counts for each bit length */
+ memset ((void *)(c), 0, sizeof(c));
+ p = b;
+ i = n;
+ do {
+ c[*p]++; /* assume all entries <= BMAX */
+ p++; /* Can't combine with above line (Solaris bug) */
+ } while (--i);
+ if (c[0] == n) { /* null input--all zero length codes */
+ *t = (huft_t *) NULL;
+ *m = 0;
+ return 0;
+ }
+
+ /* Find minimum and maximum length, bound *m by those */
+ l = *m;
+ for (j = 1; j <= BMAX; j++)
+ if (c[j])
+ break;
+ k = j; /* minimum code length */
+ if ((unsigned) l < j)
+ l = j;
+ for (i = BMAX; i; i--)
+ if (c[i])
+ break;
+ g = i; /* maximum code length */
+ if ((unsigned) l > i)
+ l = i;
+ *m = l;
+
+ /* Adjust last length count to fill out codes, if needed */
+ for (y = 1 << j; j < i; j++, y <<= 1)
+ if ((y -= c[j]) < 0)
+ return 2; /* bad input: more codes than bits */
+ if ((y -= c[i]) < 0)
+ return 2;
+ c[i] += y;
+
+ /* Generate starting offsets into the value table for each length */
+ x[1] = j = 0;
+ p = c + 1;
+ xp = x + 2;
+ while (--i) { /* note that i == g from above */
+ *xp++ = (j += *p++);
+ }
+
+ /* Make a table of values in order of bit lengths */
+ p = b;
+ i = 0;
+ do {
+ if ((j = *p++) != 0)
+ v[x[j]++] = i;
+ } while (++i < n);
+
+ /* Generate the Huffman codes and for each, make the table entries */
+ x[0] = i = 0; /* first Huffman code is zero */
+ p = v; /* grab values in bit order */
+ h = -1; /* no tables yet--level -1 */
+ w = -l; /* bits decoded == (l * h) */
+ u[0] = (huft_t *) NULL; /* just to keep compilers happy */
+ q = (huft_t *) NULL; /* ditto */
+ z = 0; /* ditto */
+
+ /* go through the bit lengths (k already is bits in shortest code) */
+ for (; k <= g; k++) {
+ a = c[k];
+ while (a--) {
+ /* here i is the Huffman code of length k bits for value *p */
+ /* make tables up to required level */
+ while (k > w + l) {
+ h++;
+ w += l; /* previous table always l bits */
+
+ /* compute minimum size table less than or equal to l bits */
+ z = (z = g - w) > (unsigned) l ? l : z; /* upper limit on table size */
+ if ((f = 1 << (j = k - w)) > a + 1) { /* try a k-w bit table *//* too few codes for k-w bit table */
+ f -= a + 1; /* deduct codes from patterns left */
+ xp = c + k;
+ while (++j < z) { /* try smaller tables up to z bits */
+ if ((f <<= 1) <= *++xp)
+ break; /* enough codes to use up j bits */
+ f -= *xp; /* else deduct codes from patterns */
+ }
+ }
+ z = 1 << j; /* table entries for j-bit table */
+
+ /* allocate and link in new table */
+ if ((q = (huft_t *) xmalloc((z + 1) * sizeof(huft_t))) == NULL) {
+ if (h) {
+ huft_free(u[0]);
+ }
+ return 3; /* not enough memory */
+ }
+ hufts += z + 1; /* track memory usage */
+ *t = q + 1; /* link to list for huft_free() */
+ *(t = &(q->v.t)) = NULL;
+ u[h] = ++q; /* table starts after link */
+
+ /* connect to last table, if there is one */
+ if (h) {
+ x[h] = i; /* save pattern for backing up */
+ r.b = (unsigned char) l; /* bits to dump before this table */
+ r.e = (unsigned char) (16 + j); /* bits in this table */
+ r.v.t = q; /* pointer to this table */
+ j = i >> (w - l); /* (get around Turbo C bug) */
+ u[h - 1][j] = r; /* connect to last table */
+ }
+ }
+
+ /* set up table entry in r */
+ r.b = (unsigned char) (k - w);
+ if (p >= v + n)
+ r.e = 99; /* out of values--invalid code */
+ else if (*p < s) {
+ r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is end-of-block code */
+ r.v.n = (unsigned short) (*p); /* simple code is just the value */
+ p++; /* one compiler does not like *p++ */
+ } else {
+ r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
+ r.v.n = d[*p++ - s];
+ }
+
+ /* fill code-like entries with r */
+ f = 1 << (k - w);
+ for (j = i >> w; j < z; j += f)
+ q[j] = r;
+
+ /* backwards increment the k-bit code i */
+ for (j = 1 << (k - 1); i & j; j >>= 1)
+ i ^= j;
+ i ^= j;
+
+ /* backup over finished tables */
+ while ((i & ((1 << w) - 1)) != x[h]) {
+ h--; /* don't need to update q */
+ w -= l;
+ }
+ }
+ }
+ /* Return true (1) if we were given an incomplete table */
+ return y != 0 && g != 1;
+}
+
+/*
+ * inflate (decompress) the codes in a deflated (compressed) block.
+ * Return an error code or zero if it all goes ok.
+ *
+ * tl, td: literal/length and distance decoder tables
+ * bl, bd: number of bits decoded by tl[] and td[]
+ */
+static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd)
+{
+ register unsigned long e; /* table entry flag/number of extra bits */
+ unsigned long n, d; /* length and index for copy */
+ unsigned long w; /* current window position */
+ huft_t *t; /* pointer to table entry */
+ unsigned ml, md; /* masks for bl and bd bits */
+ register unsigned long b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+
+ /* make local copies of globals */
+ b = bb; /* initialize bit buffer */
+ k = bk;
+ w = outcnt; /* initialize window position */
+
+ /* inflate the coded data */
+ ml = mask_bits[bl]; /* precompute masks for speed */
+ md = mask_bits[bd];
+ for (;;) { /* do until end of block */
+ while (k < (unsigned) bl) {
+ b |= ((unsigned long)fgetc(in_file)) << k;
+ k += 8;
+ }
+ if ((e = (t = tl + ((unsigned) b & ml))->e) > 16)
+ do {
+ if (e == 99) {
+ return 1;
+ }
+ b >>= t->b;
+ k -= t->b;
+ e -= 16;
+ while (k < e) {
+ b |= ((unsigned long)fgetc(in_file)) << k;
+ k += 8;
+ }
+ } while ((e = (t = t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16);
+ b >>= t->b;
+ k -= t->b;
+ if (e == 16) { /* then it's a literal */
+ window[w++] = (unsigned char) t->v.n;
+ if (w == WSIZE) {
+ outcnt=(w),
+ flush_window();
+ w = 0;
+ }
+ } else { /* it's an EOB or a length */
+
+ /* exit if end of block */
+ if (e == 15) {
+ break;
+ }
+
+ /* get length of block to copy */
+ while (k < e) {
+ b |= ((unsigned long)fgetc(in_file)) << k;
+ k += 8;
+ }
+ n = t->v.n + ((unsigned) b & mask_bits[e]);
+ b >>= e;
+ k -= e;
+
+ /* decode distance of block to copy */
+ while (k < (unsigned) bd) {
+ b |= ((unsigned long)fgetc(in_file)) << k;
+ k += 8;
+ }
+
+ if ((e = (t = td + ((unsigned) b & md))->e) > 16)
+ do {
+ if (e == 99)
+ return 1;
+ b >>= t->b;
+ k -= t->b;
+ e -= 16;
+ while (k < e) {
+ b |= ((unsigned long)fgetc(in_file)) << k;
+ k += 8;
+ }
+ } while ((e = (t = t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16);
+ b >>= t->b;
+ k -= t->b;
+ while (k < e) {
+ b |= ((unsigned long)fgetc(in_file)) << k;
+ k += 8;
+ }
+ d = w - t->v.n - ((unsigned) b & mask_bits[e]);
+ b >>= e;
+ k -= e;
+
+ /* do the copy */
+ do {
+ n -= (e = (e = WSIZE - ((d &= WSIZE - 1) > w ? d : w)) > n ? n : e);
+#if !defined(NOMEMCPY) && !defined(DEBUG)
+ if (w - d >= e) { /* (this test assumes unsigned comparison) */
+ memcpy(window + w, window + d, e);
+ w += e;
+ d += e;
+ } else /* do it slow to avoid memcpy() overlap */
+#endif /* !NOMEMCPY */
+ do {
+ window[w++] = window[d++];
+ } while (--e);
+ if (w == WSIZE) {
+ outcnt=(w),
+ flush_window();
+ w = 0;
+ }
+ } while (n);
+ }
+ }
+
+ /* restore the globals from the locals */
+ outcnt = w; /* restore global window pointer */
+ bb = b; /* restore global bit buffer */
+ bk = k;
+
+ /* done */
+ return 0;
+}
+
+/*
+ * decompress an inflated block
+ * e: last block flag
+ *
+ * GLOBAL VARIABLES: bb, kk,
+ */
+static int inflate_block(int *e)
+{
+ unsigned t; /* block type */
+ register unsigned long b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+ static unsigned short cplens[] = { /* Copy lengths for literal codes 257..285 */
+ 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
+ };
+ /* note: see note #13 above about the 258 in this list. */
+ static unsigned short cplext[] = { /* Extra bits for literal codes 257..285 */
+ 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 */
+ static unsigned short cpdist[] = { /* Copy offsets for distance codes 0..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
+ };
+ static unsigned short cpdext[] = { /* Extra bits for distance codes */
+ 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
+ };
+
+ /* make local bit buffer */
+ b = bb;
+ k = bk;
+
+ /* read in last block bit */
+ while (k < 1) {
+ b |= ((unsigned long)fgetc(in_file)) << k;
+ k += 8;
+ }
+ *e = (int) b & 1;
+ b >>= 1;
+ k -= 1;
+
+ /* read in block type */
+ while (k < 2) {
+ b |= ((unsigned long)fgetc(in_file)) << k;
+ k += 8;
+ }
+ t = (unsigned) b & 3;
+ b >>= 2;
+ k -= 2;
+
+ /* restore the global bit buffer */
+ bb = b;
+ bk = k;
+
+ /* inflate that block type */
+ switch (t) {
+ case 0: /* Inflate stored */
+ {
+ unsigned long n; /* number of bytes in block */
+ unsigned long w; /* current window position */
+ register unsigned long b_stored; /* bit buffer */
+ register unsigned long k_stored; /* number of bits in bit buffer */
+
+ /* make local copies of globals */
+ b_stored = bb; /* initialize bit buffer */
+ k_stored = bk;
+ w = outcnt; /* initialize window position */
+
+ /* go to byte boundary */
+ n = k_stored & 7;
+ b_stored >>= n;
+ k_stored -= n;
+
+ /* get the length and its complement */
+ while (k_stored < 16) {
+ b_stored |= ((unsigned long)fgetc(in_file)) << k_stored;
+ k_stored += 8;
+ }
+ n = ((unsigned) b_stored & 0xffff);
+ b_stored >>= 16;
+ k_stored -= 16;
+ while (k_stored < 16) {
+ b_stored |= ((unsigned long)fgetc(in_file)) << k_stored;
+ k_stored += 8;
+ }
+ if (n != (unsigned) ((~b_stored) & 0xffff)) {
+ return 1; /* error in compressed data */
+ }
+ b_stored >>= 16;
+ k_stored -= 16;
+
+ /* read and output the compressed data */
+ while (n--) {
+ while (k_stored < 8) {
+ b_stored |= ((unsigned long)fgetc(in_file)) << k_stored;
+ k_stored += 8;
+ }
+ window[w++] = (unsigned char) b_stored;
+ if (w == (unsigned long)WSIZE) {
+ outcnt=(w),
+ flush_window();
+ w = 0;
+ }
+ b_stored >>= 8;
+ k_stored -= 8;
+ }
+
+ /* restore the globals from the locals */
+ outcnt = w; /* restore global window pointer */
+ bb = b_stored; /* restore global bit buffer */
+ bk = k_stored;
+ return 0;
+ }
+ case 1: /* Inflate fixed
+ * decompress an inflated type 1 (fixed Huffman codes) block. We should
+ * either replace this with a custom decoder, or at least precompute the
+ * Huffman tables.
+ */
+ {
+ int i; /* temporary variable */
+ huft_t *tl; /* literal/length code table */
+ huft_t *td; /* distance code table */
+ int bl; /* lookup bits for tl */
+ int bd; /* lookup bits for td */
+ unsigned int l[288]; /* length list for huft_build */
+
+ /* set up literal table */
+ for (i = 0; i < 144; i++) {
+ l[i] = 8;
+ }
+ for (; i < 256; i++) {
+ l[i] = 9;
+ }
+ for (; i < 280; i++) {
+ l[i] = 7;
+ }
+ for (; i < 288; i++) { /* make a complete, but wrong code set */
+ l[i] = 8;
+ }
+ bl = 7;
+ if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0) {
+ return i;
+ }
+
+ /* set up distance table */
+ for (i = 0; i < 30; i++) { /* make an incomplete code set */
+ l[i] = 5;
+ }
+ bd = 5;
+ if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) {
+ huft_free(tl);
+ return i;
+ }
+
+ /* decompress until an end-of-block code */
+ if (inflate_codes(tl, td, bl, bd))
+ return 1;
+
+ /* free the decoding tables, return */
+ huft_free(tl);
+ huft_free(td);
+ return 0;
+ }
+ case 2: /* Inflate dynamic */
+ {
+ /* Tables for deflate from PKZIP's appnote.txt. */
+ static unsigned border[] = { /* Order of the bit length code lengths */
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+ };
+ int dbits = 6; /* bits in base distance lookup table */
+ int lbits = 9; /* bits in base literal/length lookup table */
+
+ int i; /* temporary variables */
+ unsigned j;
+ unsigned l; /* last length */
+ unsigned m; /* mask for bit lengths table */
+ unsigned n; /* number of lengths to get */
+ huft_t *tl; /* literal/length code table */
+ huft_t *td; /* distance code table */
+ int bl; /* lookup bits for tl */
+ int bd; /* lookup bits for td */
+ unsigned nb; /* number of bit length codes */
+ unsigned nl; /* number of literal/length codes */
+ unsigned nd; /* number of distance codes */
+
+ unsigned ll[286 + 30]; /* literal/length and distance code lengths */
+ register unsigned long b_dynamic; /* bit buffer */
+ register unsigned k_dynamic; /* number of bits in bit buffer */
+
+ /* make local bit buffer */
+ b_dynamic = bb;
+ k_dynamic = bk;
+
+ /* read in table lengths */
+ while (k_dynamic < 5) {
+ b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic;
+ k_dynamic += 8;
+ }
+ nl = 257 + ((unsigned) b_dynamic & 0x1f); /* number of literal/length codes */
+ b_dynamic >>= 5;
+ k_dynamic -= 5;
+ while (k_dynamic < 5) {
+ b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic;
+ k_dynamic += 8;
+ }
+ nd = 1 + ((unsigned) b_dynamic & 0x1f); /* number of distance codes */
+ b_dynamic >>= 5;
+ k_dynamic -= 5;
+ while (k_dynamic < 4) {
+ b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic;
+ k_dynamic += 8;
+ }
+ nb = 4 + ((unsigned) b_dynamic & 0xf); /* number of bit length codes */
+ b_dynamic >>= 4;
+ k_dynamic -= 4;
+ if (nl > 286 || nd > 30) {
+ return 1; /* bad lengths */
+ }
+
+ /* read in bit-length-code lengths */
+ for (j = 0; j < nb; j++) {
+ while (k_dynamic < 3) {
+ b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic;
+ k_dynamic += 8;
+ }
+ ll[border[j]] = (unsigned) b_dynamic & 7;
+ b_dynamic >>= 3;
+ k_dynamic -= 3;
+ }
+ for (; j < 19; j++) {
+ ll[border[j]] = 0;
+ }
+
+ /* build decoding table for trees--single level, 7 bit lookup */
+ bl = 7;
+ if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) {
+ if (i == 1) {
+ huft_free(tl);
+ }
+ return i; /* incomplete code set */
+ }
+
+ /* read in literal and distance code lengths */
+ n = nl + nd;
+ m = mask_bits[bl];
+ i = l = 0;
+ while ((unsigned) i < n) {
+ while (k_dynamic < (unsigned) bl) {
+ b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic;
+ k_dynamic += 8;
+ }
+ j = (td = tl + ((unsigned) b_dynamic & m))->b;
+ b_dynamic >>= j;
+ k_dynamic -= j;
+ j = td->v.n;
+ if (j < 16) { /* length of code in bits (0..15) */
+ ll[i++] = l = j; /* save last length in l */
+ }
+ else if (j == 16) { /* repeat last length 3 to 6 times */
+ while (k_dynamic < 2) {
+ b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic;
+ k_dynamic += 8;
+ }
+ j = 3 + ((unsigned) b_dynamic & 3);
+ b_dynamic >>= 2;
+ k_dynamic -= 2;
+ if ((unsigned) i + j > n) {
+ return 1;
+ }
+ while (j--) {
+ ll[i++] = l;
+ }
+ } else if (j == 17) { /* 3 to 10 zero length codes */
+ while (k_dynamic < 3) {
+ b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic;
+ k_dynamic += 8;
+ }
+ j = 3 + ((unsigned) b_dynamic & 7);
+ b_dynamic >>= 3;
+ k_dynamic -= 3;
+ if ((unsigned) i + j > n) {
+ return 1;
+ }
+ while (j--) {
+ ll[i++] = 0;
+ }
+ l = 0;
+ } else { /* j == 18: 11 to 138 zero length codes */
+ while (k_dynamic < 7) {
+ b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic;
+ k_dynamic += 8;
+ }
+ j = 11 + ((unsigned) b_dynamic & 0x7f);
+ b_dynamic >>= 7;
+ k_dynamic -= 7;
+ if ((unsigned) i + j > n) {
+ return 1;
+ }
+ while (j--) {
+ ll[i++] = 0;
+ }
+ l = 0;
+ }
+ }
+
+ /* free decoding table for trees */
+ huft_free(tl);
+
+ /* restore the global bit buffer */
+ bb = b_dynamic;
+ bk = k_dynamic;
+
+ /* build the decoding tables for literal/length and distance codes */
+ bl = lbits;
+ if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) {
+ if (i == 1) {
+ error_msg("Incomplete literal tree");
+ huft_free(tl);
+ }
+ return i; /* incomplete code set */
+ }
+ bd = dbits;
+ if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) {
+ if (i == 1) {
+ error_msg("incomplete distance tree");
+ huft_free(td);
+ }
+ huft_free(tl);
+ return i; /* incomplete code set */
+ }
+
+ /* decompress until an end-of-block code */
+ if (inflate_codes(tl, td, bl, bd))
+ return 1;
+
+ /* free the decoding tables, return */
+ huft_free(tl);
+ huft_free(td);
+ return 0;
+ }
+ default:
+ /* bad block type */
+ return 2;
+ }
+}
+
+/*
+ * decompress an inflated entry
+ *
+ * GLOBAL VARIABLES: outcnt, bk, bb, hufts, inptr
+ */
+static int inflate()
+{
+ int e; /* last block flag */
+ int r; /* result code */
+ unsigned h = 0; /* maximum struct huft's malloc'ed */
+
+ /* initialize window, bit buffer */
+ outcnt = 0;
+ bk = 0;
+ bb = 0;
+
+ /* decompress until the last block */
+ do {
+ hufts = 0;
+ if ((r = inflate_block(&e)) != 0) {
+ return r;
+ }
+ if (hufts > h) {
+ h = hufts;
+ }
+ } while (!e);
+
+ /* Undo too much lookahead. The next read will be byte aligned so we
+ * can discard unused bits in the last meaningful byte. */
+ while (bk >= 8) {
+ bk -= 8;
+ ungetc((bb << bk), in_file);
+ }
+
+ /* flush out window */
+ flush_window();
+
+ /* return success */
+ return 0;
+}
+
+/* ===========================================================================
+ * Unzip in to out. This routine works on both gzip and pkzip files.
+ *
+ * IN assertions: the buffer inbuf contains already the beginning of
+ * the compressed data, from offsets inptr to insize-1 included.
+ * The magic header has already been checked. The output buffer is cleared.
+ * in, out: input and output file descriptors
+ */
+extern int unzip(FILE *l_in_file, FILE *l_out_file)
+{
+ const int extra_field = 0x04; /* bit 2 set: extra field present */
+ const int orig_name = 0x08; /* bit 3 set: original file name present */
+ const int comment = 0x10; /* bit 4 set: file comment present */
+ unsigned char buf[8]; /* extended local header */
+ unsigned char flags; /* compression flags */
+ char magic[2]; /* magic header */
+ int method;
+ typedef void (*sig_type) (int);
+ int exit_code=0; /* program exit code */
+ int i;
+
+ in_file = l_in_file;
+ out_file = l_out_file;
+
+ if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
+ (void) signal(SIGINT, (sig_type) abort_gzip);
+ }
+#ifdef SIGTERM
+// if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
+// (void) signal(SIGTERM, (sig_type) abort_gzip);
+// }
+#endif
+#ifdef SIGHUP
+ if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
+ (void) signal(SIGHUP, (sig_type) abort_gzip);
+ }
+#endif
+
+ /* Allocate all global buffers (for DYN_ALLOC option) */
+ window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(unsigned char)));
+ outcnt = 0;
+ bytes_out = 0L;
+
+ magic[0] = fgetc(in_file);
+ magic[1] = fgetc(in_file);
+
+ /* Magic header for gzip files, 1F 8B = \037\213 */
+ if (memcmp(magic, "\037\213", 2) != 0) {
+ error_msg("Invalid gzip magic");
+ return EXIT_FAILURE;
+ }
+
+ method = (int) fgetc(in_file);
+ if (method != 8) {
+ error_msg("unknown method %d -- get newer version of gzip", method);
+ exit_code = 1;
+ return -1;
+ }
+
+ flags = (unsigned char) fgetc(in_file);
+
+ /* Ignore time stamp(4), extra flags(1), OS type(1) */
+ for (i = 0; i < 6; i++)
+ fgetc(in_file);
+
+ if ((flags & extra_field) != 0) {
+ size_t extra;
+ extra = fgetc(in_file);
+ extra += fgetc(in_file) << 8;
+
+ for (i = 0; i < extra; i++)
+ fgetc(in_file);
+ }
+
+ /* Discard original name if any */
+ if ((flags & orig_name) != 0) {
+ while (fgetc(in_file) != 0); /* null */
+ }
+
+ /* Discard file comment if any */
+ if ((flags & comment) != 0) {
+ while (fgetc(in_file) != 0); /* null */
+ }
+
+ if (method < 0) {
+ printf("it failed\n");
+ return(exit_code); /* error message already emitted */
+ }
+
+ make_crc_table();
+
+ /* Decompress */
+ if (method == 8) {
+
+ int res = inflate();
+
+ if (res == 3) {
+ error_msg(memory_exhausted);
+ exit_code = 1;
+ } else if (res != 0) {
+ error_msg("invalid compressed data--format violated");
+ exit_code = 1;
+ }
+
+ } else {
+ error_msg("internal error, invalid method");
+ exit_code = 1;
+ }
+
+ /* Get the crc and original length
+ * crc32 (see algorithm.doc)
+ * uncompressed input size modulo 2^32
+ */
+ fread(buf, 1, 8, in_file);
+
+ /* Validate decompression - crc */
+ if (!exit_code && (unsigned int)((buf[0] | (buf[1] << 8)) |((buf[2] | (buf[3] << 8)) << 16)) != (crc ^ 0xffffffffL)) {
+ error_msg("invalid compressed data--crc error");
+ exit_code = 1;
+ }
+ /* Validate decompression - size */
+ if (!exit_code && ((buf[4] | (buf[5] << 8)) |((buf[6] | (buf[7] << 8)) << 16)) != (unsigned long) bytes_out) {
+ error_msg("invalid compressed data--length error");
+ exit_code = 1;
+ }
+
+ free(window);
+ free(crc_table);
+
+ return exit_code;
+}
+
+/*
+ * This needs access to global variables wondow and crc_table, so its not in its own file.
+ */
+extern void gz_close(int gunzip_pid)
+{
+ if (kill(gunzip_pid, SIGTERM) == -1) {
+ error_msg_and_die("*** Couldnt kill old gunzip process *** aborting");
+ }
+
+ if (waitpid(gunzip_pid, NULL, 0) == -1) {
+ printf("Couldnt wait ?");
+ }
+ free(window);
+ free(crc_table);
+}
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
new file mode 100644
index 0000000..21cde20
--- /dev/null
+++ b/libbb/verror_msg.c
@@ -0,0 +1,43 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void verror_msg(const char *s, va_list p)
+{
+ fflush(stdout);
+ fprintf(stderr, "%s: ", applet_name);
+ vfprintf(stderr, s, p);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/vperror_msg.c b/libbb/vperror_msg.c
new file mode 100644
index 0000000..7da5bae
--- /dev/null
+++ b/libbb/vperror_msg.c
@@ -0,0 +1,45 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void vperror_msg(const char *s, va_list p)
+{
+ int err=errno;
+ if(s == 0) s = "";
+ verror_msg(s, p);
+ if (*s) s = ": ";
+ fprintf(stderr, "%s%s\n", s, strerror(err));
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/wfopen.c b/libbb/wfopen.c
new file mode 100644
index 0000000..f58ec90
--- /dev/null
+++ b/libbb/wfopen.c
@@ -0,0 +1,44 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include "libbb.h"
+
+FILE *wfopen(const char *path, const char *mode)
+{
+ FILE *fp;
+ if ((fp = fopen(path, mode)) == NULL) {
+ perror_msg("%s", path);
+ errno = 0;
+ }
+ return fp;
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
new file mode 100644
index 0000000..ee90e60
--- /dev/null
+++ b/libbb/xfuncs.c
@@ -0,0 +1,102 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "libbb.h"
+
+
+#ifndef DMALLOC
+extern void *xmalloc(size_t size)
+{
+ void *ptr = malloc(size);
+ if (ptr == NULL && size != 0)
+ error_msg_and_die(memory_exhausted);
+ return ptr;
+}
+
+extern void *xrealloc(void *ptr, size_t size)
+{
+ ptr = realloc(ptr, size);
+ if (ptr == NULL && size != 0)
+ error_msg_and_die(memory_exhausted);
+ return ptr;
+}
+
+extern void *xcalloc(size_t nmemb, size_t size)
+{
+ void *ptr = calloc(nmemb, size);
+ if (ptr == NULL && nmemb != 0 && size != 0)
+ error_msg_and_die(memory_exhausted);
+ return ptr;
+}
+
+extern char * xstrdup (const char *s) {
+ char *t;
+
+ if (s == NULL)
+ return NULL;
+
+ t = strdup (s);
+
+ if (t == NULL)
+ error_msg_and_die(memory_exhausted);
+
+ return t;
+}
+#endif
+
+extern char * xstrndup (const char *s, int n) {
+ char *t;
+
+ if (s == NULL)
+ error_msg_and_die("xstrndup bug");
+
+ t = xmalloc(++n);
+
+ return safe_strncpy(t,s,n);
+}
+
+FILE *xfopen(const char *path, const char *mode)
+{
+ FILE *fp;
+ if ((fp = fopen(path, mode)) == NULL)
+ perror_msg_and_die("%s", path);
+ return fp;
+}
+
+/* Stupid gcc always includes its own builtin strlen()... */
+#undef strlen
+size_t xstrlen(const char *string)
+{
+ return(strlen(string));
+}
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
new file mode 100644
index 0000000..932e487
--- /dev/null
+++ b/libbb/xreadlink.c
@@ -0,0 +1,37 @@
+/*
+ * xreadlink.c - safe implementation of readlink.
+ * Returns a NULL on failure...
+ */
+
+#include <stdio.h>
+
+/*
+ * NOTE: This function returns a malloced char* that you will have to free
+ * yourself. You have been warned.
+ */
+
+#include <unistd.h>
+#include "libbb.h"
+
+extern char *xreadlink(const char *path)
+{
+ static const int GROWBY = 80; /* how large we will grow strings by */
+
+ char *buf = NULL;
+ int bufsize = 0, readsize = 0;
+
+ do {
+ buf = xrealloc(buf, bufsize += GROWBY);
+ readsize = readlink(path, buf, bufsize); /* 1st try */
+ if (readsize == -1) {
+ perror_msg("%s:%s", applet_name, path);
+ return NULL;
+ }
+ }
+ while (bufsize < readsize + 1);
+
+ buf[readsize] = '\0';
+
+ return buf;
+}
+