summaryrefslogtreecommitdiff
path: root/cmds/idmap2/libidmap2/FileUtils.cpp
diff options
context:
space:
mode:
authorScott Lobdell <slobdell@google.com>2021-02-23 11:55:26 -0800
committerDaniel Norman <danielnorman@google.com>2021-03-01 15:24:51 -0800
commit24818fca475a6726f5ef0cae42149615079af6e9 (patch)
tree1a3163ac7ce01c335d8d1c05cacddf47c0a30bfd /cmds/idmap2/libidmap2/FileUtils.cpp
parent8deb6bda58c7ecd95285f4dc934269e0c98c989a (diff)
parent0f50c486e59546c32acf3f2cdf6667897600de5c (diff)
Merge SP1A.210222.001
Change-Id: If3509f3a660e820f4c8c0b29e007faa868e1f089
Diffstat (limited to 'cmds/idmap2/libidmap2/FileUtils.cpp')
-rw-r--r--cmds/idmap2/libidmap2/FileUtils.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/cmds/idmap2/libidmap2/FileUtils.cpp b/cmds/idmap2/libidmap2/FileUtils.cpp
index 3af1f70ebe39..98a4ceabdb94 100644
--- a/cmds/idmap2/libidmap2/FileUtils.cpp
+++ b/cmds/idmap2/libidmap2/FileUtils.cpp
@@ -47,4 +47,19 @@ bool UidHasWriteAccessToPath(uid_t uid ATTRIBUTE_UNUSED, const std::string& path
}
#endif
+std::string RandomStringForPath(const size_t length) {
+ constexpr char kChars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ constexpr size_t kCharLastIndex = sizeof(kChars) - 1;
+
+ std::string out_rand;
+ out_rand.reserve(length);
+
+ std::random_device rd;
+ std::uniform_int_distribution<int> dist(0, kCharLastIndex);
+ for (size_t i = 0; i < length; i++) {
+ out_rand[i] = kChars[dist(rd) % (kCharLastIndex)];
+ }
+ return out_rand;
+}
+
} // namespace android::idmap2::utils