From 9d7518c2cb43f1fb1eb54495899945523fd5dc99 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sun, 25 Feb 2018 13:53:05 +0000 Subject: toolbox: add OpenADK toolbox for very small systems, thx Thorsten Glaser --- package/toolbox/Makefile | 24 + package/toolbox/src/Makefile | 516 +++++++++++++ package/toolbox/src/cat/Makefile | 5 + package/toolbox/src/cat/cat.c | 163 ++++ package/toolbox/src/chmod/Makefile | 3 + package/toolbox/src/chown/Makefile | 3 + package/toolbox/src/clear/Makefile | 3 + package/toolbox/src/cmp/Makefile | 3 + package/toolbox/src/common.mk | 21 + package/toolbox/src/cp/Makefile | 4 + package/toolbox/src/cp/cp.c | 549 ++++++++++++++ package/toolbox/src/cp/extern.h | 63 ++ package/toolbox/src/cp/utils.c | 441 +++++++++++ package/toolbox/src/date/Makefile | 5 + package/toolbox/src/date/date.c | 272 +++++++ package/toolbox/src/dd/Makefile | 4 + package/toolbox/src/df/Makefile | 3 + package/toolbox/src/dmesg/Makefile | 3 + package/toolbox/src/du/Makefile | 3 + package/toolbox/src/exists/Makefile | 3 + package/toolbox/src/grep/Makefile | 4 + package/toolbox/src/grep/fastgrep.c | 336 +++++++++ package/toolbox/src/grep/file.c | 215 ++++++ package/toolbox/src/grep/grep.c | 695 +++++++++++++++++ package/toolbox/src/grep/grep.h | 149 ++++ package/toolbox/src/grep/queue.c | 116 +++ package/toolbox/src/grep/util.c | 499 +++++++++++++ package/toolbox/src/hd/Makefile | 3 + package/toolbox/src/id/Makefile | 3 + package/toolbox/src/ifconfig/Makefile | 3 + package/toolbox/src/iftop/Makefile | 3 + package/toolbox/src/insmod/Makefile | 3 + package/toolbox/src/ioctl/Makefile | 3 + package/toolbox/src/kill/Makefile | 3 + package/toolbox/src/lib/Makefile | 24 + package/toolbox/src/lib/fgetln.c | 48 ++ package/toolbox/src/lib/md5.c | 242 ++++++ package/toolbox/src/lib/md5.h | 48 ++ package/toolbox/src/lib/md5hlp.c | 13 + package/toolbox/src/lib/string.h | 9 + package/toolbox/src/lib/strlfun.c | 185 +++++ package/toolbox/src/ln/Makefile | 3 + package/toolbox/src/ls/Makefile | 4 + package/toolbox/src/lsof/Makefile | 3 + package/toolbox/src/md5/Makefile | 3 + package/toolbox/src/mkdir/Makefile | 3 + package/toolbox/src/mknod/Makefile | 6 + package/toolbox/src/mknod/mknod.c | 190 +++++ package/toolbox/src/mknod/setmode.c | 462 ++++++++++++ package/toolbox/src/mount/Makefile | 3 + package/toolbox/src/mv/Makefile | 3 + package/toolbox/src/netstat/Makefile | 3 + package/toolbox/src/notify/Makefile | 3 + package/toolbox/src/printenv/Makefile | 3 + package/toolbox/src/ps/Makefile | 3 + package/toolbox/src/readlink/Makefile | 3 + package/toolbox/src/renice/Makefile | 3 + package/toolbox/src/rm/Makefile | 3 + package/toolbox/src/rmdir/Makefile | 3 + package/toolbox/src/rmmod/Makefile | 3 + package/toolbox/src/route/Makefile | 3 + package/toolbox/src/schedtop/Makefile | 3 + package/toolbox/src/sed/Makefile | 6 + package/toolbox/src/sed/compile.c | 870 ++++++++++++++++++++++ package/toolbox/src/sed/defs.h | 147 ++++ package/toolbox/src/sed/extern.h | 65 ++ package/toolbox/src/sed/main.c | 523 +++++++++++++ package/toolbox/src/sed/misc.c | 166 +++++ package/toolbox/src/sed/process.c | 642 ++++++++++++++++ package/toolbox/src/setkey/Makefile | 3 + package/toolbox/src/sleep/Makefile | 3 + package/toolbox/src/src/chmod.c | 101 +++ package/toolbox/src/src/chown.c | 73 ++ package/toolbox/src/src/clear.c | 41 + package/toolbox/src/src/cmp.c | 91 +++ package/toolbox/src/src/dd.c | 1323 +++++++++++++++++++++++++++++++++ package/toolbox/src/src/dd.h | 94 +++ package/toolbox/src/src/df.c | 85 +++ package/toolbox/src/src/dmesg.c | 64 ++ package/toolbox/src/src/du.c | 322 ++++++++ package/toolbox/src/src/dynarray.c | 104 +++ package/toolbox/src/src/dynarray.h | 80 ++ package/toolbox/src/src/exists.c | 16 + package/toolbox/src/src/hd.c | 97 +++ package/toolbox/src/src/id.c | 51 ++ package/toolbox/src/src/ifconfig.c | 164 ++++ package/toolbox/src/src/iftop.c | 278 +++++++ package/toolbox/src/src/insmod.c | 97 +++ package/toolbox/src/src/ioctl.c | 124 +++ package/toolbox/src/src/kill.c | 149 ++++ package/toolbox/src/src/ln.c | 34 + package/toolbox/src/src/ls.c | 424 +++++++++++ package/toolbox/src/src/lsof.c | 253 +++++++ package/toolbox/src/src/md5.c | 75 ++ package/toolbox/src/src/mkdir.c | 77 ++ package/toolbox/src/src/mount.c | 360 +++++++++ package/toolbox/src/src/mv.c | 59 ++ package/toolbox/src/src/netstat.c | 155 ++++ package/toolbox/src/src/notify.c | 145 ++++ package/toolbox/src/src/printenv.c | 33 + package/toolbox/src/src/ps.c | 244 ++++++ package/toolbox/src/src/readlink.c | 95 +++ package/toolbox/src/src/renice.c | 161 ++++ package/toolbox/src/src/rm.c | 126 ++++ package/toolbox/src/src/rmdir.c | 28 + package/toolbox/src/src/rmmod.c | 53 ++ package/toolbox/src/src/route.c | 113 +++ package/toolbox/src/src/schedtop.c | 332 +++++++++ package/toolbox/src/src/setkey.c | 91 +++ package/toolbox/src/src/sleep.c | 64 ++ package/toolbox/src/src/sync.c | 7 + package/toolbox/src/src/top.c | 542 ++++++++++++++ package/toolbox/src/src/touch.c | 115 +++ package/toolbox/src/src/umount.c | 91 +++ package/toolbox/src/src/vmstat.c | 248 ++++++ package/toolbox/src/sync/Makefile | 3 + package/toolbox/src/tool.mk | 22 + package/toolbox/src/top/Makefile | 3 + package/toolbox/src/touch/Makefile | 3 + package/toolbox/src/umount/Makefile | 3 + package/toolbox/src/vmstat/Makefile | 3 + 121 files changed, 15149 insertions(+) create mode 100644 package/toolbox/Makefile create mode 100644 package/toolbox/src/Makefile create mode 100644 package/toolbox/src/cat/Makefile create mode 100644 package/toolbox/src/cat/cat.c create mode 100644 package/toolbox/src/chmod/Makefile create mode 100644 package/toolbox/src/chown/Makefile create mode 100644 package/toolbox/src/clear/Makefile create mode 100644 package/toolbox/src/cmp/Makefile create mode 100644 package/toolbox/src/common.mk create mode 100644 package/toolbox/src/cp/Makefile create mode 100644 package/toolbox/src/cp/cp.c create mode 100644 package/toolbox/src/cp/extern.h create mode 100644 package/toolbox/src/cp/utils.c create mode 100644 package/toolbox/src/date/Makefile create mode 100644 package/toolbox/src/date/date.c create mode 100644 package/toolbox/src/dd/Makefile create mode 100644 package/toolbox/src/df/Makefile create mode 100644 package/toolbox/src/dmesg/Makefile create mode 100644 package/toolbox/src/du/Makefile create mode 100644 package/toolbox/src/exists/Makefile create mode 100644 package/toolbox/src/grep/Makefile create mode 100644 package/toolbox/src/grep/fastgrep.c create mode 100644 package/toolbox/src/grep/file.c create mode 100644 package/toolbox/src/grep/grep.c create mode 100644 package/toolbox/src/grep/grep.h create mode 100644 package/toolbox/src/grep/queue.c create mode 100644 package/toolbox/src/grep/util.c create mode 100644 package/toolbox/src/hd/Makefile create mode 100644 package/toolbox/src/id/Makefile create mode 100644 package/toolbox/src/ifconfig/Makefile create mode 100644 package/toolbox/src/iftop/Makefile create mode 100644 package/toolbox/src/insmod/Makefile create mode 100644 package/toolbox/src/ioctl/Makefile create mode 100644 package/toolbox/src/kill/Makefile create mode 100644 package/toolbox/src/lib/Makefile create mode 100644 package/toolbox/src/lib/fgetln.c create mode 100644 package/toolbox/src/lib/md5.c create mode 100644 package/toolbox/src/lib/md5.h create mode 100644 package/toolbox/src/lib/md5hlp.c create mode 100644 package/toolbox/src/lib/string.h create mode 100644 package/toolbox/src/lib/strlfun.c create mode 100644 package/toolbox/src/ln/Makefile create mode 100644 package/toolbox/src/ls/Makefile create mode 100644 package/toolbox/src/lsof/Makefile create mode 100644 package/toolbox/src/md5/Makefile create mode 100644 package/toolbox/src/mkdir/Makefile create mode 100644 package/toolbox/src/mknod/Makefile create mode 100644 package/toolbox/src/mknod/mknod.c create mode 100644 package/toolbox/src/mknod/setmode.c create mode 100644 package/toolbox/src/mount/Makefile create mode 100644 package/toolbox/src/mv/Makefile create mode 100644 package/toolbox/src/netstat/Makefile create mode 100644 package/toolbox/src/notify/Makefile create mode 100644 package/toolbox/src/printenv/Makefile create mode 100644 package/toolbox/src/ps/Makefile create mode 100644 package/toolbox/src/readlink/Makefile create mode 100644 package/toolbox/src/renice/Makefile create mode 100644 package/toolbox/src/rm/Makefile create mode 100644 package/toolbox/src/rmdir/Makefile create mode 100644 package/toolbox/src/rmmod/Makefile create mode 100644 package/toolbox/src/route/Makefile create mode 100644 package/toolbox/src/schedtop/Makefile create mode 100644 package/toolbox/src/sed/Makefile create mode 100644 package/toolbox/src/sed/compile.c create mode 100644 package/toolbox/src/sed/defs.h create mode 100644 package/toolbox/src/sed/extern.h create mode 100644 package/toolbox/src/sed/main.c create mode 100644 package/toolbox/src/sed/misc.c create mode 100644 package/toolbox/src/sed/process.c create mode 100644 package/toolbox/src/setkey/Makefile create mode 100644 package/toolbox/src/sleep/Makefile create mode 100644 package/toolbox/src/src/chmod.c create mode 100644 package/toolbox/src/src/chown.c create mode 100644 package/toolbox/src/src/clear.c create mode 100644 package/toolbox/src/src/cmp.c create mode 100644 package/toolbox/src/src/dd.c create mode 100644 package/toolbox/src/src/dd.h create mode 100644 package/toolbox/src/src/df.c create mode 100644 package/toolbox/src/src/dmesg.c create mode 100644 package/toolbox/src/src/du.c create mode 100644 package/toolbox/src/src/dynarray.c create mode 100644 package/toolbox/src/src/dynarray.h create mode 100644 package/toolbox/src/src/exists.c create mode 100644 package/toolbox/src/src/hd.c create mode 100644 package/toolbox/src/src/id.c create mode 100644 package/toolbox/src/src/ifconfig.c create mode 100644 package/toolbox/src/src/iftop.c create mode 100644 package/toolbox/src/src/insmod.c create mode 100644 package/toolbox/src/src/ioctl.c create mode 100644 package/toolbox/src/src/kill.c create mode 100644 package/toolbox/src/src/ln.c create mode 100644 package/toolbox/src/src/ls.c create mode 100644 package/toolbox/src/src/lsof.c create mode 100644 package/toolbox/src/src/md5.c create mode 100644 package/toolbox/src/src/mkdir.c create mode 100644 package/toolbox/src/src/mount.c create mode 100644 package/toolbox/src/src/mv.c create mode 100644 package/toolbox/src/src/netstat.c create mode 100644 package/toolbox/src/src/notify.c create mode 100644 package/toolbox/src/src/printenv.c create mode 100644 package/toolbox/src/src/ps.c create mode 100644 package/toolbox/src/src/readlink.c create mode 100644 package/toolbox/src/src/renice.c create mode 100644 package/toolbox/src/src/rm.c create mode 100644 package/toolbox/src/src/rmdir.c create mode 100644 package/toolbox/src/src/rmmod.c create mode 100644 package/toolbox/src/src/route.c create mode 100644 package/toolbox/src/src/schedtop.c create mode 100644 package/toolbox/src/src/setkey.c create mode 100644 package/toolbox/src/src/sleep.c create mode 100644 package/toolbox/src/src/sync.c create mode 100644 package/toolbox/src/src/top.c create mode 100644 package/toolbox/src/src/touch.c create mode 100644 package/toolbox/src/src/umount.c create mode 100644 package/toolbox/src/src/vmstat.c create mode 100644 package/toolbox/src/sync/Makefile create mode 100644 package/toolbox/src/tool.mk create mode 100644 package/toolbox/src/top/Makefile create mode 100644 package/toolbox/src/touch/Makefile create mode 100644 package/toolbox/src/umount/Makefile create mode 100644 package/toolbox/src/vmstat/Makefile (limited to 'package/toolbox') diff --git a/package/toolbox/Makefile b/package/toolbox/Makefile new file mode 100644 index 000000000..af658336a --- /dev/null +++ b/package/toolbox/Makefile @@ -0,0 +1,24 @@ +# This file is part of the OpenADK project. OpenADK is copyrighted +# material, please see the LICENCE file in the top-level directory. + +include ${ADK_TOPDIR}/rules.mk + +PKG_NAME:= toolbox +PKG_VERSION:= 1.0 +PKG_RELEASE:= 1 +PKG_DESCR:= openadk toolbox for very small systems +PKG_SECTION:= base/apps + +NO_DISTFILES:= 1 + +include ${ADK_TOPDIR}/mk/package.mk + +$(eval $(call PKG_template,TOOLBOX,toolbox,${PKG_VERSION}-${PKG_RELEASE},${PKG_DEPENDS},${PKG_DESCR},${PKG_SECTION})) + +CONFIG_STYLE:= manual + +toolbox-install: + $(INSTALL_DIR) $(IDIR_TOOLBOX)/bin + $(CP) $(WRKINST)/bin/* $(IDIR_TOOLBOX)/bin + +include ${ADK_TOPDIR}/mk/pkg-bottom.mk diff --git a/package/toolbox/src/Makefile b/package/toolbox/src/Makefile new file mode 100644 index 000000000..50afea707 --- /dev/null +++ b/package/toolbox/src/Makefile @@ -0,0 +1,516 @@ +# toolbox for OpenADK on memory-constrained NOMMU binfmt_flat systems +# Copyright © 2017 +# mirabilos +# Derived from Android Toolbox +# platform/system/core, as of commit efbf36f2dad8f083de6f48dbb682461d7cfa9781 +# +# Provided that these terms and disclaimer and all copyright notices +# are retained or reproduced in an accompanying document, permission +# is granted to deal in this work without restriction, including un‐ +# limited rights to use, publicly perform, distribute, sell, modify, +# merge, give away, or sublicence. +# +# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to +# the utmost extent permitted by applicable law, neither express nor +# implied; without malicious intent or gross negligence. In no event +# may a licensor, author or contributor be held liable for indirect, +# direct, other damage, loss, or other issues arising in any way out +# of dealing in the work, even if advised of the possibility of such +# damage or existence of a defect, except proven that it results out +# of said person’s immediate fault when using the work as intended. +# +# Individual files are covered by their own licence notices, which are +# also reproduced below (at the end of the top-level Makefile, this file). +# Changes to those files done within the OpenADK toolbox and the build +# system of the toolbox are published under Ⓕ The MirOS Licence as above. +# +# Summarising the licences used: +# • 3-clause BSD +# • ISC (OpenBSD) +# • MirOS +# • Public Domain + + SUBDIR+= lib + + SUBDIR+= cat + SUBDIR+= chmod + SUBDIR+= chown + SUBDIR+= clear + SUBDIR+= cmp + SUBDIR+= cp + SUBDIR+= date + SUBDIR+= dd + SUBDIR+= df + SUBDIR+= dmesg + SUBDIR+= du + SUBDIR+= exists + SUBDIR+= grep + SUBDIR+= hd + SUBDIR+= id + SUBDIR+= ifconfig + SUBDIR+= iftop + SUBDIR+= insmod +# SUBDIR+= ioctl needs pthread.h + SUBDIR+= kill + SUBDIR+= ln + SUBDIR+= ls + SUBDIR+= lsof + SUBDIR+= md5 + SUBDIR+= mkdir + SUBDIR+= mknod + SUBDIR+= mount + SUBDIR+= mv + SUBDIR+= netstat + SUBDIR+= notify + SUBDIR+= printenv + SUBDIR+= ps + SUBDIR+= readlink + SUBDIR+= renice + SUBDIR+= rm + SUBDIR+= rmdir + SUBDIR+= rmmod + SUBDIR+= route + SUBDIR+= schedtop + SUBDIR+= sed + SUBDIR+= setkey + SUBDIR+= sleep + SUBDIR+= sync + SUBDIR+= top + SUBDIR+= touch + SUBDIR+= umount + SUBDIR+= vmstat + +%: + @for subdir in ${SUBDIR}; do \ + echo "==> $$subdir"; \ + ${MAKE} --no-print-directory -I.. \ + -C "$$subdir" $@ || exit $?; \ + echo "<== $$subdir"; \ + done + +all: + +#====================================== +# Now follows the original NOTICE file: +#====================================== + +# Copyright (c) 2010, The Android Open Source Project. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of The Android Open Source Project nor the names +# of its contributors may be used to endorse or promote products +# derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# Copyright (c) 2009, The Android Open Source Project. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of The Android Open Source Project nor the names +# of its contributors may be used to endorse or promote products +# derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# Copyright (c) 2008, The Android Open Source Project. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of The Android Open Source Project nor the names +# of its contributors may be used to endorse or promote products +# derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# Copyright (c) 1998 Robert Nordier +# Copyright (c) 1989, 1993 +# The Regents of the University of California. All rights reserved. +# +# This code is derived from software contributed to Berkeley by +# Kevin Fall. +# This code is derived from software contributed to Berkeley by +# Keith Muller of the University of California, San Diego and Lance +# Visser of Convex Computer Corporation. +# This code is derived from software contributed to Berkeley by +# Mike Muuss. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# Copyright (c) 1989, 1993 +# The Regents of the University of California. All rights reserved. +# +# This code is derived from software contributed to Berkeley by +# Kevin Fall. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# Copyright (c) 1991, 1993, 1994 +# The Regents of the University of California. All rights reserved. +# +# This code is derived from software contributed to Berkeley by +# Keith Muller of the University of California, San Diego and Lance +# Visser of Convex Computer Corporation. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# /* +# * Copyright (c) 1985, 1987, 1988, 1993 +# * The Regents of the University of California. All rights reserved. +# * +# * Redistribution and use in source and binary forms, with or without +# * modification, are permitted provided that the following conditions +# * are met: +# * 1. Redistributions of source code must retain the above copyright +# * notice, this list of conditions and the following disclaimer. +# * 2. Redistributions in binary form must reproduce the above copyright +# * notice, this list of conditions and the following disclaimer in the +# * documentation and/or other materials provided with the distribution. +# * 3. Neither the name of the University nor the names of its contributors +# * may be used to endorse or promote products derived from this software +# * without specific prior written permission. +# * +# * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# * SUCH DAMAGE. +# */ +# +# /*- +# * Copyright (c) 2007, 2009 +# * Thorsten Glaser +# * +# * Provided that these terms and disclaimer and all copyright notices +# * are retained or reproduced in an accompanying document, permission +# * is granted to deal in this work without restriction, including un- +# * limited rights to use, publicly perform, distribute, sell, modify, +# * merge, give away, or sublicence. +# * +# * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to +# * the utmost extent permitted by applicable law, neither express nor +# * implied; without malicious intent or gross negligence. In no event +# * may a licensor, author or contributor be held liable for indirect, +# * direct, other damage, loss, or other issues arising in any way out +# * of dealing in the work, even if advised of the possibility of such +# * damage or existence of a defect, except proven that it results out +# * of said person's immediate fault when using the work as intended. +# */ +# +# /* +# * This code implements the MD5 message-digest algorithm. +# * The algorithm is due to Ron Rivest. This code was +# * written by Colin Plumb in 1993, no copyright is claimed. +# * This code is in the public domain; do with it what you wish. +# */ +# +# /*- +# * Copyright (c) 2006, 2008, 2011 +# * mirabilos +# * +# * Provided that these terms and disclaimer and all copyright notices +# * are retained or reproduced in an accompanying document, permission +# * is granted to deal in this work without restriction, including un- +# * limited rights to use, publicly perform, distribute, sell, modify, +# * merge, give away, or sublicence. +# * +# * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to +# * the utmost extent permitted by applicable law, neither express nor +# * implied; without malicious intent or gross negligence. In no event +# * may a licensor, author or contributor be held liable for indirect, +# * direct, other damage, loss, or other issues arising in any way out +# * of dealing in the work, even if advised of the possibility of such +# * damage or existence of a defect, except proven that it results out +# * of said person's immediate fault when using the work as intended. +# */ +# +# /*- +# * Copyright (c) 1998 Todd C. Miller +# * +# * Permission to use, copy, modify, and distribute this software for any +# * purpose with or without fee is hereby granted, provided that the above +# * copyright notice and this permission notice appear in all copies. +# * +# * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# */ +# +# /* +# * Copyright (c) 1989, 1990, 1993 +# * The Regents of the University of California. All rights reserved. +# * +# * This code is derived from software contributed to Berkeley by +# * Kevin Fall. +# * +# * Redistribution and use in source and binary forms, with or without +# * modification, are permitted provided that the following conditions +# * are met: +# * 1. Redistributions of source code must retain the above copyright +# * notice, this list of conditions and the following disclaimer. +# * 2. Redistributions in binary form must reproduce the above copyright +# * notice, this list of conditions and the following disclaimer in the +# * documentation and/or other materials provided with the distribution. +# * 3. Neither the name of the University nor the names of its contributors +# * may be used to endorse or promote products derived from this software +# * without specific prior written permission. +# * +# * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# * SUCH DAMAGE. +# */ +# +# /* +# * Copyright (c) 1989, 1993, 1994 +# * The Regents of the University of California. All rights reserved. +# * +# * This code is derived from software contributed to Berkeley by +# * Dave Borman at Cray Research, Inc. +# * +# * Redistribution and use in source and binary forms, with or without +# * modification, are permitted provided that the following conditions +# * are met: +# * 1. Redistributions of source code must retain the above copyright +# * notice, this list of conditions and the following disclaimer. +# * 2. Redistributions in binary form must reproduce the above copyright +# * notice, this list of conditions and the following disclaimer in the +# * documentation and/or other materials provided with the distribution. +# * 3. Neither the name of the University nor the names of its contributors +# * may be used to endorse or promote products derived from this software +# * without specific prior written permission. +# * +# * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# * SUCH DAMAGE. +# */ +# +# /*- +# * Copyright (c) 2015, 2016, 2017 +# * mirabilos +# * Copyright (c) 1992 Diomidis Spinellis. +# * Copyright (c) 1992, 1993 +# * The Regents of the University of California. All rights reserved. +# * +# * This code is derived from software contributed to Berkeley by +# * Diomidis Spinellis of Imperial College, University of London. +# * +# * Redistribution and use in source and binary forms, with or without +# * modification, are permitted provided that the following conditions +# * are met: +# * 1. Redistributions of source code must retain the above copyright +# * notice, this list of conditions and the following disclaimer. +# * 2. Redistributions in binary form must reproduce the above copyright +# * notice, this list of conditions and the following disclaimer in the +# * documentation and/or other materials provided with the distribution. +# * 3. Neither the name of the University nor the names of its contributors +# * may be used to endorse or promote products derived from this software +# * without specific prior written permission. +# * +# * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# * SUCH DAMAGE. +# */ +# +# /* +# * Copyright (c) 2008 Otto Moerbeek +# * +# * Permission to use, copy, modify, and distribute this software for any +# * purpose with or without fee is hereby granted, provided that the above +# * copyright notice and this permission notice appear in all copies. +# * +# * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# */ +# +# /*- +# * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, +# * 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 +# * mirabilos +# * +# * Provided that these terms and disclaimer and all copyright notices +# * are retained or reproduced in an accompanying document, permission +# * is granted to deal in this work without restriction, including un- +# * limited rights to use, publicly perform, distribute, sell, modify, +# * merge, give away, or sublicence. +# * +# * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to +# * the utmost extent permitted by applicable law, neither express nor +# * implied; without malicious intent or gross negligence. In no event +# * may a licensor, author or contributor be held liable for indirect, +# * direct, other damage, loss, or other issues arising in any way out +# * of dealing in the work, even if advised of the possibility of such +# * damage or existence of a defect, except proven that it results out +# * of said person's immediate fault when using the work as intended. +# */ diff --git a/package/toolbox/src/cat/Makefile b/package/toolbox/src/cat/Makefile new file mode 100644 index 000000000..61abf9bbd --- /dev/null +++ b/package/toolbox/src/cat/Makefile @@ -0,0 +1,5 @@ +PROG= cat + +include ../tool.mk + +CFLAGS+=-Wextra diff --git a/package/toolbox/src/cat/cat.c b/package/toolbox/src/cat/cat.c new file mode 100644 index 000000000..442f72073 --- /dev/null +++ b/package/toolbox/src/cat/cat.c @@ -0,0 +1,163 @@ +/*- + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + * 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 + * mirabilos + * + * Provided that these terms and disclaimer and all copyright notices + * are retained or reproduced in an accompanying document, permission + * is granted to deal in this work without restriction, including un- + * limited rights to use, publicly perform, distribute, sell, modify, + * merge, give away, or sublicence. + * + * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to + * the utmost extent permitted by applicable law, neither express nor + * implied; without malicious intent or gross negligence. In no event + * may a licensor, author or contributor be held liable for indirect, + * direct, other damage, loss, or other issues arising in any way out + * of dealing in the work, even if advised of the possibility of such + * damage or existence of a defect, except proven that it results out + * of said person's immediate fault when using the work as intended. + */ + +#include +#include +#include +#include +#include +#include + +#define MKSH_CAT_BUFSIZ 256 + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#define ksh_sigmask(sig) (((sig) < 1 || (sig) > 127) ? 255 : 128 + (sig)) + +static char buf[MKSH_CAT_BUFSIZ]; +static volatile sig_atomic_t intrsig; + +static const char Tsynerr[] = "cat: syntax error\n"; +static const char unkerr_msg[] = "Unknown error"; +static const char sigint_msg[] = " ...\ncat: Interrupted\n"; + +static void +disperr(const char *fn) +{ + int e = errno; + + write(2, "cat: ", 5); + write(2, fn, strlen(fn)); + write(2, ": ", 2); + if (strerror_r(e, buf, MKSH_CAT_BUFSIZ)) + write(2, unkerr_msg, sizeof(unkerr_msg) - 1); + else + write(2, buf, strlen(buf)); + write(2, "\n", 1); +} + +static void +sighandler(int signo __attribute__((__unused__))) +{ + intrsig = 1; +} + +int +main(int argc __attribute__((__unused__)), char *wp[]) +{ + int fd = 0, rv; + ssize_t n, w; + const char *fn = ""; + char *cp; + + ++wp; + /* parse options (POSIX demands this) */ + while ((cp = *wp) && *cp++ == '-') { + if (!cp[0]) + break; + if (cp[0] == '-' && !cp[1]) { + ++wp; + break; + } + while (*cp == 'u') + ++cp; + if (*cp) { + write(2, Tsynerr, sizeof(Tsynerr) - 1); + return (1); + } + ++wp; + } + rv = 0; + + /* catch SIGPIPE */ + signal(SIGPIPE, SIG_IGN); + + /* abort on SIGINT */ + signal(SIGINT, sighandler); + + do { + if (*wp) { + fn = *wp++; + if (fn[0] == '-' && !fn[1]) + fd = 0; + else if ((fd = open(fn, O_RDONLY | O_BINARY)) < 0) { + disperr(fn); + rv = 1; + continue; + } + } + while (/* CONSTCOND */ 1) { + if ((n = read(fd, (cp = buf), MKSH_CAT_BUFSIZ)) == -1) { + if (errno == EINTR) { + /* give the user a chance to ^C out */ + if (intrsig) + goto has_intrsig; + /* interrupted, try again */ + continue; + } + /* an error occured during reading */ + disperr(fn); + rv = 1; + break; + } else if (n == 0) + /* end of file reached */ + break; + while (n) { + if (intrsig) + goto has_intrsig; + if ((w = write(1, cp, n)) != -1) { + n -= w; + cp += w; + continue; + } + if (errno == EINTR) { + has_intrsig: + /* give the user a chance to ^C out */ + if (intrsig) { + write(2, sigint_msg, + sizeof(sigint_msg) - 1); + return (ksh_sigmask(SIGINT)); + } + /* interrupted, try again */ + continue; + } + if (errno == EPIPE) { + /* fake receiving signal */ + rv = ksh_sigmask(SIGPIPE); + } else { + /* an error occured during writing */ + disperr(""); + rv = 1; + } + if (fd != 0) + close(fd); + goto out; + } + } + if (fd != 0) + close(fd); + } while (*wp); + + out: + return (rv); +} diff --git a/package/toolbox/src/chmod/Makefile b/package/toolbox/src/chmod/Makefile new file mode 100644 index 000000000..347b93d77 --- /dev/null +++ b/package/toolbox/src/chmod/Makefile @@ -0,0 +1,3 @@ +PROG= chmod + +include ../tool.mk diff --git a/package/toolbox/src/chown/Makefile b/package/toolbox/src/chown/Makefile new file mode 100644 index 000000000..e2bb26ae7 --- /dev/null +++ b/package/toolbox/src/chown/Makefile @@ -0,0 +1,3 @@ +PROG= chown + +include ../tool.mk diff --git a/package/toolbox/src/clear/Makefile b/package/toolbox/src/clear/Makefile new file mode 100644 index 000000000..8e2919133 --- /dev/null +++ b/package/toolbox/src/clear/Makefile @@ -0,0 +1,3 @@ +PROG= clear + +include ../tool.mk diff --git a/package/toolbox/src/cmp/Makefile b/package/toolbox/src/cmp/Makefile new file mode 100644 index 000000000..68dffd303 --- /dev/null +++ b/package/toolbox/src/cmp/Makefile @@ -0,0 +1,3 @@ +PROG= cmp + +include ../tool.mk diff --git a/package/toolbox/src/common.mk b/package/toolbox/src/common.mk new file mode 100644 index 000000000..ab0728f18 --- /dev/null +++ b/package/toolbox/src/common.mk @@ -0,0 +1,21 @@ +OBJS:= ${SRCS:.c=.o} +CFLAGS?= -Os -Wall +CPPFLAGS+= -I. +#CPPFLAGS+= -D_FILE_OFFSET_BITS=64 +CPPFLAGS+= -isystem ../lib +CPPFLAGS+= -D'__COPYRIGHT(x)=' -D'__RCSID(x)=' +CPPFLAGS+= -D'__unused=__attribute__((__unused__))' +CPPFLAGS+= -D'__dead=__attribute__((__noreturn__))' +CLEANFILES+= ${OBJS} ${PROG} + +all: + +COMPILE.c= ${CC} ${CPPFLAGS} ${CFLAGS} ${CFLAGS_$@} -c + +.c.o: + ${COMPILE.c} -o $@ $< + +clean: + rm -f ${CLEANFILES} + +# no depend magic; if you change a .h file, just make clean diff --git a/package/toolbox/src/cp/Makefile b/package/toolbox/src/cp/Makefile new file mode 100644 index 000000000..17545ac06 --- /dev/null +++ b/package/toolbox/src/cp/Makefile @@ -0,0 +1,4 @@ +PROG= cp +SRCS= cp.c utils.c + +include ../tool.mk diff --git a/package/toolbox/src/cp/cp.c b/package/toolbox/src/cp/cp.c new file mode 100644 index 000000000..d04702f2a --- /dev/null +++ b/package/toolbox/src/cp/cp.c @@ -0,0 +1,549 @@ +/* $NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $ */ + +/* + * Copyright (c) 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * David Hitz of Auspex Systems Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT( +"@(#) Copyright (c) 1988, 1993, 1994\ + The Regents of the University of California. All rights reserved."); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; +#else +__RCSID("$NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $"); +#endif +#endif /* not lint */ + +/* + * Cp copies source files to target files. + * + * The global PATH_T structure "to" always contains the path to the + * current target file. Since fts(3) does not change directories, + * this path can be either absolute or dot-relative. + * + * The basic algorithm is to initialize "to" and use fts(3) to traverse + * the file hierarchy rooted in the argument list. A trivial case is the + * case of 'cp file1 file2'. The more interesting case is the case of + * 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the + * path (relative to the root of the traversal) is appended to dir (stored + * in "to") to form the final target path. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "extern.h" + +#define STRIP_TRAILING_SLASH(p) { \ + while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \ + *--(p).p_end = '\0'; \ +} + +static char empty[] = ""; +PATH_T to = { .p_end = to.p_path, .target_end = empty }; + +uid_t myuid; +int Hflag, Lflag, Rflag, Pflag, fflag, iflag, lflag, pflag, rflag, vflag, Nflag; +mode_t myumask; +sig_atomic_t pinfo; + +enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; + +static int copy(char *[], enum op, int); + +#ifdef SIGINFO +static void +progress(int sig __unused) +{ + + pinfo++; +} +#endif + +int +main(int argc, char *argv[]) +{ + struct stat to_stat, tmp_stat; + enum op type; + int ch, fts_options, r, have_trailing_slash; + char *target, **src; + + Hflag = Lflag = Pflag = Rflag = 0; + while ((ch = getopt(argc, argv, "HLNPRfailprv")) != -1) + switch (ch) { + case 'H': + Hflag = 1; + Lflag = Pflag = 0; + break; + case 'L': + Lflag = 1; + Hflag = Pflag = 0; + break; + case 'N': + Nflag = 1; + break; + case 'P': + Pflag = 1; + Hflag = Lflag = 0; + break; + case 'R': + Rflag = 1; + break; + case 'a': + Pflag = 1; + pflag = 1; + Rflag = 1; + Hflag = Lflag = 0; + break; + case 'f': + fflag = 1; + iflag = 0; + break; + case 'i': + iflag = isatty(fileno(stdin)); + fflag = 0; + break; + case 'l': + lflag = 1; + break; + case 'p': + pflag = 1; + break; + case 'r': + rflag = 1; + break; + case 'v': + vflag = 1; + break; + case '?': + default: + cp_usage(); + /* NOTREACHED */ + } + argc -= optind; + argv += optind; + + if (argc < 2) + cp_usage(); + + fts_options = FTS_NOCHDIR | FTS_PHYSICAL; + if (rflag) { + if (Rflag) { + errx(EXIT_FAILURE, + "the -R and -r options may not be specified together."); + /* NOTREACHED */ + } + if (Hflag || Lflag || Pflag) { + errx(EXIT_FAILURE, + "the -H, -L, and -P options may not be specified with the -r option."); + /* NOTREACHED */ + } + fts_options &= ~FTS_PHYSICAL; + fts_options |= FTS_LOGICAL; + } + + if (Rflag) { + if (Hflag) + fts_options |= FTS_COMFOLLOW; + if (Lflag) { + fts_options &= ~FTS_PHYSICAL; + fts_options |= FTS_LOGICAL; + } + } else if (!Pflag) { + fts_options &= ~FTS_PHYSICAL; + fts_options |= FTS_LOGICAL | FTS_COMFOLLOW; + } + + myuid = getuid(); + + /* Copy the umask for explicit mode setting. */ + myumask = umask(0); + (void)umask(myumask); + + /* Save the target base in "to". */ + target = argv[--argc]; + if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path)) + errx(EXIT_FAILURE, "%s: name too long", target); + to.p_end = to.p_path + strlen(to.p_path); + have_trailing_slash = (to.p_end[-1] == '/'); + if (have_trailing_slash) + STRIP_TRAILING_SLASH(to); + to.target_end = to.p_end; + + /* Set end of argument list for fts(3). */ + argv[argc] = NULL; + +#ifdef SIGINFO + (void)signal(SIGINFO, progress); +#endif + + /* + * Cp has two distinct cases: + * + * cp [-R] source target + * cp [-R] source1 ... sourceN directory + * + * In both cases, source can be either a file or a directory. + * + * In (1), the target becomes a copy of the source. That is, if the + * source is a file, the target will be a file, and likewise for + * directories. + * + * In (2), the real target is not directory, but "directory/source". + */ + if (Pflag) + r = lstat(to.p_path, &to_stat); + else + r = stat(to.p_path, &to_stat); + if (r == -1 && errno != ENOENT) { + err(EXIT_FAILURE, "%s", to.p_path); + /* NOTREACHED */ + } + if (r == -1 || !S_ISDIR(to_stat.st_mode)) { + /* + * Case (1). Target is not a directory. + */ + if (argc > 1) + cp_usage(); + /* + * Need to detect the case: + * cp -R dir foo + * Where dir is a directory and foo does not exist, where + * we want pathname concatenations turned on but not for + * the initial mkdir(). + */ + if (r == -1) { + if (rflag || (Rflag && (Lflag || Hflag))) + r = stat(*argv, &tmp_stat); + else + r = lstat(*argv, &tmp_stat); + if (r == -1) { + err(EXIT_FAILURE, "%s", *argv); + /* NOTREACHED */ + } + + if (S_ISDIR(tmp_stat.st_mode) && (Rflag || rflag)) + type = DIR_TO_DNE; + else + type = FILE_TO_FILE; + } else + type = FILE_TO_FILE; + + if (have_trailing_slash && type == FILE_TO_FILE) { + if (r == -1) + errx(1, "directory %s does not exist", + to.p_path); + else + errx(1, "%s is not a directory", to.p_path); + } + } else { + /* + * Case (2). Target is a directory. + */ + type = FILE_TO_DIR; + } + + /* + * make "cp -rp src/ dst" behave like "cp -rp src dst" not + * like "cp -rp src/. dst" + */ + for (src = argv; *src; src++) { + size_t len = strlen(*src); + while (len-- > 1 && (*src)[len] == '/') + (*src)[len] = '\0'; + } + + exit(copy(argv, type, fts_options)); + /* NOTREACHED */ +} + +static int dnestack[MAXPATHLEN]; /* unlikely we'll have more nested dirs */ +static ssize_t dnesp; +static void +pushdne(int dne) +{ + + dnestack[dnesp++] = dne; + assert(dnesp < MAXPATHLEN); +} + +static int +popdne(void) +{ + int rv; + + rv = dnestack[--dnesp]; + assert(dnesp >= 0); + return rv; +} + +static int +copy(char *argv[], enum op type, int fts_options) +{ + struct stat to_stat; + FTS *ftsp; + FTSENT *curr; + int base, dne, sval; + int this_failed, any_failed; + size_t nlen; + char *p, *target_mid; + + base = 0; /* XXX gcc -Wuninitialized (see comment below) */ + + if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL) + err(EXIT_FAILURE, "%s", argv[0]); + /* NOTREACHED */ + for (any_failed = 0; (curr = fts_read(ftsp)) != NULL;) { + this_failed = 0; + switch (curr->fts_info) { + case FTS_NS: + case FTS_DNR: + case FTS_ERR: + warnx("%s: %s", curr->fts_path, + strerror(curr->fts_errno)); + this_failed = any_failed = 1; + continue; + case FTS_DC: /* Warn, continue. */ + warnx("%s: directory causes a cycle", curr->fts_path); + this_failed = any_failed = 1; + continue; + } + + /* + * If we are in case (2) or (3) above, we need to append the + * source name to the target name. + */ + if (type != FILE_TO_FILE) { + if ((curr->fts_namelen + + to.target_end - to.p_path + 1) > MAXPATHLEN) { + warnx("%s/%s: name too long (not copied)", + to.p_path, curr->fts_name); + this_failed = any_failed = 1; + continue; + } + + /* + * Need to remember the roots of traversals to create + * correct pathnames. If there's a directory being + * copied to a non-existent directory, e.g. + * cp -R a/dir noexist + * the resulting path name should be noexist/foo, not + * noexist/dir/foo (where foo is a file in dir), which + * is the case where the target exists. + * + * Also, check for "..". This is for correct path + * concatentation for paths ending in "..", e.g. + * cp -R .. /tmp + * Paths ending in ".." are changed to ".". This is + * tricky, but seems the easiest way to fix the problem. + * + * XXX + * Since the first level MUST be FTS_ROOTLEVEL, base + * is always initialized. + */ + if (curr->fts_level == FTS_ROOTLEVEL) { + if (type != DIR_TO_DNE) { + p = strrchr(curr->fts_path, '/'); + base = (p == NULL) ? 0 : + (int)(p - curr->fts_path + 1); + + if (!strcmp(&curr->fts_path[base], + "..")) + base += 1; + } else + base = curr->fts_pathlen; + } + + p = &curr->fts_path[base]; + nlen = curr->fts_pathlen - base; + target_mid = to.target_end; + if (*p != '/' && target_mid[-1] != '/') + *target_mid++ = '/'; + *target_mid = 0; + + if (target_mid - to.p_path + nlen >= PATH_MAX) { + warnx("%s%s: name too long (not copied)", + to.p_path, p); + this_failed = any_failed = 1; + continue; + } + (void)strncat(target_mid, p, nlen); + to.p_end = target_mid + nlen; + *to.p_end = 0; + STRIP_TRAILING_SLASH(to); + } + + sval = Pflag ? lstat(to.p_path, &to_stat) : stat(to.p_path, &to_stat); + /* Not an error but need to remember it happened */ + if (sval == -1) + dne = 1; + else { + if (to_stat.st_dev == curr->fts_statp->st_dev && + to_stat.st_ino == curr->fts_statp->st_ino) { + warnx("%s and %s are identical (not copied).", + to.p_path, curr->fts_path); + this_failed = any_failed = 1; + if (S_ISDIR(curr->fts_statp->st_mode)) + (void)fts_set(ftsp, curr, FTS_SKIP); + continue; + } + if (!S_ISDIR(curr->fts_statp->st_mode) && + S_ISDIR(to_stat.st_mode)) { + warnx("cannot overwrite directory %s with non-directory %s", + to.p_path, curr->fts_path); + this_failed = any_failed = 1; + continue; + } + dne = 0; + } + + switch (curr->fts_statp->st_mode & S_IFMT) { + case S_IFLNK: + /* Catch special case of a non dangling symlink */ + if((fts_options & FTS_LOGICAL) || + ((fts_options & FTS_COMFOLLOW) && curr->fts_level == 0)) { + if (copy_file(curr, dne)) + this_failed = any_failed = 1; + } else { + if (copy_link(curr, !dne)) + this_failed = any_failed = 1; + } + break; + case S_IFDIR: + if (!Rflag && !rflag) { + if (curr->fts_info == FTS_D) + warnx("%s is a directory (not copied).", + curr->fts_path); + (void)fts_set(ftsp, curr, FTS_SKIP); + this_failed = any_failed = 1; + break; + } + + /* + * Directories get noticed twice: + * In the first pass, create it if needed. + * In the second pass, after the children have been copied, set the permissions. + */ + if (curr->fts_info == FTS_D) /* First pass */ + { + /* + * If the directory doesn't exist, create the new + * one with the from file mode plus owner RWX bits, + * modified by the umask. Trade-off between being + * able to write the directory (if from directory is + * 555) and not causing a permissions race. If the + * umask blocks owner writes, we fail.. + */ + pushdne(dne); + if (dne) { + if (mkdir(to.p_path, + curr->fts_statp->st_mode | S_IRWXU) < 0) + err(EXIT_FAILURE, "%s", + to.p_path); + /* NOTREACHED */ + } else if (!S_ISDIR(to_stat.st_mode)) { + errno = ENOTDIR; + err(EXIT_FAILURE, "%s", + to.p_path); + /* NOTREACHED */ + } + } + else if (curr->fts_info == FTS_DP) /* Second pass */ + { + /* + * If not -p and directory didn't exist, set it to be + * the same as the from directory, umodified by the + * umask; arguably wrong, but it's been that way + * forever. + */ + if (pflag && setfile(curr->fts_statp, 0)) + this_failed = any_failed = 1; + else if ((dne = popdne())) + (void)chmod(to.p_path, + curr->fts_statp->st_mode); + } + else + { + warnx("directory %s encountered when not expected.", + curr->fts_path); + this_failed = any_failed = 1; + break; + } + + break; + case S_IFBLK: + case S_IFCHR: + if (Rflag) { + if (copy_special(curr->fts_statp, !dne)) + this_failed = any_failed = 1; + } else + if (copy_file(curr, dne)) + this_failed = any_failed = 1; + break; + case S_IFIFO: + if (Rflag) { + if (copy_fifo(curr->fts_statp, !dne)) + this_failed = any_failed = 1; + } else + if (copy_file(curr, dne)) + this_failed = any_failed = 1; + break; + default: + if (copy_file(curr, dne)) + this_failed = any_failed = 1; + break; + } + if (vflag && !this_failed) + (void)printf("%s -> %s\n", curr->fts_path, to.p_path); + } + if (errno) { + err(EXIT_FAILURE, "fts_read"); + /* NOTREACHED */ + } + (void)fts_close(ftsp); + return (any_failed); +} diff --git a/package/toolbox/src/cp/extern.h b/package/toolbox/src/cp/extern.h new file mode 100644 index 000000000..6aa9b1b5a --- /dev/null +++ b/package/toolbox/src/cp/extern.h @@ -0,0 +1,63 @@ +/* $NetBSD: extern.h,v 1.17 2012/01/04 15:58:37 christos Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)extern.h 8.2 (Berkeley) 4/1/94 + */ + +#ifndef _EXTERN_H_ +#define _EXTERN_H_ + +#include + +typedef struct { + char *p_end; /* pointer to NULL at end of path */ + char *target_end; /* pointer to end of target base */ + char p_path[MAXPATHLEN + 1]; /* pointer to the start of a path */ +} PATH_T; + +extern PATH_T to; +extern uid_t myuid; +extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, lflag, pflag, Nflag; +extern mode_t myumask; +extern sig_atomic_t pinfo; + +#include + +__BEGIN_DECLS +int copy_fifo(struct stat *, int); +int copy_file(FTSENT *, int); +int copy_link(FTSENT *, int); +int copy_special(struct stat *, int); +int set_utimes(const char *, struct stat *); +int setfile(struct stat *, int); +void cp_usage(void) __attribute__((__noreturn__)); +__END_DECLS + +#endif /* !_EXTERN_H_ */ diff --git a/package/toolbox/src/cp/utils.c b/package/toolbox/src/cp/utils.c new file mode 100644 index 000000000..cfb254a45 --- /dev/null +++ b/package/toolbox/src/cp/utils.c @@ -0,0 +1,441 @@ +/* $NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; +#else +__RCSID("$NetBSD: u