summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaLyong Cho <walyong.cho@samsung.com>2016-11-11 05:55:06 (GMT)
committerWaLyong Cho <walyong.cho@samsung.com>2016-11-11 05:56:31 (GMT)
commitbc85356159079bdd4870bb331c2a76958b8ac36a (patch)
treeb03da313562df1474228c5bb25d129f1a588c726
parent8f2e46db8af79b256dae28504270e968793bc8a8 (diff)
downloadlibsystem-bc85356159079bdd4870bb331c2a76958b8ac36a.zip
libsystem-bc85356159079bdd4870bb331c2a76958b8ac36a.tar.gz
libsystem-bc85356159079bdd4870bb331c2a76958b8ac36a.tar.bz2
libsystem: do_mkdir: avoid frequent malloc/free
Change-Id: I8501b84bc25c21c38199fee672400eb15d2562aa Signed-off-by: WaLyong Cho <walyong.cho@samsung.com>
-rw-r--r--src/libsystem/libsystem.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/libsystem/libsystem.c b/src/libsystem/libsystem.c
index f7aa2e3..f87dfa0 100644
--- a/src/libsystem/libsystem.c
+++ b/src/libsystem/libsystem.c
@@ -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;