History log of /freebsd-9.3-release/bin/sh/cd.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 230624 27-Jan-2012 jilles

MFC r230095: sh: Properly show "Not a directory" error in cd builtin.

The errno message display added in r222292 did not take attempting to
cd to a non-directory or something that cannot be stat()ed into account.

PR: bin/164070


# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 223060 13-Jun-2011 jilles

sh: Fix duplicate prototypes for builtins.

Have mkbuiltins write the prototypes for the *cmd functions to builtins.h
instead of builtins.c and include builtins.h in more .c files instead of
duplicating prototypes for *cmd functions in other headers.


# 222381 27-May-2011 jilles

sh: Correct criterion for using CDPATH in cd.

CDPATH should be ignored not only for pathnames starting with '/' but also
for pathnames whose first component is '.' or '..'.

The man page already describes this behaviour.


# 222292 25-May-2011 jilles

sh: Show errno messages in cd.


# 222154 20-May-2011 jilles

sh: Implement the cd -e flag proposed for the next POSIX issue.

This reflects failure to determine the pathname of the new directory in the
exit status (1). Normally, cd returns successfully if it did chdir() and the
call was successful.

In POSIX, -e only has meaning with -P; because our -L is not entirely
compliant and may fall back to -P mode, -e has some effect with -L as well.


# 216622 21-Dec-2010 jilles

sh: Add a function to print warnings (with command name and newline).
This is like error() but without raising an exception.
It is particularly useful as a replacement for the warnx macro in
bltin/bltin.h.


# 215783 23-Nov-2010 jilles

sh: Code size optimizations to "stack string" memory allocation:
* Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC.
* Add STPUTS macro (based on function) and use it instead of loops that add
nul-terminated strings to the stack string.

No functional change is intended, but code size is about 1K less on i386.


# 215727 22-Nov-2010 jilles

sh: Fix confusing behaviour if chdir succeeded but getcwd failed in cd -P.

If getcwd fails, do not treat this as an error, but print a warning and
unset PWD. This is similar to the behaviour when starting the shell in a
directory whose name cannot be determined.


# 213811 13-Oct-2010 obrien

In the spirit of r90111, depend on c89 and remove the "STATIC" macro
and its usage.


# 213760 13-Oct-2010 obrien

Consistently use "STATIC" for all functions in order to be able to set
breakpoints with in a debugger. And use naked "static" for variables.

Noticed by: bde


# 206759 17-Apr-2010 jilles

sh: On startup of the shell, use PWD from the environment if it is valid.
Unset PWD if it is incorrect and no value for it can be determined.
This preserves the logical current directory across shell invocations.

Example (assuming /home is a symlink):
$ cd
$ pwd
/home/foo
$ sh
$ pwd
/home/foo

Formerly the second pwd would show the physical path (symlinks resolved).


# 201053 27-Dec-2009 jilles

sh: Various warning fixes (from WARNS=6 NO_WERROR=1):
- const
- initializations to silence -Wuninitialized (it was safe anyway)
- remove nested extern declarations
- rename "index" locals to "idx"


# 200956 24-Dec-2009 jilles

sh: Constify various strings.

Most of this is adding const keywords, but setvar() in var.c had to be
changed somewhat more.


# 199631 21-Nov-2009 stefanf

Handle current work directories of arbitrary length. The argument to cd
continues to be limited by PATH_MAX (1024).

Obtained from: NetBSD
PR: 104456


# 176521 24-Feb-2008 stefanf

Split updatepwd() into two smaller functions. The first one, findpwd(),
computes the new path and the second one, updatepwd(), updates the variables
PWD, OLDPWD and the path used for the pwd builtin according to the new
directory. For a logical directory change, chdir() is now called between
those two functions, no longer causing wrong values to be stored in PWD etc. if
it fails.

PR: 64990, 101316, 120571


# 159551 12-Jun-2006 stefanf

Don't strip a leading ./ from the path for the cd builtin to avoid interpreting
.//dir as /dir. Rather strip it only for the purpose of checking if the
directory path should be printed.

PR: 88813
Submitted by: Josh Elsasser
Patch from: NetBSD (cd.c rev 1.38)
MFC after: 2 weeks


# 127958 06-Apr-2004 markm

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 117261 05-Jul-2003 dds

Changes following CScout analysis:

- Removed dead declarations
- Made objects that should have been declared as static, static.

The changes use STATIC instead of static, following the existing
convention in the rest of the code.

Approved by: schweikh (mentor)
MFC after: 2 weeks


# 100664 25-Jul-2002 tjr

Add a -P/-o physical option which behaves similarly to bash/ksh's options
by the same name. This option makes the cd and pwd builtins behave physically
(as opposed to logically) by default.

Submitted by: fanf


# 100663 25-Jul-2002 tjr

Set opterr to zero to avoid duplicate warnings from getopt(3) for unknown
options.


# 100661 25-Jul-2002 tjr

Use PATH_MAX instead of a local guess at it, which happened to be incorrect.

Suggested by: fanf


# 100660 25-Jul-2002 tjr

pwdcmd()'s argc and argv arguments are no longer unused, remove __unused.

Pointed out by: fanf


# 100351 19-Jul-2002 tjr

Remove broken and incomplete support for old releases of System V,
don't support system that implement getcwd(3) with a pipe to /bin/pwd.


# 99110 30-Jun-2002 obrien

Consistently use FBSDID


# 97092 22-May-2002 tjr

Bring back the cd -L and -P options from revision 1.24, but try harder not
to fail when the logical current directory no longer exists. Allow changes
to absolute paths when logical cwd is invalid, fall back to physical cd
if logical cd fails.


# 97091 22-May-2002 tjr

Temporarily back out revision 1.24; it seems to handle the case where the
current directory no longer exists incorrectly and breaks `make cleandir'.


# 96980 20-May-2002 tjr

Add the SUSv3 -L and -P options to the cd and pwd builtin utilities. `Logical'
handling of .. is now the default.


# 96948 19-May-2002 jmallett

Remove a small, annoying, nit I ran in to editing this file, a lone tab
on a line by itself.


# 90111 02-Feb-2002 imp

o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
they already are.
o Change
int
foo() {
...
to
int
foo(void)
{
...


# 86176 07-Nov-2001 tegge

Don't call setvar() with the VTEXTFIXED flag. A copy is created by
setvar() and passed to setvareq(). When the VTEXTFIXED flag is set,
that copy is never freed, causing a memory leak.

PR: 31533
Submitted by: maxim@macomnet.ru


# 53891 29-Nov-1999 cracauer

Include strerror(errno) in error messages after failed system calls.
Fix a warning.


# 50471 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 38886 06-Sep-1998 tegge

Don't blindly eliminate `..' and the previous pathname component.
PR: 2541
Obtained from: NetBSD


# 36150 18-May-1998 charnier

Add rcsid. Spelling.


# 25905 18-May-1997 steve

Use the __unused attribute where warranted.


# 25222 28-Apr-1997 steve

Nuke register keyword usage and #if -> #ifdef.

Obtained from: NetBSD


# 22988 22-Feb-1997 peter

Revert $FreeBSD$ to $Id$


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 21301 04-Jan-1997 steve

Make sh(1) think and be in the same place at the same time. This closes
PR#2331: strange output of sh's pwd on symlinked directories.


# 20887 23-Dec-1996 steve

Oops, it needs little more caulk to get it right.


# 20886 23-Dec-1996 steve

Apply a little dab of bit caulk to keep those beggars
from leaking out.

Noticed by: bde


# 20848 23-Dec-1996 steve

Don't use _POSIX_PATH_MAX to limit the size of the path, instead
use 'getcwd(NULL, 0)' just as pwd(1) does.

Suggested by: bde


# 20774 21-Dec-1996 steve

Make sh(1) a little braver in the face of adversity. sh(1)
now handles the getpwd() init problem the same way as bash
and ksh do. Also while I was in here, I cleaned up the format
a little, removed some unnnecessary #if SYMLINKS cruft, and
changed the pwd builtin to use getcwd(3) as Joerg suggested.


# 20425 14-Dec-1996 steve

Merge in NetBSD mods and -Wall cleaning.

Obtained from: NetBSD, me


# 17987 01-Sep-1996 peter

Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is a
merge of parallel duplicate work by Steve Price and myself. :-]

There are some changes to the build that are my fault... mkinit.c was
trying (poorly) to duplicate some of the work that make(1) is designed to
do. The Makefile hackery is my fault too, the depend list was incomplete
because of some explicit OBJS+= entries, so mkdep wasn't picking up their
source file #includes.

This closes a pile of /bin/sh PR's, but not all of them..

Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter


# 12273 13-Nov-1995 peter

A fix for the "cd -" coredump on a brand new /bin/sh. The problem was
noticed on a NetBSD bugs mailing list but this is entirely my own work.

Inspired by: Scott Reynolds <scottr@plexus.com>, for NetBSD


# 5234 26-Dec-1994 bde

Obtained from: partly from 1.1.5

Convert "" to "." for "cd" and "cd ''". chdir("") is required to fail
on POSIX systems.


# 4192 05-Nov-1994 jkh

Get this braindead, mongoloid shell look in /stand for pwd if it can't
find it in /bin. This is something of a kludge, I know, but consider
my limited alternatives: I can't make this an execvp() without making
people scream that I introduced a failure point or slowed down pwd,
and I can't make it an optional macro since crunch doesn't let you pass
arbitrary command-line args to the build of one of its crunch-ees.
This is the simplest, if not the nicest looking, solution I could come up
with.


# 3044 24-Sep-1994 dg

Added $Id$


# 1557 26-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1556,
which included commits to RCS files with non-trunk default branches.


# 1556 26-May-1994 rgrimes

BSD 4.4 Lite bin Sources