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

10
misc.c
View File

@ -1,9 +1,9 @@
/* $OpenBSD: misc.c,v 1.28 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: misc.c,v 1.30 2006/03/12 00:26:58 deraadt Exp $ */
/* $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.10 2005/11/24 19:39:10 tg Exp $"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.11 2006/05/10 18:54:11 tg Exp $"
"\t" MKSH_SH_H_ID);
short chtypes[UCHAR_MAX+1]; /* type bits for unsigned char */
@ -328,7 +328,7 @@ parse_args(char **argv,
} else
opts = set_opts;
ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
while ((optc = ksh_getopt(argv, &go, opts)) != EOF) {
while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
set = (go.info & GI_PLUS) ? 0 : 1;
switch (optc) {
case 'A':
@ -896,14 +896,14 @@ ksh_getopt(char **argv, Getopt *go, const char *optionsp)
go->optind++;
go->p = 0;
go->info |= GI_MINUSMINUS;
return EOF;
return -1;
}
if (arg == NULL ||
((flag != '-' ) && /* neither a - nor a + (if + allowed) */
(!(go->flags & GF_PLUSOPT) || flag != '+')) ||
(c = arg[1]) == '\0') {
go->p = 0;
return EOF;
return -1;
}
go->optind++;
go->info &= ~(GI_MINUS|GI_PLUS);