From 6049e2ca2a32bf3cd895ac1279495d4bf61c638d Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Sun, 23 May 2021 11:50:48 -0400 Subject: shell_cmds: Fix compilation for lower targets --- shell_cmds/find/misc.c | 4 +++ shell_cmds/find/rpmatch.c | 57 +++++++++++++++++++++++++++++++++++++ shell_cmds/nohup/nohup.c | 1 + shell_cmds/systime/systime.c | 1 + shell_cmds/xargs/Makefile | 2 +- shell_cmds/xargs/strtonum.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ shell_cmds/xargs/xargs.c | 2 ++ 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 shell_cmds/find/rpmatch.c create mode 100644 shell_cmds/xargs/strtonum.c diff --git a/shell_cmds/find/misc.c b/shell_cmds/find/misc.c index a165c5e..e45b864 100644 --- a/shell_cmds/find/misc.c +++ b/shell_cmds/find/misc.c @@ -52,6 +52,10 @@ __FBSDID("$FreeBSD: src/usr.bin/find/misc.c,v 1.13 2010/12/11 08:32:16 joel Exp #include "find.h" +#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000 +#include "rpmatch.c" +#endif + /* * brace_subst -- * Replace occurrences of {} in s1 with s2 and return the result string. diff --git a/shell_cmds/find/rpmatch.c b/shell_cmds/find/rpmatch.c new file mode 100644 index 0000000..e4c366a --- /dev/null +++ b/shell_cmds/find/rpmatch.c @@ -0,0 +1,57 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004-2005 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +int +rpmatch(const char *response) +{ + regex_t yes, no; + int ret; + + if (regcomp(&yes, nl_langinfo(YESEXPR), REG_EXTENDED|REG_NOSUB) != 0) + return (-1); + if (regcomp(&no, nl_langinfo(NOEXPR), REG_EXTENDED|REG_NOSUB) != 0) { + regfree(&yes); + return (-1); + } + if (regexec(&yes, response, 0, NULL, 0) == 0) + ret = 1; + else if (regexec(&no, response, 0, NULL, 0) == 0) + ret = 0; + else + ret = -1; + regfree(&yes); + regfree(&no); + return (ret); +} diff --git a/shell_cmds/nohup/nohup.c b/shell_cmds/nohup/nohup.c index f33e21b..d2b9f81 100644 --- a/shell_cmds/nohup/nohup.c +++ b/shell_cmds/nohup/nohup.c @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD: src/usr.bin/nohup/nohup.c,v 1.10 2003/05/03 19:44:46 obrien #ifdef __APPLE__ #include #include +typedef char *kobject_description_t[512]; #include #endif diff --git a/shell_cmds/systime/systime.c b/shell_cmds/systime/systime.c index 555fc6a..38159b8 100644 --- a/shell_cmds/systime/systime.c +++ b/shell_cmds/systime/systime.c @@ -21,6 +21,7 @@ * @APPLE_LICENSE_HEADER_END@ */ +typedef char *kobject_description_t[512]; #include #include #include diff --git a/shell_cmds/xargs/Makefile b/shell_cmds/xargs/Makefile index a316efb..d7f3518 100644 --- a/shell_cmds/xargs/Makefile +++ b/shell_cmds/xargs/Makefile @@ -1,5 +1,5 @@ PROG= xargs -SRCS= strnsubst.c xargs.c +SRCS= strnsubst.c xargs.c strtonum.c LDADD+=-liosexec diff --git a/shell_cmds/xargs/strtonum.c b/shell_cmds/xargs/strtonum.c new file mode 100644 index 0000000..aa433d8 --- /dev/null +++ b/shell_cmds/xargs/strtonum.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 2004 Ted Unangst and Todd Miller + * All rights reserved. + * + * 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. + * + * $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#define INVALID 1 +#define TOOSMALL 2 +#define TOOLARGE 3 + +long long +strtonum(const char *numstr, long long minval, long long maxval, + const char **errstrp) +{ + long long ll = 0; + int error = 0; + char *ep; + struct errval { + const char *errstr; + int err; + } ev[4] = { + { NULL, 0 }, + { "invalid", EINVAL }, + { "too small", ERANGE }, + { "too large", ERANGE }, + }; + + ev[0].err = errno; + errno = 0; + if (minval > maxval) { + error = INVALID; + } else { + ll = strtoll(numstr, &ep, 10); + if (errno == EINVAL || numstr == ep || *ep != '\0') + error = INVALID; + else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) + error = TOOSMALL; + else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) + error = TOOLARGE; + } + if (errstrp != NULL) + *errstrp = ev[error].errstr; + errno = ev[error].err; + if (error) + ll = 0; + + return (ll); +} diff --git a/shell_cmds/xargs/xargs.c b/shell_cmds/xargs/xargs.c index 1b71a6d..7865be3 100644 --- a/shell_cmds/xargs/xargs.c +++ b/shell_cmds/xargs/xargs.c @@ -75,6 +75,8 @@ __FBSDID("$FreeBSD$"); #define COMPAT_MODE(a,b) (1) #endif /* __APPLE__ */ +long long strtonum(const char*, long long, long long, const char**); + static void parse_input(int, char *[]); static void prerun(int, char *[]); static int prompt(void); -- cgit v1.2.3-56-ge451