summaryrefslogtreecommitdiffstats
path: root/bin/sh/cd.c
Commit message (Collapse)AuthorAgeFilesLines
* Sync sh(1) in stable/10 to head.jmmv2014-03-091-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a MFC of all the commits listed below. My original goal of this change was to only merge the move of the tests from tools/regression/bin/ into the new layout (which include tests for sh(1) and other tools as well). However, doing so is tricky due to the ongoing work in sh(1) and, especially, the many changes to its tests since stable/10 was first branched. Merging everything is the simplest way to achieve this goal and, as a bonus point, we get various fixes and miscellaneous improvements into the branch. Per jilles' suggestion, I'm avoiding the merge of a couple of changes (r256850 and r257506) that required depending kernel changes. I'm also avoiding very recent changes that have not had a long enough time to be validated in current. This is "make tinderbox" clean. r256735 sh: Remove one syscall when waiting for a foreground job. r257399 sh: Allow trapping SIGINT/SIGQUIT after ignore because of '&'. r257504 sh: Reorder union node to reduce its size on 64-bit platforms. r257920 sh: Add a test case for would-be assignments that are not due to quoting. r257929 sh: Properly quote alias output from command -v. r258489 sh: Add tests for the </dev/null implicit in a background command. r258533 sh: Add more tests for the </dev/null implicit in a background command. r258535 sh: Make <&0 disable the </dev/null implicit in a background command. r258776 sh: Prefer memcpy() to strcpy() in most cases. Remove the scopy macro. r259047 sh: Split set -x output into a separate function. r259210 Migrate tools/regression/bin/ tests to the new layout. r259844 sh: Remove an unused variable. r259846 sh: Initialize OPTIND=1 even if it came from the environment. r259874 sh: Simplify code related to PPID variable. r259946 sh: Don't check input for non-whitespace if history is disabled. r260246 sh(1): Discourage use of -e. r260506 Run the sh(1) and test(1) tests as unprivileged. r260586 Mark the bin/pax tests as requiring perl. r260634 Use TAP_TESTS_PERL to register the legacy_test in bin/pax. r260635 Replace hand-crafted Kyuafiles with automatic generation. r260654 sh: Remove SIGWINCH handler and just check for resize before every read. r261121 sh: Add test for nested alias. r261125 sh: Solve the alias recursion problem in a less hackish way. r261141 sh: Do not depend on parse/execute split in new alias test. r261160 sh: Add tests for alias names after another alias. r261192 sh: Allow aliases to force alias substitution on the following word. r262533 sh: Make expari() static. r262565 sh: Do not corrupt internal representation if LINENO inner expansion fails. r262697 sh: Simplify expari(). Reviewed by: jilles
* sh: Prefer internal nextopt() to libc getopt().jilles2012-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.
* sh: Properly show "Not a directory" error in cd builtin.jilles2012-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
* sh: Fix duplicate prototypes for builtins.jilles2011-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.
* sh: Correct criterion for using CDPATH in cd.jilles2011-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.
* sh: Show errno messages in cd.jilles2011-05-251-1/+4
|
* sh: Implement the cd -e flag proposed for the next POSIX issue.jilles2011-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.
* sh: Add a function to print warnings (with command name and newline).jilles2010-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.
* sh: Code size optimizations to "stack string" memory allocation:jilles2010-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.
* sh: Fix confusing behaviour if chdir succeeded but getcwd failed in cd -P.jilles2010-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.
* In the spirit of r90111, depend on c89 and remove the "STATIC" macroobrien2010-10-131-16/+16
| | | | and its usage.
* Consistently use "STATIC" for all functions in order to be able to setobrien2010-10-131-3/+3
| | | | | | breakpoints with in a debugger. And use naked "static" for variables. Noticed by: bde
* sh: On startup of the shell, use PWD from the environment if it is valid.jilles2010-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).
* sh: Various warning fixes (from WARNS=6 NO_WERROR=1):jilles2009-12-271-1/+1
| | | | | | | - const - initializations to silence -Wuninitialized (it was safe anyway) - remove nested extern declarations - rename "index" locals to "idx"
* sh: Constify various strings.jilles2009-12-241-1/+1
| | | | | Most of this is adding const keywords, but setvar() in var.c had to be changed somewhat more.
* Handle current work directories of arbitrary length. The argument to cdstefanf2009-11-211-22/+29
| | | | | | | continues to be limited by PATH_MAX (1024). Obtained from: NetBSD PR: 104456
* Split updatepwd() into two smaller functions. The first one, findpwd(),stefanf2008-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
* Don't strip a leading ./ from the path for the cd builtin to avoid interpretingstefanf2006-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
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* Changes following CScout analysis:dds2003-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
* Add a -P/-o physical option which behaves similarly to bash/ksh's optionstjr2002-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
* Set opterr to zero to avoid duplicate warnings from getopt(3) for unknowntjr2002-07-251-2/+2
| | | | options.
* Use PATH_MAX instead of a local guess at it, which happened to be incorrect.tjr2002-07-251-4/+3
| | | | Suggested by: fanf
* pwdcmd()'s argc and argv arguments are no longer unused, remove __unused.tjr2002-07-251-1/+1
| | | | Pointed out by: fanf
* Remove broken and incomplete support for old releases of System V,tjr2002-07-191-55/+0
| | | | don't support system that implement getcwd(3) with a pipe to /bin/pwd.
* Consistently use FBSDIDobrien2002-06-301-2/+2
|
* Bring back the cd -L and -P options from revision 1.24, but try harder nottjr2002-05-221-33/+105
| | | | | | 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.
* Temporarily back out revision 1.24; it seems to handle the case where thetjr2002-05-221-78/+22
| | | | current directory no longer exists incorrectly and breaks `make cleandir'.
* Add the SUSv3 -L and -P options to the cd and pwd builtin utilities. `Logical'tjr2002-05-201-22/+78
| | | | handling of .. is now the default.
* Remove a small, annoying, nit I ran in to editing this file, a lone tabjmallett2002-05-191-1/+1
| | | | on a line by itself.
* o __P has been reovedimp2002-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) { ...
* Don't call setvar() with the VTEXTFIXED flag. A copy is created bytegge2001-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
* Include strerror(errno) in error messages after failed system calls.cracauer1999-11-291-1/+1
| | | | Fix a warning.
* $Id$ -> $FreeBSD$peter1999-08-271-1/+1
|
* Don't blindly eliminate `..' and the previous pathname component.tegge1998-09-061-17/+156
| | | | | PR: 2541 Obtained from: NetBSD
* Add rcsid. Spelling.charnier1998-05-181-3/+5
|
* Use the __unused attribute where warranted.steve1997-05-191-5/+5
|
* Nuke register keyword usage and #if -> #ifdef.steve1997-04-281-2/+2
| | | | Obtained from: NetBSD
* Revert $FreeBSD$ to $Id$peter1997-02-221-1/+1
|
* Make the long-awaited change from $Id$ to $FreeBSD$jkh1997-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.
* Make sh(1) think and be in the same place at the same time. This closessteve1997-01-041-15/+11
| | | | PR#2331: strange output of sh's pwd on symlinked directories.
* Oops, it needs little more caulk to get it right.steve1996-12-231-2/+2
|
* Apply a little dab of bit caulk to keep those beggarssteve1996-12-231-6/+2
| | | | | | from leaking out. Noticed by: bde
* Don't use _POSIX_PATH_MAX to limit the size of the path, insteadsteve1996-12-231-3/+3
| | | | | | use 'getcwd(NULL, 0)' just as pwd(1) does. Suggested by: bde
* Make sh(1) a little braver in the face of adversity. sh(1)steve1996-12-211-163/+16
| | | | | | | 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.
* Merge in NetBSD mods and -Wall cleaning.steve1996-12-141-16/+20
| | | | Obtained from: NetBSD, me
* Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is apeter1996-09-011-27/+31
| | | | | | | | | | | | | | 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
* A fix for the "cd -" coredump on a brand new /bin/sh. The problem waspeter1995-11-141-2/+5
| | | | | | noticed on a NetBSD bugs mailing list but this is entirely my own work. Inspired by: Scott Reynolds <scottr@plexus.com>, for NetBSD
* Obtained from: partly from 1.1.5bde1994-12-261-2/+4
| | | | | Convert "" to "." for "cd" and "cd ''". chdir("") is required to fail on POSIX systems.
* Get this braindead, mongoloid shell look in /stand for pwd if it can'tjkh1994-11-061-3/+8
| | | | | | | | | | 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.
OpenPOWER on IntegriCloud