Patch pat.2

From: Andrew Valencia <vandys_at_nospam.org>
Date: Tue Aug 17 1993 - 21:19:41 PDT

This patch fixes a problem with readdir() not correctly creating
pseudo-directories for mount paths which include our path. For
instance, if you have a mount path of the console driver to /dev/cons,
when you chdir to /dev and list files, you should get "cons". This
worked for chdir'ing to / and seeing "dev", but not for the former.
This patch fixes that.

*** c:/tmp/T0AA.AAA Mon Aug 16 18:20:04 1993
--- libc/dir.c Mon Aug 16 18:14:02 1993
***************
*** 21,52 ****
--- 21,76 ----
  DIR *
  opendir(char *path)
  {
          DIR *d;
          char *p;
          extern char *__cwd;
  
          /*
+ * Bogus.
+ */
+ if (!path || !path[0]) {
+ return(0);
+ }
+
+ /*
           * Get private, writable copy of path. Flatten to absolute.
           */
          if (path[0] == '/') {
                  p = strdup(path);
          } else {
                  p = malloc(strlen(path) + strlen(__cwd) + 1);
                  if (p ) {
                          sprintf(p, "%s/%s", __cwd, path);
                  }
          }
+
          if (p == 0) {
                  return(0);
          }
          if (__dotdot(p)) {
                  free(p);
                  return(0);
+ }
+
+ /*
+ * All directory paths should end in "/". Add one if
+ * it isn't present.
+ */
+ if (p && (p[strlen(p)-1] != '/')) {
+ char *q;
+
+ q = realloc(p, strlen(p)+2);
+ if (!q) {
+ free(p);
+ return(0);
+ }
+ p = q;
+ strcat(p, "/");
          }
  
          /*
           * Get a DIR
           */
          d = malloc(sizeof(DIR));
          if (d == 0) {
                  free(p);
Received on Tue Aug 17 21:26:40 1993

This archive was generated by hypermail 2.1.8 : Wed Sep 21 2005 - 19:37:12 PDT