Skip to content

Instantly share code, notes, and snippets.

@szaffarano
Created February 17, 2013 22:47
Show Gist options
  • Select an option

  • Save szaffarano/4973890 to your computer and use it in GitHub Desktop.

Select an option

Save szaffarano/4973890 to your computer and use it in GitHub Desktop.
diff --git a/src/deviceManager.cpp b/src/deviceManager.cpp
index a1dbac1..2b4668e 100644
--- a/src/deviceManager.cpp
+++ b/src/deviceManager.cpp
@@ -29,6 +29,19 @@
#include <algorithm>
#include <string>
+// from http://stackoverflow.com/questions/11635/case-insensitive-string-comparison-in-c
+bool icompare(const string& str1, const string& str2) {
+ if (str1.size() != str2.size()) {
+ return false;
+ }
+ for (string::const_iterator c1 = str1.begin(), c2 = str2.begin(); c1 != str1.end(); ++c1, ++c2) {
+ if (tolower(*c1) != tolower(*c2)) {
+ return false;
+ }
+ }
+ return true;
+}
+
DeviceManager::DeviceManager()
:configuration(0)
{
@@ -320,12 +333,9 @@ GpsDevice * DeviceManager::createGarminDeviceFromPath(string devicepath, TiXmlDo
}
bool garminDirFound = false;
- while ((dirp = readdir(dp)) != NULL) {
+ while ((dirp = readdir(dp)) != NULL && !garminDirFound) {
string dir = string(dirp->d_name);
- if (dir.compare("Garmin") == 0) {
- garminDirFound = true;
- break;
- }
+ garminDirFound = icompare(dir, "Garmin");
}
closedir(dp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment