home-etc: src/core.c, src/home_etc.c - major fixes and optimizations

siefca siefca at pld-linux.org
Thu May 18 14:31:45 CEST 2006


Author: siefca                       Date: Thu May 18 12:31:40 2006 GMT
Module: home-etc                      Tag: HEAD
---- Log message:
- major fixes and optimizations

---- Files affected:
home-etc/src:
   core.c (1.23 -> 1.24) , home_etc.c (1.17 -> 1.18) 

---- Diffs:

================================================================
Index: home-etc/src/core.c
diff -u home-etc/src/core.c:1.23 home-etc/src/core.c:1.24
--- home-etc/src/core.c:1.23	Thu May 18 13:53:17 2006
+++ home-etc/src/core.c	Thu May 18 14:31:35 2006
@@ -47,14 +47,14 @@
 
 /*********************************************************************/
 
-inline static void fix_trailslash(char *p, char trailslash)
+inline static void fix_trailslash(char *p, size_t psize, char trailslash)
 {
   size_t s;
 
   s = strlen(p);
   if (s > 0)
     {
-      if(trailslash && (*(p+s-1) != '/') && s < sizeof(p)-2)
+       if(trailslash && (*(p+s-1) != '/') && s < psize-2)
         {
           *(p+s) = '/';
           *(p+s+1) = '\0';
@@ -68,6 +68,32 @@
 
 /*********************************************************************/
 
+inline static void rem_dslash(char *p)
+{
+  char s = 0;
+  char *q, *b;
+
+  /* remove doubled slashes */
+  q = b = p;
+  while (*q != '\0')
+    {
+      if (*q == '/' && *(q+1) == '/' && (s=1))
+        while (*(q+1) == '/') q++;
+      else
+        {
+          if (s)
+            {
+              *b = *q;
+            }
+        }
+      q++; b++;
+    }
+  if (q > b)
+    *b = '\0';
+}
+
+/*********************************************************************/
+
 inline static int absolutize_dir(char *path, size_t s)
 {
   /* change dir to path */
@@ -160,7 +186,7 @@
 	  return NULL;
 	}
       strcpy(pbuff, intbuf);/* strcpy checked */
-      strcat(pbuff, "/");   /* strcpy checked */
+      strcat(pbuff, "/");   /* strcat checked */
       strcat(pbuff, buff);  /* strcat checked */
     }
   else /* or if we have absolute pathname */
@@ -183,8 +209,10 @@
       /* make it absolute and return fast */
       if(absolutize_dir(pbuff, sizeof(pbuff)-1) == -1)
 	return NULL;
-      /* add or remove trailing slash as memorized before */
-      fix_trailslash(pbuff, trailslash);
+      if(*pbuff == '/' && *(pbuff+1) == '\0')
+	return pbuff;
+      rem_dslash(pbuff);
+      fix_trailslash(pbuff, sizeof(buff), trailslash);
       return pbuff;
     }
 
@@ -214,8 +242,9 @@
   /* do we have pure unresolvable path?   */
   if (q == NULL)
     {
+      rem_dslash(pbuff);
       /* add or remove trailing slash as memorized before */
-      fix_trailslash(pbuff, trailslash);
+      fix_trailslash(pbuff, sizeof(pbuff), trailslash);
       /* return fast */
       return pbuff;
     }
@@ -256,8 +285,12 @@
       strcat(pbuff, intbuf);   /* strcat checked */
     }
 
+  if(*pbuff == '/' && *(pbuff+1) == '\0')
+    return pbuff;
+
+  rem_dslash(pbuff);
   /* add or remove trailing slash as memorized before */
-  fix_trailslash(pbuff, trailslash);
+  fix_trailslash(pbuff, sizeof(pbuff), trailslash);
 
   /* go back to the directory we were and return pointer to buffer */
   chdir(prev);

================================================================
Index: home-etc/src/home_etc.c
diff -u home-etc/src/home_etc.c:1.17 home-etc/src/home_etc.c:1.18
--- home-etc/src/home_etc.c:1.17	Thu May 18 01:41:23 2006
+++ home-etc/src/home_etc.c	Thu May 18 14:31:35 2006
@@ -255,28 +255,10 @@
   if (p == NULL)
     return NULL;
 
-  /* remove doubled slashes */
-  q = b = p;
-  while (*q != '\0')
-    {
-      if (*q == '/' && *(q+1) == '/' && (s=1))
-        while (*(q+1) == '/') q++;
-      else
-        {
-	  if (s)
-            {
-              *b = *q;
-            }
-        }
-      q++; b++;
-    }
-  if (q > b)
-    *b = '\0';
-
   /* check whether the trailing slash should be removed */
-  s = strlen(p);
-  if (s > 0 && *(p+s-1) == '/' && !isdir(p))
-    *(p+s-1) = '\0';
+//  s = strlen(p);
+  //if (s > 0 && *(p+s-1) == '/' && !isdir(p))
+    //*(p+s-1) = '\0';
 
   r = (const char *) p;
   return r;
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/home-etc/src/core.c?r1=1.23&r2=1.24&f=u
    http://cvs.pld-linux.org/home-etc/src/home_etc.c?r1=1.17&r2=1.18&f=u



More information about the pld-cvs-commit mailing list