From 32bfcc034f41276f0fad036dece8a8f632913dff Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Sat, 8 Feb 2014 14:23:34 +1300 Subject: Some tidy up of sprintf to StringFromFormat Includes a small fix to SetupWiiMemory --- Source/Core/Common/CDUtils.cpp | 43 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 569ceb3c3b..763fbf7f45 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -2,6 +2,7 @@ #include "CDUtils.h" #include "Common.h" +#include "StringUtil.h" #include // for std::unique_ptr #ifdef _WIN32 @@ -150,10 +151,10 @@ static struct }; // Returns true if a device is a block or char device and not a symbolic link -bool is_device(const char *source_name) +bool is_device(const std::string& source_name) { struct stat buf; - if (0 != lstat(source_name, &buf)) + if (0 != lstat(source_name.c_str(), &buf)) return false; return ((S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)) && @@ -161,17 +162,15 @@ bool is_device(const char *source_name) } // Check a device to see if it is a DVD/CD-ROM drive -static bool is_cdrom(const char *drive, char *mnttype) +static bool is_cdrom(const std::string& drive, char *mnttype) { - bool is_cd=false; - int cdfd; - // Check if the device exists if (!is_device(drive)) return(false); + bool is_cd=false; // If it does exist, verify that it is a cdrom/dvd drive - cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0); + int cdfd = open(drive.c_str(), (O_RDONLY|O_NONBLOCK), 0); if ( cdfd >= 0 ) { #ifdef __linux__ @@ -186,21 +185,16 @@ static bool is_cdrom(const char *drive, char *mnttype) // Returns a pointer to an array of strings with the device names std::vector cdio_get_devices () { - unsigned int i; - char drive[40]; std::vector drives; - // Scan the system for DVD/CD-ROM drives. - for ( i=0; checklist[i].format; ++i ) + for (unsigned int i = 0; checklist[i].format; ++i) { - unsigned int j; - for ( j=checklist[i].num_min; j<=checklist[i].num_max; ++j ) + for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j) { - sprintf(drive, checklist[i].format, j); - if ( (is_cdrom(drive, NULL)) > 0 ) + std::string drive = StringFromFormat(checklist[i].format, j); + if ( (is_cdrom(drive.c_str(), NULL)) > 0 ) { - std::string str = drive; - drives.push_back(str); + drives.push_back(std::move(drive)); } } } @@ -222,17 +216,10 @@ bool cdio_is_cdrom(std::string device) #endif std::vector devices = cdio_get_devices(); - bool res = false; - for (auto& odevice : devices) + for (const std::string& d : devices) { - if (strncmp(odevice.c_str(), device.c_str(), MAX_PATH) == 0) - { - res = true; - break; - } + if (d == device) + return true; } - - devices.clear(); - return res; + return false; } - -- cgit v1.2.3