Browse code

openvpnserv: clarify return values type

Functions openvpn_vsntprintf and openvpn_sntprintf return
values of type int, but in reality it is always 0 or 1 (and -1 for
snrptinf), which can be represented as boolean.

To make code clearer, change return type to BOOL. Also
use stdbool.h header instead of bool definition macros in automatic.c.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <1538587281-3209-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17532.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Lev Stipakov authored on 2018/10/04 02:21:21
Showing 3 changed files
... ...
@@ -36,13 +36,9 @@
36 36
 
37 37
 #include <stdio.h>
38 38
 #include <stdarg.h>
39
+#include <stdbool.h>
39 40
 #include <process.h>
40 41
 
41
-/* bool definitions */
42
-#define bool int
43
-#define true 1
44
-#define false 0
45
-
46 42
 static SERVICE_STATUS_HANDLE service;
47 43
 static SERVICE_STATUS status = { .dwServiceType = SERVICE_WIN32_SHARE_PROCESS };
48 44
 
... ...
@@ -31,7 +31,7 @@ static wchar_t win_sys_path[MAX_PATH];
31 31
  * These are necessary due to certain buggy implementations of (v)snprintf,
32 32
  * that don't guarantee null termination for size > 0.
33 33
  */
34
-int
34
+BOOL
35 35
 openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist)
36 36
 {
37 37
     int len = -1;
... ...
@@ -42,18 +42,19 @@ openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist)
42 42
     }
43 43
     return (len >= 0 && (size_t)len < size);
44 44
 }
45
-int
45
+
46
+BOOL
46 47
 openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...)
47 48
 {
48 49
     va_list arglist;
49
-    int len = -1;
50
+    BOOL res = FALSE;
50 51
     if (size > 0)
51 52
     {
52 53
         va_start(arglist, format);
53
-        len = openvpn_vsntprintf(str, size, format, arglist);
54
+        res = openvpn_vsntprintf(str, size, format, arglist);
54 55
         va_end(arglist);
55 56
     }
56
-    return len;
57
+    return res;
57 58
 }
58 59
 
59 60
 static DWORD
... ...
@@ -65,7 +66,7 @@ GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_v
65 65
     if (status == ERROR_FILE_NOT_FOUND && default_value)
66 66
     {
67 67
         size_t len = size/sizeof(data[0]);
68
-        if (openvpn_sntprintf(data, len, default_value) > 0)
68
+        if (openvpn_sntprintf(data, len, default_value))
69 69
         {
70 70
             status = ERROR_SUCCESS;
71 71
         }
... ...
@@ -82,9 +82,9 @@ VOID WINAPI ServiceStartAutomatic(DWORD argc, LPTSTR *argv);
82 82
 VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv);
83 83
 VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv);
84 84
 
85
-int openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist);
85
+BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist);
86 86
 
87
-int openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...);
87
+BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...);
88 88
 
89 89
 DWORD GetOpenvpnSettings(settings_t *s);
90 90