cd.c (3b8f08459569bf0faa21473e5cec2491e95c9349) cd.c (a4652c280b6f8a5b34143413f685d94b86e8b78c)
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

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

177cdlogical(char *dest)
178{
179 char *p;
180 char *q;
181 char *component;
182 struct stat statb;
183 int first;
184 int badstat;
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

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

177cdlogical(char *dest)
178{
179 char *p;
180 char *q;
181 char *component;
182 struct stat statb;
183 int first;
184 int badstat;
185 size_t len;
186
187 /*
188 * Check each component of the path. If we find a symlink or
189 * something we can't stat, clear curdir to force a getcwd()
190 * next time we get the value of the current directory.
191 */
192 badstat = 0;
185
186 /*
187 * Check each component of the path. If we find a symlink or
188 * something we can't stat, clear curdir to force a getcwd()
189 * next time we get the value of the current directory.
190 */
191 badstat = 0;
193 len = strlen(dest);
194 cdcomppath = stalloc(len + 1);
195 memcpy(cdcomppath, dest, len + 1);
192 cdcomppath = stsavestr(dest);
196 STARTSTACKSTR(p);
197 if (*dest == '/') {
198 STPUTC('/', p);
199 cdcomppath++;
200 }
201 first = 1;
202 while ((q = getcomponent()) != NULL) {
203 if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0'))

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

272}
273
274
275static char *
276findcwd(char *dir)
277{
278 char *new;
279 char *p;
193 STARTSTACKSTR(p);
194 if (*dest == '/') {
195 STPUTC('/', p);
196 cdcomppath++;
197 }
198 first = 1;
199 while ((q = getcomponent()) != NULL) {
200 if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0'))

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

269}
270
271
272static char *
273findcwd(char *dir)
274{
275 char *new;
276 char *p;
280 size_t len;
281
282 /*
283 * If our argument is NULL, we don't know the current directory
284 * any more because we traversed a symbolic link or something
285 * we couldn't stat().
286 */
287 if (dir == NULL || curdir == NULL)
288 return getpwd2();
277
278 /*
279 * If our argument is NULL, we don't know the current directory
280 * any more because we traversed a symbolic link or something
281 * we couldn't stat().
282 */
283 if (dir == NULL || curdir == NULL)
284 return getpwd2();
289 len = strlen(dir);
290 cdcomppath = stalloc(len + 1);
291 memcpy(cdcomppath, dir, len + 1);
285 cdcomppath = stsavestr(dir);
292 STARTSTACKSTR(new);
293 if (*dir != '/') {
294 STPUTS(curdir, new);
295 if (STTOPC(new) == '/')
296 STUNPUTC(new);
297 }
298 while ((p = getcomponent()) != NULL) {
299 if (equal(p, "..")) {

--- 128 unchanged lines hidden ---
286 STARTSTACKSTR(new);
287 if (*dir != '/') {
288 STPUTS(curdir, new);
289 if (STTOPC(new) == '/')
290 STUNPUTC(new);
291 }
292 while ((p = getcomponent()) != NULL) {
293 if (equal(p, "..")) {

--- 128 unchanged lines hidden ---