Merge remote-tracking branch 'mksh/master'

Conflicts:
	Build.sh
	check.pl
	check.t
	edit.c
	emacsfn.h
	exec.c
	funcs.c
	main.c
	misc.c
	sh.h
	var.c
This commit is contained in:
KO Myung-Hun 2015-07-21 14:23:39 +09:00
commit 834349f3be
16 changed files with 415 additions and 255 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.681 2015/07/06 17:48:28 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.689 2015/07/10 17:16:23 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015
@ -578,8 +578,8 @@ if test -d $tfn || test -d $tfn.exe; then
echo "$me: Error: ./$tfn is a directory!" >&2
exit 1
fi
rmf a.exe* a.out* conftest.c *core core.* ${tfn}* *.bc *.dbg *.ll *.o *.gen \
Rebuild.sh lft no signames.inc test.sh x vv.out
rmf a.exe* a.out* conftest.c conftest.exe* *core core.* ${tfn}* *.bc *.dbg \
*.ll *.o *.gen Rebuild.sh lft no signames.inc test.sh x vv.out
SRCS="lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c"
SRCS="$SRCS lex.c main.c misc.c shf.c syn.c tree.c var.c"
@ -683,14 +683,14 @@ esac
# Configuration depending on OS name
case $TARGET_OS in
386BSD)
: ${HAVE_CAN_OTWO=0}
: "${HAVE_CAN_OTWO=0}"
add_cppflags -DMKSH_NO_SIGSETJMP
add_cppflags -DMKSH_TYPEDEF_SIG_ATOMIC_T=int
add_cppflags -DMKSH_CONSERVATIVE_FDS
;;
AIX)
add_cppflags -D_ALL_SOURCE
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
BeOS)
case $KSH_VERSION in
@ -709,7 +709,7 @@ BeOS)
add_cppflags -DMKSH__NO_SETEUGID
;;
BSD/OS)
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
Coherent)
oswarn="; it has major issues"
@ -720,7 +720,7 @@ Coherent)
add_cppflags -DMKSH_DISABLE_TTY_WARNING
;;
CYGWIN*)
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
Darwin)
add_cppflags -D_DARWIN_C_SOURCE
@ -733,7 +733,7 @@ FreeMiNT)
oswarn="; it has minor issues"
add_cppflags -D_GNU_SOURCE
add_cppflags -DMKSH_CONSERVATIVE_FDS
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
GNU)
case $CC in
@ -758,11 +758,11 @@ Interix)
ccpc='-X '
ccpl='-Y '
add_cppflags -D_ALL_SOURCE
: ${LIBS='-lcrypt'}
: ${HAVE_SETLOCALE_CTYPE=0}
: "${LIBS=-lcrypt}"
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
IRIX*)
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
Linux)
case $CC in
@ -770,7 +770,7 @@ Linux)
*) add_cppflags -D_GNU_SOURCE ;;
esac
add_cppflags -DSETUID_CAN_FAIL_WITH_EAGAIN
: ${HAVE_REVOKE=0}
: "${HAVE_REVOKE=0}"
;;
LynxOS)
oswarn="; it has minor issues"
@ -783,7 +783,7 @@ Minix-vmd)
add_cppflags -DMKSH_CONSERVATIVE_FDS
add_cppflags -D_MINIX_SOURCE
oldish_ed=no-stderr-ed # no /bin/ed, maybe see below
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
Minix3)
add_cppflags -DMKSH_UNEMPLOYED
@ -791,23 +791,24 @@ Minix3)
add_cppflags -DMKSH_NO_LIMITS
add_cppflags -D_POSIX_SOURCE -D_POSIX_1_SOURCE=2 -D_MINIX
oldish_ed=no-stderr-ed # /usr/bin/ed(!) is broken
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
MirBSD)
;;
MSYS_*)
add_cppflags -DMKSH_ASSUME_UTF8=0; HAVE_ISSET_MKSH_ASSUME_UTF8=1
# almost same as CYGWIN* (from RT|Chatzilla)
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
# broken on this OE (from ir0nh34d)
: ${HAVE_STDINT_H=0}
: "${HAVE_STDINT_H=0}"
;;
NetBSD)
;;
NEXTSTEP)
add_cppflags -D_NEXT_SOURCE
add_cppflags -D_POSIX_SOURCE
: ${AWK=gawk} ${CC=cc -posix}
: "${AWK=gawk}"
: "${CC=cc -posix}"
add_cppflags -DMKSH_NO_SIGSETJMP
# NeXTstep cannot get a controlling tty
add_cppflags -DMKSH_UNEMPLOYED
@ -828,11 +829,15 @@ Ninix3)
oswarn="; it has unknown issues"
;;
OpenBSD)
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
OS/2)
: ${CC=gcc}
: ${SIZE=echo ignore size}
HAVE_TERMIOS_H=0
HAVE_MKNOD=0 # setmode() incompatible
oswarn="; it is currently being ported"
check_categories="$check_categories nosymlink"
: "${CC=gcc}"
: "${SIZE=: size}"
SRCS="$SRCS os2.c"
add_cppflags -DMKSH_UNEMPLOYED
add_cppflags -DMKSH_NOPROSPECTOFWORK
@ -843,7 +848,7 @@ OSF1)
add_cppflags -D_POSIX_C_SOURCE=200112L
add_cppflags -D_XOPEN_SOURCE=600
add_cppflags -D_XOPEN_SOURCE_EXTENDED
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
Plan9)
add_cppflags -D_POSIX_SOURCE
@ -861,7 +866,7 @@ Plan9)
PW32*)
HAVE_SIG_T=0 # incompatible
oswarn=' and will currently not work'
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
QNX)
add_cppflags -D__NO_EXT_QNX
@ -871,7 +876,7 @@ QNX)
oldish_ed=no-stderr-ed # oldish /bin/ed is broken
;;
esac
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
SCO_SV)
case $TARGET_OSREV in
@ -888,7 +893,7 @@ SCO_SV)
;;
esac
add_cppflags -DMKSH_CONSERVATIVE_FDS
: ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0}
: "${HAVE_SYS_SIGLIST=0}${HAVE__SYS_SIGLIST=0}"
;;
skyos)
oswarn="; it has minor issues"
@ -903,15 +908,15 @@ syllable)
oswarn=' and will currently not work'
;;
ULTRIX)
: ${CC=cc -YPOSIX}
: "${CC=cc -YPOSIX}"
add_cppflags -DMKSH_TYPEDEF_SSIZE_T=int
add_cppflags -DMKSH_CONSERVATIVE_FDS
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
UnixWare|UNIX_SV)
# SCO UnixWare
add_cppflags -DMKSH_CONSERVATIVE_FDS
: ${HAVE_SYS_SIGLIST=0} ${HAVE__SYS_SIGLIST=0}
: "${HAVE_SYS_SIGLIST=0}${HAVE__SYS_SIGLIST=0}"
;;
UWIN*)
ccpc='-Yc,'
@ -919,7 +924,7 @@ UWIN*)
tsts=" 3<>/dev/tty"
oswarn="; it will compile, but the target"
oswarn="$oswarn${nl}platform itself is very flakey/unreliable"
: ${HAVE_SETLOCALE_CTYPE=0}
: "${HAVE_SETLOCALE_CTYPE=0}"
;;
_svr4)
# generic target for SVR4 Unix with uname -s = uname -n
@ -933,9 +938,9 @@ _svr4)
;;
esac
: ${HAVE_MKNOD=0}
: "${HAVE_MKNOD=0}"
: ${AWK=awk} ${CC=cc} ${NROFF=nroff} ${SIZE=size}
: "${AWK=awk}${CC=cc}${NROFF=nroff}${SIZE=size}"
test 0 = $r && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
echo | $NROFF -c >/dev/null 2>&1 && NROFF="$NROFF -c"
@ -1058,7 +1063,7 @@ ct="unknown"
#endif
;
const char *
#if defined(__KLIBC__)
#if defined(__KLIBC__) && !defined(__OS2__)
et="klibc"
#else
et="unknown"
@ -1202,7 +1207,7 @@ uslc)
SCO_SV:3.2*)
# SCO OpenServer 5
CFLAGS="$CFLAGS -g"
: ${HAVE_CAN_OTWO=0} ${HAVE_CAN_OPTIMISE=0}
: "${HAVE_CAN_OTWO=0}${HAVE_CAN_OPTIMISE=0}"
;;
esac
vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
@ -1241,7 +1246,7 @@ unknown)
;;
esac
$e "$bi==> which compiler seems to be used...$ao $ui$ct${et+ on $et}$ao"
rmf conftest.c conftest.o conftest a.out* a.exe* vv.out
rmf conftest.c conftest.o conftest a.out* a.exe* conftest.exe* vv.out
#
# Compiler: works as-is, with -Wno-error and -Werror
@ -1256,7 +1261,7 @@ test $ct = unknown || HAVE_COMPILER_KNOWN=1
if ac_ifcpp 'if 0' compiler_fails '' \
'if the compiler does not fail correctly'; then
save_CFLAGS=$CFLAGS
: ${HAVE_CAN_DELEXE=x}
: "${HAVE_CAN_DELEXE=x}"
case $ct in
dec)
CFLAGS="$CFLAGS ${ccpl}-non_shared"
@ -1618,8 +1623,8 @@ phase=x
#
if ac_ifcpp 'ifdef MKSH_SMALL' isset_MKSH_SMALL '' \
"if a reduced-feature mksh is requested"; then
: ${HAVE_NICE=0}
: ${HAVE_PERSISTENT_HISTORY=0}
: "${HAVE_NICE=0}"
: "${HAVE_PERSISTENT_HISTORY=0}"
check_categories="$check_categories smksh"
HAVE_ISSET_MKSH_CONSERVATIVE_FDS=1 # from sh.h
fi
@ -1633,7 +1638,7 @@ ac_ifcpp 'ifdef MKSH_NOPROSPECTOFWORK' isset_MKSH_NOPROSPECTOFWORK '' \
"if mksh will be built without job signals" && \
check_categories="$check_categories arge nojsig"
ac_ifcpp 'ifdef MKSH_ASSUME_UTF8' isset_MKSH_ASSUME_UTF8 '' \
'if the default UTF-8 mode is specified' && : ${HAVE_SETLOCALE_CTYPE=0}
'if the default UTF-8 mode is specified' && : "${HAVE_SETLOCALE_CTYPE=0}"
ac_ifcpp 'ifdef MKSH_CONSERVATIVE_FDS' isset_MKSH_CONSERVATIVE_FDS '' \
'if traditional/conservative fd use is requested' && \
check_categories="$check_categories convfds"
@ -2338,7 +2343,7 @@ addsrcs '!' HAVE_STRLCPY strlcpy.c
addsrcs USE_PRINTF_BUILTIN printf.c
test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
add_cppflags -DMKSH_BUILD_R=510
add_cppflags -DMKSH_BUILD_R=511
$e $bi$me: Finished configuration testing, now producing output.$ao
@ -2346,8 +2351,13 @@ files=
objs=
sp=
case $tcfn in
a.exe | conftest.exe) mkshexe=$tfn.exe ;;
*) mkshexe=$tfn ;;
a.exe|conftest.exe)
mkshexe=$tfn.exe
add_cppflags -DMKSH_EXE_EXT
;;
*)
mkshexe=$tfn
;;
esac
case $curdir in
*\ *) mkshshebang="#!./$mkshexe" ;;

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.141 2015/04/11 23:28:17 tg Exp $
# $MirOS: src/bin/mksh/Makefile,v 1.142 2015/07/09 20:52:36 tg Exp $
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015
@ -43,21 +43,22 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
-DHAVE_SYS_MKDEV_H=0 -DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_PARAM_H=1 \
-DHAVE_SYS_RESOURCE_H=1 -DHAVE_SYS_SELECT_H=1 \
-DHAVE_SYS_SYSMACROS_H=0 -DHAVE_BSTRING_H=0 -DHAVE_GRP_H=1 \
-DHAVE_LIBGEN_H=1 -DHAVE_LIBUTIL_H=0 -DHAVE_PATHS_H=1 \
-DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_TERMIOS_H=1 \
-DHAVE_ULIMIT_H=0 -DHAVE_VALUES_H=0 -DHAVE_CAN_INTTYPES=1 \
-DHAVE_CAN_UCBINTS=1 -DHAVE_CAN_INT8TYPE=1 \
-DHAVE_CAN_UCBINT8=1 -DHAVE_RLIM_T=1 -DHAVE_SIG_T=1 \
-DHAVE_SYS_ERRLIST=1 -DHAVE_SYS_SIGNAME=1 -DHAVE_SYS_SIGLIST=1 \
-DHAVE_FLOCK=1 -DHAVE_LOCK_FCNTL=1 -DHAVE_GETRUSAGE=1 \
-DHAVE_GETSID=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_ISSETUGID=1 \
-DHAVE_KILLPG=1 -DHAVE_MEMMOVE=1 -DHAVE_MKNOD=0 -DHAVE_MMAP=1 \
-DHAVE_NICE=1 -DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=0 \
-DHAVE_LANGINFO_CODESET=0 -DHAVE_SELECT=1 -DHAVE_SETRESUGID=1 \
-DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \
-DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
-DHAVE_IO_H=0 -DHAVE_LIBGEN_H=1 -DHAVE_LIBUTIL_H=0 \
-DHAVE_PATHS_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 \
-DHAVE_TERMIOS_H=1 -DHAVE_ULIMIT_H=0 -DHAVE_VALUES_H=0 \
-DHAVE_CAN_INTTYPES=1 -DHAVE_CAN_UCBINTS=1 \
-DHAVE_CAN_INT8TYPE=1 -DHAVE_CAN_UCBINT8=1 -DHAVE_RLIM_T=1 \
-DHAVE_SIG_T=1 -DHAVE_SYS_ERRLIST=1 -DHAVE_SYS_SIGNAME=1 \
-DHAVE_SYS_SIGLIST=1 -DHAVE_FLOCK=1 -DHAVE_LOCK_FCNTL=1 \
-DHAVE_GETRUSAGE=1 -DHAVE_GETSID=1 -DHAVE_GETTIMEOFDAY=1 \
-DHAVE_ISSETUGID=1 -DHAVE_KILLPG=1 -DHAVE_MEMMOVE=1 \
-DHAVE_MKNOD=0 -DHAVE_MMAP=1 -DHAVE_NICE=1 -DHAVE_REVOKE=1 \
-DHAVE_SETLOCALE_CTYPE=0 -DHAVE_LANGINFO_CODESET=0 \
-DHAVE_SELECT=1 -DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 \
-DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 -DHAVE_STRLCPY=1 \
-DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
-DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=510
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=511
CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
CPPFLAGS+= -I.
COPTS+= -std=c89 -Wall

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.pl,v 1.39 2015/04/29 19:01:03 tg Exp $
# $MirOS: src/bin/mksh/check.pl,v 1.40 2015/07/10 19:36:31 tg Exp $
# $OpenBSD: th,v 1.1 2013/12/02 20:39:44 millert Exp $
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
@ -73,11 +73,12 @@
# the following minimal environment:
# HOME, LD_LIBRARY_PATH, LOCPATH,
# LOGNAME, PATH, SHELL, UNIXMODE,
# USER
# UNIXROOT, USER
# (values taken from the environment of
# the test harness).
# CYGWIN is set to nodosfilewarning.
# ENV is set to /nonexistant.
# PATHSEP is set to either : or ;.
# __progname is set to the -p argument.
# __perlname is set to $^X (perlexe).
# file-setup mps Used to create files, directories
@ -275,12 +276,12 @@ $all_tests = @ARGV == 0;
# Set up a very minimal environment
%new_env = ();
foreach $env (('HOME', 'LD_LIBRARY_PATH', 'LOCPATH', 'LOGNAME',
'PATH', 'SHELL', 'UNIXMODE', 'USER', 'UNIXROOT')) {
'PATH', 'SHELL', 'UNIXMODE', 'UNIXROOT', 'USER')) {
$new_env{$env} = $ENV{$env} if defined $ENV{$env};
}
$new_env{'CYGWIN'} = 'nodosfilewarning';
$new_env{'ENV'} = '/nonexistant';
$new_env{'PATH_SEPARATOR'} = $os eq 'os2' ? ';' : ':';
$new_env{'PATHSEP'} = $os eq 'os2' ? ';' : ':';
if (($os eq 'VMS') || ($Config{perlpath} =~ m/$Config{_exe}$/i)) {
$new_env{'__perlname'} = $Config{perlpath};
} else {
@ -313,12 +314,10 @@ die "$prog: couldn't get temporary directory\n" if $temp_dir eq '';
die "$prog: couldn't cd to $pwd - $!\n" if !chdir($pwd);
if (!$program_kludge) {
$test_prog = "$pwd/$test_prog"
if substr($test_prog, 0, 1) ne '/' &&
($os ne 'os2' || (substr($test_prog, 0, 1) ne '\\' &&
substr($test_prog, 1, 1) ne ':'));
$test_prog = "$pwd/$test_prog" if (substr($test_prog, 0, 1) ne '/') &&
($os ne 'os2' || substr($test_prog, 1, 1) ne ':');
die "$prog: $test_prog is not executable - bye\n"
if (! -x $test_prog && $os ne 'os2');
if (! -x $test_prog && $os ne 'os2');
}
@trap_sigs = ('TERM', 'QUIT', 'INT', 'PIPE', 'HUP');

123
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.699 2015/07/06 17:48:29 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.703 2015/07/10 19:36:31 tg Exp $
# -*- mode: sh -*-
#-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -30,7 +30,7 @@
# (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
expected-stdout:
@(#)MIRBSD KSH R51 2015/07/06
@(#)MIRBSD KSH R51 2015/07/10
description:
Check version of shell.
stdin:
@ -39,7 +39,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R51 2015/07/06
@(#)LEGACY KSH R51 2015/07/10
description:
Check version of legacy shell.
stdin:
@ -232,7 +232,7 @@ time-limit: 3
stdin:
print '#!'"$__progname"'\necho tf' >lq
chmod +x lq
PATH="$PWD$PATH_SEPARATOR$PATH"
PATH=$PWD$PATHSEP$PATH
alias lq=lq
lq
echo = now
@ -2075,11 +2075,10 @@ expected-stdout:
name: glob-bad-2
description:
Check that symbolic links aren't stat()'d
# breaks on FreeMiNT (cannot unlink dangling symlinks)
# breaks on MSYS (does not support symlinks)
# breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
# breaks on OS/2 (does not support symlinks)
category: !os:mint,!os:msys,!os:svr4.0,!os:os2,!nosymlink
# breaks on FreeMiNT (cannot unlink dangling symlinks)
# breaks on MSYS, OS/2 (do not support symlinks)
category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
file-setup: dir 755 "dir"
file-setup: symlink 644 "dir/abc"
non-existent-file
@ -2133,7 +2132,7 @@ description:
# breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
# breaks on Cygwin 1.7 (files are now UTF-16 or something)
# breaks on QNX 6.4.1 (says RT)
category: !os:cygwin,!os:darwin,!os:msys,!os:os2,!os:nto
category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2
need-pass: no
file-setup: file 644 "aÂc"
stdin:
@ -3556,7 +3555,6 @@ name: history-ed-3-old
description:
Newly created multi line commands show up as single command
in history.
(NOTE: adjusted for COMPLEX HISTORY compile time option)
(ksh88 fails 'cause it lists the fc command)
category: stdout-ed
need-ctty: yes
@ -5020,8 +5018,8 @@ description:
need to be moved out of the switch to before findcom() is
called - I don't know what this will break.
stdin:
: ${PWD:-`pwd 2> /dev/null`}
: ${PWD:?"PWD not set - can't do test"}
: "${PWD:-`pwd 2> /dev/null`}"
: "${PWD:?"PWD not set - can't do test"}"
mkdir Y
cat > Y/xxxscript << EOF
#!/bin/sh
@ -5559,7 +5557,7 @@ description:
stdin:
print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
done >env; chmod +x env; PATH=".$PATH_SEPARATOR$PATH"
done >env; chmod +x env; PATH=".$PATHSEP$PATH"
foo=bar
readonly foo
foo=stuff env | grep '^foo'
@ -6265,7 +6263,7 @@ description:
stdin:
print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
done >env; chmod +x env; PATH=".$PATH_SEPARATOR$PATH"
done >env; chmod +x env; PATH=".$PATHSEP$PATH"
FOO=bar exec env
expected-stdout-pattern:
/(^|.*\n)FOO=bar\n/
@ -6277,7 +6275,7 @@ description:
stdin:
print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
done >env; chmod +x env; PATH=".$PATH_SEPARATOR$PATH"
done >env; chmod +x env; PATH=".$PATHSEP$PATH"
env >bar1
FOO=bar exec; env >bar2
cmp -s bar1 bar2
@ -6521,7 +6519,7 @@ stdin:
print '#!'"$__progname"'\nexec "$1"' >env
print '#!'"$__progname"'\nexit 1' >false
chmod +x env false
PATH=".$PATH_SEPARATOR$PATH"
PATH=".$PATHSEP$PATH"
set -ex
env false && echo something
echo END
@ -6539,7 +6537,7 @@ stdin:
print '#!'"$__progname"'\nexit 1' >false
print '#!'"$__progname"'\nexit 0' >true
chmod +x env false
PATH=".$PATH_SEPARATOR$PATH"
PATH=".$PATHSEP$PATH"
set -ex
if env true; then
env false && echo something
@ -7283,7 +7281,7 @@ stdin:
set -A anzahl -- foo/*
echo got ${#anzahl[*]} files
chmod +x foo/*
export PATH="$(pwd)/foo$PATH_SEPARATOR$PATH"
export PATH="$(pwd)/foo$PATHSEP$PATH"
"$__progname" -c 'fnord'
echo =
"$__progname" -c 'fnord; fnord; fnord; fnord'
@ -7453,7 +7451,7 @@ expected-stdout:
name: aliases-1
description:
Check if built-in shell aliases are okay
category: !android,!arge
category: !android,!arge,!os:os2
stdin:
alias
typeset -f
@ -7514,10 +7512,31 @@ expected-stdout:
source='PATH="$PATH;." \command .'
type='\builtin whence -v'
---
name: aliases-1-os2
description:
Check if built-in shell aliases are okay
category: os:os2
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH="$PATH;." \command .'
type='\builtin whence -v'
---
name: aliases-2b
description:
Check if âœset -o shâ<EFBFBD> does not influence built-in aliases
category: !android,!arge
category: !android,!arge,!os:os2
arguments: !-o!sh!
stdin:
alias
@ -7540,7 +7559,7 @@ expected-stdout:
name: aliases-3b
description:
Check if running as sh does not influence built-in aliases
category: !android,!arge
category: !android,!arge,!os:os2
stdin:
cp "$__progname" sh
./sh -c 'alias; typeset -f'
@ -7648,6 +7667,50 @@ expected-stdout:
source='PATH="$PATH;." \command .'
type='\builtin whence -v'
---
name: aliases-2b-os2
description:
Check if set -o sh does not influence built-in aliases
category: os:os2
arguments: !-o!sh!
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH="$PATH;." \command .'
type='\builtin whence -v'
---
name: aliases-3b-os2
description:
Check if running as sh does not influence built-in aliases
category: os:os2
stdin:
cp "$__progname" sh
./sh -c 'alias; typeset -f'
rm -f sh
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH="$PATH;." \command .'
type='\builtin whence -v'
---
name: aliases-cmdline
description:
Check that aliases work from the command line (Debian #517009)
@ -8680,6 +8743,7 @@ stdin:
cat >foo <<-'EOF'
x='bar
' #
echo .${#x} #
if test x"$KSH_VERSION" = x""; then #
printf '<%s>' "$x" #
else #
@ -8691,8 +8755,10 @@ stdin:
print -r -- "{$line}"
done
expected-stdout:
[<bar
[.5
<bar
>]
{.5}
{<bar }
---
name: print-lf
@ -8702,6 +8768,7 @@ stdin:
cat >foo <<-'EOF'
x='bar
' #
echo .${#x} #
if test x"$KSH_VERSION" = x""; then #
printf '<%s>' "$x" #
else #
@ -8713,8 +8780,10 @@ stdin:
print -r -- "{$line}"
done
expected-stdout:
[<bar
[.4
<bar
>]
{.4}
{<bar}
---
name: print-nul-chars
@ -9968,7 +10037,7 @@ description:
stdin:
print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
done >env; chmod +x env; PATH=".$PATH_SEPARATOR$PATH"
done >env; chmod +x env; PATH=".$PATHSEP$PATH"
function k {
if [ x$FOO != xbar ]; then
echo 1
@ -10140,7 +10209,7 @@ description:
is a must (a non-recursive parser cannot pass all three of
these test cases, especially the â˜#’ is difficult)
stdin:
print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=".$PATH_SEPARATOR$PATH"
print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=".$PATHSEP$PATH"
echo $(typeset -i10 x=16#20; echo $x)
echo $(typeset -Uui16 x=16#$(id -u)
) .
@ -11375,7 +11444,7 @@ file-setup: file 755 "!false"
#! /bin/sh
echo si
stdin:
export PATH=".$PATH_SEPARATOR$PATH"
export PATH=".$PATHSEP$PATH"
falsetto
echo yeap
!false
@ -11405,7 +11474,7 @@ file-setup: file 755 "!false"
#! /bin/sh
echo si
stdin:
export PATH=".$PATH_SEPARATOR$PATH"
export PATH=".$PATHSEP$PATH"
falsetto
echo yeap
!false

View File

@ -1,9 +1,9 @@
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.99 2015/07/05 19:02:16 tg Exp $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.101 2015/07/18 23:03:24 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015
# Thorsten Glaser <tg@mirbsd.org>
# mirabilos <tg@mirbsd.org>
#
# Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission
@ -384,7 +384,11 @@ function Lstripcom {
# give MidnightBSD's laffer1 a bit of csh feeling
function setenv {
\eval "'export' \"$1\""'="$2"'
if (( $# )); then
\eval '\export "$1"="${2:-}"'
else
\typeset -x
fi
}
# toggle built-in aliases and utilities, and aliases and functions from mkshrc
@ -406,6 +410,7 @@ function enable {
i_alias[nalias]=nameref; b_alias[nalias++]='\typeset -n'
i_alias[nalias]=nohup; b_alias[nalias++]='nohup '
i_alias[nalias]=r; b_alias[nalias++]='\builtin fc -e -'
#XXX OS/2
i_alias[nalias]=source; b_alias[nalias++]='PATH=$PATH:. \command .'
i_alias[nalias]=stop; b_alias[nalias++]='\kill -STOP'
i_alias[nalias]=type; b_alias[nalias++]='\builtin whence -v'
@ -582,6 +587,7 @@ function enable {
for p in ~/.etc/bin ~/bin; do
[[ -d $p/. ]] || \continue
#XXX OS/2
[[ :$PATH: = *:$p:* ]] || PATH=$p:$PATH
done

123
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.287 2015/07/05 19:37:13 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.290 2015/07/10 19:36:34 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -777,7 +777,7 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath)
Xinit(xs, xp, patlen + 128, ATEMP);
while (sp) {
xp = Xstring(xs, xp);
if (!(p = cstrchr(sp, PATH_SEP)))
if (!(p = cstrchr(sp, MKSH_PATHSEPC)))
p = sp + strlen(sp);
pathlen = p - sp;
if (pathlen) {
@ -893,11 +893,7 @@ struct x_defbindings {
/* Separator for motion */
#define is_mfs(c) (!(ksh_isalnux(c) || (c) == '$' || ((c) & 0x80)))
#ifndef __OS2__
#define X_NTABS 3 /* normal, meta1, meta2 */
#else
#define X_NTABS 4 /* normal, meta1, meta2, meta3 */
#endif
#define X_NTABS 4 /* normal, meta1, meta2, pc */
#define X_TABSZ 256 /* size of keydef tables etc */
/*-
@ -1101,13 +1097,6 @@ static struct x_defbindings const x_defbindings[] = {
{ XFUNC_next_com, 2, 'B' },
{ XFUNC_mv_forw, 2, 'C' },
{ XFUNC_mv_back, 2, 'D' },
#ifdef __OS2__
{ XFUNC_meta3, 0, 0xE0 },
{ XFUNC_prev_com, 3, 'H' },
{ XFUNC_next_com, 3, 'P' },
{ XFUNC_mv_forw, 3, 'M' },
{ XFUNC_mv_back, 3, 'K' },
#endif
#ifndef MKSH_SMALL
{ XFUNC_vt_hack, 2, '1' },
{ XFUNC_mv_begin | 0x80, 2, '7' },
@ -1116,9 +1105,28 @@ static struct x_defbindings const x_defbindings[] = {
{ XFUNC_mv_end | 0x80, 2, '8' },
{ XFUNC_mv_end, 2, 'F' },
{ XFUNC_del_char | 0x80, 2, '3' },
{ XFUNC_del_char, 2, 'P' },
{ XFUNC_del_char, 2, 'P' },
{ XFUNC_search_hist_up | 0x80, 2, '5' },
{ XFUNC_search_hist_dn | 0x80, 2, '6' },
#endif
/* PC scancodes */
#if !defined(MKSH_SMALL) || defined(__OS2__)
{ XFUNC_meta3, 0, 0 },
{ XFUNC_mv_begin, 3, 71 },
{ XFUNC_prev_com, 3, 72 },
#ifndef MKSH_SMALL
{ XFUNC_search_hist_up, 3, 73 },
#endif
{ XFUNC_mv_back, 3, 75 },
{ XFUNC_mv_forw, 3, 77 },
{ XFUNC_mv_end, 3, 79 },
{ XFUNC_next_com, 3, 80 },
#ifndef MKSH_SMALL
{ XFUNC_search_hist_dn, 3, 81 },
#endif
{ XFUNC_del_char, 3, 83 },
#endif
#ifndef MKSH_SMALL
/* more non-standard ones */
{ XFUNC_edit_line, 2, 'e' }
#endif
@ -2232,14 +2240,12 @@ x_meta2(int c MKSH_A_UNUSED)
return (KSTD);
}
#ifdef __OS2__
static int
x_meta3(int c MKSH_A_UNUSED)
{
x_curprefix = 3;
return (KSTD);
}
#endif
static int
x_kill(int c MKSH_A_UNUSED)
@ -2391,12 +2397,6 @@ x_mapin(const char *cp, Area *ap)
/* XXX -- should handle \^ escape? */
if (*cp == '^') {
cp++;
#ifdef __OS2__
/* define function keys */
if (*cp == '0')
*op++ = 0xE0;
else
#endif
/*XXX or ^^ escape? this is ugly. */
if (*cp >= '?')
/* includes '?'; ASCII */
@ -2419,12 +2419,6 @@ x_mapout2(int c, char **buf)
{
char *p = *buf;
#ifdef __OS2__
if (c == 0xE0) {
*p++ = '^';
*p++ = '0';
} else
#endif
if (ISCTRL(c)) {
*p++ = '^';
*p++ = UNCTRL(c);
@ -2449,15 +2443,10 @@ x_print(int prefix, int key)
{
int f = x_tab[prefix][key];
#ifdef __OS2__
if (prefix == 3)
shf_puts(x_mapout(0xE0), shl_stdout);
else
#endif
if (prefix)
/* prefix == 1 || prefix == 2 */
shf_puts(x_mapout(prefix == 1 ?
CTRL('[') : CTRL('X')), shl_stdout);
shf_puts(x_mapout(prefix == 1 ? CTRL('[') :
prefix == 2 ? CTRL('X') : 0), shl_stdout);
#ifdef MKSH_SMALL
shprintf("%s = ", x_mapout(key));
#else
@ -2522,10 +2511,8 @@ x_bind(const char *a1, const char *a2,
prefix = 1;
else if (f == XFUNC_meta2)
prefix = 2;
#ifdef __OS2__
else if (f == XFUNC_meta3)
prefix = 3;
#endif
else
break;
}
@ -3338,20 +3325,22 @@ x_mode(bool onoff)
edchars.eof = tty_state.c_cc[VEOF];
#ifdef VWERASE
edchars.werase = tty_state.c_cc[VWERASE];
#else
edchars.werase = 0;
#endif
#ifdef __OS2__
if (edchars.erase == 0)
edchars.erase = 8;
if (edchars.kill == 0)
edchars.kill = 21;
if (edchars.intr == 0)
edchars.intr = 3;
if (edchars.quit == 0)
edchars.quit = 28;
if (edchars.eof == 0)
edchars.eof = 4;
#endif
if (!edchars.erase)
edchars.erase = CTRL('H');
if (!edchars.kill)
edchars.kill = CTRL('U');
if (!edchars.intr)
edchars.intr = CTRL('C');
if (!edchars.quit)
edchars.quit = CTRL('\\');
if (!edchars.eof)
edchars.eof = CTRL('D');
if (!edchars.werase)
edchars.werase = CTRL('W');
#ifdef _POSIX_VDISABLE
/* Convert unset values to internal 'unset' value */
@ -3663,6 +3652,18 @@ vi_hook(int ch)
switch (state) {
case VNORMAL:
/* PC scancodes */
if (!ch) switch (cmdlen = 0, (ch = x_getc())) {
case 71: ch = '0'; goto pseudo_vi_command;
case 72: ch = 'k'; goto pseudo_vi_command;
case 73: ch = 'A'; goto vi_xfunc_search_up;
case 75: ch = 'h'; goto pseudo_vi_command;
case 77: ch = 'l'; goto pseudo_vi_command;
case 79: ch = '$'; goto pseudo_vi_command;
case 80: ch = 'j'; goto pseudo_vi_command;
case 83: ch = 'x'; goto pseudo_vi_command;
default: ch = 0; goto vi_insert_failed;
}
if (insert != 0) {
if (ch == CTRL('v')) {
state = VLIT;
@ -3670,24 +3671,9 @@ vi_hook(int ch)
}
switch (vi_insert(ch)) {
case -1:
#ifdef __OS2__
/* arrow keys generate 0xe0X, where X is H.. */
state = VCMD;
argc1 = 1;
switch (x_getc()) {
case 'H': *curcmd='k'; break;
case 'K': *curcmd='h'; break;
case 'P': *curcmd='j'; break;
case 'M': *curcmd='l'; break;
default:
vi_error();
state = VNORMAL;
}
break;
#else
vi_insert_failed:
vi_error();
state = VNORMAL;
#endif
break;
case 0:
if (state == VLIT) {
@ -3708,6 +3694,7 @@ vi_hook(int ch)
argc1 = ksh_numdig(ch);
state = VARG1;
} else {
pseudo_vi_command:
curcmd[cmdlen++] = ch;
state = nextstate(ch);
if (state == VSEARCH) {
@ -3876,6 +3863,7 @@ vi_hook(int ch)
break;
case VPREFIX2:
vi_xfunc_search_up:
state = VFAIL;
switch (ch) {
case 'A':
@ -4046,9 +4034,6 @@ vi_insert(int ch)
if (first_insert && ch != CTRL('['))
saved_inslen = 0;
switch (ch) {
#ifdef __OS2__
case 0xE0: /* function key prefix */
#endif
case '\0':
return (-1);

View File

@ -1,5 +1,5 @@
#if defined(EMACSFN_DEFNS)
__RCSID("$MirOS: src/bin/mksh/emacsfn.h,v 1.5 2010/07/17 22:09:33 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/emacsfn.h,v 1.6 2015/07/10 18:41:07 tg Exp $");
#define FN(cname,sname,flags) static int x_##cname(int);
#elif defined(EMACSFN_ENUMS)
#define FN(cname,sname,flags) XFUNC_##cname,
@ -52,9 +52,7 @@ FN(list_file, "list-file", 0)
FN(literal, "quote", 0)
FN(meta1, "prefix-1", XF_PREFIX)
FN(meta2, "prefix-2", XF_PREFIX)
#ifdef __OS2__
FN(meta3, "prefix-3", XF_PREFIX)
#endif
FN(meta_yank, "yank-pop", 0)
FN(mv_back, "backward-char", XF_ARG)
FN(mv_begin, "beginning-of-line", 0)

58
exec.c
View File

@ -23,10 +23,10 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.155 2015/07/06 17:48:31 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.160 2015/07/10 19:36:35 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL UNIXROOT "/bin/sh"
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
#endif
static int comexec(struct op *, struct tbl * volatile, const char **,
@ -551,7 +551,11 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
}
if ((tp = findcom(cp, FC_BI)) == NULL)
errorf("%s: %s: %s", Tbuiltin, cp, "not a builtin");
if (tp->type == CSHELL && tp->val.f == c_cat)
if (tp->type == CSHELL && (tp->val.f == c_cat
#ifdef MKSH_PRINTF_BUILTIN
|| tp->val.f == c_printf
#endif
))
break;
continue;
} else if (tp->val.f == c_exec) {
@ -622,6 +626,16 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
tp = ext_cat;
}
break;
#ifdef MKSH_PRINTF_BUILTIN
} else if (tp->val.f == c_printf) {
struct tbl *ext_printf;
ext_printf = findcom(Tprintf, FC_PATH | FC_FUNC);
if (ext_printf && (ext_printf->type != CTALIAS ||
(ext_printf->flag & ISSET)))
tp = ext_printf;
break;
#endif
} else if (tp->val.f == c_trap) {
t->u.evalflags &= ~DOTCOMEXEC;
break;
@ -731,6 +745,13 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
tp = findcom(Tcat, FC_BI);
goto do_call_builtin;
}
#ifdef MKSH_PRINTF_BUILTIN
if (!strcmp(cp, Tprintf)) {
no_printf_in_FPATH:
tp = findcom(Tprintf, FC_BI);
goto do_call_builtin;
}
#endif
warningf(true, "%s: %s %s %s: %s", cp,
"can't open", "function definition file",
tp->u.fpath, cstrerror(errno));
@ -741,6 +762,10 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
!(ftp->flag & ISSET)) {
if (!strcmp(cp, Tcat))
goto no_cat_in_FPATH;
#ifdef MKSH_PRINTF_BUILTIN
if (!strcmp(cp, Tprintf))
goto no_printf_in_FPATH;
#endif
warningf(true, "%s: %s %s", cp,
"function not defined by", tp->u.fpath);
rv = 127;
@ -900,7 +925,7 @@ scriptexec(struct op *tp, const char **ap)
*tp->args-- = tp->str;
#ifndef MKSH_SMALL
if ((fd = open(tp->str, O_RDONLY | O_BINARY)) >= 0) {
if ((fd = binopen2(tp->str, O_RDONLY)) >= 0) {
unsigned char *cp;
unsigned short m;
ssize_t n;
@ -933,13 +958,15 @@ scriptexec(struct op *tp, const char **ap)
/* restore begin of shebang position (buf+0 or buf+3) */
cp = buf + n;
/* bail out if no shebang magic found */
if ((cp[0] != '#') || (cp[1] != '!'))
if (cp[0] == '#' && cp[1] == '!')
cp += 2;
#ifdef __OS2__
if (strncmp(cp, "extproc", 7) || (cp[7] != ' ' && cp[7] != '\t'))
else if (!strncmp(cp, Textproc, 7) &&
(cp[7] == ' ' || cp[7] == '\t'))
cp += 8;
#endif
else
goto noshebang;
cp += *cp == '#' ? 2 : 7;
/* skip whitespace before shell name */
while (*cp == ' ' || *cp == '\t')
++cp;
@ -985,9 +1012,10 @@ scriptexec(struct op *tp, const char **ap)
(m == /* ECOFF_I386 */ 0x4C01) ||
(m == /* ECOFF_M68K */ 0x0150 || m == 0x5001) ||
(m == /* ECOFF_SH */ 0x0500 || m == 0x0005) ||
#ifndef __OS2__
(m == /* "MZ" */ 0x4D5A) ||
#endif
(m == /* bzip */ 0x425A) || (m == /* "MZ" */ 0x4D5A) ||
(m == /* "NE" */ 0x4E45) || (m == /* "LX" */ 0x4C58) ||
(m == /* xz */ 0xFD37 && buf[2] == 'z' && buf[3] == 'X' &&
buf[4] == 'Z') || (m == /* 7zip */ 0x377A) ||
(m == /* gzip */ 0x1F8B) || (m == /* .Z */ 0x1F9D))
errorf("%s: not executable: magic %04X", tp->str, m);
#ifdef __OS2__
@ -1246,7 +1274,7 @@ flushcom(bool all)
struct tstate ts;
for (ktwalk(&ts, &taliases); (tp = ktnext(&ts)) != NULL; )
if ((tp->flag&ISSET) && (all || !IS_ABS_PATH(tp->val.s))) {
if ((tp->flag&ISSET) && (all || !mksh_abspath(tp->val.s))) {
if (tp->flag&ALLOC) {
tp->flag &= ~(ALLOC|ISSET);
afree(tp->val.s, APERM);
@ -1322,7 +1350,7 @@ search_path(const char *name, const char *lpath,
sp = lpath;
while (sp != NULL) {
xp = Xstring(xs, xp);
if (!(p = cstrchr(sp, PATH_SEP)))
if (!(p = cstrchr(sp, MKSH_PATHSEPC)))
p = sp + strlen(sp);
if (p != sp) {
XcheckN(xs, xp, p - sp);
@ -1459,7 +1487,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
warningf(true, "%s: %s", cp, "restricted");
return (-1);
}
u = open(cp, flags | O_BINARY, 0666);
u = binopen3(cp, flags, 0666);
}
if (u < 0) {
/* herein() may already have printed message */
@ -1592,7 +1620,7 @@ herein(struct ioword *iop, char **resbuf)
* so temp doesn't get removed too soon).
*/
h = maketemp(ATEMP, TT_HEREDOC_EXP, &e->temps);
if (!(shf = h->shf) || (fd = open(h->tffn, O_RDONLY | O_BINARY, 0)) < 0) {
if (!(shf = h->shf) || (fd = binopen3(h->tffn, O_RDONLY, 0)) < 0) {
i = errno;
warningf(true, "can't %s temporary file %s: %s",
!shf ? "create" : "open", h->tffn, cstrerror(i));

View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.277 2015/07/06 17:48:32 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.280 2015/07/09 20:52:39 tg Exp $");
#if HAVE_KILLPG
/*
@ -152,7 +152,7 @@ const struct builtin mkshbuiltins[] = {
{"mknod", c_mknod},
#endif
#ifdef MKSH_PRINTF_BUILTIN
{"printf", c_printf},
{Tprintf, c_printf},
#endif
#if HAVE_SELECT
{"sleep", c_sleep},
@ -162,7 +162,7 @@ const struct builtin mkshbuiltins[] = {
{"domainname", c_true},
#endif
#ifdef __OS2__
{"extproc", c_true},
{Textproc, c_true},
#endif
{NULL, (int (*)(const char **))NULL}
};
@ -3676,7 +3676,7 @@ c_cat(const char **wp)
fn = *wp++;
if (ksh_isdash(fn))
fd = STDIN_FILENO;
else if ((fd = open(fn, O_RDONLY | O_BINARY)) < 0) {
else if ((fd = binopen2(fn, O_RDONLY)) < 0) {
eno = errno;
bi_errorf("%s: %s", fn, cstrerror(eno));
rv = 1;

View File

@ -27,7 +27,7 @@
#include <sys/file.h>
#endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.148 2015/07/05 19:53:45 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.149 2015/07/09 20:52:40 tg Exp $");
Trap sigtraps[ksh_NSIG + 1];
static struct sigaction Sigact_ign;
@ -764,8 +764,7 @@ hist_init(Source *s)
retry:
/* we have a file and are interactive */
if ((fd = open(hname, O_RDWR | O_CREAT | O_APPEND | O_BINARY,
0600)) < 0)
if ((fd = binopen3(hname, O_RDWR | O_CREAT | O_APPEND, 0600)) < 0)
return;
histfd = savefd(fd);
@ -800,8 +799,8 @@ hist_init(Source *s)
/* create temporary file */
nhname = shf_smprintf("%s.%d", hname, (int)procpid);
if ((fd = open(nhname, O_RDWR | O_CREAT | O_TRUNC |
O_EXCL | O_BINARY, 0600)) < 0) {
if ((fd = binopen3(nhname, O_RDWR | O_CREAT | O_TRUNC |
O_EXCL, 0600)) < 0) {
/* just don't truncate then, meh. */
goto hist_trunc_dont;
}

50
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.295 2015/07/06 17:48:34 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.300 2015/07/10 19:36:35 tg Exp $");
extern char **environ;
@ -43,7 +43,7 @@ extern char **environ;
#endif
#ifndef MKSH_DEFAULT_TMPDIR
#define MKSH_DEFAULT_TMPDIR UNIXROOT "/tmp"
#define MKSH_DEFAULT_TMPDIR MKSH_UNIXROOT "/tmp"
#endif
static uint8_t isuc(const char *);
@ -82,7 +82,7 @@ static const char *initcoms[] = {
"nameref=\\typeset -n",
"nohup=nohup ",
"r=\\builtin fc -e -",
"source=PATH=\"$PATH" PATH_SEP_STR ".\" \\command .",
"source=PATH=\"$PATH" MKSH_PATHSEPS ".\" \\command .",
"login=\\exec login",
NULL,
/* this is what AT&T ksh seems to track, with the addition of emacs */
@ -193,6 +193,12 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
ssize_t k;
#endif
#ifdef __OS2__
for (i = 0; i < 3; ++i)
if (!isatty(i))
setmode(i, O_BINARY);
#endif
/* do things like getpgrp() et al. */
chvt_reinit();
@ -269,7 +275,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
#define EXE_EXT ""
#endif
/* are we called as -sh or /bin/sh or so? */
if (!strcmp(ccp, "sh" EXE_EXT)) {
if (!strcmp(ccp, "sh" MKSH_EXE_EXT)) {
/* either also turns off braceexpand */
#ifdef MKSH_BINSHPOSIX
/* enable better POSIX conformance */
@ -323,9 +329,10 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
* "keeping a regular /usr"; this is supposed
* to be a sane 'basic' default PATH
*/
def_path = UNIXROOT "/bin" PATH_SEP_STR
UNIXROOT "/usr/bin" PATH_SEP_STR
UNIXROOT "/sbin" PATH_SEP_STR UNIXROOT "/usr/sbin";
def_path = MKSH_UNIXROOT "/bin" MKSH_PATHSEPS
MKSH_UNIXROOT "/usr/bin" MKSH_PATHSEPS
MKSH_UNIXROOT "/sbin" MKSH_PATHSEPS
MKSH_UNIXROOT "/usr/sbin";
#endif
/*
@ -368,7 +375,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
vp = global("PWD");
cp = str_val(vp);
/* Try to use existing $PWD if it is valid */
set_current_wd((IS_ABS_PATH(cp) && test_eval(NULL, TO_FILEQ, cp, ".",
set_current_wd((mksh_abspath(cp) && test_eval(NULL, TO_FILEQ, cp, ".",
true)) ? cp : NULL);
if (current_wd[0])
simplify_path(current_wd);
@ -461,17 +468,18 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
kshname = argv[argi++];
} else if (argi < argc && !Flag(FSTDIN)) {
s = pushs(SFILE, ATEMP);
#ifndef __OS2__
s->file = argv[argi++];
#else
/* a bug in os2 extproc shell processing doesn't pass full pathname
* of a script so we have to search for it.
* This changes the behavior of 'ksh arg' to search the users search
* path but it can't be helped.
#ifdef __OS2__
/*
* A bug in OS/2 extproc (like shebang) handling makes
* it not pass the full pathname of a script, so we need
* to search for it. This changes the behaviour of a
* simple "mksh foo", but can't be helped.
*/
s->file = search_path(argv[argi++], path, X_OK, NULL);
if (!s->file || !*s->file)
s->file = argv[argi - 1];
#else
s->file = argv[argi++];
#endif
s->u.shf = shf_open(s->file, O_RDONLY, 0,
SHF_MAPHI | SHF_CLEXEC);
@ -1376,7 +1384,7 @@ initio(void)
shf_fdopen(2, SHF_WR, shl_xtrace);
#ifdef DF
if ((lfp = getenv("SDMKSH_PATH")) == NULL) {
if ((lfp = getenv("HOME")) == NULL || !IS_ABS_PATH(lfp))
if ((lfp = getenv("HOME")) == NULL || !mksh_abspath(lfp))
errorf("cannot get home directory");
lfp = shf_smprintf("%s/mksh-dbg.txt", lfp);
}
@ -1416,12 +1424,6 @@ ksh_dup2(int ofd, int nfd, bool errok)
return (rv);
}
#ifdef __OS2__
#define IS_EXPECTED_ERRNO(e) ((e) == EBADF || (e) == EPERM)
#else
#define IS_EXPECTED_ERRNO(e) ((e) == EBADF)
#endif
/*
* Move fd from user space (0 <= fd < 10) to shell space (fd >= 10),
* set close-on-exec flag. See FDBASE in sh.h, maybe 24 not 10 here.
@ -1432,7 +1434,7 @@ savefd(int fd)
int nfd = fd;
if (fd < FDBASE && (nfd = fcntl(fd, F_DUPFD, FDBASE)) < 0 &&
IS_EXPECTED_ERRNO(errno))
(errno == EBADF || errno == EPERM))
return (-1);
if (nfd < 0 || nfd > SHRT_MAX)
errorf("too many files open in shell");
@ -1657,7 +1659,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist)
} while (len < 6);
/* check if this one works */
if ((i = open(tp->tffn, O_CREAT | O_EXCL | O_RDWR | O_BINARY,
if ((i = binopen3(tp->tffn, O_CREAT | O_EXCL | O_RDWR,
0600)) < 0 && errno != EEXIST)
goto maketemp_out;
} while (i < 0);

26
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.236 2015/07/05 14:58:33 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.238 2015/07/10 19:36:36 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -1421,12 +1421,12 @@ do_realpath(const char *upath)
/* max. recursion depth */
int symlinks = 32;
if (IS_ABS_PATH(upath)) {
if (mksh_abspath(upath)) {
/* upath is an absolute pathname */
strdupx(ipath, upath, ATEMP);
} else {
/* upath is a relative pathname, prepend cwd */
if ((tp = ksh_get_wd()) == NULL || !IS_ABS_PATH(tp))
if ((tp = ksh_get_wd()) == NULL || !mksh_abspath(tp))
return (NULL);
ipath = shf_smprintf("%s%s%s", tp, "/", upath);
afree(tp, ATEMP);
@ -1529,7 +1529,7 @@ do_realpath(const char *upath)
tp = shf_smprintf("%s%s%s", ldest, *ip ? "/" : "", ip);
afree(ipath, ATEMP);
ip = ipath = tp;
if (!IS_ABS_PATH(ldest)) {
if (!mksh_abspath(ldest)) {
/* symlink target is a relative path */
xp = Xrestpos(xs, xp, pos);
} else
@ -1629,7 +1629,7 @@ make_path(const char *cwd, const char *file,
if (!file)
file = null;
if (IS_ABS_PATH(file)) {
if (mksh_abspath(file)) {
*phys_pathp = 0;
use_cdpath = false;
} else {
@ -1646,15 +1646,15 @@ make_path(const char *cwd, const char *file,
if (!plist)
use_cdpath = false;
else if (use_cdpath) {
char *pend;
char *pend = plist;
for (pend = plist; *pend && *pend != PATH_SEP; pend++)
;
while (*pend && *pend != MKSH_PATHSEPC)
++pend;
plen = pend - plist;
*cdpathp = *pend ? pend + 1 : NULL;
}
if ((!use_cdpath || !plen || !IS_ABS_PATH(plist)) &&
if ((!use_cdpath || !plen || !mksh_abspath(plist)) &&
(cwd && *cwd)) {
len = strlen(cwd);
XcheckN(*xsp, xp, len);
@ -1743,7 +1743,7 @@ simplify_path(char *p)
continue;
else if (len == 2 && tp[1] == '.') {
/* parent level, but how? */
if (IS_ABS_PATH(p))
if (mksh_abspath(p))
/* absolute path, only one way */
goto strip_last_component;
else if (dp > sp) {
@ -1943,7 +1943,7 @@ c_cd(const char **wp)
/* Ignore failure (happens if readonly or integer) */
setstr(oldpwd_s, current_wd, KSH_RETURN_ERROR);
if (!IS_ABS_PATH(Xstring(xs, xp))) {
if (!mksh_abspath(Xstring(xs, xp))) {
pwd = NULL;
} else if (!physical) {
goto norealpath_PWD;
@ -2021,9 +2021,9 @@ chvt(const Getopt *go)
#endif
}
}
if ((fd = open(dv, O_RDWR | O_BINARY)) < 0) {
if ((fd = binopen2(dv, O_RDWR)) < 0) {
sleep(1);
if ((fd = open(dv, O_RDWR | O_BINARY)) < 0) {
if ((fd = binopen2(dv, O_RDWR)) < 0) {
errorf("%s: %s %s", "chvt", "can't open", dv);
}
}

53
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.373 2015/07/06 17:48:35 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.378 2015/07/12 19:09:50 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -74,7 +74,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
.Dd $Mdocdate: July 6 2015 $
.Dd $Mdocdate: July 12 2015 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
@ -3691,6 +3691,9 @@ and
See
.Xr mknod 8
for further information.
This is not normally part of
.Nm mksh ;
however, distributors may have added this as builtin as a speed hack.
.Pp
.It Xo
.Ic print
@ -3751,8 +3754,9 @@ Approximately the same as the
.Xr printf 1 ,
utility, except it uses the same
.Sx Backslash expansion
and I/O code and does hot handle floating point as the rest of
and I/O code and does not handle floating point as the rest of
.Nm mksh .
An external utility is preferred over the builtin.
This is not normally part of
.Nm mksh ;
however, distributors may have added this as builtin as a speed hack.
@ -5394,7 +5398,7 @@ Simply causes the character to appear as literal input.
Most ordinary characters are bound to this.
.It Xo backward\-char:
.Op Ar n
.No \*(haB , \*(haXD , ANSI-CurLeft
.No \*(haB , \*(haXD , ANSI-CurLeft , PC-CurLeft
.Xc
Moves the cursor backward
.Ar n
@ -5411,7 +5415,7 @@ and dollar sign
characters.
.It beginning\-of\-history: \*(ha[\*(Lt
Moves to the beginning of the history.
.It beginning\-of\-line: \*(haA, ANSI-Home
.It beginning\-of\-line: \*(haA, ANSI-Home, PC-Home
Moves the cursor to the beginning of the edited input line.
.It Xo capitalise\-word:
.Op Ar n
@ -5467,7 +5471,7 @@ Deletes
characters before the cursor.
.It Xo delete\-char\-forward:
.Op Ar n
.No ANSI-Del
.No ANSI-Del , PC-Del
.Xc
Deletes
.Ar n
@ -5488,7 +5492,7 @@ Deletes characters after the cursor up to the end of
words.
.It Xo down\-history:
.Op Ar n
.No \*(haN , \*(haXB , ANSI-CurDown
.No \*(haN , \*(haXB , ANSI-CurDown , PC-CurDown
.Xc
Scrolls the history buffer forward
.Ar n
@ -5520,7 +5524,7 @@ The actual command executed is
.Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
.It end\-of\-history: \*(ha[\*(Gt
Moves to the end of the history.
.It end\-of\-line: \*(haE, ANSI-End
.It end\-of\-line: \*(haE, ANSI-End, PC-End
Moves the cursor to the end of the input line.
.It eot: \*(ha_
Acts as an end-of-file; this is useful because edit-mode input disables
@ -5545,7 +5549,7 @@ globbing on the word.
If no files match the pattern, the bell is rung.
.It Xo forward\-char:
.Op Ar n
.No \*(haF , \*(haXC , ANSI-CurRight
.No \*(haF , \*(haXC , ANSI-CurRight , PC-CurRight
.Xc
Moves the cursor forward
.Ar n
@ -5659,12 +5663,12 @@ commands continue searching backward to the next previous occurrence of the
pattern.
The history buffer retains only a finite number of lines; the oldest
are discarded as necessary.
.It search\-history\-up: ANSI-PgUp
.It search\-history\-up: ANSI-PgUp, PC-PgUp
Search backwards through the history buffer for commands whose beginning match
the portion of the input line before the cursor.
When used on an empty line, this has the same effect as
.Ic up\-history .
.It search\-history\-down: ANSI-PgDn
.It search\-history\-down: ANSI-PgDn, PC-PgDn
Search forwards through the history buffer for commands whose beginning match
the portion of the input line before the cursor.
When used on an empty line, this has the same effect as
@ -5684,7 +5688,7 @@ exchanges the previous and current characters and moves the cursor one
character to the right.
.It Xo up\-history:
.Op Ar n
.No \*(haP , \*(haXA , ANSI-CurUp
.No \*(haP , \*(haXA , ANSI-CurUp , PC-CurUp
.Xc
Scrolls the history buffer backward
.Ar n
@ -6112,7 +6116,7 @@ Search for the
.Ar n Ns th
occurrence of the last search string;
the direction of the search is the opposite of the last search.
.It Ar ANSI-CurUp
.It Ar ANSI-CurUp , PC-PgUp
Take the characters from the beginning of the line to the current
cursor position as search string and do a backwards history search
for lines beginning with this string; keep the cursor position.
@ -6263,6 +6267,8 @@ times.
Undo the last edit command.
.It U
Undo all changes that have been made to the current line.
.It PC Home, End, Del, and cursor keys
They move as expected, both in insert and command mode.
.It Ar intr No and Ar quit
The interrupt and quit terminal characters cause the current line to be
deleted and a new prompt to be printed.
@ -6322,8 +6328,6 @@ contains the system and suid profile.
.Xr utf\-8 7 ,
.Xr mknod 8
.Pp
.Pa http://docsrv.sco.com:507/en/man/html.C/sh.C.html
.Pp
.Pa https://www.mirbsd.org/ksh\-chan.htm
.Rs
.%A Morris Bolsky
@ -6435,9 +6439,6 @@ The complete legalese is at:
.\"
.Sh CAVEATS
.Nm
only supports the Unicode BMP (Basic Multilingual Plane).
.Pp
.Nm
has a different scope model from
.At
.Nm ksh ,
@ -6482,8 +6483,20 @@ For the purpose of
supports only the
.Dq C
locale.
For users of UTF-8 locales, the following sh code makes the shell
match the locale:
.Nm mksh Ns 's
.Ic utf8\-mode
only supports the Unicode BMP (Basic Multilingual Plane) and maps
raw octets into the U+EF80..U+EFFF wide character range; compare
.Sx Arithmetic expressions .
The following
.Tn POSIX
.Nm sh
code toggles the
.Ic utf8\-mode
option dependent on the current
.Tn POSIX
locale for mksh to allow using the UTF-8 mode, within the constraints
outlined above, in code portable across various shell implementations:
.Bd -literal -offset indent
case ${KSH_VERSION:\-} in
*MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)

58
sh.h
View File

@ -172,9 +172,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.734 2015/07/06 17:48:37 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.739 2015/07/10 19:36:37 tg Exp $");
#endif
#define MKSH_VERSION "R51 2015/07/06"
#define MKSH_VERSION "R51 2015/07/10"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -256,7 +256,7 @@ typedef MKSH_TYPEDEF_SSIZE_T ssize_t;
/* extra types */
/* OS/2 kLIBC has only a declaration of getrusage() without implementation */
/* getrusage does not exist on OS/2 kLIBC */
#if !HAVE_GETRUSAGE && !defined(__OS2__)
#undef rusage
#undef RUSAGE_SELF
@ -415,6 +415,23 @@ struct rusage {
/* OS-dependent additions (functions, variables, by OS) */
#ifdef MKSH_EXE_EXT
#undef MKSH_EXE_EXT
#define MKSH_EXE_EXT ".exe"
#else
#define MKSH_EXE_EXT ""
#endif
#ifdef __OS2__
#define MKSH_PATHSEPS ";"
#define MKSH_PATHSEPC ';'
#define MKSH_UNIXROOT "/@unixroot"
#else
#define MKSH_PATHSEPS ":"
#define MKSH_PATHSEPC ':'
#define MKSH_UNIXROOT ""
#endif
#if !HAVE_FLOCK_DECL
extern int flock(int, int);
#endif
@ -592,7 +609,7 @@ char *ucstrstr(char *, const char *);
#define mkssert(e) do { } while (/* CONSTCOND */ 0)
#endif
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 510)
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 511)
#error Must run Build.sh to compile this.
extern void thiswillneverbedefinedIhope(void);
int
@ -862,6 +879,12 @@ EXTERN const char T_typeset[] E_INIT("=typeset");
EXTERN const char Talias[] E_INIT("alias");
EXTERN const char Tunalias[] E_INIT("unalias");
EXTERN const char Tcat[] E_INIT("cat");
#ifdef __OS2__
EXTERN const char Textproc[] E_INIT("extproc");
#endif
#ifdef MKSH_PRINTF_BUILTIN
EXTERN const char Tprintf[] E_INIT("printf");
#endif
EXTERN const char Tsgset[] E_INIT("*=set");
#define Tset (Tsgset + 2) /* "set" */
EXTERN const char Tsgexport[] E_INIT("*=export");
@ -2115,6 +2138,33 @@ EXTERN bool tty_hasstate; /* true if tty_state is valid */
extern int tty_init_fd(void); /* initialise tty_fd, tty_devtty */
#ifdef __OS2__
#ifndef __GNUC__
# error oops?
#endif
#define binopen2(path,flags) __extension__({ \
int binopen2_fd = open((path), (flags) | O_BINARY); \
if (binopen2_fd >= 0) \
setmode(binopen2_fd, O_BINARY); \
(binopen2_fd); \
})
#define binopen3(path,flags,mode) __extension__({ \
int binopen3_fd = open((path), (flags) | O_BINARY, (mode)); \
if (binopen3_fd >= 0) \
setmode(binopen3_fd, O_BINARY); \
(binopen3_fd); \
})
#define mksh_abspath(s) __extension__({ \
const char *mksh_abspath_s = (s); \
(mksh_abspath_s[0] == '/' || (ksh_isalphx(mksh_abspath_s[0]) && \
mksh_abspath_s[1] == ':')); \
})
#else
#define binopen2(path,flags) open((path), (flags) | O_BINARY)
#define binopen3(path,flags,mode) open((path), (flags) | O_BINARY, (mode))
#define mksh_abspath(s) ((s)[0] == '/')
#endif
/* be sure not to interfere with anyone else's idea about EXTERN */
#ifdef EXTERN_DEFINED
# undef EXTERN_DEFINED

4
shf.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.65 2015/04/29 20:07:35 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.66 2015/07/09 20:52:43 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -62,7 +62,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
shf->flags = SHF_ALLOCS;
/* Rest filled in by reopen. */
fd = open(name, oflags | O_BINARY, mode);
fd = binopen3(name, oflags, mode);
if (fd < 0) {
eno = errno;
afree(shf, shf->areap);

4
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.192 2015/04/29 20:07:35 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.193 2015/07/10 19:36:38 tg Exp $");
/*-
* Variables
@ -1300,7 +1300,7 @@ setspec(struct tbl *vp)
s = str_val(vp);
/* LINTED use of access */
if (IS_ABS_PATH(s) && access(s, W_OK|X_OK) == 0 &&
if (mksh_abspath(s) && access(s, W_OK|X_OK) == 0 &&
stat(s, &statb) == 0 && S_ISDIR(statb.st_mode))
strdupx(tmpdir, s, APERM);
}