Преглед изворни кода

cmSystemTools: Add StringToULong helper

Convert a string to an unsigned integer and reject any extra input.
Brad King пре 10 година
родитељ
комит
8bf5a80b96
2 измењених фајлова са 10 додато и 0 уклоњено
  1. 9 0
      Source/cmSystemTools.cxx
  2. 1 0
      Source/cmSystemTools.h

+ 9 - 0
Source/cmSystemTools.cxx

@@ -2955,3 +2955,12 @@ bool cmSystemTools::StringToLong(const char* str, long* value)
   *value = strtol(str, &endp, 10);
   return (*endp == '\0') && (endp != str) && (errno == 0);
 }
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::StringToULong(const char* str, unsigned long* value)
+{
+  errno = 0;
+  char *endp;
+  *value = strtoul(str, &endp, 10);
+  return (*endp == '\0') && (endp != str) && (errno == 0);
+}

+ 1 - 0
Source/cmSystemTools.h

@@ -469,6 +469,7 @@ public:
 
   /** Convert string to long. Expected that the whole string is an integer */
   static bool StringToLong(const char* str, long* value);
+  static bool StringToULong(const char* str, unsigned long* value);
 
 #ifdef _WIN32
   struct WindowsFileRetry