Explorar el Código

cmSystemTools: Add StringToULong helper

Convert a string to an unsigned integer and reject any extra input.
Brad King hace 10 años
padre
commit
8bf5a80b96
Se han modificado 2 ficheros con 10 adiciones y 0 borrados
  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