add new builtin “realpath” calling realpath(3) on its argument, skipping
over “--” for compatibility to Debian realpath(1) and possibly busybox’ “sounds handy” replaced@TNF
This commit is contained in:
parent
b40ba2c8d1
commit
b41a72ac2e
18
Build.sh
18
Build.sh
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.323 2008/05/17 18:19:11 tg Exp $'
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.324 2008/05/17 18:27:53 tg Exp $'
|
||||
#-
|
||||
# Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS
|
||||
# CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI
|
||||
@ -1045,6 +1045,22 @@ ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
|
||||
}
|
||||
EOF
|
||||
|
||||
ac_test realpath mksh_full 0 <<-'EOF'
|
||||
#if HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
char *res, dst[PATH_MAX];
|
||||
const char src[] = ".";
|
||||
int main(void) {
|
||||
res = realpath(src, dst);
|
||||
return (res == NULL ? 1 : 0);
|
||||
}
|
||||
EOF
|
||||
|
||||
ac_test revoke mksh_full 0 <<-'EOF'
|
||||
#if HAVE_LIBUTIL_H
|
||||
#include <libutil.h>
|
||||
|
8
Makefile
8
Makefile
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.58 2008/05/04 01:51:29 tg Exp $
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.59 2008/05/17 18:27:54 tg Exp $
|
||||
#-
|
||||
# use CPPFLAGS=-DDEBUG __CRAZY=Yes to check for certain more stuff
|
||||
|
||||
@ -19,9 +19,9 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 \
|
||||
-DHAVE_SYS_SIGLIST=1 -DHAVE_STRSIGNAL=0 -DHAVE_ARC4RANDOM=1 \
|
||||
-DHAVE_ARC4RANDOM_PUSHB=1 -DHAVE_MKSTEMP=1 \
|
||||
-DHAVE_SETLOCALE_CTYPE=1 -DHAVE_LANGINFO_CODESET=1 \
|
||||
-DHAVE_MKNOD=1 -DHAVE_REVOKE=1 -DHAVE_SETMODE=1 \
|
||||
-DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 -DHAVE_STRCASESTR=1 \
|
||||
-DHAVE_STRLCPY=1 -DHAVE_ARC4RANDOM_DECL=1 \
|
||||
-DHAVE_MKNOD=1 -DHAVE_REALPATH=1 -DHAVE_REVOKE=1 \
|
||||
-DHAVE_SETMODE=1 -DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 \
|
||||
-DHAVE_STRCASESTR=1 -DHAVE_STRLCPY=1 -DHAVE_ARC4RANDOM_DECL=1 \
|
||||
-DHAVE_ARC4RANDOM_PUSHB_DECL=1 -DHAVE_FLOCK_DECL=1 \
|
||||
-DHAVE_REVOKE_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
|
||||
-DHAVE_PERSISTENT_HISTORY=1
|
||||
|
4
check.t
4
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.195 2008/05/15 15:24:09 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.196 2008/05/17 18:27:54 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 R34 2008/05/15
|
||||
@(#)MIRBSD KSH R34 2008/05/17
|
||||
description:
|
||||
Check version of shell.
|
||||
category: pdksh
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.36 2008/05/16 22:22:11 tg Exp $
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.37 2008/05/17 18:27:55 tg Exp $
|
||||
#-
|
||||
# ~/.mkshrc: mksh initialisation file for interactive shells
|
||||
|
||||
@ -42,10 +42,10 @@ whence -p hd >&- || function hd {
|
||||
|
||||
# Berkeley C shell compatible dirs, popd, and pushd functions
|
||||
# Z shell compatible chpwd() hook, used to update DIRSTACK[0]
|
||||
DIRSTACKBASE=$(readlink -nf ~/. 2>&- || print -nr -- "$HOME")
|
||||
DIRSTACKBASE=$(realpath ~/. 2>&- || print -nr -- "$HOME")
|
||||
set -A DIRSTACK
|
||||
function chpwd {
|
||||
DIRSTACK[0]=$(readlink -nf . 2>&- || print -r -- "$PWD")
|
||||
DIRSTACK[0]=$(realpath . 2>&- || print -r -- "$PWD")
|
||||
[[ $DIRSTACKBASE = ?(*/) ]] || \
|
||||
DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/~}
|
||||
:
|
||||
|
43
funcs.c
43
funcs.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.79 2008/04/22 18:58:20 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.80 2008/05/17 18:27:55 tg Exp $");
|
||||
|
||||
/* A leading = means assignments before command are kept;
|
||||
* a leading * means a POSIX special builtin;
|
||||
@ -56,6 +56,9 @@ const struct builtin mkshbuiltins[] = {
|
||||
{"bind", c_bind},
|
||||
#if HAVE_MKNOD
|
||||
{"mknod", c_mknod},
|
||||
#endif
|
||||
#if HAVE_REALPATH
|
||||
{"realpath", c_realpath},
|
||||
#endif
|
||||
{"rename", c_rename},
|
||||
{NULL, (int (*)(const char **))NULL}
|
||||
@ -3047,3 +3050,41 @@ c_rename(const char **wp)
|
||||
|
||||
return (rv);
|
||||
}
|
||||
|
||||
#if HAVE_REALPATH
|
||||
int
|
||||
c_realpath(const char **wp)
|
||||
{
|
||||
int rv = 1;
|
||||
|
||||
if (wp != NULL && wp[0] != NULL && wp[1] != NULL) {
|
||||
if (strcmp(wp[1], "--")) {
|
||||
if (wp[2] == NULL) {
|
||||
wp += 1;
|
||||
rv = 0;
|
||||
}
|
||||
} else {
|
||||
if (wp[2] != NULL && wp[3] == NULL) {
|
||||
wp += 2;
|
||||
rv = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rv)
|
||||
bi_errorf(T_synerr);
|
||||
else {
|
||||
char *buf;
|
||||
|
||||
buf = alloc(PATH_MAX, ATEMP);
|
||||
if (realpath(*wp, buf) == NULL) {
|
||||
rv = errno;
|
||||
bi_errorf("%s: %s", *wp, strerror(rv));
|
||||
} else
|
||||
shprintf("%s\n", buf);
|
||||
afree(buf, ATEMP);
|
||||
}
|
||||
|
||||
return (rv);
|
||||
}
|
||||
#endif
|
||||
|
12
mksh.1
12
mksh.1
@ -1,4 +1,4 @@
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.127 2008/05/15 15:24:10 tg Exp $
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.128 2008/05/17 18:27:56 tg Exp $
|
||||
.\" $OpenBSD: ksh.1,v 1.121 2008/03/21 12:51:19 millert Exp $
|
||||
.\"-
|
||||
.\" Try to make GNU groff and AT&T nroff more compatible
|
||||
@ -30,7 +30,7 @@
|
||||
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
|
||||
..
|
||||
.\"-
|
||||
.Dd $Mdocdate: May 15 2008 $
|
||||
.Dd $Mdocdate: May 17 2008 $
|
||||
.Dt MKSH 1
|
||||
.Os MirBSD
|
||||
.Sh NAME
|
||||
@ -3279,6 +3279,14 @@ option is used, in which case
|
||||
commands defining all read-only parameters, including their values, are
|
||||
printed.
|
||||
.Pp
|
||||
.It Xo
|
||||
.Ic realpath
|
||||
.Op Fl \-
|
||||
.Ar name
|
||||
.Xc
|
||||
Prints the resolved absolute pathname corresponding to
|
||||
.Ar name .
|
||||
.Pp
|
||||
.It Ic rename Ar from to
|
||||
Renames the file
|
||||
.Ar from
|
||||
|
10
sh.h
10
sh.h
@ -96,9 +96,9 @@
|
||||
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.215 2008/05/15 15:24:11 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.216 2008/05/17 18:27:57 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R34 2008/05/15"
|
||||
#define MKSH_VERSION "R34 2008/05/17"
|
||||
|
||||
#ifndef MKSH_INCLUDES_ONLY
|
||||
|
||||
@ -166,6 +166,9 @@ typedef int bool;
|
||||
#define ksh_isspace(c) ksh_isspace_((unsigned int)(c))
|
||||
#endif
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
#ifndef S_ISLNK
|
||||
#define S_ISLNK(m) ((m & 0170000) == 0120000)
|
||||
#endif
|
||||
@ -1292,6 +1295,9 @@ int c_test(const char **);
|
||||
#if HAVE_MKNOD
|
||||
int c_mknod(const char **);
|
||||
#endif
|
||||
#if HAVE_REALPATH
|
||||
int c_realpath(const char **);
|
||||
#endif
|
||||
int c_rename(const char **);
|
||||
/* histrap.c */
|
||||
void init_histvec(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user