From da3d37ae16f1af9735699ae444128b1224a7103f Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Wed, 1 Jan 2014 12:39:20 +0000 Subject: [PATCH] Added str_number(). Wrapper function around _tcstoul(). --- nssm.cpp | 11 +++++++++++ nssm.h | 1 + 2 files changed, 12 insertions(+) diff --git a/nssm.cpp b/nssm.cpp index 02ad21f..781a228 100644 --- a/nssm.cpp +++ b/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); diff --git a/nssm.h b/nssm.h index 636524d..cf6133e 100644 --- a/nssm.h +++ b/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") -- 2.7.4