Browse code

Print format spec changes for tapctl and openvpnmscia

The tapctl and openvpnmscia codebase is written with an intent of
supporting both unicode and ansi builds. This patch does not attempt
to change that although non-unicode support looks untested
and buggy.

The main change is to replace %s by PRIsLPTSR that is defined
as %ls or %s depending on _UNICODE is defined ot not.

v2: add missing ')' and fix whitespace

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

Selva Nair authored on 2021/05/26 02:38:38
Showing 3 changed files
... ...
@@ -108,7 +108,8 @@ _debug_popup(_In_z_ LPCTSTR szFunctionName)
108 108
 
109 109
     /* Compose pop-up title. The dialog title will contain function name to ease the process
110 110
      * locating. Mind that Visual Studio displays window titles on the process list. */
111
-    _stprintf_s(szTitle, _countof(szTitle), TEXT("%s v%s"), szFunctionName, TEXT(PACKAGE_VERSION));
111
+    _stprintf_s(szTitle, _countof(szTitle), TEXT("%") TEXT(PRIsLPTSTR) TEXT("v%") TEXT(PRIsLPTSTR),
112
+                szFunctionName, TEXT(PACKAGE_VERSION));
112 113
 
113 114
     /* Get process name. */
114 115
     GetModuleFileName(NULL, szProcessPath, _countof(szProcessPath));
... ...
@@ -118,7 +119,8 @@ _debug_popup(_In_z_ LPCTSTR szFunctionName)
118 118
     /* Compose the pop-up message. */
119 119
     _stprintf_s(
120 120
         szMessage, _countof(szMessage),
121
-        TEXT("The %s process (PID: %u) has started to execute the %s custom action.\r\n")
121
+        TEXT("The %") TEXT(PRIsLPTSTR) TEXT(" process (PID: %u) has started to execute the %")
122
+        TEXT(PRIsLPTSTR) TEXT(" custom action.\r\n")
122 123
         TEXT("\r\n")
123 124
         TEXT("If you would like to debug the custom action, attach a debugger to this process and set breakpoints before dismissing this dialog.\r\n")
124 125
         TEXT("\r\n")
... ...
@@ -49,7 +49,7 @@ const TCHAR title_string[] =
49 49
 ;
50 50
 
51 51
 static const TCHAR usage_message[] =
52
-    TEXT("%s\n")
52
+    TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n")
53 53
     TEXT("\n")
54 54
     TEXT("Usage:\n")
55 55
     TEXT("\n")
... ...
@@ -66,7 +66,7 @@ static const TCHAR usage_message[] =
66 66
 ;
67 67
 
68 68
 static const TCHAR usage_message_create[] =
69
-    TEXT("%s\n")
69
+    TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n")
70 70
     TEXT("\n")
71 71
     TEXT("Creates a new TUN/TAP adapter\n")
72 72
     TEXT("\n")
... ...
@@ -91,7 +91,7 @@ static const TCHAR usage_message_create[] =
91 91
 ;
92 92
 
93 93
 static const TCHAR usage_message_list[] =
94
-    TEXT("%s\n")
94
+    TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n")
95 95
     TEXT("\n")
96 96
     TEXT("Lists TUN/TAP adapters\n")
97 97
     TEXT("\n")
... ...
@@ -110,7 +110,7 @@ static const TCHAR usage_message_list[] =
110 110
 ;
111 111
 
112 112
 static const TCHAR usage_message_delete[] =
113
-    TEXT("%s\n")
113
+    TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n")
114 114
     TEXT("\n")
115 115
     TEXT("Deletes the specified network adapter\n")
116 116
     TEXT("\n")
... ...
@@ -170,7 +170,8 @@ _tmain(int argc, LPCTSTR argv[])
170 170
         }
171 171
         else
172 172
         {
173
-            _ftprintf(stderr, TEXT("Unknown command \"%s\". Please, use \"tapctl help\" to list supported commands.\n"), argv[2]);
173
+            _ftprintf(stderr, TEXT("Unknown command \"%") TEXT(PRIsLPTSTR)
174
+                      TEXT("\". Please, use \"tapctl help\" to list supported commands.\n"), argv[2]);
174 175
         }
175 176
 
176 177
         return 1;
... ...
@@ -194,7 +195,9 @@ _tmain(int argc, LPCTSTR argv[])
194 194
             }
195 195
             else
196 196
             {
197
-                _ftprintf(stderr, TEXT("Unknown option \"%s\". Please, use \"tapctl help create\" to list supported options. Ignored.\n"), argv[i]);
197
+                _ftprintf(stderr, TEXT("Unknown option \"%") TEXT(PRIsLPTSTR)
198
+                          TEXT("\". Please, use \"tapctl help create\" to list supported options. Ignored.\n"),
199
+                          argv[i]);
198 200
             }
199 201
         }
200 202
 
... ...
@@ -230,7 +233,8 @@ _tmain(int argc, LPCTSTR argv[])
230 230
                 if (_tcsicmp(szName, pAdapter->szName) == 0)
231 231
                 {
232 232
                     StringFromIID((REFIID)&pAdapter->guid, &szAdapterId);
233
-                    _ftprintf(stderr, TEXT("Adapter \"%s\" already exists (GUID %") TEXT(PRIsLPOLESTR) TEXT(").\n"), pAdapter->szName, szAdapterId);
233
+                    _ftprintf(stderr, TEXT("Adapter \"%") TEXT(PRIsLPTSTR) TEXT("\" already exists (GUID %")
234
+                              TEXT(PRIsLPOLESTR) TEXT(").\n"), pAdapter->szName, szAdapterId);
234 235
                     CoTaskMemFree(szAdapterId);
235 236
                     iResult = 1; goto create_cleanup_pAdapterList;
236 237
                 }
... ...
@@ -241,7 +245,9 @@ _tmain(int argc, LPCTSTR argv[])
241 241
             if (dwResult != ERROR_SUCCESS)
242 242
             {
243 243
                 StringFromIID((REFIID)&guidAdapter, &szAdapterId);
244
-                _ftprintf(stderr, TEXT("Renaming TUN/TAP adapter %") TEXT(PRIsLPOLESTR) TEXT(" to \"%s\" failed (error 0x%x).\n"), szAdapterId, szName, dwResult);
244
+                _ftprintf(stderr, TEXT("Renaming TUN/TAP adapter %") TEXT(PRIsLPOLESTR)
245
+                          TEXT(" to \"%") TEXT(PRIsLPTSTR) TEXT("\" failed (error 0x%x).\n"),
246
+                          szAdapterId, szName, dwResult);
245 247
                 CoTaskMemFree(szAdapterId);
246 248
                 iResult = 1; goto quit;
247 249
             }
... ...
@@ -289,7 +295,9 @@ create_delete_adapter:
289 289
             }
290 290
             else
291 291
             {
292
-                _ftprintf(stderr, TEXT("Unknown option \"%s\". Please, use \"tapctl help list\" to list supported options. Ignored.\n"), argv[i]);
292
+                _ftprintf(stderr, TEXT("Unknown option \"%") TEXT(PRIsLPTSTR)
293
+                          TEXT("\". Please, use \"tapctl help list\" to list supported options. Ignored.\n"),
294
+                          argv[i]);
293 295
             }
294 296
         }
295 297
 
... ...
@@ -306,7 +314,8 @@ create_delete_adapter:
306 306
         {
307 307
             LPOLESTR szAdapterId = NULL;
308 308
             StringFromIID((REFIID)&pAdapter->guid, &szAdapterId);
309
-            _ftprintf(stdout, TEXT("%") TEXT(PRIsLPOLESTR) TEXT("\t%") TEXT(PRIsLPTSTR) TEXT("\n"), szAdapterId, pAdapter->szName);
309
+            _ftprintf(stdout, TEXT("%") TEXT(PRIsLPOLESTR) TEXT("\t%")
310
+                      TEXT(PRIsLPTSTR) TEXT("\n"), szAdapterId, pAdapter->szName);
310 311
             CoTaskMemFree(szAdapterId);
311 312
         }
312 313
 
... ...
@@ -337,7 +346,7 @@ create_delete_adapter:
337 337
             {
338 338
                 if (pAdapter == NULL)
339 339
                 {
340
-                    _ftprintf(stderr, TEXT("\"%s\" adapter not found.\n"), argv[2]);
340
+                    _ftprintf(stderr, TEXT("\"%") TEXT(PRIsLPTSTR) TEXT("\" adapter not found.\n"), argv[2]);
341 341
                     iResult = 1; goto delete_cleanup_pAdapterList;
342 342
                 }
343 343
                 else if (_tcsicmp(argv[2], pAdapter->szName) == 0)
... ...
@@ -364,7 +373,8 @@ delete_cleanup_pAdapterList:
364 364
             &bRebootRequired);
365 365
         if (dwResult != ERROR_SUCCESS)
366 366
         {
367
-            _ftprintf(stderr, TEXT("Deleting adapter \"%s\" failed (error 0x%x).\n"), argv[2], dwResult);
367
+            _ftprintf(stderr, TEXT("Deleting adapter \"%") TEXT(PRIsLPTSTR)
368
+                      TEXT("\" failed (error 0x%x).\n"), argv[2], dwResult);
368 369
             iResult = 1; goto quit;
369 370
         }
370 371
 
... ...
@@ -372,7 +382,8 @@ delete_cleanup_pAdapterList:
372 372
     }
373 373
     else
374 374
     {
375
-        _ftprintf(stderr, TEXT("Unknown command \"%s\". Please, use \"tapctl help\" to list supported commands.\n"), argv[1]);
375
+        _ftprintf(stderr, TEXT("Unknown command \"%") TEXT(PRIsLPTSTR)
376
+                  TEXT("\". Please, use \"tapctl help\" to list supported commands.\n"), argv[1]);
376 377
         return 1;
377 378
     }
378 379
 
... ...
@@ -434,7 +445,7 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
434 434
             }
435 435
 
436 436
             /* Output error message. */
437
-            _ftprintf(stderr, TEXT("Error 0x%x: %s\n"), dwResult, szErrMessage);
437
+            _ftprintf(stderr, TEXT("Error 0x%x: %") TEXT(PRIsLPTSTR) TEXT("\n"), dwResult, szErrMessage);
438 438
 
439 439
             LocalFree(szErrMessage);
440 440
         }
... ...
@@ -1117,7 +1117,8 @@ tap_set_adapter_name(
1117 1117
     }
1118 1118
 
1119 1119
     /* rename adapter via netsh call */
1120
-    const TCHAR* szFmt = _T("netsh interface set interface name=\"%s\" newname=\"%s\"");
1120
+    const TCHAR* szFmt = TEXT("netsh interface set interface name=\"%")
1121
+                         TEXT(PRIsLPTSTR) TEXT("\" newname=\"%") TEXT(PRIsLPTSTR) TEXT("\"");
1121 1122
     size_t ncmdline = _tcslen(szFmt) + _tcslen(szOldName) + _tcslen(szName) + 1;
1122 1123
     WCHAR* szCmdLine = malloc(ncmdline * sizeof(TCHAR));
1123 1124
     _stprintf_s(szCmdLine, ncmdline, szFmt, szOldName, szName);