From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/Common/CDUtils.cpp | 238 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 Source/Core/Common/CDUtils.cpp (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp new file mode 100644 index 0000000000..569ceb3c3b --- /dev/null +++ b/Source/Core/Common/CDUtils.cpp @@ -0,0 +1,238 @@ +// Most of the code in this file was shamelessly ripped from libcdio With minor adjustments + +#include "CDUtils.h" +#include "Common.h" + +#include // for std::unique_ptr +#ifdef _WIN32 +#include +#include "StringUtil.h" +#elif __APPLE__ +#include +#include +#include +#include +#include +#include +#else +#include +#include +#include +#endif // WIN32 + +#ifdef __linux__ +#include +#endif + +#ifdef _WIN32 +// takes a root drive path, returns true if it is a cdrom drive +bool is_cdrom(const TCHAR* drive) +{ + return (DRIVE_CDROM == GetDriveType(drive)); +} + +// Returns a vector with the device names +std::vector cdio_get_devices() +{ + std::vector drives; + + const DWORD buffsize = GetLogicalDriveStrings(0, NULL); + std::vector buff(buffsize); + if (GetLogicalDriveStrings(buffsize, buff.data()) == buffsize - 1) + { + auto drive = buff.data(); + while (*drive) + { + if (is_cdrom(drive)) + { + std::string str(TStrToUTF8(drive)); + str.pop_back(); // we don't want the final backslash + drives.push_back(std::move(str)); + } + + // advance to next drive + while (*drive++) {} + } + } + return drives; +} +#elif defined __APPLE__ +// Returns a pointer to an array of strings with the device names +std::vector cdio_get_devices() +{ + io_object_t next_media; + mach_port_t master_port; + kern_return_t kern_result; + io_iterator_t media_iterator; + CFMutableDictionaryRef classes_to_match; + std::vector drives; + + kern_result = IOMasterPort( MACH_PORT_NULL, &master_port ); + if( kern_result != KERN_SUCCESS ) + return( drives ); + + classes_to_match = IOServiceMatching( kIOCDMediaClass ); + if( classes_to_match == NULL ) + return( drives ); + + CFDictionarySetValue( classes_to_match, + CFSTR(kIOMediaEjectableKey), kCFBooleanTrue ); + + kern_result = IOServiceGetMatchingServices( master_port, + classes_to_match, &media_iterator ); + if( kern_result != KERN_SUCCESS) + return( drives ); + + next_media = IOIteratorNext( media_iterator ); + if( next_media != 0 ) + { + char psz_buf[0x32]; + size_t dev_path_length; + CFTypeRef str_bsd_path; + + do + { + str_bsd_path = + IORegistryEntryCreateCFProperty( next_media, + CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, + 0 ); + if( str_bsd_path == NULL ) + { + IOObjectRelease( next_media ); + continue; + } + + // Below, by appending 'r' to the BSD node name, we indicate + // 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 != NULL) + { + std::string str = psz_buf; + drives.push_back(str); + } + } + CFRelease( str_bsd_path ); + IOObjectRelease( next_media ); + + } while( ( next_media = IOIteratorNext( media_iterator ) ) != 0 ); + } + IOObjectRelease( media_iterator ); + return drives; +} +#else +// checklist: /dev/cdrom, /dev/dvd /dev/hd?, /dev/scd? /dev/sr? +static struct +{ + const char * format; + unsigned int num_min; + unsigned int num_max; +} checklist[] = + { +#ifdef __linux__ + { "/dev/cdrom", 0, 0 }, + { "/dev/dvd", 0, 0 }, + { "/dev/hd%c", 'a', 'z' }, + { "/dev/scd%d", 0, 27 }, + { "/dev/sr%d", 0, 27 }, +#else + { "/dev/acd%d", 0, 27 }, + { "/dev/cd%d", 0, 27 }, +#endif + { NULL, 0, 0 } + }; + +// Returns true if a device is a block or char device and not a symbolic link +bool is_device(const char *source_name) +{ + struct stat buf; + if (0 != lstat(source_name, &buf)) + return false; + + return ((S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)) && + !S_ISLNK(buf.st_mode)); +} + +// Check a device to see if it is a DVD/CD-ROM drive +static bool is_cdrom(const char *drive, char *mnttype) +{ + bool is_cd=false; + int cdfd; + + // Check if the device exists + if (!is_device(drive)) + return(false); + + // If it does exist, verify that it is a cdrom/dvd drive + cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0); + if ( cdfd >= 0 ) + { +#ifdef __linux__ + if (ioctl(cdfd, CDROM_GET_CAPABILITY, 0) != -1) +#endif + is_cd = true; + close(cdfd); + } + return(is_cd); +} + +// 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 ) + { + unsigned int j; + for ( 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 str = drive; + drives.push_back(str); + } + } + } + return drives; +} +#endif + +// Returns true if device is a cdrom/dvd drive +bool cdio_is_cdrom(std::string device) +{ +#ifndef _WIN32 + // Resolve symbolic links. This allows symbolic links to valid + // drives to be passed from the command line with the -e flag. + char resolved_path[MAX_PATH]; + char *devname = realpath(device.c_str(), resolved_path); + if (!devname) + return false; + device = devname; +#endif + + std::vector devices = cdio_get_devices(); + bool res = false; + for (auto& odevice : devices) + { + if (strncmp(odevice.c_str(), device.c_str(), MAX_PATH) == 0) + { + res = true; + break; + } + } + + devices.clear(); + return res; +} + -- cgit v1.2.3 From ebff7974c3373cb96516cac0aa944e48b54e1d6b 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 --- Source/Core/Common/CDUtils.cpp | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 569ceb3c3b..7e1ebebd27 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,5 @@ bool cdio_is_cdrom(std::string device) #endif std::vector devices = cdio_get_devices(); - bool res = false; - for (auto& odevice : devices) - { - if (strncmp(odevice.c_str(), device.c_str(), MAX_PATH) == 0) - { - res = true; - break; - } - } - - devices.clear(); - return res; + return std::find(devices.begin(), devices.end(), device) != devices.end();; } - -- cgit v1.2.3 From e59f770ccbf61f012d148a390e7f76775ab2a02e Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Sun, 9 Feb 2014 16:12:59 +0100 Subject: Revert "Merge pull request #49 from Parlane/sprintf_tidy" Change broke the build on Debian stable. This reverts commit 28755439b36ac8e875d764da5db31ad693459ace, reversing changes made to 64e01ec763d21915e7166e625f8a3e85b46fbcbb. --- Source/Core/Common/CDUtils.cpp | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 7e1ebebd27..569ceb3c3b 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -2,7 +2,6 @@ #include "CDUtils.h" #include "Common.h" -#include "StringUtil.h" #include // for std::unique_ptr #ifdef _WIN32 @@ -151,10 +150,10 @@ static struct }; // Returns true if a device is a block or char device and not a symbolic link -bool is_device(const std::string& source_name) +bool is_device(const char *source_name) { struct stat buf; - if (0 != lstat(source_name.c_str(), &buf)) + if (0 != lstat(source_name, &buf)) return false; return ((S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)) && @@ -162,15 +161,17 @@ bool is_device(const std::string& source_name) } // Check a device to see if it is a DVD/CD-ROM drive -static bool is_cdrom(const std::string& drive, char *mnttype) +static bool is_cdrom(const char *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 - int cdfd = open(drive.c_str(), (O_RDONLY|O_NONBLOCK), 0); + cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0); if ( cdfd >= 0 ) { #ifdef __linux__ @@ -185,16 +186,21 @@ static bool is_cdrom(const std::string& 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 (unsigned int i = 0; checklist[i].format; ++i) + for ( i=0; checklist[i].format; ++i ) { - for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j) + unsigned int j; + for ( j=checklist[i].num_min; j<=checklist[i].num_max; ++j ) { - std::string drive = StringFromFormat(checklist[i].format, j); - if ( (is_cdrom(drive.c_str(), NULL)) > 0 ) + sprintf(drive, checklist[i].format, j); + if ( (is_cdrom(drive, NULL)) > 0 ) { - drives.push_back(std::move(drive)); + std::string str = drive; + drives.push_back(str); } } } @@ -216,5 +222,17 @@ bool cdio_is_cdrom(std::string device) #endif std::vector devices = cdio_get_devices(); - return std::find(devices.begin(), devices.end(), device) != devices.end();; + bool res = false; + for (auto& odevice : devices) + { + if (strncmp(odevice.c_str(), device.c_str(), MAX_PATH) == 0) + { + res = true; + break; + } + } + + devices.clear(); + return res; } + -- cgit v1.2.3 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 From 404624bf0b0125e5a408021c616ee9b9e2dde382 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Wed, 12 Feb 2014 16:00:34 +0100 Subject: Turn loops into range-based form and some things suggested by cppcheck and compiler warnings. --- Source/Core/Common/CDUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 763fbf7f45..cd9d881fb7 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -192,7 +192,7 @@ std::vector cdio_get_devices () for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j) { std::string drive = StringFromFormat(checklist[i].format, j); - if ( (is_cdrom(drive.c_str(), NULL)) > 0 ) + if ( (is_cdrom(drive, NULL)) > 0 ) { drives.push_back(std::move(drive)); } -- cgit v1.2.3 From 3fd87a7636ff434118a5d7f7334550be8db55c0b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Feb 2014 23:51:41 -0500 Subject: Second and final pass of clearing out tabs. --- Source/Core/Common/CDUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index cd9d881fb7..37b5f281c5 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -47,7 +47,7 @@ std::vector cdio_get_devices() if (is_cdrom(drive)) { std::string str(TStrToUTF8(drive)); - str.pop_back(); // we don't want the final backslash + str.pop_back(); // we don't want the final backslash drives.push_back(std::move(str)); } -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/Common/CDUtils.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 37b5f281c5..156b758749 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -1,13 +1,13 @@ // Most of the code in this file was shamelessly ripped from libcdio With minor adjustments -#include "CDUtils.h" -#include "Common.h" -#include "StringUtil.h" - #include // for std::unique_ptr + +#include "Common/CDUtils.h" +#include "Common/Common.h" +#include "Common/StringUtil.h" + #ifdef _WIN32 #include -#include "StringUtil.h" #elif __APPLE__ #include #include -- cgit v1.2.3 From 83b7bb64aa5e1ee6b18eaa5d08c17bb5b6c57048 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Thu, 20 Feb 2014 04:11:52 +0100 Subject: Make Common/ mostly IWYU clean (and fix errors in rest of the project detected by this change). --- Source/Core/Common/CDUtils.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 156b758749..4adcf7cee9 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -1,6 +1,9 @@ // Most of the code in this file was shamelessly ripped from libcdio With minor adjustments -#include // for std::unique_ptr +#include +#include +#include +#include #include "Common/CDUtils.h" #include "Common/Common.h" @@ -19,6 +22,7 @@ #include #include #include +#include #endif // WIN32 #ifdef __linux__ -- cgit v1.2.3 From 315a8ba1c04bf8cffd9b04096be898ac462fa89e Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 23 Feb 2014 23:03:39 +0100 Subject: Various changes suggested by cppcheck - remove unused variables - reduce the scope where it makes sense - correct limits (did you know that strcat()'s last parameter does not include the \0 that is always added?) - set some free()'d pointers to NULL --- Source/Core/Common/CDUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 4adcf7cee9..9652b98f08 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -196,7 +196,7 @@ std::vector cdio_get_devices () for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j) { std::string drive = StringFromFormat(checklist[i].format, j); - if ( (is_cdrom(drive, NULL)) > 0 ) + if (is_cdrom(drive, NULL)) { drives.push_back(std::move(drive)); } -- cgit v1.2.3 From d802d392811be44d34ae9cd23f616db93e54c50f Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 9 Mar 2014 21:14:26 +0100 Subject: clang-modernize -use-nullptr and s/\bNULL\b/nullptr/g for *.cpp/h/mm files not compiled on my machine --- Source/Core/Common/CDUtils.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 9652b98f08..2f1c24f146 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -41,7 +41,7 @@ std::vector cdio_get_devices() { std::vector drives; - const DWORD buffsize = GetLogicalDriveStrings(0, NULL); + const DWORD buffsize = GetLogicalDriveStrings(0, nullptr); std::vector buff(buffsize); if (GetLogicalDriveStrings(buffsize, buff.data()) == buffsize - 1) { @@ -77,7 +77,7 @@ std::vector cdio_get_devices() return( drives ); classes_to_match = IOServiceMatching( kIOCDMediaClass ); - if( classes_to_match == NULL ) + if( classes_to_match == nullptr ) return( drives ); CFDictionarySetValue( classes_to_match, @@ -101,7 +101,7 @@ std::vector cdio_get_devices() IORegistryEntryCreateCFProperty( next_media, CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, 0 ); - if( str_bsd_path == NULL ) + if( str_bsd_path == nullptr ) { IOObjectRelease( next_media ); continue; @@ -118,7 +118,7 @@ std::vector cdio_get_devices() sizeof(psz_buf) - dev_path_length, kCFStringEncodingASCII)) { - if(psz_buf != NULL) + if(psz_buf != nullptr) { std::string str = psz_buf; drives.push_back(str); @@ -151,7 +151,7 @@ static struct { "/dev/acd%d", 0, 27 }, { "/dev/cd%d", 0, 27 }, #endif - { NULL, 0, 0 } + { nullptr, 0, 0 } }; // Returns true if a device is a block or char device and not a symbolic link @@ -196,7 +196,7 @@ std::vector cdio_get_devices () for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j) { std::string drive = StringFromFormat(checklist[i].format, j); - if (is_cdrom(drive, NULL)) + if (is_cdrom(drive, nullptr)) { drives.push_back(std::move(drive)); } -- cgit v1.2.3 From 31cfc73a09a8685cbab20502b4bc132e98e2feb5 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Tue, 11 Mar 2014 00:30:55 +1300 Subject: Fixes spacing for "for", "while", "switch" and "if" Also moved && and || to ends of lines instead of start. Fixed misc vertical alignments and some { needed newlining. --- Source/Core/Common/CDUtils.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 2f1c24f146..4dfdcacd64 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -73,11 +73,11 @@ std::vector cdio_get_devices() std::vector drives; kern_result = IOMasterPort( MACH_PORT_NULL, &master_port ); - if( kern_result != KERN_SUCCESS ) + if (kern_result != KERN_SUCCESS) return( drives ); classes_to_match = IOServiceMatching( kIOCDMediaClass ); - if( classes_to_match == nullptr ) + if (classes_to_match == nullptr) return( drives ); CFDictionarySetValue( classes_to_match, @@ -85,11 +85,11 @@ std::vector cdio_get_devices() kern_result = IOServiceGetMatchingServices( master_port, classes_to_match, &media_iterator ); - if( kern_result != KERN_SUCCESS) + if (kern_result != KERN_SUCCESS) return( drives ); next_media = IOIteratorNext( media_iterator ); - if( next_media != 0 ) + if (next_media != 0) { char psz_buf[0x32]; size_t dev_path_length; @@ -101,7 +101,7 @@ std::vector cdio_get_devices() IORegistryEntryCreateCFProperty( next_media, CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, 0 ); - if( str_bsd_path == nullptr ) + if (str_bsd_path == nullptr) { IOObjectRelease( next_media ); continue; @@ -113,12 +113,12 @@ std::vector cdio_get_devices() snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' ); dev_path_length = strlen( psz_buf ); - if( CFStringGetCString( (CFStringRef)str_bsd_path, + if (CFStringGetCString( (CFStringRef)str_bsd_path, (char*)&psz_buf + dev_path_length, sizeof(psz_buf) - dev_path_length, kCFStringEncodingASCII)) { - if(psz_buf != nullptr) + if (psz_buf != nullptr) { std::string str = psz_buf; drives.push_back(str); @@ -127,7 +127,7 @@ std::vector cdio_get_devices() CFRelease( str_bsd_path ); IOObjectRelease( next_media ); - } while( ( next_media = IOIteratorNext( media_iterator ) ) != 0 ); + } while (( next_media = IOIteratorNext( media_iterator ) ) != 0); } IOObjectRelease( media_iterator ); return drives; @@ -175,7 +175,7 @@ static bool is_cdrom(const std::string& drive, char *mnttype) bool is_cd=false; // If it does exist, verify that it is a cdrom/dvd drive int cdfd = open(drive.c_str(), (O_RDONLY|O_NONBLOCK), 0); - if ( cdfd >= 0 ) + if (cdfd >= 0) { #ifdef __linux__ if (ioctl(cdfd, CDROM_GET_CAPABILITY, 0) != -1) -- cgit v1.2.3 From 22e1aa5bb4a159d6d66a321f978917614aa36331 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 8 Jul 2014 14:29:26 +0200 Subject: mark all local functions as static --- Source/Core/Common/CDUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 4dfdcacd64..e0ccd20dab 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -155,7 +155,7 @@ static struct }; // Returns true if a device is a block or char device and not a symbolic link -bool is_device(const std::string& source_name) +static bool is_device(const std::string& source_name) { struct stat buf; if (0 != lstat(source_name.c_str(), &buf)) -- cgit v1.2.3 From fbc64984ca7de7db10b1a8a4f49002f260c93569 Mon Sep 17 00:00:00 2001 From: Rohit Nirmal Date: Sun, 7 Sep 2014 20:06:58 -0500 Subject: Include CommonTypes.h instead of Common.h. --- Source/Core/Common/CDUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index e0ccd20dab..45f2011149 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -6,7 +6,7 @@ #include #include "Common/CDUtils.h" -#include "Common/Common.h" +#include "Common/CommonTypes.h" #include "Common/StringUtil.h" #ifdef _WIN32 -- cgit v1.2.3 From 06433652bead1e902539d01712591a0aca5eb392 Mon Sep 17 00:00:00 2001 From: comex Date: Tue, 21 Oct 2014 03:11:58 -0400 Subject: 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. --- Source/Core/Common/CDUtils.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 45f2011149..50c1902eac 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -91,8 +91,6 @@ std::vector cdio_get_devices() next_media = IOIteratorNext( media_iterator ); if (next_media != 0) { - char psz_buf[0x32]; - size_t dev_path_length; CFTypeRef str_bsd_path; do @@ -107,22 +105,20 @@ std::vector cdio_get_devices() continue; } - // Below, by appending 'r' to the BSD node name, we indicate - // 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 (CFGetTypeID(str_bsd_path) == CFStringGetTypeID()) { - 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; - drives.push_back(str); + // Below, by appending 'r' to the BSD node name, we indicate + // 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 ); IOObjectRelease( next_media ); -- cgit v1.2.3 From 93b16a4a2d5f3e6d467d1315c461aff12852b26c Mon Sep 17 00:00:00 2001 From: Stevoisiak Date: Sun, 15 Feb 2015 14:43:31 -0500 Subject: Formatting/Whitespace Cleanup Various fixes to formatting and whitespace --- Source/Core/Common/CDUtils.cpp | 47 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 50c1902eac..bbe7b4c2c6 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -72,23 +72,23 @@ std::vector cdio_get_devices() CFMutableDictionaryRef classes_to_match; std::vector drives; - kern_result = IOMasterPort( MACH_PORT_NULL, &master_port ); + kern_result = IOMasterPort(MACH_PORT_NULL, &master_port); if (kern_result != KERN_SUCCESS) - return( drives ); + return drives; - classes_to_match = IOServiceMatching( kIOCDMediaClass ); + classes_to_match = IOServiceMatching(kIOCDMediaClass); if (classes_to_match == nullptr) - return( drives ); + return drives; - CFDictionarySetValue( classes_to_match, - CFSTR(kIOMediaEjectableKey), kCFBooleanTrue ); + CFDictionarySetValue(classes_to_match, + CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); - kern_result = IOServiceGetMatchingServices( master_port, - classes_to_match, &media_iterator ); + kern_result = IOServiceGetMatchingServices(master_port, + classes_to_match, &media_iterator); if (kern_result != KERN_SUCCESS) - return( drives ); + return drives; - next_media = IOIteratorNext( media_iterator ); + next_media = IOIteratorNext(media_iterator); if (next_media != 0) { CFTypeRef str_bsd_path; @@ -96,12 +96,12 @@ std::vector cdio_get_devices() do { str_bsd_path = - IORegistryEntryCreateCFProperty( next_media, - CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, - 0 ); + IORegistryEntryCreateCFProperty(next_media, + CFSTR(kIOBSDNameKey), kCFAllocatorDefault, + 0); if (str_bsd_path == nullptr) { - IOObjectRelease( next_media ); + IOObjectRelease(next_media); continue; } @@ -120,12 +120,11 @@ std::vector cdio_get_devices() delete[] buf; } - CFRelease( str_bsd_path ); - IOObjectRelease( next_media ); - - } while (( next_media = IOIteratorNext( media_iterator ) ) != 0); + CFRelease(str_bsd_path); + IOObjectRelease(next_media); + } while ((next_media = IOIteratorNext(media_iterator)) != 0); } - IOObjectRelease( media_iterator ); + IOObjectRelease(media_iterator); return drives; } #else @@ -166,11 +165,11 @@ static bool is_cdrom(const std::string& drive, char *mnttype) { // Check if the device exists if (!is_device(drive)) - return(false); + return false; - bool is_cd=false; + bool is_cd = false; // If it does exist, verify that it is a cdrom/dvd drive - int cdfd = open(drive.c_str(), (O_RDONLY|O_NONBLOCK), 0); + int cdfd = open(drive.c_str(), (O_RDONLY | O_NONBLOCK), 0); if (cdfd >= 0) { #ifdef __linux__ @@ -179,11 +178,11 @@ static bool is_cdrom(const std::string& drive, char *mnttype) is_cd = true; close(cdfd); } - return(is_cd); + return is_cd; } // Returns a pointer to an array of strings with the device names -std::vector cdio_get_devices () +std::vector cdio_get_devices() { std::vector drives; // Scan the system for DVD/CD-ROM drives. -- cgit v1.2.3 From 268f52e05479dc8e0f2cbf550472ca8d4867cf22 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:32:32 +0200 Subject: Add missing license headers --- Source/Core/Common/CDUtils.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Source/Core/Common/CDUtils.cpp') diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index bbe7b4c2c6..bb71c435b0 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -1,3 +1,7 @@ +// Copyright 2009 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + // Most of the code in this file was shamelessly ripped from libcdio With minor adjustments #include -- cgit v1.2.3