libsystem: do_mkdir: avoid frequent malloc/free
authorWaLyong Cho <walyong.cho@samsung.com>
Fri, 11 Nov 2016 05:55:06 +0000 (14:55 +0900)
committerWaLyong Cho <walyong.cho@samsung.com>
Fri, 11 Nov 2016 05:56:31 +0000 (14:56 +0900)
Change-Id: I8501b84bc25c21c38199fee672400eb15d2562aa
Signed-off-by: WaLyong Cho <walyong.cho@samsung.com>
src/libsystem/libsystem.c

index f7aa2e3..f87dfa0 100644 (file)
@@ -424,26 +424,22 @@ int do_copy(const char *src, const char *dst, const char *option, int64_t timeou
 }
 
 int do_mkdir(const char *path, mode_t mode) {
+        char d[PATH_MAX];
         size_t s, l;
-        int p;
-        int r;
+        int r, p;
 
         assert(path);
 
         l = strlen(path);
 
-        for (p = 0, s = 0; p < l; p += s+1) {
-                _cleanup_free_ char *d = NULL;
-
-                s = strcspn(path+p, "/");
+        for (p = 0, s = 0; p < l; p += s + 1) {
+                s = strcspn(path + p, "/");
                 if (!s)
                         continue;
 
-                d = new0(char, p+s+1);
-                if (!d)
-                        return -ENOMEM;
+                assert(PATH_MAX > p + s + 1);
 
-                r = snprintf(d, p+s+1, "%s", path);
+                r = snprintf(d, p + s + 1, "%s", path);
                 if (r < 0)
                         return r;