-xcuserdata
+*~
+xcuserdata/
+build/
+project.xcworkspace/
.El
.Sh SEE ALSO
.Xr csh 1 ,
+.Xr dash 1 ,
.Xr echo 1 ,
.Xr false 1 ,
.Xr info 1 ,
.Xr test 1 ,
.Xr time 1 ,
.Xr true 1 ,
-.Xr which 1
+.Xr which 1 ,
+.Xr zsh 1
.Sh HISTORY
The
.Nm
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
}
-#ifdef __APPLE__
- return (resp[0] == 'y');
-#else
- return (rpmatch(resp) == 1);
-#endif
+
+ return (rpmatch(resp) == 1);
}
miblen = 4;
}
- st = sysctl(mib, miblen, NULL, &size, NULL, 0);
do {
+ st = sysctl(mib, miblen, NULL, &size, NULL, 0);
+ if (st == -1)
+ err(1, "could not sysctl(KERN_PROC)");
+ if (!size)
+ errx(1, "could not get size from sysctl(KERN_PROC)");
size += size / 10;
newprocs = realloc(procs, size);
if (newprocs == 0) {
continue;
mib[0] = CTL_KERN;
-#if defined(__APPLE__) && TARGET_OS_EMBEDDED
mib[1] = KERN_PROCARGS2;
-#else
- mib[1] = KERN_PROCARGS;
-#endif
mib[2] = thispid;
syssize = (size_t)argmax;
<array>
<string>/usr/libexec/locate.updatedb</string>
</array>
- <key>LowPriorityIO</key>
- <true/>
- <key>Nice</key>
- <integer>5</integer>
+ <key>ProcessType</key>
+ <string>Background</string>
<key>KeepAlive</key>
<dict>
<key>PathState</key>
excludes="! (" or=""
for fstype in $FILESYSTEMS
do
- excludes="$excludes $or -fstype $fstype"
- or="-or"
+ excludes="$excludes $or -fstype $fstype"
+ or="-or"
done
excludes="$excludes ) -prune"
case X"$PRUNEPATHS" in
X) ;;
*) for path in $PRUNEPATHS
- do
+ do
excludes="$excludes -or -path $path -prune"
- done;;
+ done;;
esac
+# Ignore the target of firmlinks
+while read firmlink; do
+ excludes="$excludes -or -path $firmlink -prune"
+done <<< "$(awk -F'\t' '{print "/System/Volumes/Data/" $2}' /usr/share/firmlinks)"
+
tmp=$TMPDIR/_updatedb$$
trap 'rm -f $tmp; rmdir $TMPDIR; exit' 0 1 2 3 5 10 15
-
+
# search locally
# echo $find $SEARCHPATHS $excludes -or -print && exit
if $find -s $SEARCHPATHS $excludes -or -print 2>/dev/null |
(void)signal(SIGHUP, SIG_IGN);
-#if defined(__APPLE__) && !TARGET_OS_EMBEDDED
+#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
if (_vprocmgr_detach_from_console(0) != NULL)
err(EXIT_MISC, "can't detach from console");
#endif
# @(#)Makefile 8.4 (Berkeley) 5/5/95
-# $FreeBSD: head/bin/sh/Makefile 301285 2016-06-03 19:25:41Z bdrewery $
+# $FreeBSD: head/bin/sh/Makefile 322515 2017-08-14 19:21:37Z ngie $
.include <src.opts.mk>
WFORMAT=0
.PATH: ${.CURDIR}/bltin \
- ${.CURDIR}/../kill \
- ${.CURDIR}/../test \
- ${.CURDIR}/../../usr.bin/printf
+ ${.CURDIR:H}/kill \
+ ${.CURDIR:H}/test \
+ ${SRCTOP}/usr.bin/printf
CLEANFILES+= mknodes mknodes.o \
mksyntax mksyntax.o
token.h: mktokens
sh ${.CURDIR}/mktokens
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
.include <bsd.prog.mk>
-# $FreeBSD: head/bin/sh/Makefile.depend 295989 2016-02-24 17:20:11Z bdrewery $
+# $FreeBSD: head/bin/sh/Makefile.depend 325188 2017-10-31 00:07:04Z bdrewery $
# Autogenerated - do NOT edit!
DIRDEPS = \
gnu/lib/csu \
- gnu/lib/libgcc \
include \
include/xlocale \
lib/${CSU_DIR} \
# @(#)TOUR 8.1 (Berkeley) 5/31/93
-# $FreeBSD: head/bin/sh/TOUR 253650 2013-07-25 15:08:41Z jilles $
+# $FreeBSD: head/bin/sh/TOUR 317882 2017-05-06 13:28:42Z jilles $
NOTE -- This is the original TOUR paper distributed with ash and
does not represent the current state of the shell. It is provided anyway
program input files generates
------- ----------- ---------
- mkbuiltins builtins builtins.h builtins.c
+ mkbuiltins builtins.def builtins.h builtins.c
mknodes nodetypes nodes.h nodes.c
mksyntax - syntax.h syntax.c
mktokens - token.h
word. The text consists of ordinary characters and a number of
special codes defined in parser.h. The special codes are:
- CTLVAR Variable substitution
- CTLENDVAR End of variable substitution
+ CTLVAR Parameter expansion
+ CTLENDVAR End of parameter expansion
CTLBACKQ Command substitution
CTLBACKQ|CTLQUOTE Command substitution inside double quotes
+ CTLARI Arithmetic expansion
+ CTLENDARI End of arithmetic expansion
CTLESC Escape next character
A variable substitution contains the following elements:
VSQUESTION|VSNUL ${var:?text}
VSASSIGN ${var=text}
VSASSIGN|VSNUL ${var:=text}
+ VSTRIMLEFT ${var#text}
+ VSTRIMLEFTMAX ${var##text}
+ VSTRIMRIGHT ${var%text}
+ VSTRIMRIGHTMAX ${var%%text}
+ VSLENGTH ${#var}
+ VSERROR delayed error
In addition, the type field will have the VSQUOTE flag set if the
-variable is enclosed in double quotes. The name of the variable
-comes next, terminated by an equals sign. If the type is not
-VSNORMAL, then the text field in the substitution follows, ter-
-minated by a CTLENDVAR byte.
+variable is enclosed in double quotes and the VSLINENO flag if
+LINENO is being expanded (the parameter name is the decimal line
+number). The parameter's name comes next, terminated by an equals
+sign. If the type is not VSNORMAL (including when it is VSLENGTH),
+then the text field in the substitution follows, terminated by a
+CTLENDVAR byte.
+
+The type VSERROR is used to allow parsing bad substitutions like
+${var[7]} and generate an error when they are expanded.
Commands in back quotes are parsed and stored in a linked list.
The locations of these commands in the string are indicated by
CTLBACKQ and CTLBACKQ+CTLQUOTE characters, depending upon whether
the back quotes were enclosed in double quotes.
+Arithmetic expansion starts with CTLARI and ends with CTLENDARI.
+
The character CTLESC escapes the next character, so that in case
any of the CTL characters mentioned above appear in the input,
they can be passed through transparently. CTLESC is also used to
variable and command substitution, the parser doesn't insert any
CTLESC characters to begin with (so the contents of the text
field can be written without any processing). Other here docu-
-ments, and words which are not subject to splitting and file name
-generation, have the CTLESC characters removed during the vari-
-able and command substitution phase. Words which are subject to
-splitting and file name generation have the CTLESC characters re-
-moved as part of the file name phase.
+ments, and words which are not subject to file name generation,
+have the CTLESC characters removed during the variable and command
+substitution phase. Words which are subject to file name
+generation have the CTLESC characters removed as part of the file
+name phase.
EXECUTION: Command execution is handled by the following files:
eval.c The top level routines.
The routine shellexec is the interface to the exec system call.
-EXPAND.C: Arguments are processed in three passes. The first
-(performed by the routine argstr) performs variable and command
-substitution. The second (ifsbreakup) performs word splitting
-and the third (expandmeta) performs file name generation.
+EXPAND.C: As the routine argstr generates words by parameter
+expansion, command substitution and arithmetic expansion, it
+performs word splitting on the result. As each word is output,
+the routine expandmeta performs file name generation (if enabled).
VAR.C: Variables are stored in a hash table. Probably we should
switch to extensible hashing. The variable name is stored in the
tered throughout the code, depending on which location appears
most appropriate. They can be recognized because their names al-
ways end in "cmd". The mapping from names to procedures is
-specified in the file builtins, which is processed by the mkbuilt-
-ins command.
+specified in the file builtins.def, which is processed by the
+mkbuiltins command.
A builtin command is invoked with argc and argv set up like a
normal program. A builtin command is allowed to overwrite its
ing. This is kind of like getopt, but you don't pass argc and
argv to it. Builtin routines can also call error. This routine
normally terminates the shell (or returns to the main command
-loop if the shell is interactive), but when called from a builtin
-command it causes the builtin command to terminate with an exit
-status of 2.
+loop if the shell is interactive), but when called from a non-
+special builtin command it causes the builtin command to
+terminate with an exit status of 2.
The directory bltins contains commands which can be compiled in-
dependently but can also be built into the shell for efficiency
-reasons. The makefile in this directory compiles these programs
-in the normal fashion (so that they can be run regardless of
-whether the invoker is ash), but also creates a library named
-bltinlib.a which can be linked with ash. The header file bltin.h
-takes care of most of the differences between the ash and the
-stand-alone environment. The user should call the main routine
-"main", and #define main to be the name of the routine to use
-when the program is linked into ash. This #define should appear
-before bltin.h is included; bltin.h will #undef main if the pro-
-gram is to be compiled stand-alone.
+reasons. The header file bltin.h takes care of most of the
+differences between the ash and the stand-alone environment.
+The user should call the main routine "main", and #define main to
+be the name of the routine to use when the program is linked into
+ash. This #define should appear before bltin.h is included;
+bltin.h will #undef main if the program is to be compiled
+stand-alone. A similar approach is used for a few utilities from
+bin and usr.bin.
CD.C: This file defines the cd and pwd builtins.
When an interrupt is caught and no trap has been set for that
signal, the routine "onint" in error.c is called.
-OUTPUT: Ash uses it's own output routines. There are three out-
+OUTPUT: Ash uses its own output routines. There are three out-
put structures allocated. "Output" represents the standard out-
put, "errout" the standard error, and "memout" contains output
which is to be stored in memory. This last is used when a buil-
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/alias.c 295868 2016-02-21 20:58:24Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/alias.c 317039 2017-04-16 22:10:02Z jilles $");
#include <stdlib.h>
#include "shell.h"
#include "memalloc.h"
#include "mystring.h"
#include "alias.h"
-#include "options.h" /* XXX for argptr (should remove?) */
+#include "options.h"
#include "builtins.h"
#define ATABSIZE 39
{
struct alias *ap, **app;
+ unalias(name);
app = hashalias(name);
- for (ap = *app; ap; ap = ap->next) {
- if (equal(name, ap->name)) {
- INTOFF;
- ckfree(ap->val);
- ap->val = savestr(val);
- INTON;
- return;
- }
- }
- /* not found */
INTOFF;
ap = ckmalloc(sizeof (struct alias));
ap->name = savestr(name);
INTON;
}
+static void
+freealias(struct alias *ap)
+{
+ ckfree(ap->name);
+ ckfree(ap->val);
+ ckfree(ap);
+}
+
static int
unalias(const char *name)
{
else {
INTOFF;
*app = ap->next;
- ckfree(ap->name);
- ckfree(ap->val);
- ckfree(ap);
+ freealias(ap);
INTON;
}
aliases--;
static void
rmaliases(void)
{
- struct alias *ap, *tmp;
+ struct alias *ap, **app;
int i;
INTOFF;
for (i = 0; i < ATABSIZE; i++) {
- ap = atab[i];
- atab[i] = NULL;
- while (ap) {
- ckfree(ap->name);
- ckfree(ap->val);
- tmp = ap;
- ap = ap->next;
- ckfree(tmp);
+ app = &atab[i];
+ while (*app) {
+ ap = *app;
+ if (ap->flag & ALIASINUSE) {
+ *ap->name = '\0';
+ app = &(*app)->next;
+ } else {
+ *app = ap->next;
+ freealias(ap);
+ }
}
}
aliases = 0;
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)alias.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/alias.h 223060 2011-06-13 21:03:27Z jilles $
+ * $FreeBSD: head/bin/sh/alias.h 314436 2017-02-28 23:42:47Z imp $
*/
#define ALIASINUSE 1
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)arith.h 1.1 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/arith.h 223060 2011-06-13 21:03:27Z jilles $
+ * $FreeBSD: head/bin/sh/arith.h 315511 2017-03-18 20:41:07Z jilles $
*/
#include "shell.h"
#define DIGITS(var) (3 + (2 + CHAR_BIT * sizeof((var))) / 3)
arith_t arith(const char *);
-void arith_lex_reset(void);
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)bltin.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/bltin/bltin.h 279503 2015-03-01 21:46:55Z jilles $
+ * $FreeBSD: head/bin/sh/bltin/bltin.h 326025 2017-11-20 19:49:47Z pfg $
*/
/*
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/bltin/echo.c 127958 2004-04-06 20:06:54Z markm $");
+__FBSDID("$FreeBSD: head/bin/sh/bltin/echo.c 326025 2017-11-20 19:49:47Z pfg $");
/*
* Echo command.
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)builtins.def 8.4 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/builtins.def 288430 2015-09-30 21:32:29Z jilles $
+# $FreeBSD: head/bin/sh/builtins.def 319576 2017-06-04 21:02:48Z bdrewery $
#
# This file lists all the builtin commands. The first column is the name
# without job control.
# The -h flag specifies that this command is to be excluded from systems
# based on the NO_HISTORY compile-time symbol.
+# The -n flag specifies that this command can safely be run in the same
+# process when it is the only command in a command substitution. Some
+# commands have special logic defined in safe_builtin().
# The -s flag specifies that this is a POSIX 'special built-in' command.
# The rest of the line specifies the command name or names used to run the
# command. The entry for bltincmd, which is run when the user does not specify
#
# NOTE: bltincmd must come first!
-bltincmd builtin
+bltincmd -n builtin
aliascmd alias
bgcmd -j bg
bindcmd bind
breakcmd -s break -s continue
cdcmd cd chdir
-commandcmd command
+commandcmd -n command
dotcmd -s .
-echocmd echo
+echocmd -n echo
evalcmd -s eval
execcmd -s exec
exitcmd -s exit
letcmd let
exportcmd -s export -s readonly
#exprcmd expr
-falsecmd false
+falsecmd -n false
fgcmd -j fg
freebsd_wordexpcmd freebsd_wordexp
getoptscmd getopts
hashcmd hash
histcmd -h fc
-jobidcmd jobid
-jobscmd jobs
-killcmd kill
+jobidcmd -n jobid
+jobscmd -n jobs
+killcmd -n kill
localcmd local
-printfcmd printf
-pwdcmd pwd
+printfcmd -n printf
+pwdcmd -n pwd
readcmd read
returncmd -s return
setcmd -s set
setvarcmd setvar
shiftcmd -s shift
-testcmd test [
-timescmd -s times
+testcmd -n test [
+timescmd -n -s times
trapcmd -s trap
-truecmd -s : true
-typecmd type
+truecmd -n -s : true
+typecmd -n type
ulimitcmd ulimit
umaskcmd umask
unaliascmd unalias
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/cd.c 294667 2016-01-24 17:01:34Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/cd.c 320340 2017-06-25 21:53:08Z jilles $");
#include <sys/types.h>
#include <sys/stat.h>
if ((phys || (rc = cdlogical(dest)) < 0) && (rc = cdphysical(dest)) < 0)
return (-1);
- if (print && iflag && curdir)
+ if (print && iflag && curdir) {
out1fmt("%s\n", curdir);
+ /*
+ * Ignore write errors to preserve the invariant that the
+ * current directory is changed iff the exit status is 0
+ * (or 1 if -e was given and the full pathname could not be
+ * determined).
+ */
+ flushout(out1);
+ outclearerror(out1);
+ }
return (rc);
}
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/bin/sh/cd.h 223060 2011-06-13 21:03:27Z jilles $
+ * $FreeBSD: head/bin/sh/cd.h 314436 2017-02-28 23:42:47Z imp $
*/
void pwd_init(int);
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/error.c 279569 2015-03-03 21:21:43Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/error.c 314436 2017-02-28 23:42:47Z imp $");
/*
* Errors and exceptions.
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)error.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/error.h 276038 2014-12-21 23:09:59Z jilles $
+ * $FreeBSD: head/bin/sh/error.h 319591 2017-06-04 21:58:02Z jilles $
*/
/*
#define INTOFF suppressint++
#define INTON { if (--suppressint == 0 && intpending) onint(); }
#define is_int_on() suppressint
-#define SETINTON(s) suppressint = (s)
+#define SETINTON(s) do { suppressint = (s); if (suppressint == 0 && intpending) onint(); } while (0)
#define FORCEINTON {suppressint = 0; if (intpending) onint();}
#define SET_PENDING_INT intpending = 1
#define CLEAR_PENDING_INT intpending = 0
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/eval.c 293635 2016-01-10 16:31:28Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/eval.c 327212 2017-12-26 16:23:18Z jilles $");
#include <paths.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/resource.h>
-#include <sys/wait.h> /* For WIFSIGNALED(status) */
#include <errno.h>
/*
if (e == EXERROR || e == EXEXEC) {
if (in_redirect) {
exitstatus = 2;
+ FORCEINTON;
return;
}
}
static int
safe_builtin(int idx, int argc, char **argv)
{
- if (idx == BLTINCMD || idx == COMMANDCMD || idx == ECHOCMD ||
- idx == FALSECMD || idx == JOBIDCMD || idx == JOBSCMD ||
- idx == KILLCMD || idx == PRINTFCMD || idx == PWDCMD ||
- idx == TESTCMD || idx == TIMESCMD || idx == TRUECMD ||
- idx == TYPECMD)
+ /* Generated from builtins.def. */
+ if (safe_builtin_always(idx))
return (1);
if (idx == EXPORTCMD || idx == TRAPCMD || idx == ULIMITCMD ||
idx == UMASKCMD)
struct parsefile *savetopfile;
volatile int e;
char *lastarg;
- int realstatus;
+ int signaled;
int do_clearcmdentry;
const char *path = pathval();
int i;
#endif
mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
if (flags == EV_BACKCMD) {
- memout.nleft = 0;
memout.nextc = memout.buf;
- memout.bufsize = 64;
mode |= REDIR_BACKQ;
}
savecmdname = commandname;
exitshell(exitstatus);
if (flags == EV_BACKCMD) {
backcmd->buf = memout.buf;
- backcmd->nleft = memout.nextc - memout.buf;
+ backcmd->nleft = memout.buf != NULL ?
+ memout.nextc - memout.buf : 0;
memout.buf = NULL;
+ memout.nextc = NULL;
+ memout.bufend = NULL;
+ memout.bufsize = 64;
}
if (cmdentry.u.index != EXECCMD)
popredir();
parent: /* parent process gets here (if we forked) */
if (mode == FORK_FG) { /* argument to fork */
INTOFF;
- exitstatus = waitforjob(jp, &realstatus);
+ exitstatus = waitforjob(jp, &signaled);
INTON;
- if (iflag && loopnest > 0 && WIFSIGNALED(realstatus)) {
+ if (iflag && loopnest > 0 && signaled) {
evalskip = SKIPBREAK;
skipcount = loopnest;
}
return 127;
}
/*
- * Preserve exitstatus of a previous possible redirection
+ * Preserve exitstatus of a previous possible command substitution
* as POSIX mandates
*/
return exitstatus;
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)eval.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/eval.h 289159 2015-10-11 21:33:00Z jilles $
+ * $FreeBSD: head/bin/sh/eval.h 314436 2017-02-28 23:42:47Z imp $
*/
extern char *commandname; /* currently executing command */
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/exec.c 296813 2016-03-13 22:54:14Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/exec.c 317882 2017-05-06 13:28:42Z jilles $");
#include <sys/types.h>
#include <sys/stat.h>
#include "jobs.h"
#include "alias.h"
+
#ifdef __APPLE__
#define eaccess(path, mode) faccessat(AT_FDCWD, path, mode, AT_EACCESS)
#endif /* __APPLE__ */
cd = 0;
- /* If name is in the table, and not invalidated by cd, we're done */
+ /* If name is in the table, we're done */
if ((cmdp = cmdlookup(name, 0)) != NULL) {
if (cmdp->cmdtype == CMDFUNCTION && act & DO_NOFUNC)
cmdp = NULL;
/*
- * Clear out command entries. The argument specifies the first entry in
- * PATH which has changed.
+ * Clear out cached utility locations.
*/
void
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)exec.h 8.3 (Berkeley) 6/8/95
- * $FreeBSD: head/bin/sh/exec.h 238468 2012-07-15 10:19:43Z jilles $
+ * $FreeBSD: head/bin/sh/exec.h 314436 2017-02-28 23:42:47Z imp $
*/
/* values of cmdtype */
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/expand.c 303586 2016-07-31 13:11:34Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/expand.c 318269 2017-05-14 13:14:19Z jilles $");
#include <sys/types.h>
#include <sys/time.h>
};
static char *expdest; /* output of current string */
-static struct nodelist *argbackq; /* list of back quote expressions */
-static const char *argstr(const char *, int, struct worddest *);
+static const char *argstr(const char *, struct nodelist **restrict, int,
+ struct worddest *);
static const char *exptilde(const char *, int);
-static const char *expari(const char *, int, struct worddest *);
+static const char *expari(const char *, struct nodelist **restrict, int,
+ struct worddest *);
static void expbackq(union node *, int, int, struct worddest *);
-static void subevalvar_trim(const char *, int, int, int);
-static int subevalvar_misc(const char *, const char *, int, int, int);
-static const char *evalvar(const char *, int, struct worddest *);
+static const char *subevalvar_trim(const char *, struct nodelist **restrict,
+ int, int, int);
+static const char *subevalvar_misc(const char *, struct nodelist **restrict,
+ const char *, int, int, int);
+static const char *evalvar(const char *, struct nodelist **restrict, int,
+ struct worddest *);
static int varisset(const char *, int);
static void strtodest(const char *, int, int, int, struct worddest *);
static void reprocess(int, int, int, int, struct worddest *);
static int
collate_range_cmp(wchar_t c1, wchar_t c2)
{
- static wchar_t s1[2], s2[2];
+ wchar_t s1[2], s2[2];
s1[0] = c1;
+ s1[1] = L'\0';
s2[0] = c2;
+ s2[1] = L'\0';
return (wcscoll(s1, s2));
}
* The result is left in the stack string.
* When arglist is NULL, perform here document expansion.
*
- * Caution: this function uses global state and is not reentrant.
- * However, a new invocation after an interrupted invocation is safe
- * and will reset the global state for the new call.
+ * When doing something that may cause this to be re-entered, make sure
+ * the stack string is empty via grabstackstr() and do not assume expdest
+ * remains valid.
*/
void
expandarg(union node *arg, struct arglist *arglist, int flag)
{
struct worddest exparg;
+ struct nodelist *argbackq;
if (fflag)
flag &= ~EXP_GLOB;
exparg.list = arglist;
exparg.state = WORD_IDLE;
STARTSTACKSTR(expdest);
- argstr(arg->narg.text, flag, &exparg);
+ argstr(arg->narg.text, &argbackq, flag, &exparg);
if (arglist == NULL) {
STACKSTRNUL(expdest);
return; /* here document expanded */
* If EXP_SPLIT is set, dst receives any complete words produced.
*/
static const char *
-argstr(const char *p, int flag, struct worddest *dst)
+argstr(const char *p, struct nodelist **restrict argbackq, int flag,
+ struct worddest *dst)
{
char c;
int quotes = flag & (EXP_GLOB | EXP_CASE); /* do CTLESC */
USTPUTC(c, expdest);
break;
case CTLVAR:
- p = evalvar(p, flag, dst);
+ p = evalvar(p, argbackq, flag, dst);
break;
case CTLBACKQ:
case CTLBACKQ|CTLQUOTE:
- expbackq(argbackq->n, c & CTLQUOTE, flag, dst);
- argbackq = argbackq->next;
+ expbackq((*argbackq)->n, c & CTLQUOTE, flag, dst);
+ *argbackq = (*argbackq)->next;
break;
case CTLARI:
- p = expari(p, flag, dst);
+ p = expari(p, argbackq, flag, dst);
break;
case ':':
case '=':
* Expand arithmetic expression.
*/
static const char *
-expari(const char *p, int flag, struct worddest *dst)
+expari(const char *p, struct nodelist **restrict argbackq, int flag,
+ struct worddest *dst)
{
char *q, *start;
arith_t result;
quoted = *p++ == '"';
begoff = expdest - stackblock();
- p = argstr(p, 0, NULL);
+ p = argstr(p, argbackq, 0, NULL);
STPUTC('\0', expdest);
start = stackblock() + begoff;
fmtstr(expdest, DIGITS(result), ARITH_FORMAT_STR, result);
adj = strlen(expdest);
STADJUST(adj, expdest);
- if (!quoted)
- reprocess(expdest - adj - stackblock(), flag, VSNORMAL, 0, dst);
+ /*
+ * If this is quoted, a '-' must not indicate a range in [...].
+ * If this is not quoted, splitting may occur.
+ */
+ if (quoted ?
+ result < 0 && begoff > 1 && flag & (EXP_GLOB | EXP_CASE) :
+ flag & EXP_SPLIT)
+ reprocess(expdest - adj - stackblock(), flag, VSNORMAL, quoted,
+ dst);
return p;
}
char buf[128];
char *p;
char *dest = expdest;
- struct nodelist *saveargbackq;
char lastc;
char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
int quotes = flag & (EXP_GLOB | EXP_CASE);
size_t nnl;
const char *ifs;
+ int startloc;
INTOFF;
- saveargbackq = argbackq;
p = grabstackstr(dest);
evalbackcmd(cmd, &in);
ungrabstackstr(p, dest);
- argbackq = saveargbackq;
p = in.buf;
+ startloc = dest - stackblock();
nnl = 0;
if (!quoted && flag & EXP_SPLIT)
ifs = ifsset() ? ifsval() : " \t\n";
else
ifs = "";
- /* Don't copy trailing newlines */
+ /* Remove trailing newlines */
for (;;) {
if (--in.nleft < 0) {
if (in.fd < 0)
lastc = *p++;
if (lastc == '\0')
continue;
- if (lastc == '\n') {
- nnl++;
- } else {
- if (nnl > 0) {
- if (strchr(ifs, '\n') != NULL) {
- NEXTWORD('\n', flag, dest, dst);
- nnl = 0;
- } else {
- CHECKSTRSPACE(nnl + 2, dest);
- while (nnl > 0) {
- nnl--;
- USTPUTC('\n', dest);
- }
- }
- }
- if (strchr(ifs, lastc) != NULL)
+ if (nnl > 0 && lastc != '\n') {
+ NEXTWORD('\n', flag, dest, dst);
+ nnl = 0;
+ }
+ if (strchr(ifs, lastc) != NULL) {
+ if (lastc == '\n')
+ nnl++;
+ else
NEXTWORD(lastc, flag, dest, dst);
- else {
- CHECKSTRSPACE(2, dest);
- if (quotes && syntax[(int)lastc] == CCTL)
- USTPUTC(CTLESC, dest);
- USTPUTC(lastc, dest);
- }
+ } else {
+ CHECKSTRSPACE(2, dest);
+ if (quotes && syntax[(int)lastc] == CCTL)
+ USTPUTC(CTLESC, dest);
+ USTPUTC(lastc, dest);
}
}
+ while (dest > stackblock() + startloc && STTOPC(dest) == '\n')
+ STUNPUTC(dest);
if (in.fd >= 0)
close(in.fd);
if (in.buf)
ckfree(in.buf);
- if (in.jp)
+ if (in.jp) {
+ p = grabstackstr(dest);
exitstatus = waitforjob(in.jp, (int *)NULL);
- TRACE(("expbackq: size=%td: \"%.*s\"\n",
- ((dest - stackblock()) - startloc),
- (int)((dest - stackblock()) - startloc),
- stackblock() + startloc));
+ ungrabstackstr(p, dest);
+ }
+ TRACE(("expbackq: done\n"));
expdest = dest;
INTON;
}
*startp++ = *loc++;
}
-static void
-subevalvar_trim(const char *p, int strloc, int subtype, int startloc)
+static const char *
+subevalvar_trim(const char *p, struct nodelist **restrict argbackq, int strloc,
+ int subtype, int startloc)
{
char *startp;
char *loc = NULL;
char *str;
int c = 0;
- struct nodelist *saveargbackq = argbackq;
int amount;
- argstr(p, EXP_CASE | EXP_TILDE, NULL);
+ p = argstr(p, argbackq, EXP_CASE | EXP_TILDE, NULL);
STACKSTRNUL(expdest);
- argbackq = saveargbackq;
startp = stackblock() + startloc;
str = stackblock() + strloc;
if (patmatch(str, startp)) {
*loc = c;
recordleft(str, loc, startp);
- return;
+ return p;
}
*loc = c;
}
if (patmatch(str, startp)) {
*loc = c;
recordleft(str, loc, startp);
- return;
+ return p;
}
*loc = c;
loc--;
if (patmatch(str, loc)) {
amount = loc - expdest;
STADJUST(amount, expdest);
- return;
+ return p;
}
loc--;
}
if (patmatch(str, loc)) {
amount = loc - expdest;
STADJUST(amount, expdest);
- return;
+ return p;
}
}
break;
}
amount = (expdest - stackblock() - strloc) + 1;
STADJUST(-amount, expdest);
+ return p;
}
-static int
-subevalvar_misc(const char *p, const char *var, int subtype, int startloc,
- int varflags)
+static const char *
+subevalvar_misc(const char *p, struct nodelist **restrict argbackq,
+ const char *var, int subtype, int startloc, int varflags)
{
char *startp;
- struct nodelist *saveargbackq = argbackq;
int amount;
- argstr(p, EXP_TILDE, NULL);
+ p = argstr(p, argbackq, EXP_TILDE, NULL);
STACKSTRNUL(expdest);
- argbackq = saveargbackq;
startp = stackblock() + startloc;
switch (subtype) {
setvar(var, startp, 0);
amount = startp - expdest;
STADJUST(amount, expdest);
- return 1;
+ return p;
case VSQUESTION:
if (*p != CTLENDVAR) {
}
error("%.*s: parameter %snot set", (int)(p - var - 1),
var, (varflags & VSNUL) ? "null or " : "");
- return 0;
default:
abort();
*/
static const char *
-evalvar(const char *p, int flag, struct worddest *dst)
+evalvar(const char *p, struct nodelist **restrict argbackq, int flag,
+ struct worddest *dst)
{
int subtype;
int varflags;
if (! is_name(*p))
special = 1;
p = strchr(p, '=') + 1;
-again: /* jump here after setting a variable with ${var=text} */
if (varflags & VSLINENO) {
set = 1;
special = 1;
break;
case VSNORMAL:
- break;
+ return p;
case VSPLUS:
case VSMINUS:
if (!set) {
- argstr(p, flag | (flag & EXP_SPLIT ? EXP_SPLIT_LIT : 0) |
+ return argstr(p, argbackq,
+ flag | (flag & EXP_SPLIT ? EXP_SPLIT_LIT : 0) |
(varflags & VSQUOTE ? EXP_LIT_QUOTED : 0), dst);
- break;
}
break;
*/
STPUTC('\0', expdest);
patloc = expdest - stackblock();
- subevalvar_trim(p, patloc, subtype, startloc);
+ p = subevalvar_trim(p, argbackq, patloc, subtype, startloc);
reprocess(startloc, flag, VSNORMAL, varflags & VSQUOTE, dst);
if (flag & EXP_SPLIT && *var == '@' && varflags & VSQUOTE)
dst->state = WORD_QUOTEMARK;
- break;
+ return p;
case VSASSIGN:
case VSQUESTION:
if (!set) {
- if (subevalvar_misc(p, var, subtype, startloc,
- varflags)) {
- varflags &= ~VSNUL;
- goto again;
- }
- break;
+ p = subevalvar_misc(p, argbackq, var, subtype,
+ startloc, varflags);
+ /* assert(subtype == VSASSIGN); */
+ val = lookupvar(var);
+ strtodest(val, flag, subtype, varflags & VSQUOTE, dst);
+ return p;
}
break;
abort();
}
- if (subtype != VSNORMAL) { /* skip to end of alternative */
+ { /* skip to end of alternative */
int nesting = 1;
for (;;) {
if ((c = *p++) == CTLESC)
p++;
- else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) {
- if (set)
- argbackq = argbackq->next;
- } else if (c == CTLVAR) {
+ else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE))
+ *argbackq = (*argbackq)->next;
+ else if (c == CTLVAR) {
if ((*p++ & VSTYPE) != VSNORMAL)
nesting++;
} else if (c == CTLENDVAR) {
/*
- * Test whether a specialized variable is set.
+ * Test whether a special or positional parameter is set.
*/
static int
}
/*
- * Add the value of a specialized variable to the stack string.
+ * Add the value of a special or positional parameter to the stack string.
*/
static void
casematch(union node *pattern, const char *val)
{
struct stackmark smark;
+ struct nodelist *argbackq;
int result;
char *p;
setstackmark(&smark);
argbackq = pattern->narg.backquote;
STARTSTACKSTR(expdest);
- argstr(pattern->narg.text, EXP_TILDE | EXP_CASE, NULL);
+ argstr(pattern->narg.text, &argbackq, EXP_TILDE | EXP_CASE, NULL);
STPUTC('\0', expdest);
p = grabstackstr(expdest);
result = patmatch(p, val);
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)expand.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/expand.h 292994 2015-12-31 18:47:54Z jilles $
+ * $FreeBSD: head/bin/sh/expand.h 314436 2017-02-28 23:42:47Z imp $
*/
struct arglist {
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)cmv 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/funcs/cmv 139969 2005-01-10 08:39:26Z imp $
+# $FreeBSD: head/bin/sh/funcs/cmv 314436 2017-02-28 23:42:47Z imp $
# Conditional move--don't replace an existing file.
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)dirs 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/funcs/dirs 139969 2005-01-10 08:39:26Z imp $
+# $FreeBSD: head/bin/sh/funcs/dirs 314436 2017-02-28 23:42:47Z imp $
# pushd, popd, and dirs --- written by Chris Bertin
# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)login 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/funcs/login 139969 2005-01-10 08:39:26Z imp $
+# $FreeBSD: head/bin/sh/funcs/login 314436 2017-02-28 23:42:47Z imp $
# replaces the login builtin in the BSD shell
login () exec login "$@"
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)newgrp 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/funcs/newgrp 139969 2005-01-10 08:39:26Z imp $
+# $FreeBSD: head/bin/sh/funcs/newgrp 314436 2017-02-28 23:42:47Z imp $
newgrp() exec newgrp "$@"
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)popd 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/funcs/popd 139969 2005-01-10 08:39:26Z imp $
+# $FreeBSD: head/bin/sh/funcs/popd 314436 2017-02-28 23:42:47Z imp $
# pushd, popd, and dirs --- written by Chris Bertin
# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)pushd 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/funcs/pushd 139969 2005-01-10 08:39:26Z imp $
+# $FreeBSD: head/bin/sh/funcs/pushd 314436 2017-02-28 23:42:47Z imp $
# pushd, popd, and dirs --- written by Chris Bertin
# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)suspend 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/funcs/suspend 215268 2010-11-13 22:20:46Z jilles $
+# $FreeBSD: head/bin/sh/funcs/suspend 314436 2017-02-28 23:42:47Z imp $
suspend() {
local -
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/histedit.c 296429 2016-03-06 17:24:02Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/histedit.c 319635 2017-06-06 21:08:05Z jilles $");
#include <sys/param.h>
#include <limits.h>
char *editcmd;
fclose(efp);
+ INTON;
editcmd = stalloc(strlen(editor) + strlen(editfile) + 2);
sprintf(editcmd, "%s %s", editor, editfile);
evalstring(editcmd, 0); /* XXX - should use no JC command */
- INTON;
readcmdfile(editfile); /* XXX - should read back - quick tst */
unlink(editfile);
}
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/input.c 295937 2016-02-23 22:44:01Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/input.c 314436 2017-02-28 23:42:47Z imp $");
#include <stdio.h> /* defines BUFSIZ */
#include <fcntl.h>
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)input.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/input.h 271593 2014-09-14 16:46:30Z jilles $
+ * $FreeBSD: head/bin/sh/input.h 314436 2017-02-28 23:42:47Z imp $
*/
/* PEOF (the end of file marker) is defined in syntax.h */
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/jobs.c 296326 2016-03-02 21:24:46Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/jobs.c 328818 2018-02-02 22:53:58Z jilles $");
#include <sys/ioctl.h>
#include <sys/param.h>
#include "builtins.h"
+/*
+ * A job structure contains information about a job. A job is either a
+ * single process or a set of processes contained in a pipeline. In the
+ * latter case, pidlist will be non-NULL, and will point to a -1 terminated
+ * array of pids.
+ */
+
+struct procstat {
+ pid_t pid; /* process id */
+ int status; /* status flags (defined above) */
+ char *cmd; /* text of command being run */
+};
+
+
+/* states */
+#define JOBSTOPPED 1 /* all procs are stopped */
+#define JOBDONE 2 /* all procs are completed */
+
+
+struct job {
+ struct procstat ps0; /* status of process */
+ struct procstat *ps; /* status or processes when more than one */
+ short nprocs; /* number of processes */
+ pid_t pgrp; /* process group of this job */
+ char state; /* true if job is finished */
+ char used; /* true if this entry is in used */
+ char changed; /* true if status has changed */
+ char foreground; /* true if running in the foreground */
+ char remembered; /* true if $! referenced */
+#if JOBS
+ char jobctl; /* job running under job control */
+ struct job *next; /* job used after this one */
+#endif
+};
+
+
static struct job *jobtab; /* array of jobs */
static int njobs; /* size of array */
static pid_t backgndpid = -1; /* pid of last background process */
const char *statestr, *coredump;
struct procstat *ps;
struct job *j;
- int col, curr, i, jobno, prev, procno;
+ int col, curr, i, jobno, prev, procno, status;
char c;
procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs;
}
#endif
coredump = "";
- ps = jp->ps + jp->nprocs - 1;
+ status = jp->ps[jp->nprocs - 1].status;
if (jp->state == 0) {
statestr = "Running";
#if JOBS
} else if (jp->state == JOBSTOPPED) {
+ ps = jp->ps + jp->nprocs - 1;
while (!WIFSTOPPED(ps->status) && ps > jp->ps)
ps--;
if (WIFSTOPPED(ps->status))
if (statestr == NULL)
statestr = "Suspended";
#endif
- } else if (WIFEXITED(ps->status)) {
- if (WEXITSTATUS(ps->status) == 0)
+ } else if (WIFEXITED(status)) {
+ if (WEXITSTATUS(status) == 0)
statestr = "Done";
else {
fmtstr(statebuf, sizeof(statebuf), "Done(%d)",
- WEXITSTATUS(ps->status));
+ WEXITSTATUS(status));
statestr = statebuf;
}
} else {
- i = WTERMSIG(ps->status);
+ i = WTERMSIG(status);
statestr = strsignal(i);
if (statestr == NULL)
statestr = "Unknown signal";
- if (WCOREDUMP(ps->status))
+ if (WCOREDUMP(status))
coredump = " (core dumped)";
}
*/
int
-waitforjob(struct job *jp, int *origstatus)
+waitforjob(struct job *jp, int *signaled)
{
#if JOBS
int propagate_int = jp->jobctl && jp->foreground;
setcurjob(jp);
#endif
status = jp->ps[jp->nprocs - 1].status;
- if (origstatus != NULL)
- *origstatus = status;
+ if (signaled != NULL)
+ *signaled = WIFSIGNALED(status);
/* convert to 8 bits */
if (WIFEXITED(status))
st = WEXITSTATUS(status);
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)jobs.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/jobs.h 255157 2013-09-02 21:57:46Z jilles $
+ * $FreeBSD: head/bin/sh/jobs.h 327475 2018-01-01 22:31:52Z jilles $
*/
/* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */
#include <signal.h> /* for sig_atomic_t */
-/*
- * A job structure contains information about a job. A job is either a
- * single process or a set of processes contained in a pipeline. In the
- * latter case, pidlist will be non-NULL, and will point to a -1 terminated
- * array of pids.
- */
-
-struct procstat {
- pid_t pid; /* process id */
- int status; /* status flags (defined above) */
- char *cmd; /* text of command being run */
-};
-
-
-/* states */
-#define JOBSTOPPED 1 /* all procs are stopped */
-#define JOBDONE 2 /* all procs are completed */
-
-
-struct job {
- struct procstat ps0; /* status of process */
- struct procstat *ps; /* status or processes when more than one */
- short nprocs; /* number of processes */
- pid_t pgrp; /* process group of this job */
- char state; /* true if job is finished */
- char used; /* true if this entry is in used */
- char changed; /* true if status has changed */
- char foreground; /* true if running in the foreground */
- char remembered; /* true if $! referenced */
-#if JOBS
- char jobctl; /* job running under job control */
- struct job *next; /* job used after this one */
-#endif
-};
+struct job;
enum {
SHOWJOBS_DEFAULT, /* job number, status, command */
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/mail.c 278820 2015-02-15 21:47:43Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/mail.c 314436 2017-02-28 23:42:47Z imp $");
/*
* Routines to check for mail. (Perhaps make part of main.c?)
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)mail.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/mail.h 127958 2004-04-06 20:06:54Z markm $
+ * $FreeBSD: head/bin/sh/mail.h 326025 2017-11-20 19:49:47Z pfg $
*/
void chkmail(int);
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/main.c 265772 2014-05-09 13:27:30Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/main.c 326025 2017-11-20 19:49:47Z pfg $");
#include <stdio.h>
#include <signal.h>
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)main.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/main.h 229220 2012-01-01 22:17:12Z jilles $
+ * $FreeBSD: head/bin/sh/main.h 326025 2017-11-20 19:49:47Z pfg $
*/
extern int rootpid; /* pid of main shell */
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/memalloc.c 278818 2015-02-15 21:41:29Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/memalloc.c 326025 2017-11-20 19:49:47Z pfg $");
#include <sys/param.h>
#include "shell.h"
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)memalloc.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/memalloc.h 278818 2015-02-15 21:41:29Z jilles $
+ * $FreeBSD: head/bin/sh/memalloc.h 326025 2017-11-20 19:49:47Z pfg $
*/
#include <string.h>
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/miscbltin.c 301452 2016-06-05 16:09:31Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/miscbltin.c 326025 2017-11-20 19:49:47Z pfg $");
/*
* Miscellaneous builtins.
const char *name;
const char *units;
int cmd;
- int factor; /* multiply by to get rlim_{cur,max} values */
+ short factor; /* multiply by to get rlim_{cur,max} values */
char option;
};
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)mkbuiltins 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/mkbuiltins 293118 2016-01-03 21:30:22Z jilles $
+# $FreeBSD: head/bin/sh/mkbuiltins 328934 2018-02-06 15:41:35Z arichardson $
-temp=`/usr/bin/mktemp -t ka`
+temp=`mktemp -t ka`
havehist=1
if [ "X$1" = "X-h" ]; then
havehist=0
awk '{ for (i = 2 ; i <= NF ; i++) {
if ($i == "-s") {
spc = 1;
+ } else if ($i == "-n") {
+ # Handled later for builtins.h
+ continue
} else {
printf "\t\"\\%03o\\%03o%s\"\n", length($i), (spc ? 128 : 0) + NR-1, $i
spc = 0;
extern const unsigned char builtincmd[];
'
awk '{ printf "int %s(int, char **);\n", $1}' $temp
+
+# Build safe_builtin_always()
+cat <<EOF
+
+static inline int
+safe_builtin_always(int idx)
+{
+EOF
+awk '
+BEGIN { printed = 0 }
+{
+ for (i = 2 ; i <= NF ; i++) {
+ if ($i == "-s") {
+ continue
+ } else if ($i == "-n") {
+ nofork = 1;
+ } else {
+ if (nofork == 0) {
+ continue
+ }
+ if (printed == 1) {
+ printf " || \n\t "
+ } else {
+ printf "\tif ("
+ }
+ printf "idx == " toupper($1)
+ printed = 1
+ nofork = 0;
+ # Only need to check each once
+ break
+ }
+ }
+}' $temp
+
+cat << EOF
+)
+ return (1);
+ return(0);
+}
+EOF
+
rm -f $temp
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif /* not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/mknodes.c 292517 2015-12-20 16:40:36Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/mknodes.c 326025 2017-11-20 19:49:47Z pfg $");
/*
* This program reads the nodetypes file and nodes.c.pat file. It generates
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif /* not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/mksyntax.c 279569 2015-03-03 21:21:43Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/mksyntax.c 326025 2017-11-20 19:49:47Z pfg $");
/*
* This program creates syntax.h and syntax.c.
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)mktokens 8.1 (Berkeley) 5/31/93
-# $FreeBSD: head/bin/sh/mktokens 279503 2015-03-01 21:46:55Z jilles $
+# $FreeBSD: head/bin/sh/mktokens 328934 2018-02-06 15:41:35Z arichardson $
# The following is a list of tokens. The second column is nonzero if the
# token marks the end of a list. The third column is the name to print in
# error messages.
-temp=`/usr/bin/mktemp -t ka`
+temp=`mktemp -t ka`
cat > $temp <<\!
TEOF 1 end of file
TNL 0 newline
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)myhistedit.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/myhistedit.h 229220 2012-01-01 22:17:12Z jilles $
+ * $FreeBSD: head/bin/sh/myhistedit.h 326025 2017-11-20 19:49:47Z pfg $
*/
#include <histedit.h>
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/mystring.c 270102 2014-08-17 16:40:29Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/mystring.c 326025 2017-11-20 19:49:47Z pfg $");
/*
* String functions.
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)mystring.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/mystring.h 268920 2014-07-20 12:06:52Z jilles $
+ * $FreeBSD: head/bin/sh/mystring.h 326025 2017-11-20 19:49:47Z pfg $
*/
#include <string.h>
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)nodes.c.pat 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/nodes.c.pat 291267 2015-11-24 22:47:19Z jilles $
+ * $FreeBSD: head/bin/sh/nodes.c.pat 314436 2017-02-28 23:42:47Z imp $
*/
#include <sys/param.h>
# 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.
-# 4. Neither the name of the University nor the names of its contributors
+# 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.
#
# SUCH DAMAGE.
#
# @(#)nodetypes 8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/nodetypes 278820 2015-02-15 21:47:43Z jilles $
+# $FreeBSD: head/bin/sh/nodetypes 314436 2017-02-28 23:42:47Z imp $
# This file describes the nodes used in parse trees. Unindented lines
# contain a node type followed by a structure tag. Subsequent indented
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/options.c 296577 2016-03-09 21:00:57Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/options.c 326025 2017-11-20 19:49:47Z pfg $");
#include <signal.h>
#include <unistd.h>
void
optschanged(void)
{
- setinteractive(iflag);
+ setinteractive();
#ifndef NO_HISTORY
histedit();
#endif
/*
* Process shell options. The global variable argptr contains a pointer
* to the argument list; we advance it past the options.
+ * If cmdline is true, process the shell's argv; otherwise, process arguments
+ * to the set special builtin.
*/
static void
while ((c = *p++) != '\0') {
if (c == 'c' && cmdline) {
char *q;
-#ifdef NOHACK /* removing this code allows sh -ce 'foo' for compat */
- if (*p == '\0')
-#endif
- q = *argptr++;
+
+ q = *argptr++;
if (q == NULL || minusc != NULL)
error("Bad -c option");
minusc = q;
-#ifdef NOHACK
- break;
-#endif
} else if (c == 'o') {
minus_o(*argptr, val);
if (*argptr)
/*
- * The set command builtin.
+ * The set builtin command.
*/
int
/*
* Standard option processing (a la getopt) for builtin routines. The
* only argument that is passed to nextopt is the option string; the
- * other arguments are unnecessary. It return the character, or '\0' on
+ * other arguments are unnecessary. It returns the option, or '\0' on
* end of input.
*/
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)options.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/options.h 294348 2016-01-19 22:41:26Z jilles $
+ * $FreeBSD: head/bin/sh/options.h 326025 2017-11-20 19:49:47Z pfg $
*/
struct shparam {
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/output.c 275766 2014-12-14 16:26:19Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/output.c 326025 2017-11-20 19:49:47Z pfg $");
/*
* Shell output routines. We use our own output routines because:
static int doformat_wr(void *, const char *, int);
-struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};
-struct output errout = {NULL, 0, NULL, 256, 2, 0};
-struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};
+struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0};
+struct output errout = {NULL, NULL, NULL, 256, 2, 0};
+struct output memout = {NULL, NULL, NULL, 64, MEM_OUT, 0};
struct output *out1 = &output;
struct output *out2 = &errout;
void
emptyoutbuf(struct output *dest)
{
- int offset;
+ int offset, newsize;
if (dest->buf == NULL) {
INTOFF;
dest->buf = ckmalloc(dest->bufsize);
dest->nextc = dest->buf;
- dest->nleft = dest->bufsize;
+ dest->bufend = dest->buf + dest->bufsize;
INTON;
} else if (dest->fd == MEM_OUT) {
- offset = dest->bufsize;
+ offset = dest->nextc - dest->buf;
+ newsize = dest->bufsize << 1;
INTOFF;
- dest->bufsize <<= 1;
- dest->buf = ckrealloc(dest->buf, dest->bufsize);
- dest->nleft = dest->bufsize - offset;
+ dest->buf = ckrealloc(dest->buf, newsize);
+ dest->bufsize = newsize;
+ dest->bufend = dest->buf + newsize;
dest->nextc = dest->buf + offset;
INTON;
} else {
flushout(dest);
}
- dest->nleft--;
}
if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0)
dest->flags |= OUTPUT_ERR;
dest->nextc = dest->buf;
- dest->nleft = dest->bufsize;
}
void
freestdout(void)
{
- INTOFF;
- if (output.buf) {
- ckfree(output.buf);
- output.buf = NULL;
- output.nleft = 0;
- }
- INTON;
+ output.nextc = output.buf;
}
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)output.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/output.h 244162 2012-12-12 22:01:10Z jilles $
+ * $FreeBSD: head/bin/sh/output.h 326025 2017-11-20 19:49:47Z pfg $
*/
#ifndef OUTPUT_INCL
struct output {
char *nextc;
- int nleft;
+ char *bufend;
char *buf;
int bufsize;
short fd;
void doformat(struct output *, const char *, va_list) __printflike(2, 0);
int xwrite(int, const char *, int);
-#define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
+#define outc(c, file) ((file)->nextc == (file)->bufend ? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
#define out1c(c) outc(c, out1);
#define out2c(c) outcslow(c, out2);
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/parser.c 301139 2016-06-01 16:56:29Z truckman $");
+__FBSDID("$FreeBSD: head/bin/sh/parser.c 326025 2017-11-20 19:49:47Z pfg $");
#include <stdlib.h>
#include <unistd.h>
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)parser.h 8.3 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/parser.h 288430 2015-09-30 21:32:29Z jilles $
+ * $FreeBSD: head/bin/sh/parser.h 326025 2017-11-20 19:49:47Z pfg $
*/
/* control characters in argument strings */
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/redir.c 295085 2016-01-30 21:21:25Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/redir.c 326025 2017-11-20 19:49:47Z pfg $");
#include <sys/types.h>
#include <sys/stat.h>
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)redir.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/redir.h 254426 2013-08-16 20:24:41Z jilles $
+ * $FreeBSD: head/bin/sh/redir.h 326025 2017-11-20 19:49:47Z pfg $
*/
/* flags passed to redirect */
.\" 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.
-.\" 4. Neither the name of the University nor the names of its contributors
+.\" 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.
.\"
.\" SUCH DAMAGE.
.\"
.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95
-.\" $FreeBSD: head/bin/sh/sh.1 306843 2016-10-08 13:40:12Z jilles $
+.\" $FreeBSD: head/bin/sh/sh.1 327121 2017-12-23 22:58:19Z jilles $
.\"
.Dd October 8, 2016
.Dt SH 1
variable subjected to parameter expansion and arithmetic expansion)
to standard error before it is executed.
Useful for debugging.
-.It nolog
+.It Li nolog
Another do-nothing option for
.Tn POSIX
compliance.
command is:
.Bd -unfilled -offset indent -compact
.Ic case Ar word Ic in
-.Ar pattern Ns Li ) Ar list Li ;;
+.Ar pattern ) Ar list Li ;;
.Ar ...
.Ic esac
.Ed
cannot be determined reliably or at all.
Normally this is not considered an error,
although a warning is printed.
+.Pp
+If changing the directory fails, the exit status is greater than 1.
+If the directory is changed, the exit status is 0, or also 1 if
+.Fl e
+was given.
.It Ic chdir
A synonym for the
.Ic cd
If no operands are given, wait for all jobs to complete
and return an exit status of zero.
.El
-.Ss Commandline Editing
+.Ss Command Line Editing
When
.Nm
is being used interactively from a terminal, the current command
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)shell.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/shell.h 253658 2013-07-25 19:48:15Z jilles $
+ * $FreeBSD: head/bin/sh/shell.h 326025 2017-11-20 19:49:47Z pfg $
*/
#ifndef SHELL_H_
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/show.c 258776 2013-11-30 21:27:11Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/show.c 326025 2017-11-20 19:49:47Z pfg $");
#include <fcntl.h>
#include <stdio.h>
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1995
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)show.h 1.1 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/show.h 200956 2009-12-24 18:41:14Z jilles $
+ * $FreeBSD: head/bin/sh/show.h 326025 2017-11-20 19:49:47Z pfg $
*/
void showtree(union node *);
-# $FreeBSD: head/bin/sh/tests/Makefile 299094 2016-05-04 23:20:53Z ngie $
+# $FreeBSD: head/bin/sh/tests/Makefile 322438 2017-08-12 19:17:48Z jilles $
.include <bsd.own.mk>
TESTS_SUBDIRS+= errors
TESTS_SUBDIRS+= execution
TESTS_SUBDIRS+= expansion
+TESTS_SUBDIRS+= invocation
TESTS_SUBDIRS+= parameters
TESTS_SUBDIRS+= parser
TESTS_SUBDIRS+= set-e
-# $FreeBSD: head/bin/sh/tests/builtins/Makefile 305305 2016-09-02 21:13:46Z jilles $
+# $FreeBSD: head/bin/sh/tests/builtins/Makefile 320340 2017-06-25 21:53:08Z jilles $
PACKAGE= tests
${PACKAGE}FILES+= case18.0
${PACKAGE}FILES+= case19.0
${PACKAGE}FILES+= case20.0
+${PACKAGE}FILES+= case21.0
+${PACKAGE}FILES+= case22.0
${PACKAGE}FILES+= cd1.0
${PACKAGE}FILES+= cd2.0
${PACKAGE}FILES+= cd3.0
${PACKAGE}FILES+= cd7.0
${PACKAGE}FILES+= cd8.0
${PACKAGE}FILES+= cd9.0 cd9.0.stdout
+${PACKAGE}FILES+= cd10.0
${PACKAGE}FILES+= command1.0
${PACKAGE}FILES+= command2.0
${PACKAGE}FILES+= command3.0
.if ${MK_NLS} != "no"
${PACKAGE}FILES+= locale1.0
.endif
+${PACKAGE}FILES+= locale2.0
${PACKAGE}FILES+= printf1.0
${PACKAGE}FILES+= printf2.0
${PACKAGE}FILES+= printf3.0
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/builtins/case21.0 318258 2017-05-13 20:28:32Z jilles $
+
+case 5 in
+[0$((-9))]) ;;
+*) echo bad1 ;;
+esac
+
+case - in
+[0$((-9))]) echo bad2 ;;
+esac
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/builtins/case22.0 318269 2017-05-14 13:14:19Z jilles $
+
+case 5 in
+[0"$((-9))"]) echo bad1 ;;
+esac
+
+case - in
+[0"$((-9))"]) ;;
+*) echo bad2 ;;
+esac
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/builtins/cd10.0 320340 2017-06-25 21:53:08Z jilles $
+
+# Precondition
+(cd /bin) || exit
+# Verify write error is ignored.
+$SH +m -ic 'CDPATH=/:; cd bin 1</dev/null'
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/builtins/locale2.0 317912 2017-05-07 19:49:46Z jilles $
+
+$SH -c 'LC_ALL=C true; kill -INT $$; echo continued'
+r=$?
+[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ]
-# $FreeBSD: head/bin/sh/tests/builtins/var-assign.0 213738 2010-10-12 18:20:38Z obrien $
+# $FreeBSD: head/bin/sh/tests/builtins/var-assign.0 327281 2017-12-28 08:22:26Z eadler $
IFS=,
SPECIAL="break,\
${SH} -c "VAR=1; VAR=0 ${cmd}; exit \${VAR}" >/dev/null 2>&1
done
-# For other built-ins and utilites they do not.
+# For other built-ins and utilities they do not.
set -- ${UTILS}
for cmd in "$@"
do
-# $FreeBSD: head/bin/sh/tests/errors/Makefile 299094 2016-05-04 23:20:53Z ngie $
+# $FreeBSD: head/bin/sh/tests/errors/Makefile 319575 2017-06-04 20:52:55Z jilles $
PACKAGE= tests
${PACKAGE}FILES+= redirection-error5.0
${PACKAGE}FILES+= redirection-error6.0
${PACKAGE}FILES+= redirection-error7.0
+${PACKAGE}FILES+= redirection-error8.0
${PACKAGE}FILES+= write-error1.0
.include <bsd.test.mk>
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/errors/redirection-error8.0 319575 2017-06-04 20:52:55Z jilles $
+
+$SH -c '{ { :; } </var/empty/x; } 2>/dev/null || kill -INT $$; echo continued'
+r=$?
+[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ]
-# $FreeBSD: head/bin/sh/tests/execution/Makefile 299094 2016-05-04 23:20:53Z ngie $
+# $FreeBSD: head/bin/sh/tests/execution/Makefile 308229 2016-11-02 22:33:37Z jilles $
PACKAGE= tests
${PACKAGE}FILES+= redir5.0
${PACKAGE}FILES+= redir6.0
${PACKAGE}FILES+= redir7.0
+${PACKAGE}FILES+= set-C1.0
${PACKAGE}FILES+= set-n1.0
${PACKAGE}FILES+= set-n2.0
${PACKAGE}FILES+= set-n3.0
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/execution/set-C1.0 308229 2016-11-02 22:33:37Z jilles $
+
+T=$(mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX") || exit
+trap 'rm -rf "$T"' 0
+
+set -C
+echo . >"$T/a" &&
+[ -s "$T/a" ] &&
+{ ! true >"$T/a"; } 2>/dev/null &&
+[ -s "$T/a" ] &&
+ln -s /dev/null "$T/b" &&
+true >"$T/b"
-# $FreeBSD: head/bin/sh/tests/expansion/Makefile 302937 2016-07-16 13:26:18Z ache $
+# $FreeBSD: head/bin/sh/tests/expansion/Makefile 317514 2017-04-27 18:52:18Z jilles $
PACKAGE= tests
${PACKAGE}FILES+= cmdsubst15.0
${PACKAGE}FILES+= cmdsubst16.0
${PACKAGE}FILES+= cmdsubst17.0
+${PACKAGE}FILES+= cmdsubst18.0
+${PACKAGE}FILES+= cmdsubst19.0
+${PACKAGE}FILES+= cmdsubst20.0
+${PACKAGE}FILES+= cmdsubst21.0
+${PACKAGE}FILES+= cmdsubst22.0
+${PACKAGE}FILES+= cmdsubst23.0
+${PACKAGE}FILES+= cmdsubst24.0
+${PACKAGE}FILES+= cmdsubst25.0
+${PACKAGE}FILES+= cmdsubst26.0
${PACKAGE}FILES+= export1.0
${PACKAGE}FILES+= export2.0
${PACKAGE}FILES+= export3.0
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst18.0 314637 2017-03-03 22:46:20Z jilles $
+
+x=X
+unset n
+r=${x+$(echo a)}${x-$(echo b)}${n+$(echo c)}${n-$(echo d)}$(echo e)
+[ "$r" = aXde ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst19.0 314637 2017-03-03 22:46:20Z jilles $
+
+b=200 c=30 d=5 x=4
+r=$(echo a)$(($(echo b) + ${x+$(echo c)} + ${x-$(echo d)}))$(echo e)
+[ "$r" = a234e ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst20.0 314637 2017-03-03 22:46:20Z jilles $
+
+set -T
+trapped=''
+trap "trapped=x$trapped" USR1
+[ "x$(kill -USR1 $$)y" = xy ] && [ "$trapped" = x ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst21.0 314686 2017-03-04 22:58:34Z jilles $
+
+set -T
+trapped=''
+trap "trapped=x$trapped" TERM
+[ "x$($SH -c "kill $$")y" = xy ] && [ "$trapped" = x ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst22.0 314686 2017-03-04 22:58:34Z jilles $
+
+set -T
+trapped=''
+trap "trapped=x$trapped" TERM
+[ "x$(:; kill $$)y" = xy ] && [ "$trapped" = x ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst23.0 315005 2017-03-10 16:04:00Z jilles $
+
+unset n
+x=abcd
+[ "X${n#$(echo a)}X${x#$(echo ab)}X$(echo abc)X" = XXcdXabcX ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst24.0 317347 2017-04-23 21:58:17Z jilles $
+# POSIX leaves the effect of NUL bytes in command substitution output
+# unspecified but we have always discarded them.
+
+failures=0
+
+check() {
+ if [ "$2" != "$3" ]; then
+ printf "Failed at line %s: got \"%s\" expected \"%s\"\n" "$1" "$2" "$3"
+ : $((failures += 1))
+ fi
+}
+
+fmt='\0a\0 \0b\0c d\0'
+assign_builtin=$(printf "$fmt")
+check "$LINENO" "$assign_builtin" "a bc d"
+assign_pipeline=$(printf "$fmt" | cat)
+check "$LINENO" "$assign_pipeline" "a bc d"
+set -- $(printf "$fmt") $(printf "$fmt" | cat) "$(printf "$fmt")" "$(printf "$fmt" | cat)"
+IFS=@
+splits="$*"
+check "$LINENO" "$splits" "a@bc@d@a@bc@d@a bc d@a bc d"
+
+[ "$failures" = 0 ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst25.0 317514 2017-04-27 18:52:18Z jilles $
+
+IFS=' '
+set -- `printf '\n '`
+IFS=:
+[ "$*" = '
+' ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst26.0 317514 2017-04-27 18:52:18Z jilles $
+
+nl='
+'
+v=$nl`printf '\n'`
+[ "$v" = "$nl" ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/invocation/Makefile 322455 2017-08-13 14:36:10Z jilles $
+
+PACKAGE= tests
+
+TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
+
+.PATH: ${.CURDIR:H}
+ATF_TESTS_SH= functional_test
+
+${PACKAGE}FILES+= sh-ac1.0
+${PACKAGE}FILES+= sh-c-missing1.0
+${PACKAGE}FILES+= sh-c1.0
+${PACKAGE}FILES+= sh-ca1.0
+${PACKAGE}FILES+= sh-fca1.0
+
+.include <bsd.test.mk>
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/invocation/Makefile.depend 325187 2017-10-31 00:04:07Z bdrewery $
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/invocation/sh-ac1.0 322438 2017-08-12 19:17:48Z jilles $
+# Test that attached options before c are processed
+
+case `${SH} -ac 'echo $-:$0' moo` in
+*a*:moo) true ;;
+*) false ;;
+esac
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/invocation/sh-c-missing1.0 322455 2017-08-13 14:36:10Z jilles $
+
+! echo echo bad | ${SH} -c 2>/dev/null
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/invocation/sh-c1.0 322438 2017-08-12 19:17:48Z jilles $
+# Test that -c executes command_string with the given name and arg
+
+${SH} -c 'echo $0 $@' moo foo | grep -qx -- "moo foo"
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/invocation/sh-ca1.0 322438 2017-08-12 19:17:48Z jilles $
+# Test that attached options after c are processed
+
+case `${SH} -ca 'echo $-:$0' moo` in
+*a*:moo) true ;;
+*) false ;;
+esac
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/invocation/sh-fca1.0 322438 2017-08-12 19:17:48Z jilles $
+# Test that attached options before and after c are processed
+
+case `${SH} -fca 'echo $-:$-:$0:$@' foo -bar` in
+*f*:*a*:foo:-bar) true ;;
+*) false ;;
+esac
-# $FreeBSD: head/bin/sh/tests/parser/Makefile 299094 2016-05-04 23:20:53Z ngie $
+# $FreeBSD: head/bin/sh/tests/parser/Makefile 317039 2017-04-16 22:10:02Z jilles $
PACKAGE= tests
${PACKAGE}FILES+= alias13.0
${PACKAGE}FILES+= alias14.0
${PACKAGE}FILES+= alias15.0 alias15.0.stdout
+${PACKAGE}FILES+= alias16.0
+${PACKAGE}FILES+= alias17.0
+${PACKAGE}FILES+= alias18.0
${PACKAGE}FILES+= and-pipe-not.0
${PACKAGE}FILES+= case1.0
${PACKAGE}FILES+= case2.0
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/parser/alias16.0 316646 2017-04-08 21:57:59Z jilles $
+
+v=1
+alias a='unalias a
+v=2'
+eval a
+[ "$v" = 2 ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/parser/alias17.0 317037 2017-04-16 21:42:43Z jilles $
+
+v=1
+alias a='unalias -a
+v=2'
+eval a
+[ "$v" = 2 ]
--- /dev/null
+# $FreeBSD: head/bin/sh/tests/parser/alias18.0 317039 2017-04-16 22:10:02Z jilles $
+
+v=1
+alias a='alias a=v=2
+v=3
+a'
+eval a
+[ "$v" = 2 ]
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/trap.c 297360 2016-03-28 18:58:40Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/trap.c 326025 2017-11-20 19:49:47Z pfg $");
#include <signal.h>
#include <unistd.h>
/*
- * Controls whether the shell is interactive or not.
+ * Controls whether the shell is interactive or not based on iflag.
*/
void
-setinteractive(int on)
+setinteractive(void)
{
- static int is_interactive = -1;
-
- if (on == is_interactive)
- return;
setsignal(SIGINT);
setsignal(SIGQUIT);
setsignal(SIGTERM);
- is_interactive = on;
}
*/
evalskip = 0;
trap[0] = NULL;
+ FORCEINTON;
evalstring(p, 0);
}
}
if (!setjmp(loc2.loc)) {
handler = &loc2; /* probably unnecessary */
+ FORCEINTON;
flushall();
#if JOBS
setjobctl(0);
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)trap.h 8.3 (Berkeley) 6/5/95
- * $FreeBSD: head/bin/sh/trap.h 276038 2014-12-21 23:09:59Z jilles $
+ * $FreeBSD: head/bin/sh/trap.h 326025 2017-11-20 19:49:47Z pfg $
*/
extern volatile sig_atomic_t pendingsig;
int issigchldtrapped(void);
void onsig(int);
void dotrap(void);
-void setinteractive(int);
+void setinteractive(void);
void exitshell(int) __dead2;
void exitshell_savedstatus(void) __dead2;
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/var.c 306843 2016-10-08 13:40:12Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/var.c 329221 2018-02-13 16:48:57Z bdrewery $");
#include <unistd.h>
#include <stdlib.h>
#endif
+#ifndef VTABSIZE
#define VTABSIZE 39
+#endif
struct varinit {
if (localevar(cmdenviron->args[i])) {
setlocale(LC_ALL, "");
updatecharset();
- return;
+ break;
}
}
INTON;
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
*
* SUCH DAMAGE.
*
* @(#)var.h 8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/var.h 289159 2015-10-11 21:33:00Z jilles $
+ * $FreeBSD: head/bin/sh/var.h 326025 2017-11-20 19:49:47Z pfg $
*/
/*
FC80BF5714A05A2F00C6F7F5 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0430;
+ LastUpgradeCheck = 1100;
ORGANIZATIONNAME = "Apple Inc.";
TargetAttributes = {
FD6060B11B7C0388004BCA6A = {
};
buildConfigurationList = FC80BF5A14A05A2F00C6F7F5 /* Build configuration list for PBXProject "shell_cmds" */;
compatibilityVersion = "Xcode 3.2";
- developmentRegion = English;
+ developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
+ Base,
);
mainGroup = FC80BF5514A05A2F00C6F7F5;
productRefGroup = FC80BF6114A05A2F00C6F7F5 /* Products */;
C686857D154725700025D623 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /usr/local/bin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FC5D638A14B9819E00123E48 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FC5D639614B9822D00123E48 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
APPLY_RULES_IN_COPY_FILES = YES;
+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = "$(RC_ProjectSourceVersion)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = "__FBSDID=__RCSID";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INSTALL_PATH = /usr/bin;
+ SDKROOT = macosx.internal;
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
FCBA149D14A141FF00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA14B314A1422D00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA14BC14A1423E00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /usr/sbin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA14C414A1426800AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
INSTALL_PATH = /bin;
PRODUCT_NAME = "$(TARGET_NAME)";
FCBA14CC14A1428000AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA14D414A1433F00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /bin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA14DC14A1434A00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA14FF14A144EC00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA151314A1453A00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /bin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA151B14A1454D00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA152314A1455600AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"__FBSDID=__RCSID",
_DARWIN_USE_64_BIT_INODE,
FCBA152B14A1455900AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA153314A1455C00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /bin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA153B14A1455F00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"__FBSDID=__RCSID",
USE_BSM_AUDIT,
FCBA154314A1456100AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA154B14A1456400AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /bin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA155314A1456700AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA155B14A1456A00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA156314A1456E00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA156B14A1457100AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA157B14A1457B00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA158314A1457F00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA158B14A1458500AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA159314A1458800AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /usr/libexec;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA159B14A1458C00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA15A314A1459000AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA15AB14A1459500AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /bin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA15B314A1459700AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA15BB14A1459900AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA15C314A1459E00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA15CB14A145A200AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA15D314A145A500AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /bin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA15DB14A145A700AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_MODE_FLAG = "u+s,u+w,go-w,a+rX";
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA15E314A145A900AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA15EB14A145AE00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /bin;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCBA15F314A145B000AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA15FB14A145B200AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA160314A145B500AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA160B14A145B800AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA161314A145BA00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"__FBSDID=__RCSID",
"HAVE_KVM=0",
FCBA161B14A145BC00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA162314A145C000AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA162B14A145C500AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"__FBSDID=__RCSID",
_UTMPX_COMPAT,
FCBA163314A145C700AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCBA163B14A145CA00AA698B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
FCE30ED114B5368A00CC0294 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /usr/libexec;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCE30EDD14B536C900CC0294 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
INSTALL_PATH = /usr/libexec;
PRODUCT_NAME = "$(TARGET_NAME)";
};
FCE30F4C14B619B000CC0294 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
isa = XCBuildConfiguration;
baseConfigurationReference = FD6061311B7D2DDE004BCA6A /* sh.xcconfig */;
buildSettings = {
+ CLANG_ENABLE_OBJC_WEAK = YES;
};
name = Release;
};
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
+#include <langinfo.h>
+#include <locale.h>
int lflag;
int portableflag;
int ch, status;
struct timeval before, after;
struct rusage ru;
+ char * radix = NULL;
#ifdef __GNUC__ /* XXX: borken gcc */
(void)&argv;
timersub(&after, &before, &after);
if (portableflag) {
- fprintf (stderr, "real %9ld.%02ld\n",
- (long)after.tv_sec, (long)after.tv_usec/10000);
- fprintf (stderr, "user %9ld.%02ld\n",
- (long)ru.ru_utime.tv_sec, (long)ru.ru_utime.tv_usec/10000);
- fprintf (stderr, "sys %9ld.%02ld\n",
- (long)ru.ru_stime.tv_sec, (long)ru.ru_stime.tv_usec/10000);
- } else {
+ setlocale(LC_ALL, "");
+ radix = nl_langinfo(RADIXCHAR);
+ if (!radix || radix[0] == '\0') {
+ radix = ".";
+ }
+
+ fprintf (stderr, "real %9ld%s%02ld\n",
+ (long)after.tv_sec, radix, (long)after.tv_usec/10000);
+ fprintf (stderr, "user %9ld%s%02ld\n",
+ (long)ru.ru_utime.tv_sec, radix, (long)ru.ru_utime.tv_usec/10000);
+ fprintf (stderr, "sys %9ld%s%02ld\n",
+ (long)ru.ru_stime.tv_sec, radix, (long)ru.ru_stime.tv_usec/10000);
+ } else {
fprintf(stderr, "%9ld.%02ld real ",
(long)after.tv_sec, (long)after.tv_usec/10000);
fprintf(stderr, "%9ld.%02ld user ",
argc -= optind;
argv += optind;
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
if (!(_res.options & RES_INIT))
res_init();
_res.retrans = 2; /* resolver timeout to 2 seconds per try */