From: Zoltan Hidvegi <hzoli@frontiernet.net>
To: harres@ghidora.uwyo.edu (John M. Harres)
Cc: zsh-workers@math.gatech.edu (Zsh hacking and development)
Subject: Re: zgetcwd patch?
Date: Mon, 25 Aug 1997 01:06:54 -0400 (EDT) [thread overview]
Message-ID: <199708250506.BAA04326@hzoli.home> (raw)
In-Reply-To: <199708151315.HAA24323@ghidora.uwyo.edu> from "John M. Harres" at "Aug 15, 97 07:15:37 am"
> I never heard a response to the patch I sent to compat.c.
> Does it appear correct?
>
> I'm also curious under what circumstances these two operations differ (aside
> from the obvious chdir side effect):
>
> 1. opendir( ".." );
>
> 2. chdir( ".." );
> opendir( "." );
Sorry for my silence about this. Zsh-3.1.1 already had a fix for this
promlem, here is the patch for zsh-3.0.4. It avoids the double scan you
noticed.
Zoltan
*** compat.c.3.0.4 Tue Dec 17 15:14:11 1996
--- compat.c Mon Aug 25 00:58:18 1997
***************
*** 115,122 ****
struct stat sbuf;
struct dirent *de;
DIR *dir;
! ino_t ino, rootino = (ino_t) ~ 0;
! dev_t dev, rootdev = (dev_t) ~ 0;
holdintr();
buf2[0] = '\0';
--- 115,122 ----
struct stat sbuf;
struct dirent *de;
DIR *dir;
! ino_t ino, pino, rootino = (ino_t) ~ 0;
! dev_t dev, pdev, rootdev = (dev_t) ~ 0;
holdintr();
buf2[0] = '\0';
***************
*** 127,146 ****
rootdev = sbuf.st_dev;
}
for (;;) {
- if (stat(".", &sbuf) < 0) {
- chdir(buf0);
- noholdintr();
- return ztrdup(".");
- }
- ino = sbuf.st_ino;
- dev = sbuf.st_dev;
if (stat("..", &sbuf) < 0) {
chdir(buf0);
noholdintr();
return ztrdup(".");
}
! if ((sbuf.st_ino == ino && sbuf.st_dev == dev) ||
(ino == rootino && dev == rootdev)) {
chdir(buf0);
noholdintr();
--- 127,153 ----
rootdev = sbuf.st_dev;
}
+ if (stat(".", &sbuf) < 0) {
+ noholdintr();
+ return ztrdup(".");
+ }
+
+ pino = sbuf.st_ino;
+ pdev = sbuf.st_dev;
+
for (;;) {
if (stat("..", &sbuf) < 0) {
chdir(buf0);
noholdintr();
return ztrdup(".");
}
!
! ino = pino;
! dev = pdev;
! pino = sbuf.st_ino;
! pdev = sbuf.st_dev;
!
! if ((ino == pino && dev == pdev) ||
(ino == rootino && dev == rootdev)) {
chdir(buf0);
noholdintr();
***************
*** 160,194 ****
(fn[1] == '\0' ||
(fn[1] == '.' && fn[2] == '\0')))
continue;
! if ((ino_t) de->d_ino == ino) {
lstat(fn, &sbuf);
! if (sbuf.st_dev == dev)
! goto match;
}
}
closedir(dir);
! dir = opendir(".");
! while ((de = readdir(dir))) {
! char *fn = de->d_name;
! /* Ignore `.' and `..'. */
! if (fn[0] == '.' &&
! (fn[1] == '\0' ||
! (fn[1] == '.' && fn[2] == '\0')))
! continue;
! lstat(fn, &sbuf);
! if (sbuf.st_dev == dev)
! goto match;
}
- noholdintr();
- closedir(dir);
- return ztrdup(".");
- match:
- strcpy(buf3, de->d_name);
if (*buf2)
strcat(buf3, "/");
strcat(buf3, buf2);
strcpy(buf2, buf3);
- closedir(dir);
}
}
--- 167,189 ----
(fn[1] == '\0' ||
(fn[1] == '.' && fn[2] == '\0')))
continue;
! if (dev != pdev || (ino_t) de->d_ino == ino) {
lstat(fn, &sbuf);
! if (sbuf.st_dev == dev && sbuf.st_ino == ino) {
! strcpy(buf3, de->d_name);
! break;
! }
}
}
closedir(dir);
! if (!de) {
! noholdintr();
! return ztrdup(".");
}
if (*buf2)
strcat(buf3, "/");
strcat(buf3, buf2);
strcpy(buf2, buf3);
}
}
next prev parent reply other threads:[~1997-08-25 5:37 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-08-08 20:51 weird zsh startup behavior John M. Harres
1997-08-09 1:16 ` Zoltan Hidvegi
1997-08-09 4:39 ` John M. Harres
1997-08-09 5:11 ` Geoff Wing
1997-08-09 5:58 ` John M. Harres
1997-08-10 7:30 ` Todd Larason
1997-08-12 15:31 ` John M. Harres
1997-08-12 16:04 ` Todd Larason
1997-08-12 16:15 ` John M. Harres
1997-08-15 13:15 ` zgetcwd patch? John M. Harres
1997-08-18 5:05 ` Bart Schaefer
1997-08-18 16:28 ` John M. Harres
1997-08-18 19:48 ` Todd Larason
1997-08-19 9:31 ` Bart Schaefer
1997-08-25 5:06 ` Zoltan Hidvegi [this message]
1997-08-25 17:06 ` zsh-3.0.4 blessed patches (was Re: zgetcwd patch?) Mark Borges
1997-08-25 17:46 ` Zoltan T. Hidvegi
1997-08-25 21:35 ` Geoff Wing
1997-08-25 22:08 ` Zoltan Hidvegi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199708250506.BAA04326@hzoli.home \
--to=hzoli@frontiernet.net \
--cc=harres@ghidora.uwyo.edu \
--cc=zsh-workers@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).