From owner-svn-src-stable@FreeBSD.ORG Sat Oct 9 12:57:06 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E5C63106566B; Sat, 9 Oct 2010 12:57:06 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D4AF08FC19; Sat, 9 Oct 2010 12:57:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o99Cv6Ka040227; Sat, 9 Oct 2010 12:57:06 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o99Cv6q6040225; Sat, 9 Oct 2010 12:57:06 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201010091257.o99Cv6q6040225@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 9 Oct 2010 12:57:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r213654 - stable/8/bin/sh X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Oct 2010 12:57:07 -0000 Author: jilles Date: Sat Oct 9 12:57:06 2010 New Revision: 213654 URL: http://svn.freebsd.org/changeset/base/213654 Log: MFC r209653: sh: Use $PWD instead of getcwd() for \w \W prompt expansions. This ensures that the logical working directory (which may include symlinks) is shown and is similar to the default behaviour of the pwd builtin. Modified: stable/8/bin/sh/parser.c Directory Properties: stable/8/bin/sh/ (props changed) Modified: stable/8/bin/sh/parser.c ============================================================================== --- stable/8/bin/sh/parser.c Sat Oct 9 11:43:00 2010 (r213653) +++ stable/8/bin/sh/parser.c Sat Oct 9 12:57:06 2010 (r213654) @@ -1583,7 +1583,8 @@ getprompt(void *unused __unused) { static char ps[PROMPTLEN]; char *fmt; - int i, j, trim; + const char *pwd; + int i, trim; static char internal_error[] = ""; /* @@ -1634,17 +1635,15 @@ getprompt(void *unused __unused) */ case 'W': case 'w': - ps[i] = '\0'; - getcwd(&ps[i], PROMPTLEN - i); - if (*fmt == 'W' && ps[i + 1] != '\0') { - /* Final path component only. */ - trim = 1; - for (j = i; ps[j] != '\0'; j++) - if (ps[j] == '/') - trim = j + 1; - memmove(&ps[i], &ps[trim], - j - trim + 1); - } + pwd = lookupvar("PWD"); + if (pwd == NULL) + pwd = "?"; + if (*fmt == 'W' && + *pwd == '/' && pwd[1] != '\0') + strlcpy(&ps[i], strrchr(pwd, '/') + 1, + PROMPTLEN - i); + else + strlcpy(&ps[i], pwd, PROMPTLEN - i); /* Skip to end of path. */ while (ps[i + 1] != '\0') i++;