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

finddir() and long directories



-----BEGIN PGP SIGNED MESSAGE-----

This patch fixes finddir() to handle arbitrarily long directories.

There are a lot more PATH_MAX dependencies to fix yet.

 -zefram

      *** Src/utils.c	1996/12/30 14:11:41	1.47
      --- Src/utils.c	1996/12/30 15:07:32
      ***************
      *** 404,410 ****
        
        /* static variables needed by finddir(). */
        
      ! static char finddir_full[PATH_MAX];
        static Nameddir finddir_last;
        static int finddir_best;
        
      --- 404,410 ----
        
        /* static variables needed by finddir(). */
        
      ! static char *finddir_full;
        static Nameddir finddir_last;
        static int finddir_best;
        
      ***************
      *** 432,437 ****
      --- 432,438 ----
        finddir(char *s)
        {
            static struct nameddir homenode = { NULL, "", 0, NULL, 0 };
      +     static int ffsz;
        
            /* Invalidate directory cache if argument is NULL.  This is called *
             * whenever a node is added to or removed from the hash table, and *
      ***************
      *** 439,453 ****
            if (!s) {
        	homenode.dir = home;
        	homenode.diff = strlen(home);
      ! 	if(homenode.diff==1 || homenode.diff>=PATH_MAX)
        	    homenode.diff = 0;
        	finddir_full[0] = 0;
        	return finddir_last = NULL;
            }
        
      !     if (!strcmp(s, finddir_full))
        	return finddir_last;
        
            strcpy(finddir_full, s);
            finddir_best=0;
            finddir_last=NULL;
      --- 440,460 ----
            if (!s) {
        	homenode.dir = home;
        	homenode.diff = strlen(home);
      ! 	if(homenode.diff==1)
        	    homenode.diff = 0;
      + 	if(!finddir_full)
      + 	    finddir_full = zalloc(ffsz = PATH_MAX);
        	finddir_full[0] = 0;
        	return finddir_last = NULL;
            }
        
      !     if(!strcmp(s, finddir_full) && *finddir_full)
        	return finddir_last;
        
      +     if(strlen(s) >= ffsz) {
      + 	free(finddir_full);
      + 	finddir_full = zalloc(ffsz = strlen(s) * 2);
      +     }
            strcpy(finddir_full, s);
            finddir_best=0;
            finddir_last=NULL;

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMsfb93D/+HJTpU/hAQHSlQP/RNknLJGuNjSrg30xgB+XnB2Bjmhvnq3i
fk7Av7pZL15eYRls97mQj2klPgqlOoxiEMTQT+AOiAomlkB7Qg436kVFwVxOBONj
7YQ2NM82H/ghowVikEpJewYofdLVr6s43Si0Nz6YZWsTfMg4TzByCcHztZidxY2m
TbE2ghjb/GU=
=aLjV
-----END PGP SIGNATURE-----



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