aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/cd.c
Commit message (Collapse)AuthorAgeFilesLines
* sh: Fix rare memory leak with SIGINTJilles Tjoelker2020-01-011-1/+4
| | | | | | | | | | | | | | | | | | If getcwd() failed earlier on but later succeeded in the pwd builtin, there was no INTOFF protection between calling savestr() and storing its result. It is quite rare for getcwd() to fail, and rarer for it to succeed later in the same directory. Found via code inspection for changing ckmalloc() and similar to assert INTOFF protection instead of applying it directly (which protects against corrupting malloc's internal state but allows memory leaks or double frees). MFC after: 1 week Notes: svn path=/head/; revision=356251
* sh: Don't treat % specially in CDPATHJilles Tjoelker2018-07-151-1/+1
| | | | Notes: svn path=/head/; revision=336320
* sh: Ignore error when cd writes the directory actually switched to.Jilles Tjoelker2017-06-251-1/+10
| | | | | | | | | | | | If CDPATH is used non-trivially or the operand is "-", cd writes the directory actually switched to. (We currently do this only in interactive shells, but POSIX requires this in non-interactive shells as well.) As mentioned in Austin group bug #1045, cd shall not return an error while leaving the current directory changed. Therefore, ignore any write error. Notes: svn path=/head/; revision=320340
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* sh: Remove a global variable from cd.c.Jilles Tjoelker2016-01-241-14/+15
| | | | Notes: svn path=/head/; revision=294667
* sh: Use OLDPWD shell variable for 'cd -'.Jilles Tjoelker2016-01-231-10/+9
| | | | | | | | | | | Per POSIX, 'cd -' should use the OLDPWD shell variable, not internal state. This variable is normally exported. Also, if OLDPWD is not set, fail 'cd -' instead of changing to the current directory. Notes: svn path=/head/; revision=294649
* sh: Prefer "" to nullstr where possible.Jilles Tjoelker2015-02-151-1/+1
| | | | Notes: svn path=/head/; revision=278820
* sh: Add stsavestr(), like savestr() but allocates using stalloc().Jilles Tjoelker2015-02-151-8/+2
| | | | Notes: svn path=/head/; revision=278818
* sh: Prefer memcpy() to strcpy() in most cases. Remove the scopy macro.Jilles Tjoelker2013-11-301-4/+8
| | | | Notes: svn path=/head/; revision=258776
* sh: Prefer internal nextopt() to libc getopt().Jilles Tjoelker2012-09-151-19/+7
| | | | | | | | | | | | This reduces code duplication and code size. /usr/bin/printf is not affected. Side effect: different error messages when certain builtins are passed invalid options. Notes: svn path=/head/; revision=240541
* sh: Properly show "Not a directory" error in cd builtin.Jilles Tjoelker2012-01-131-1/+6
| | | | | | | | | | | 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 MFC after: 10 days Notes: svn path=/head/; revision=230095
* sh: Fix duplicate prototypes for builtins.Jilles Tjoelker2011-06-131-0/+1
| | | | | | | | | 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. Notes: svn path=/head/; revision=223060
* sh: Correct criterion for using CDPATH in cd.Jilles Tjoelker2011-05-271-1/+4
| | | | | | | | | | 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. Notes: svn path=/head/; revision=222381
* sh: Show errno messages in cd.Jilles Tjoelker2011-05-251-1/+4
| | | | Notes: svn path=/head/; revision=222292
* sh: Implement the cd -e flag proposed for the next POSIX issue.Jilles Tjoelker2011-05-201-8/+17
| | | | | | | | | | | | 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. Notes: svn path=/head/; revision=222154
* sh: Add a function to print warnings (with command name and newline).Jilles Tjoelker2010-12-211-1/+1
| | | | | | | | | This is like error() but without raising an exception. It is particularly useful as a replacement for the warnx macro in bltin/bltin.h. Notes: svn path=/head/; revision=216622
* sh: Code size optimizations to "stack string" memory allocation:Jilles Tjoelker2010-11-231-8/+4
| | | | | | | | | | | * 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. Notes: svn path=/head/; revision=215783
* sh: Fix confusing behaviour if chdir succeeded but getcwd failed in cd -P.Jilles Tjoelker2010-11-221-2/+5
| | | | | | | | | 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. Notes: svn path=/head/; revision=215727
* In the spirit of r90111, depend on c89 and remove the "STATIC" macroDavid E. O'Brien2010-10-131-16/+16
| | | | | | | and its usage. Notes: svn path=/head/; revision=213811
* Consistently use "STATIC" for all functions in order to be able to setDavid E. O'Brien2010-10-131-3/+3
| | | | | | | | | breakpoints with in a debugger. And use naked "static" for variables. Noticed by: bde Notes: svn path=/head/; revision=213760
* sh: On startup of the shell, use PWD from the environment if it is valid.Jilles Tjoelker2010-04-171-5/+22
| | | | | | | | | | | | | | | | | | 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). Notes: svn path=/head/; revision=206759
* sh: Various warning fixes (from WARNS=6 NO_WERROR=1):Jilles Tjoelker2009-12-271-1/+1
| | | | | | | | | | - const - initializations to silence -Wuninitialized (it was safe anyway) - remove nested extern declarations - rename "index" locals to "idx" Notes: svn path=/head/; revision=201053
* sh: Constify various strings.Jilles Tjoelker2009-12-241-1/+1
| | | | | | | | Most of this is adding const keywords, but setvar() in var.c had to be changed somewhat more. Notes: svn path=/head/; revision=200956
* Handle current work directories of arbitrary length. The argument to cdStefan Farfeleder2009-11-211-21/+28
| | | | | | | | | | continues to be limited by PATH_MAX (1024). Obtained from: NetBSD PR: 104456 Notes: svn path=/head/; revision=199631
* Split updatepwd() into two smaller functions. The first one, findpwd(),Stefan Farfeleder2008-02-241-38/+45
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=176521
* Don't strip a leading ./ from the path for the cd builtin to avoid interpretingStefan Farfeleder2006-06-121-2/+3
| | | | | | | | | | | | | .//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 Notes: svn path=/head/; revision=159551
* Remove clause 3 from the UCB licenses.Mark Murray2004-04-061-4/+0
| | | | | | | OK'ed by: imp, core Notes: svn path=/head/; revision=127958
* Changes following CScout analysis:Diomidis Spinellis2003-07-051-2/+2
| | | | | | | | | | | | | | - 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 Notes: svn path=/head/; revision=117261
* Add a -P/-o physical option which behaves similarly to bash/ksh's optionsTim J. Robbins2002-07-251-2/+2
| | | | | | | | | | by the same name. This option makes the cd and pwd builtins behave physically (as opposed to logically) by default. Submitted by: fanf Notes: svn path=/head/; revision=100664
* Set opterr to zero to avoid duplicate warnings from getopt(3) for unknownTim J. Robbins2002-07-251-2/+2
| | | | | | | options. Notes: svn path=/head/; revision=100663
* Use PATH_MAX instead of a local guess at it, which happened to be incorrect.Tim J. Robbins2002-07-251-4/+3
| | | | | | | Suggested by: fanf Notes: svn path=/head/; revision=100661
* pwdcmd()'s argc and argv arguments are no longer unused, remove __unused.Tim J. Robbins2002-07-251-1/+1
| | | | | | | Pointed out by: fanf Notes: svn path=/head/; revision=100660
* Remove broken and incomplete support for old releases of System V,Tim J. Robbins2002-07-191-55/+0
| | | | | | | don't support system that implement getcwd(3) with a pipe to /bin/pwd. Notes: svn path=/head/; revision=100351
* Consistently use FBSDIDDavid E. O'Brien2002-06-301-2/+2
| | | | Notes: svn path=/head/; revision=99110
* Bring back the cd -L and -P options from revision 1.24, but try harder notTim J. Robbins2002-05-221-32/+104
| | | | | | | | | 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. Notes: svn path=/head/; revision=97092
* Temporarily back out revision 1.24; it seems to handle the case where theTim J. Robbins2002-05-221-77/+21
| | | | | | | current directory no longer exists incorrectly and breaks `make cleandir'. Notes: svn path=/head/; revision=97091
* Add the SUSv3 -L and -P options to the cd and pwd builtin utilities. `Logical'Tim J. Robbins2002-05-201-21/+77
| | | | | | | handling of .. is now the default. Notes: svn path=/head/; revision=96980
* Remove a small, annoying, nit I ran in to editing this file, a lone tabJuli Mallett2002-05-191-1/+1
| | | | | | | on a line by itself. Notes: svn path=/head/; revision=96948
* o __P has been reovedWarner Losh2002-02-021-16/+9
| | | | | | | | | | | | | | | | | | | | | 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) { ... Notes: svn path=/head/; revision=90111
* Don't call setvar() with the VTEXTFIXED flag. A copy is created byTor Egge2001-11-071-4/+4
| | | | | | | | | | | 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 Notes: svn path=/head/; revision=86176
* Include strerror(errno) in error messages after failed system calls.Martin Cracauer1999-11-291-1/+1
| | | | | | | Fix a warning. Notes: svn path=/head/; revision=53891
* $Id$ -> $FreeBSD$Peter Wemm1999-08-271-1/+1
| | | | Notes: svn path=/head/; revision=50471
* Don't blindly eliminate `..' and the previous pathname component.Tor Egge1998-09-061-17/+156
| | | | | | | | PR: 2541 Obtained from: NetBSD Notes: svn path=/head/; revision=38886
* Add rcsid. Spelling.Philippe Charnier1998-05-181-3/+5
| | | | Notes: svn path=/head/; revision=36150
* Use the __unused attribute where warranted.Steve Price1997-05-191-5/+5
| | | | Notes: svn path=/head/; revision=25905
* Nuke register keyword usage and #if -> #ifdef.Steve Price1997-04-281-2/+2
| | | | | | | Obtained from: NetBSD Notes: svn path=/head/; revision=25222
* Revert $FreeBSD$ to $Id$Peter Wemm1997-02-221-1/+1
| | | | Notes: svn path=/head/; revision=22988
* Make the long-awaited change from $Id$ to $FreeBSD$Jordan K. Hubbard1997-01-141-1/+1
| | | | | | | | | | | 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. Notes: svn path=/head/; revision=21673
* Make sh(1) think and be in the same place at the same time. This closesSteve Price1997-01-041-15/+11
| | | | | | | PR#2331: strange output of sh's pwd on symlinked directories. Notes: svn path=/head/; revision=21301
* Oops, it needs little more caulk to get it right.Steve Price1996-12-231-2/+2
| | | | Notes: svn path=/head/; revision=20887