Przeglądaj źródła

Added str_number().

Wrapper function around _tcstoul().
Iain Patterson 10 lat temu
rodzic
commit
da3d37ae16
2 zmienionych plików z 12 dodań i 0 usunięć
  1. 11 0
      nssm.cpp
  2. 1 0
      nssm.h

+ 11 - 0
nssm.cpp

@@ -12,6 +12,17 @@ int str_equiv(const TCHAR *a, const TCHAR *b) {
   return 1;
 }
 
+/* Convert a string to a number. */
+int str_number(const TCHAR *string, unsigned long *number) {
+  if (! string) return 1;
+
+  TCHAR *bogus;
+  *number = _tcstoul(string, &bogus, 0);
+  if (*bogus) return 2;
+
+  return 0;
+}
+
 /* Remove basename of a path. */
 void strip_basename(TCHAR *buffer) {
   size_t len = _tcslen(buffer);

+ 1 - 0
nssm.h

@@ -18,6 +18,7 @@
 
 int str_equiv(const TCHAR *, const TCHAR *);
 void strip_basename(TCHAR *);
+int str_number(const TCHAR *, unsigned long *);
 int usage(int);
 
 #define NSSM _T("nssm")