mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 22:49:00 +01:00
Improve some libcdio CoreFoundation code.
I found it via clang complaining about a useless null check on an array, but I decided to get rid of the array in favor of dynamic allocation, as there was no reason to assume a maximum length of 0x32 bytes. Plus, add a CFString type check just in case, and switch to UTF-8 in the off-chance it matters. The result has not actually been tested, as I have no CD drive.
This commit is contained in:
parent
8492d04dfa
commit
06433652be
@ -91,8 +91,6 @@ std::vector<std::string> cdio_get_devices()
|
|||||||
next_media = IOIteratorNext( media_iterator );
|
next_media = IOIteratorNext( media_iterator );
|
||||||
if (next_media != 0)
|
if (next_media != 0)
|
||||||
{
|
{
|
||||||
char psz_buf[0x32];
|
|
||||||
size_t dev_path_length;
|
|
||||||
CFTypeRef str_bsd_path;
|
CFTypeRef str_bsd_path;
|
||||||
|
|
||||||
do
|
do
|
||||||
@ -107,22 +105,20 @@ std::vector<std::string> cdio_get_devices()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Below, by appending 'r' to the BSD node name, we indicate
|
if (CFGetTypeID(str_bsd_path) == CFStringGetTypeID())
|
||||||
// a raw disk. Raw disks receive I/O requests directly and
|
|
||||||
// don't go through a buffer cache.
|
|
||||||
snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
|
|
||||||
dev_path_length = strlen( psz_buf );
|
|
||||||
|
|
||||||
if (CFStringGetCString( (CFStringRef)str_bsd_path,
|
|
||||||
(char*)&psz_buf + dev_path_length,
|
|
||||||
sizeof(psz_buf) - dev_path_length,
|
|
||||||
kCFStringEncodingASCII))
|
|
||||||
{
|
{
|
||||||
if (psz_buf != nullptr)
|
size_t buf_size = CFStringGetLength((CFStringRef)str_bsd_path) * 4 + 1;
|
||||||
|
char* buf = new char[buf_size];
|
||||||
|
|
||||||
|
if (CFStringGetCString((CFStringRef)str_bsd_path, buf, buf_size, kCFStringEncodingUTF8))
|
||||||
{
|
{
|
||||||
std::string str = psz_buf;
|
// Below, by appending 'r' to the BSD node name, we indicate
|
||||||
drives.push_back(str);
|
// a raw disk. Raw disks receive I/O requests directly and
|
||||||
|
// don't go through a buffer cache.
|
||||||
|
drives.push_back(std::string(_PATH_DEV "r") + buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete[] buf;
|
||||||
}
|
}
|
||||||
CFRelease( str_bsd_path );
|
CFRelease( str_bsd_path );
|
||||||
IOObjectRelease( next_media );
|
IOObjectRelease( next_media );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user