Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

zgetcwd bug



My previous patch to zgetcwd introduced a bug.  Fix is included below.

Zoltan


*** Src/init.c	1996/12/28 00:04:58	3.1.1.6
--- Src/init.c	1996/12/30 02:27:03
***************
*** 505,511 ****
      else if ((ptr = zgetenv("PWD")) && ispwd(ptr))
  	pwd = ztrdup(ptr);
      else
! 	pwd = metafy(zgetcwd(), -1, META_REALLOC);
  
      oldpwd = ztrdup(pwd);  /* initialize `OLDPWD' = `PWD' */
  
--- 505,511 ----
      else if ((ptr = zgetenv("PWD")) && ispwd(ptr))
  	pwd = ztrdup(ptr);
      else
! 	pwd = metafy(zgetcwd(), -1, META_DUP);
  
      oldpwd = ztrdup(pwd);  /* initialize `OLDPWD' = `PWD' */
  
*** Src/builtin.c	1996/12/26 03:55:34	3.1.1.2
--- Src/builtin.c	1996/12/30 02:26:51
***************
*** 897,909 ****
  
      if (stat(unmeta(pwd), &st1) < 0) {
  	zsfree(pwd);
! 	pwd = metafy(zgetcwd(), -1, META_REALLOC);
      } else if (stat(".", &st2) < 0)
  	chdir(unmeta(pwd));
      else if (st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev) {
  	if (isset(CHASELINKS)) {
  	    zsfree(pwd);
! 	    pwd = metafy(zgetcwd(), -1, META_REALLOC);
  	} else {
  	    chdir(unmeta(pwd));
  	}
--- 897,909 ----
  
      if (stat(unmeta(pwd), &st1) < 0) {
  	zsfree(pwd);
! 	pwd = metafy(zgetcwd(), -1, META_DUP);
      } else if (stat(".", &st2) < 0)
  	chdir(unmeta(pwd));
      else if (st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev) {
  	if (isset(CHASELINKS)) {
  	    zsfree(pwd);
! 	    pwd = metafy(zgetcwd(), -1, META_DUP);
  	} else {
  	    chdir(unmeta(pwd));
  	}
*** Src/compat.c	1996/12/26 03:55:34	3.1.1.1
--- Src/compat.c	1996/12/30 02:25:17
***************
*** 118,135 ****
      ino_t ino, pino;
      dev_t dev, pdev;
  
-     if (stat(".", &sbuf) < 0)
- 	return(ztrdup("."));
- 
-     holdintr();
      buf = halloc(bufsiz = PATH_MAX);
      pos = bufsiz - 1;
      buf[pos] = '\0';
      strcpy(nbuf, "../");
  
      pino = sbuf.st_ino;
      pdev = sbuf.st_dev;
  
      for (;;) {
  	if (stat("..", &sbuf) < 0)
  	    break;
--- 118,137 ----
      ino_t ino, pino;
      dev_t dev, pdev;
  
      buf = halloc(bufsiz = PATH_MAX);
      pos = bufsiz - 1;
      buf[pos] = '\0';
      strcpy(nbuf, "../");
+     if (stat(".", &sbuf) < 0) {
+ 	buf[0] = ".";
+ 	buf[1] = '\0';
+ 	return buf;
+     }
  
      pino = sbuf.st_ino;
      pdev = sbuf.st_dev;
  
+     holdintr();
      for (;;) {
  	if (stat("..", &sbuf) < 0)
  	    break;
***************
*** 183,189 ****
      if (*buf)
  	zchdir(buf + pos + 1);
      noholdintr();
!     return ztrdup(".");
  }
  
  /* chdir with arbitrary long pathname */
--- 185,193 ----
      if (*buf)
  	zchdir(buf + pos + 1);
      noholdintr();
!     buf[0] = ".";
!     buf[1] = '\0';
!     return buf;
  }
  
  /* chdir with arbitrary long pathname */



Messages sorted by: Reverse Date, Date, Thread, Author