diff --git a/Build.sh b/Build.sh index 7161fc2..bd1496f 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/bin/sh -srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.687 2015/07/09 20:11:44 tg Exp $' +srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.688 2015/07/09 20:52:34 tg Exp $' #- # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # 2011, 2012, 2013, 2014, 2015 @@ -1673,6 +1673,7 @@ ac_header sys/select.h sys/types.h ac_header sys/sysmacros.h ac_header bstring.h ac_header grp.h sys/types.h +ac_header io.h ac_header libgen.h ac_header libutil.h sys/types.h ac_header paths.h @@ -2340,7 +2341,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 diff --git a/Makefile b/Makefile index 2485e08..db6e767 100644 --- a/Makefile +++ b/Makefile @@ -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 -D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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 diff --git a/check.t b/check.t index 820c136..7ee8d44 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.701 2015/07/09 20:11:45 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.702 2015/07/09 20:52:36 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/09 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/09 description: Check version of legacy shell. stdin: @@ -8613,6 +8613,7 @@ stdin: cat >foo <<-'EOF' x='bar ' # + echo .${#x} # if test x"$KSH_VERSION" = x""; then # printf '<%s>' "$x" # else # @@ -8624,8 +8625,10 @@ stdin: print -r -- "{$line}" done expected-stdout: - [] + {.5} {foo <<-'EOF' x='bar ' # + echo .${#x} # if test x"$KSH_VERSION" = x""; then # printf '<%s>' "$x" # else # @@ -8646,8 +8650,10 @@ stdin: print -r -- "{$line}" done expected-stdout: - [] + {.4} {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; @@ -1445,7 +1445,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 */ @@ -1578,7 +1578,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)); diff --git a/funcs.c b/funcs.c index 223ab8a..0d2aec3 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.279 2015/07/09 20:20:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.280 2015/07/09 20:52:39 tg Exp $"); #if HAVE_KILLPG /* @@ -3668,7 +3668,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; diff --git a/histrap.c b/histrap.c index d19dbb6..7a96aa8 100644 --- a/histrap.c +++ b/histrap.c @@ -27,7 +27,7 @@ #include #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; } diff --git a/main.c b/main.c index 3e4dee0..2799829 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.298 2015/07/09 19:46:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.299 2015/07/09 20:52:40 tg Exp $"); extern char **environ; @@ -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(); @@ -1637,7 +1643,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); diff --git a/misc.c b/misc.c index 8ad5864..c7cfdbc 100644 --- a/misc.c +++ b/misc.c @@ -30,7 +30,7 @@ #include #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.237 2015/07/09 20:52:41 tg Exp $"); #define KSH_CHVT_FLAG #ifdef MKSH_SMALL @@ -2009,9 +2009,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); } } diff --git a/sh.h b/sh.h index 1e5c386..3c8fa5d 100644 --- a/sh.h +++ b/sh.h @@ -64,6 +64,9 @@ #include #include #include +#if HAVE_IO_H +#include +#endif #if HAVE_LIBGEN_H #include #endif @@ -169,9 +172,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.737 2015/07/09 20:20:45 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.738 2015/07/09 20:52:42 tg Exp $"); #endif -#define MKSH_VERSION "R51 2015/07/06" +#define MKSH_VERSION "R51 2015/07/09" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -560,7 +563,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 @@ -2081,6 +2084,27 @@ 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); \ +}) +#else +#define binopen2(path,flags) open((path), (flags) | O_BINARY) +#define binopen3(path,flags,mode) open((path), (flags) | O_BINARY, (mode)) +#endif + /* be sure not to interfere with anyone else's idea about EXTERN */ #ifdef EXTERN_DEFINED # undef EXTERN_DEFINED diff --git a/shf.c b/shf.c index 9647ce6..1c9e3d5 100644 --- a/shf.c +++ b/shf.c @@ -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);