Deleted Added
full compact
cd.c (20887) cd.c (21301)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 19 unchanged lines hidden (view full) ---

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 19 unchanged lines hidden (view full) ---

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id: cd.c,v 1.10 1996/12/23 22:16:35 steve Exp $
36 * $Id: cd.c,v 1.11 1996/12/23 22:29:03 steve Exp $
37 */
38
39#ifndef lint
40static char const sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95";
41#endif /* not lint */
42
43#include <sys/types.h>
44#include <sys/stat.h>
45#include <stdlib.h>
46#include <string.h>
47#include <unistd.h>
48#include <errno.h>
37 */
38
39#ifndef lint
40static char const sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95";
41#endif /* not lint */
42
43#include <sys/types.h>
44#include <sys/stat.h>
45#include <stdlib.h>
46#include <string.h>
47#include <unistd.h>
48#include <errno.h>
49#include <limits.h>
50
51/*
52 * The cd and pwd commands.
53 */
54
55#include "shell.h"
56#include "var.h"
57#include "nodes.h" /* for jobs.h */

--- 69 unchanged lines hidden (view full) ---

127STATIC int
128docd(dest, print)
129 char *dest;
130 int print;
131{
132
133 TRACE(("docd(\"%s\", %d) called\n", dest, print));
134 INTOFF;
49
50/*
51 * The cd and pwd commands.
52 */
53
54#include "shell.h"
55#include "var.h"
56#include "nodes.h" /* for jobs.h */

--- 69 unchanged lines hidden (view full) ---

126STATIC int
127docd(dest, print)
128 char *dest;
129 int print;
130{
131
132 TRACE(("docd(\"%s\", %d) called\n", dest, print));
133 INTOFF;
135 if (chdir(dest) < 0) {
134 updatepwd(dest);
135 if (chdir(stackblock()) < 0) {
136 INTON;
137 return -1;
138 }
136 INTON;
137 return -1;
138 }
139 updatepwd(dest);
139 hashcd(); /* update command hash table */
140 if (prevdir)
141 ckfree(prevdir);
142 prevdir = curdir;
143 curdir = savestr(stackblock());
140 INTON;
141 if (print && iflag)
142 out1fmt("%s\n", stackblock());
143 return 0;
144}
145
146
147/*

--- 17 unchanged lines hidden (view full) ---

165 *p++ = '\0';
166 cdcomppath = p;
167 }
168 return start;
169}
170
171
172/*
144 INTON;
145 if (print && iflag)
146 out1fmt("%s\n", stackblock());
147 return 0;
148}
149
150
151/*

--- 17 unchanged lines hidden (view full) ---

169 *p++ = '\0';
170 cdcomppath = p;
171 }
172 return start;
173}
174
175
176/*
173 * Update curdir (the name of the current directory) in response to a
174 * cd command. We also call hashcd to let the routines in exec.c know
175 * that the current directory has changed.
177 * Determine the new working directory, but don't actually enforce
178 * any changes.
176 */
177STATIC void
178updatepwd(dir)
179 char *dir;
180{
181 char *new;
182 char *p;
183
179 */
180STATIC void
181updatepwd(dir)
182 char *dir;
183{
184 char *new;
185 char *p;
186
184 hashcd(); /* update command hash table */
185 cdcomppath = stalloc(strlen(dir) + 1);
186 scopy(dir, cdcomppath);
187 STARTSTACKSTR(new);
188 if (*dir != '/') {
189 if (curdir == NULL)
190 return;
191 p = curdir;
192 while (*p)

--- 8 unchanged lines hidden (view full) ---

201 STPUTC('/', new);
202 while (*p)
203 STPUTC(*p++, new);
204 }
205 }
206 if (new == stackblock())
207 STPUTC('/', new);
208 STACKSTRNUL(new);
187 cdcomppath = stalloc(strlen(dir) + 1);
188 scopy(dir, cdcomppath);
189 STARTSTACKSTR(new);
190 if (*dir != '/') {
191 if (curdir == NULL)
192 return;
193 p = curdir;
194 while (*p)

--- 8 unchanged lines hidden (view full) ---

203 STPUTC('/', new);
204 while (*p)
205 STPUTC(*p++, new);
206 }
207 }
208 if (new == stackblock())
209 STPUTC('/', new);
210 STACKSTRNUL(new);
209 INTOFF;
210 if (prevdir)
211 ckfree(prevdir);
212 prevdir = curdir;
213 curdir = savestr(stackblock());
214 INTON;
215}
216
217
218int
219pwdcmd(argc, argv)
220 int argc;
221 char **argv;
222{
211}
212
213
214int
215pwdcmd(argc, argv)
216 int argc;
217 char **argv;
218{
223 if(!getpwd())
219 if (!getpwd())
224 error("getcwd() failed: %s", strerror(errno));
225 out1str(curdir);
226 out1c('\n');
227 return 0;
228}
229
230
231/*
232 * Find out what the current directory is. If we already know the current
233 * directory, this routine returns immediately.
234 */
235char *
236getpwd()
237{
238 if (curdir)
239 return (curdir);
240 return ((curdir = getcwd(NULL, 0)));
241}
220 error("getcwd() failed: %s", strerror(errno));
221 out1str(curdir);
222 out1c('\n');
223 return 0;
224}
225
226
227/*
228 * Find out what the current directory is. If we already know the current
229 * directory, this routine returns immediately.
230 */
231char *
232getpwd()
233{
234 if (curdir)
235 return (curdir);
236 return ((curdir = getcwd(NULL, 0)));
237}