Magellan Linux

Diff of /trunk/mkinitrd-magellan/klibc/usr/dash/cd.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1121 by niro, Sat Sep 1 22:45:15 2007 UTC revision 1122 by niro, Wed Aug 18 21:11:40 2010 UTC
# Line 52  Line 52 
52  #include "error.h"  #include "error.h"
53  #include "exec.h"  #include "exec.h"
54  #include "redir.h"  #include "redir.h"
55    #include "main.h"
56  #include "mystring.h"  #include "mystring.h"
57  #include "show.h"  #include "show.h"
58  #include "cd.h"  #include "cd.h"
# Line 105  cdcmd(int argc, char **argv) Line 106  cdcmd(int argc, char **argv)
106   if (!dest)   if (!dest)
107   dest = nullstr;   dest = nullstr;
108   if (*dest == '/')   if (*dest == '/')
109   goto step7;   goto step6;
110   if (*dest == '.') {   if (*dest == '.') {
111   c = dest[1];   c = dest[1];
112  dotdot:  dotdot:
# Line 121  dotdot: Line 122  dotdot:
122   }   }
123   if (!*dest)   if (!*dest)
124   dest = ".";   dest = ".";
125   if (!(path = bltinlookup("CDPATH"))) {   path = bltinlookup("CDPATH");
126  step6:   while (path) {
 step7:  
  p = dest;  
  goto docd;  
  }  
  do {  
127   c = *path;   c = *path;
128   p = padvance(&path, dest);   p = padvance(&path, dest);
129   if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {   if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
# Line 136  step7: Line 132  step7:
132  docd:  docd:
133   if (!docd(p, flags))   if (!docd(p, flags))
134   goto out;   goto out;
135   break;   goto err;
136   }   }
137   } while (path);   }
138    
139    step6:
140     p = dest;
141     goto docd;
142    
143    err:
144   sh_error("can't cd to %s", dest);   sh_error("can't cd to %s", dest);
145   /* NOTREACHED */   /* NOTREACHED */
146  out:  out:
# Line 241  updatepwd(const char *dir) Line 243  updatepwd(const char *dir)
243  }  }
244    
245    
 #define MAXPWD 256  
   
246  /*  /*
247   * Find out what the current directory is. If we already know the current   * Find out what the current directory is. If we already know the current
248   * directory, this routine returns immediately.   * directory, this routine returns immediately.
# Line 251  inline Line 251  inline
251  STATIC char *  STATIC char *
252  getpwd()  getpwd()
253  {  {
254    #ifdef __GLIBC__
255     char *dir = getcwd(0, 0);
256     if (dir)
257     return dir;
258    #else
259   char buf[PATH_MAX];   char buf[PATH_MAX];
260   char *dir = getcwd(buf, sizeof(buf));   if(getcwd(buf, sizeof(buf)))
261   return dir ? savestr(dir) : nullstr;   return savestr(buf);
262    #endif
263     sh_warnx("getcwd() failed: %s", strerror(errno));
264     return nullstr;
265  }  }
266    
267  int  int

Legend:
Removed from v.1121  
changed lines
  Added in v.1122