summaryrefslogtreecommitdiff
path: root/src/openvpnserv/automatic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvpnserv/automatic.c')
-rw-r--r--src/openvpnserv/automatic.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/openvpnserv/automatic.c b/src/openvpnserv/automatic.c
index 5569ce9..3f2ca34 100644
--- a/src/openvpnserv/automatic.c
+++ b/src/openvpnserv/automatic.c
@@ -36,13 +36,9 @@
#include <stdio.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <process.h>
-/* bool definitions */
-#define bool int
-#define true 1
-#define false 0
-
static SERVICE_STATUS_HANDLE service;
static SERVICE_STATUS status = { .dwServiceType = SERVICE_WIN32_SHARE_PROCESS };
@@ -115,41 +111,36 @@ close_if_open(HANDLE h)
static bool
match(const WIN32_FIND_DATA *find, LPCTSTR ext)
{
- int i;
-
if (find->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
return false;
}
- if (!_tcslen(ext))
+ if (*ext == TEXT('\0'))
{
return true;
}
- i = _tcslen(find->cFileName) - _tcslen(ext) - 1;
- if (i < 1)
- {
- return false;
- }
+ /* find the pointer to that last '.' in filename and match ext against the rest */
- return find->cFileName[i] == '.' && !_tcsicmp(find->cFileName + i + 1, ext);
+ const TCHAR *p = _tcsrchr(find->cFileName, TEXT('.'));
+ return p && p != find->cFileName && _tcsicmp(p + 1, ext) == 0;
}
/*
* Modify the extension on a filename.
*/
static bool
-modext(LPTSTR dest, int size, LPCTSTR src, LPCTSTR newext)
+modext(LPTSTR dest, size_t size, LPCTSTR src, LPCTSTR newext)
{
- int i;
+ size_t i;
if (size > 0 && (_tcslen(src) + 1) <= size)
{
_tcscpy(dest, src);
dest [size - 1] = TEXT('\0');
i = _tcslen(dest);
- while (--i >= 0)
+ while (i-- > 0)
{
if (dest[i] == TEXT('\\'))
{