do not use PATH_MAX on GNU/Hurd (even if it *was* defined), but use

some glibc-only functions that don’t require its use instead

tested on gnubber, where (admittedly) sysconf(_PC_PATH_MAX) == 1024…
This commit is contained in:
tg 2009-10-27 17:00:02 +00:00
parent ceb591bf6a
commit dc98ec23a6
5 changed files with 44 additions and 11 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.429 2009/10/16 18:51:30 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.430 2009/10/27 16:59:59 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009
# Thorsten Glaser <tg@mirbsd.org>
@ -362,7 +362,8 @@ DragonFly)
FreeBSD)
;;
GNU)
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
# define NO_PATH_MAX to use Hurd-only functions
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE -DNO_PATH_MAX"
;;
GNU/kFreeBSD)
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.334 2009/10/18 12:30:04 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.335 2009/10/27 17:00:00 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 $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R39 2009/10/18
@(#)MIRBSD KSH R39 2009/10/27
description:
Check version of shell.
stdin:

24
funcs.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.140 2009/10/15 16:36:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.141 2009/10/27 17:00:01 tg Exp $");
#if HAVE_KILLPG
/*
@ -267,12 +267,29 @@ do_realpath(const char *upath)
}
/* get symlink(7) target */
#ifdef NO_PATH_MAX
if (ldest) {
afree(ldest, ATEMP);
ldest = NULL;
}
{
struct stat hurd_sb;
if (lstat(Xstring(xs, xp), &hurd_sb))
goto notfound;
ldest = alloc(hurd_sb.st_size + 1, ATEMP);
if ((llen = readlink(Xstring(xs, xp), ldest,
hurd_sb.st_size)) < 0)
goto notfound;
}
#else
if (!ldest)
ldest = alloc(PATH_MAX + 1, ATEMP);
if ((llen = readlink(Xstring(xs, xp), ldest,
PATH_MAX)) < 0)
/* oops... */
goto notfound;
#endif
ldest[llen] = '\0';
/*
@ -398,7 +415,12 @@ c_cd(const char **wp)
return (1);
}
#ifdef NO_PATH_MAX
/* only a first guess; make_path will enlarge xs if necessary */
XinitN(xs, 1024, ATEMP);
#else
XinitN(xs, PATH_MAX, ATEMP);
#endif
cdpath = str_val(global("CDPATH"));
do {

11
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.125 2009/10/02 18:08:35 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.126 2009/10/27 17:00:02 tg Exp $");
#undef USE_CHVT
/* XXX conditions correct? */
@ -1038,10 +1038,19 @@ ksh_get_wd(size_t *dlen)
char *ret, *b;
size_t len = 1;
#ifdef NO_PATH_MAX
if ((b = get_current_dir_name())) {
len = strlen(b) + 1;
strndupx(ret, b, len - 1, ATEMP);
free(b);
} else
ret = NULL;
#else
if ((ret = getcwd((b = alloc(PATH_MAX + 1, ATEMP)), PATH_MAX)))
ret = aresize(b, len = (strlen(b) + 1), ATEMP);
else
afree(b, ATEMP);
#endif
if (dlen)
*dlen = len;

11
sh.h
View File

@ -134,9 +134,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.357 2009/10/18 12:30:05 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.358 2009/10/27 17:00:02 tg Exp $");
#endif
#define MKSH_VERSION "R39 2009/10/18"
#define MKSH_VERSION "R39 2009/10/27"
#ifndef MKSH_INCLUDES_ONLY
@ -211,9 +211,13 @@ typedef int bool;
#define ksh_isdash(s) (((s) != NULL) && ((s)[0] == '-') && ((s)[1] == '\0'))
#define ksh_isspace(c) ((((c) >= 0x09) && ((c) <= 0x0D)) || ((c) == 0x20))
#ifdef NO_PATH_MAX
#undef PATH_MAX
#else
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
#endif
#ifndef SIZE_MAX
#ifdef SIZE_T_MAX
#define SIZE_MAX SIZE_T_MAX
@ -344,9 +348,6 @@ typedef uint32_t mksh_uari_t;
#define NOT '!' /* might use ^ (ie, [!...] vs [^..]) */
#define LINE 4096 /* input line size */
#ifndef PATH_MAX
#define PATH_MAX 1024 /* pathname size */
#endif
EXTERN struct {
const char *kshname_; /* $0 */