]> arthur.barton.de Git - netatalk.git/commitdiff
speed up a little ad_dir
authordidg <didg>
Sat, 7 Nov 2009 01:18:50 +0000 (01:18 +0000)
committerdidg <didg>
Sat, 7 Nov 2009 01:18:50 +0000 (01:18 +0000)
libatalk/adouble/ad_open.c

index fe15d37c7415f8086e4ca3980681b2429d753f40..5f7ca0f1864762fcaf9d9987052baeeace4d1984 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ad_open.c,v 1.56 2009-11-07 01:02:58 didg Exp $
+ * $Id: ad_open.c,v 1.57 2009-11-07 01:18:50 didg Exp $
  *
  * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
@@ -939,36 +939,46 @@ char
 {
     static char     modebuf[ MAXPATHLEN + 1];
     char        *slash;
-    size_t              len;
-
-    if ( (len = strlen( path )) >= MAXPATHLEN ) {
-        errno = ENAMETOOLONG;
-        return NULL;  /* can't do it */
-    }
-
     /*
      * For a path with directories in it, remove the final component
      * (path or subdirectory name) to get the name we want to stat.
      * For a path which is just a filename, use "." instead.
      */
-    strcpy( modebuf, path );
-    slash = strrchr( modebuf, '/' );
-    /* is last char a '/' */
-    if (slash && slash[1] == 0) {
-        while (modebuf < slash && slash[-1] == '/') {
-            --slash;
+    slash = strrchr( path, '/' );
+    if (slash) {
+        size_t len;
+
+        len = slash - path;
+        if (len >= MAXPATHLEN) {
+            errno = ENAMETOOLONG;
+            return NULL;  /* can't do it */
         }
-        if (modebuf < slash) {
+        memcpy( modebuf, path, len );
+        modebuf[len] = '\0';
+        /* is last char a '/' ? */
+        if (slash[1] == 0) {
+            slash = modebuf+ len;
+            /* remove them */
+            while (modebuf < slash && slash[-1] == '/') {
+                --slash;
+            }
+            if (modebuf == slash) {
+                goto use_cur;
+            }
+            *slash = '\0';
+            while (modebuf < slash && *slash != '/') {
+                --slash;
+            }
+            if (modebuf == slash) {
+                goto use_cur;
+            }
             *slash = '\0';      /* remove pathname component */
-            slash = strrchr( modebuf, '/' );
         }
+        return modebuf;
     }
-    if (slash) {
-        *slash = '\0';      /* remove pathname component */
-    } else {
-        modebuf[0] = '.';   /* use current directory */
-        modebuf[1] = '\0';
-    }
+use_cur:
+    modebuf[0] = '.';   /* use current directory */
+    modebuf[1] = '\0';
     return modebuf;
 }