提交 0b80e979 编写于 作者: J Jun Li

Fix dirname bug on MacOS

上级 dd5a627b
...@@ -261,11 +261,20 @@ int tfsMkdirRecurAt(const char *rname, int level, int id) { ...@@ -261,11 +261,20 @@ int tfsMkdirRecurAt(const char *rname, int level, int id) {
// Try to create upper // Try to create upper
char *s = strdup(rname); char *s = strdup(rname);
if (tfsMkdirRecurAt(dirname(s), level, id) < 0) { // Make a copy of dirname(s) because the implementation of 'dirname' differs on different platforms.
tfree(s); // 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; return -1;
} }
tfree(s); free(s);
free(dir);
if (tfsMkdirAt(rname, level, id) < 0) { if (tfsMkdirAt(rname, level, id) < 0) {
return -1; return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册