* main.c: prevent segmentation faults on inferiour operating systems

such as Debian GNU/Linux "etch" 4.0 with not installed locale file
  corresponding to the current environmental settings. ばかたち!
This commit is contained in:
tg 2007-01-06 17:08:14 +00:00
parent 8a59ee0311
commit dbf5cdf632
3 changed files with 10 additions and 8 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.77 2007/01/03 22:43:47 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.78 2007/01/06 17:08:14 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R29 2007/01/03
@(#)MIRBSD KSH R29 2007/01/06
description:
Check version of shell.
category: pdksh

10
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.63 2007/01/03 22:43:47 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.64 2007/01/06 17:08:14 tg Exp $");
extern char **environ;
@ -280,16 +280,18 @@ main(int argc, char *argv[])
/* Do this after j_init(), as tty_fd is not initialized 'til then */
if (Flag(FTALKING)) {
#if HAVE_SETLOCALE_CTYPE
#define isuc(x) (((x) != NULL) && \
(strcasestr((x), "UTF-8") || strcasestr((x), "utf8")))
/* Check if we're in a UTF-8 locale */
if (!Flag(FUTFHACK)) {
cc = setlocale(LC_CTYPE, "");
#if HAVE_LANGINFO_CODESET
if (!strcasestr(cc, "UTF-8") && !strcasestr(cc, "utf8"))
if (!isuc(cc))
cc = nl_langinfo(CODESET);
#endif
Flag(FUTFHACK) = strcasestr(cc, "UTF-8") ||
strcasestr(cc, "utf8");
Flag(FUTFHACK) = isuc(cc);
}
#undef isuc
#endif
x_init();
}

4
sh.h
View File

@ -8,8 +8,8 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.89 2007/01/03 22:43:48 tg Exp $"
#define MKSH_VERSION "R29 2007/01/03"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.90 2007/01/06 17:08:14 tg Exp $"
#define MKSH_VERSION "R29 2007/01/06"
#if HAVE_SYS_PARAM_H
#include <sys/param.h>