Fix regression in FindDevice function (introduced in newlib 2.5.0) #55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In newlib 2.0.0, FindDevice function was able to return proper mounted device index even if a digit was appended to the mounted device name (cf. https://github.com/devkitPro/buildscripts/blob/v20170117/dkppc/patches/newlib-2.0.0.patch#L5224)
In newlib 2.5.0, FindDevice function code was modified to apparently add some additional robustness check while keeping support for appended digit in name parameter compared to mounted device name (cf. https://github.com/devkitPro/buildscripts/blob/v20170117/dkppc/patches/newlib-2.5.0.patch#L6061)), however the additional check (
dev_namelen == namelen
) defeats the purpose of the two following alternate checks asname[namelen] == ':'
is always true andisdigit(name[namelen])
is always false whendev_namelen == namelen
is true.This change can cause a problem in case of homebrew application loaded from another program that supports multi-partitioning (like Wiiflow), which appends a digit to the device name when setting the loaded application path in argv[0]. libfatInitDefault function will call newlib's chdir function using that application path as it only checks that the first digits match a default device name (cf. https://github.com/devkitPro/libfat/blob/master/source/libfat.c#L185) but chdir function will fail since FindDevice will not be able to identify the associated mounted device. This leads to defaultDevice not being set in newlib and any syscall (like fopen, opendir, mkdir, etc) to fail (and eventually crash, cf. #54, ekeeke/Genesis-Plus-GX#357 and Fledge68/WiiFlow_Lite#254) when used with a relative path instead of an absolute path.
This path restores the ability that existed in previous newlibs function while trying to keep robustness when checking provided pathname parameter.