expand ~foo to getpwnam("foo")->dir only #if !defined(MKSH_SMALL)

this makes it possible to build a (small) mksh on glibc systems statically
This commit is contained in:
tg 2007-01-11 00:32:31 +00:00
parent 56e8571167
commit e960fabf63
5 changed files with 25 additions and 7 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.78 2007/01/06 17:08:14 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.79 2007/01/11 00:32:30 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas 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: 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 $ # $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 # http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R29 2007/01/06 @(#)MIRBSD KSH R29 2007/01/11
description: description:
Check version of shell. Check version of shell.
category: pdksh category: pdksh

8
eval.c
View File

@ -2,7 +2,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.19 2006/11/12 14:58:14 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.20 2007/01/11 00:32:30 tg Exp $");
/* /*
* string expansion * string expansion
@ -43,7 +43,11 @@ static void glob(char *, XPtrV *, int);
static void globit(XString *, char **, char *, XPtrV *, int); static void globit(XString *, char **, char *, XPtrV *, int);
static char *maybe_expand_tilde(char *, XString *, char **, int); static char *maybe_expand_tilde(char *, XString *, char **, int);
static char *tilde(char *); static char *tilde(char *);
#ifndef MKSH_SMALL
static char *homedir(char *); static char *homedir(char *);
#else
#define homedir(x) null
#endif
static void alt_expand(XPtrV *, char *, char *, char *, int); static void alt_expand(XPtrV *, char *, char *, char *, int);
/* compile and expand word */ /* compile and expand word */
@ -1171,6 +1175,7 @@ tilde(char *cp)
return dp; return dp;
} }
#ifndef MKSH_SMALL
/* /*
* map userid to user's home directory. * map userid to user's home directory.
* note that 4.3's getpw adds more than 6K to the shell, * note that 4.3's getpw adds more than 6K to the shell,
@ -1195,6 +1200,7 @@ homedir(char *name)
} }
return ap->val.s; return ap->val.s;
} }
#endif
static void static void
alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo) alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)

10
funcs.c
View File

@ -5,7 +5,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.39 2006/12/06 13:41:23 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.40 2007/01/11 00:32:31 tg Exp $");
int int
c_cd(char **wp) c_cd(char **wp)
@ -815,7 +815,11 @@ c_alias(char **wp)
prefix = builtin_opt.info & GI_PLUS ? '+' : '-'; prefix = builtin_opt.info & GI_PLUS ? '+' : '-';
switch (optc) { switch (optc) {
case 'd': case 'd':
#ifdef MKSH_SMALL
return (0);
#else
t = &homedirs; t = &homedirs;
#endif
break; break;
case 'p': case 'p':
pflag = 1; pflag = 1;
@ -950,7 +954,11 @@ c_unalias(char **wp)
all = 1; all = 1;
break; break;
case 'd': case 'd':
#ifdef MKSH_SMALL
return (0);
#else
t = &homedirs; t = &homedirs;
#endif
break; break;
case 't': case 't':
t = &taliases; t = &taliases;

4
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.64 2007/01/06 17:08:14 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.65 2007/01/11 00:32:31 tg Exp $");
extern char **environ; extern char **environ;
@ -117,7 +117,9 @@ main(int argc, char *argv[])
/* set up variable and command dictionaries */ /* set up variable and command dictionaries */
ktinit(&taliases, APERM, 0); ktinit(&taliases, APERM, 0);
ktinit(&aliases, APERM, 0); ktinit(&aliases, APERM, 0);
#ifndef MKSH_SMALL
ktinit(&homedirs, APERM, 0); ktinit(&homedirs, APERM, 0);
#endif
/* define shell keywords */ /* define shell keywords */
initkeywords(); initkeywords();

6
sh.h
View File

@ -8,8 +8,8 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $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 $ */ /* $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.91 2007/01/06 18:48:27 tg Exp $" #define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.92 2007/01/11 00:32:31 tg Exp $"
#define MKSH_VERSION "R29 2007/01/06" #define MKSH_VERSION "R29 2007/01/11"
#if HAVE_SYS_PARAM_H #if HAVE_SYS_PARAM_H
#include <sys/param.h> #include <sys/param.h>
@ -683,7 +683,9 @@ EXTERN struct table taliases; /* tracked aliases */
EXTERN struct table builtins; /* built-in commands */ EXTERN struct table builtins; /* built-in commands */
EXTERN struct table aliases; /* aliases */ EXTERN struct table aliases; /* aliases */
EXTERN struct table keywords; /* keywords */ EXTERN struct table keywords; /* keywords */
#ifndef MKSH_SMALL
EXTERN struct table homedirs; /* homedir() cache */ EXTERN struct table homedirs; /* homedir() cache */
#endif
struct builtin { struct builtin {
const char *name; const char *name;