Skip to content

Commit 6bf92dd

Browse files
authored
Merge pull request #2678 from compnerd/prefix
CoreFoundation: finish up file numeration Windows TODO
2 parents cd0bc7b + 4f31458 commit 6bf92dd

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

CoreFoundation/Base.subproj/CFFileUtilities.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,14 +1058,28 @@ CF_PRIVATE void _CFIterateDirectory(CFStringRef directoryPath, Boolean appendSla
10581058
continue;
10591059
}
10601060

1061-
assert(!stuffToPrefix && "prefix not yet implemented");
1061+
const UniChar kSlash = CFPreferredSlash;
1062+
1063+
CFStringAppendBuffer buffer;
1064+
CFStringInitAppendBuffer(kCFAllocatorSystemDefault, &buffer);
1065+
1066+
if (stuffToPrefix) {
1067+
for (CFIndex i = 0, e = CFArrayGetCount(stuffToPrefix); i < e; i++) {
1068+
CFStringRef entry = CFArrayGetValueAtIndex(stuffToPrefix, i);
1069+
CFStringAppendStringToAppendBuffer(&buffer, entry);
1070+
if (CFStringGetCharacterAtIndex(entry, CFStringGetLength(entry) - 1) != _CFGetSlash()) {
1071+
CFStringAppendCharactersToAppendBuffer(&buffer, &kSlash, 1);
1072+
}
1073+
}
1074+
}
1075+
1076+
CFStringAppendStringToAppendBuffer(&buffer, fileName);
10621077
Boolean isDirectory = file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
1063-
CFMutableStringRef filePath = CFStringCreateMutableCopy(kCFAllocatorSystemDefault, nameLen + 1, fileName);
10641078
if (appendSlashForDirectories && isDirectory) {
1065-
UniChar slash = CFPreferredSlash;
1066-
CFStringAppendCharacters(filePath, &slash, 1);
1079+
CFStringAppendCharactersToAppendBuffer(&buffer, &kSlash, 1);
10671080
}
10681081

1082+
CFMutableStringRef filePath = CFStringCreateMutableWithAppendBuffer(&buffer);
10691083
Boolean result = fileHandler(fileName, filePath, isDirectory ? DT_DIR : DT_REG);
10701084
CFRelease(fileName);
10711085
CFRelease(filePath);

0 commit comments

Comments
 (0)