未验证 提交 04e929d3 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #7144 from junli1026/jun/dirname

Fix dirname bug on MacOS
......@@ -261,11 +261,20 @@ int tfsMkdirRecurAt(const char *rname, int level, int id) {
// Try to create upper
char *s = strdup(rname);
if (tfsMkdirRecurAt(dirname(s), level, id) < 0) {
tfree(s);
// Make a copy of dirname(s) because the implementation of 'dirname' differs on different platforms.
// Some platform may modify the contents of the string passed into dirname(). Others may return a pointer to
// internal static storage space that will be overwritten by next call. For case like that, we should not use
// the pointer directly in this recursion.
// See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dirname.3.html
char *dir = strdup(dirname(s));
if (tfsMkdirRecurAt(dir, level, id) < 0) {
free(s);
free(dir);
return -1;
}
tfree(s);
free(s);
free(dir);
if (tfsMkdirAt(rname, level, id) < 0) {
return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册