apply some fixes from OpenBSD and don't apply some others

but sync RCS IDs for easier future adaption:
* Simplify savefd() by removing the "noclose" flag and make noclose
  behavior the default. Almost all uses of savefd() are followed
  by an implicit or explicit close.
* fix typos
* might as well make ksh_getopt() match real getopt(), ie. get rid of that
  stupid EOF concept that was never true. adobriyan@gmail
* use SEEK_* for lseek()
* fix lint comments, no functional changes
* remove excessive optimization; from adobriyan@gmail
* only santa checks things twice; from adobriyan@gmail
* Interpret zero-filled numbers as decimal; PR 4213; from Alexey Dobriyan
This commit is contained in:
tg
2006-05-10 18:54:13 +00:00
parent 301066165b
commit 7672b9b346
16 changed files with 96 additions and 93 deletions

33
main.c
View File

@@ -1,12 +1,12 @@
/* $OpenBSD: main.c,v 1.40 2005/12/11 20:31:21 otto Exp $ */
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: main.c,v 1.41 2006/04/10 14:38:59 jaredy Exp $ */
/* $OpenBSD: tty.c,v 1.9 2006/03/14 22:08:01 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.22 2006/03/17 16:30:13 millert Exp $ */
/* $OpenBSD: table.c,v 1.12 2005/12/11 20:31:21 otto Exp $ */
#define EXTERN /* define EXTERNs in sh.h */
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.35 2006/05/08 11:42:36 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.36 2006/05/10 18:54:11 tg Exp $");
#define MKSH_VERSION "@(#)MIRBSD KSH R26 2006/05/08"
@@ -676,12 +676,9 @@ tty_init(int init_ttystate)
tty_devtty = 1;
if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) {
if (tfd < 0) {
tty_devtty = 0;
warningf(false,
"No controlling tty (open /dev/tty: %s)",
strerror(errno));
}
tty_devtty = 0;
warningf(false, "No controlling tty (open /dev/tty: %s)",
strerror(errno));
}
if (tfd < 0) {
do_close = 0;
@@ -878,7 +875,7 @@ ksh_dup2(int ofd, int nfd, int errok)
* set close-on-exec flag.
*/
int
savefd(int fd, int noclose)
savefd(int fd)
{
int nfd;
@@ -890,8 +887,6 @@ savefd(int fd, int noclose)
else
errorf("too many files open in shell");
}
if (!noclose)
close(fd);
} else
nfd = fd;
fcntl(nfd, F_SETFD, FD_CLOEXEC);
@@ -914,10 +909,16 @@ restfd(int fd, int ofd)
void
openpipe(int *pv)
{
if (pipe(pv) < 0)
int lpv[2];
if (pipe(lpv) < 0)
errorf("can't create pipe - try again");
pv[0] = savefd(pv[0], 0);
pv[1] = savefd(pv[1], 0);
pv[0] = savefd(lpv[0]);
if (pv[0] != lpv[0])
close(lpv[0]);
pv[1] = savefd(lpv[1]);
if (pv[1] != lpv[1])
close(lpv[1]);
}
void