Make it explicit that WIndows build requires UNICODE support
PATCH 1/3 Make it explicit that WIndows build requires UNICODE support
From: Selva Nair <[email protected]...>
The interactive service code implicitly treats TCHAR == WCHAR in several places with the assumption that we build only with UNICODE defined. Make this explicit and remove some redundant code.
Also replace openvpn_sntprintf(), _tprintf() and similar with explicit wide string functions. This adds some definiteness as to which stdio functions are used, and helps the next commit that makes those calls C-standard compliant.
Also, replace direct swprintf calls with openvpn_swprintf.
Note: we need UNICODE defined mainly because of the use of TEXT("..") throughout the code. If those are replaced by L"..", we could build with just -municode as done for OpenVPN core.
--- src/openvpnserv/common.c | 53 ++++++++++++-------------------- src/openvpnserv/interactive.c | 41 ++++++------------------- src/openvpnserv/service.c | 58 +++++++++++++++++------------------ src/openvpnserv/service.h | 5 +++ src/openvpnserv/validate.c | 12 -------- 5 files changed, 62 insertions(+), 107 deletions(-)
src/openvpnserv/common.c +19 -34
@@ -32,46 +32,31 @@ static wchar_t win_sys_path[MAX_PATH];* that don't guarantee null termination for size > 0. */ BOOL -openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist) +openvpn_vswprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist) {int len =-1 ;if (size >0 ) { - len =_vsntprintf_s (str, size, _TRUNCATE, format, arglist); + len =vswprintf_s (str, size, format, arglist); str[size -1 ] =0 ; }return (len >=0 && (size_t )len < size); }BOOL -openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...) +openvpn_swprintf (LPTSTR str,size_t size,LPCTSTR format, ...) {va_list arglist;BOOL res = FALSE;if (size >0 ) {va_start (arglist, format); - res =openvpn_vsntprintf (str, size, format, arglist); + res =openvpn_vswprintf (str, size, format, arglist);va_end (arglist); }return res; } -BOOL -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} -static DWORD GetRegString (HKEY key,LPCTSTR value,LPTSTR data,DWORD size,LPCTSTR default_value) {
@@ -81,7 +66,7 @@ GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_vif (status ==ERROR_FILE_NOT_FOUND && default_value) {size_t len = size/sizeof (data[0 ]); -if (openvpn_sntprintf (data, len, default_value)) +if (openvpn_swprintf (data, len, default_value)) { status =ERROR_SUCCESS ; }
@@ -108,7 +93,7 @@ GetOpenvpnSettings(settings_t *s)TCHAR install_path[MAX_PATH ];TCHAR default_value[MAX_PATH ]; -openvpn_sntprintf (reg_path,_countof (reg_path),TEXT ("SOFTWARE\\" PACKAGE_NAME "%s" ), service_instance); +openvpn_swprintf (reg_path,_countof (reg_path),TEXT ("SOFTWARE\\" PACKAGE_NAME "%s" ), service_instance);LONG status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &key);if (status !=ERROR_SUCCESS )
@@ -125,7 +110,7 @@ GetOpenvpnSettings(settings_t *s) goto out; } -openvpn_sntprintf (default_value,_countof (default_value),TEXT ("%s\\bin\\openvpn.exe" ), +openvpn_swprintf (default_value,_countof (default_value),TEXT ("%s\\bin\\openvpn.exe" ), install_path); error =GetRegString (key,TEXT ("exe_path" ), s->exe_path,sizeof (s->exe_path), default_value);if (error !=ERROR_SUCCESS )
@@ -133,7 +118,7 @@ GetOpenvpnSettings(settings_t *s) goto out; } -openvpn_sntprintf (default_value,_countof (default_value),TEXT ("%s\\config" ), install_path); +openvpn_swprintf (default_value,_countof (default_value),TEXT ("%s\\config" ), install_path); error =GetRegString (key,TEXT ("config_dir" ), s->config_dir,sizeof (s->config_dir), default_value);if (error !=ERROR_SUCCESS )
@@ -148,7 +133,7 @@ GetOpenvpnSettings(settings_t *s) goto out; } -openvpn_sntprintf (default_value,_countof (default_value),TEXT ("%s\\log" ), install_path); +openvpn_swprintf (default_value,_countof (default_value),TEXT ("%s\\log" ), install_path); error =GetRegString (key,TEXT ("log_dir" ), s->log_dir,sizeof (s->log_dir), default_value);if (error !=ERROR_SUCCESS ) {
@@ -176,23 +161,23 @@ GetOpenvpnSettings(settings_t *s) goto out; }/* set process priority */ -if (!_tcsicmp (priority,TEXT ("IDLE_PRIORITY_CLASS" ))) +if (!_wcsicmp (priority,TEXT ("IDLE_PRIORITY_CLASS" ))) { s->priority =IDLE_PRIORITY_CLASS ; } -else if (!_tcsicmp (priority,TEXT ("BELOW_NORMAL_PRIORITY_CLASS" ))) +else if (!_wcsicmp (priority,TEXT ("BELOW_NORMAL_PRIORITY_CLASS" ))) { s->priority =BELOW_NORMAL_PRIORITY_CLASS ; } -else if (!_tcsicmp (priority,TEXT ("NORMAL_PRIORITY_CLASS" ))) +else if (!_wcsicmp (priority,TEXT ("NORMAL_PRIORITY_CLASS" ))) { s->priority =NORMAL_PRIORITY_CLASS ; } -else if (!_tcsicmp (priority,TEXT ("ABOVE_NORMAL_PRIORITY_CLASS" ))) +else if (!_wcsicmp (priority,TEXT ("ABOVE_NORMAL_PRIORITY_CLASS" ))) { s->priority =ABOVE_NORMAL_PRIORITY_CLASS ; } -else if (!_tcsicmp (priority,TEXT ("HIGH_PRIORITY_CLASS" ))) +else if (!_wcsicmp (priority,TEXT ("HIGH_PRIORITY_CLASS" ))) { s->priority =HIGH_PRIORITY_CLASS ; }
@@ -235,7 +220,7 @@ GetLastErrorText() error =GetLastError (); len =FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY , -NULL , error,LANG_NEUTRAL , (LPTSTR )&tmp,0 ,NULL ); +NULL , error,LANG_NEUTRAL , tmp,0 ,NULL );if (len ==0 || (long )_countof (buf) < (long ) len +14 ) {
@@ -243,8 +228,8 @@ GetLastErrorText() }else { - tmp[_tcslen (tmp) -2 ] =TEXT ('\0' );/* remove CR/LF characters */ -openvpn_sntprintf (buf,_countof (buf),TEXT ("%s (0x%x)" ), tmp, error); + tmp[wcslen (tmp) -2 ] =TEXT ('\0' );/* remove CR/LF characters */ +openvpn_swprintf (buf,_countof (buf),TEXT ("%s (0x%x)" ), tmp, error); }if (tmp)
@@ -274,12 +259,12 @@ MsgToEventLog(DWORD flags, LPCTSTR format, ...) hEventSource =RegisterEventSource (NULL ,APPNAME );if (hEventSource !=NULL ) { -openvpn_sntprintf (msg[0 ],_countof (msg[0 ]), +openvpn_swprintf (msg[0 ],_countof (msg[0 ]),TEXT ("%s%s%s: %s" ),APPNAME , service_instance, (flags &MSG_FLAGS_ERROR ) ?TEXT (" error" ) :TEXT ("" ), err_msg);va_start (arglist, format); -openvpn_vsntprintf (msg[1 ],_countof (msg[1 ]), format, arglist); +openvpn_vswprintf (msg[1 ],_countof (msg[1 ]), format, arglist);va_end (arglist);const TCHAR *mesg[] = { msg[0 ], msg[1 ] };
src/openvpnserv/interactive.c +9 -32
123 lines not on this page · raw message
src/openvpnserv/service.c +29 -29
177 lines not on this page · raw message
src/openvpnserv/service.h +5 -0
@@ -24,6 +24,11 @@#ifndef _SERVICE_H#define _SERVICE_H +/* We do not support non-unicode builds */ +#ifndef UNICODE +#define UNICODE +#endif +#ifdef HAVE_CONFIG_H #include "config.h" #elif defined(_MSC_VER)
src/openvpnserv/validate.c +0 -12
@@ -64,9 +64,6 @@ CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t *s)WCHAR tmp[MAX_PATH ];const WCHAR *config_file =NULL ;const WCHAR *config_dir =NULL ; -#ifndef UNICODE -WCHAR widepath[MAX_PATH ]; -#endif /* convert fname to full path */ if (PathIsRelativeW (fname) )
@@ -79,16 +76,7 @@ CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t *s) config_file = fname; } -#ifdef UNICODE config_dir = s->config_dir; -#else -if (MultiByteToWideChar (CP_UTF8 ,0 , s->config_dir,-1 , widepath,MAX_PATH ) ==0 ) - { -MsgToEventLog (M_SYSERR ,TEXT ("Failed to convert config_dir name to WideChar" )); -return FALSE; - } - config_dir = widepath; -#endif if (wcsncmp (config_dir, config_file,wcslen (config_dir)) ==0 &&wcsstr (config_file +wcslen (config_dir),L".." ) ==NULL )
Signature · 1 line
2.20.1
PATCH 2/3 Use C standard compliant format specs in wprintf functions
From: Selva Nair <[email protected]...>
- Use %ls for wchar_t * and %hs for char * variables
This makes it possible to build correctly with or without __USE_MINGW_ANIS_STDIO defined. When this define is not used all printf/scanf family functions are resolved from the windows runtime MSVCRT. Newer (since version 8) mingw-w64 versions have started automatically enabling this macro under some feature sets such as _GNU_SOURCE and C99.
The changes should not affect MSVC builds as Windows support these format specifications.
--- src/openvpn/tun.c | 2 +- src/openvpn/win32.c | 4 ++-- src/openvpnserv/common.c | 20 ++++++++-------- src/openvpnserv/interactive.c | 43 +++++++++++++++++------------------ src/openvpnserv/service.c | 34 +++++++++++++-------------- src/openvpnserv/validate.c | 6 ++--- 6 files changed, 54 insertions(+), 55 deletions(-)
src/openvpn/tun.c +1 -1
@@ -4833,7 +4833,7 @@ get_adapter_index_method_1(const char *guid)DWORD index;ULONG aindex;wchar_t wbuf[256 ]; -openvpn_swprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); +openvpn_swprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%hs" , guid);if (GetAdapterIndex (wbuf, &aindex) !=NO_ERROR ) { index =TUN_ADAPTER_INDEX_INVALID ;
src/openvpn/win32.c +2 -2
@@ -1040,13 +1040,13 @@ openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned in }else { -msg (M_WARN |M_ERRNO ,"openvpn_execve: GetExitCodeProcess %S failed" , cmd); +msg (M_WARN |M_ERRNO ,"openvpn_execve: GetExitCodeProcess %ls failed" , cmd); }CloseHandle (proc_info.hProcess); }else { -msg (M_WARN |M_ERRNO ,"openvpn_execve: CreateProcess %S failed" , cmd); +msg (M_WARN |M_ERRNO ,"openvpn_execve: CreateProcess %ls failed" , cmd); }free (env);gc_free (&gc);
src/openvpnserv/common.c +10 -10
@@ -75,7 +75,7 @@ GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_vif (status !=ERROR_SUCCESS ) {SetLastError (status); -return MsgToEventLog (M_SYSERR ,TEXT ("Error querying registry value: HKLM\\SOFTWARE\\" PACKAGE_NAME "%s\\%s" ), service_instance, value); +return MsgToEventLog (M_SYSERR ,TEXT ("Error querying registry value: HKLM\\SOFTWARE\\" PACKAGE_NAME "%ls\\%ls" ), service_instance, value); }return ERROR_SUCCESS ;
@@ -93,13 +93,13 @@ GetOpenvpnSettings(settings_t *s)TCHAR install_path[MAX_PATH ];TCHAR default_value[MAX_PATH ]; -openvpn_swprintf (reg_path,_countof (reg_path),TEXT ("SOFTWARE\\" PACKAGE_NAME "%s" ), service_instance); +openvpn_swprintf (reg_path,_countof (reg_path),TEXT ("SOFTWARE\\" PACKAGE_NAME "%ls" ), service_instance);LONG status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &key);if (status !=ERROR_SUCCESS ) {SetLastError (status); -return MsgToEventLog (M_SYSERR ,TEXT ("Could not open Registry key HKLM\\%s not found" ), reg_path); +return MsgToEventLog (M_SYSERR ,TEXT ("Could not open Registry key HKLM\\%ls not found" ), reg_path); }/* The default value of REG_KEY is the install path */
@@ -110,7 +110,7 @@ GetOpenvpnSettings(settings_t *s) goto out; } -openvpn_swprintf (default_value,_countof (default_value),TEXT ("%s\\bin\\openvpn.exe" ), +openvpn_swprintf (default_value,_countof (default_value),TEXT ("%ls\\bin\\openvpn.exe" ), install_path); error =GetRegString (key,TEXT ("exe_path" ), s->exe_path,sizeof (s->exe_path), default_value);if (error !=ERROR_SUCCESS )
@@ -118,7 +118,7 @@ GetOpenvpnSettings(settings_t *s) goto out; } -openvpn_swprintf (default_value,_countof (default_value),TEXT ("%s\\config" ), install_path); +openvpn_swprintf (default_value,_countof (default_value),TEXT ("%ls\\config" ), install_path); error =GetRegString (key,TEXT ("config_dir" ), s->config_dir,sizeof (s->config_dir), default_value);if (error !=ERROR_SUCCESS )
@@ -133,7 +133,7 @@ GetOpenvpnSettings(settings_t *s) goto out; } -openvpn_swprintf (default_value,_countof (default_value),TEXT ("%s\\log" ), install_path); +openvpn_swprintf (default_value,_countof (default_value),TEXT ("%ls\\log" ), install_path); error =GetRegString (key,TEXT ("log_dir" ), s->log_dir,sizeof (s->log_dir), default_value);if (error !=ERROR_SUCCESS ) {
@@ -184,7 +184,7 @@ GetOpenvpnSettings(settings_t *s)else {SetLastError (ERROR_INVALID_DATA ); - error =MsgToEventLog (M_SYSERR ,TEXT ("Unknown priority name: %s" ), priority); + error =MsgToEventLog (M_SYSERR ,TEXT ("Unknown priority name: %ls" ), priority); goto out; }
@@ -200,7 +200,7 @@ GetOpenvpnSettings(settings_t *s)else {SetLastError (ERROR_INVALID_DATA ); - error =MsgToEventLog (M_ERR ,TEXT ("Log file append flag (given as '%s') must be '0' or '1'" ), append); + error =MsgToEventLog (M_ERR ,TEXT ("Log file append flag (given as '%ls') must be '0' or '1'" ), append); goto out; }
@@ -229,7 +229,7 @@ GetLastErrorText()else { tmp[wcslen (tmp) -2 ] =TEXT ('\0' );/* remove CR/LF characters */ -openvpn_swprintf (buf,_countof (buf),TEXT ("%s (0x%x)" ), tmp, error); +openvpn_swprintf (buf,_countof (buf),TEXT ("%ls (0x%x)" ), tmp, error); }if (tmp)
@@ -260,7 +260,7 @@ MsgToEventLog(DWORD flags, LPCTSTR format, ...)if (hEventSource !=NULL ) {openvpn_swprintf (msg[0 ],_countof (msg[0 ]), -TEXT ("%s%s%s: %s" ),APPNAME , service_instance, +TEXT ("%ls%ls%ls: %ls" ),APPNAME , service_instance, (flags &MSG_FLAGS_ERROR ) ?TEXT (" error" ) :TEXT ("" ), err_msg);va_start (arglist, format);
src/openvpnserv/interactive.c +21 -22
144 lines not on this page · raw message
src/openvpnserv/service.c +17 -17
@@ -63,7 +63,7 @@ CmdInstallServices()if (GetModuleFileName (NULL , path +1 ,_countof (path) -2 ) ==0 ) { -wprintf (TEXT ("Unable to install service - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("Unable to install service - %ls\n" ),GetLastErrorText ());return 1 ; }
@@ -73,7 +73,7 @@ CmdInstallServices() svc_ctl_mgr =OpenSCManager (NULL ,NULL ,SC_MANAGER_CONNECT |SC_MANAGER_CREATE_SERVICE );if (svc_ctl_mgr ==NULL ) { -wprintf (TEXT ("OpenSCManager failed - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("OpenSCManager failed - %ls\n" ),GetLastErrorText ());return 1 ; }
@@ -91,13 +91,13 @@ CmdInstallServices() NULL, NULL);if (service) { -wprintf (TEXT ("%s installed.\n" ), openvpn_service[i].display_name); +wprintf (TEXT ("%ls installed.\n" ), openvpn_service[i].display_name);CloseServiceHandle (service); --ret; }else { -wprintf (TEXT ("CreateService failed - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("CreateService failed - %ls\n" ),GetLastErrorText ()); } }
@@ -116,7 +116,7 @@ CmdStartService(openvpn_service_type type) svc_ctl_mgr =OpenSCManager (NULL ,NULL ,SC_MANAGER_ALL_ACCESS );if (svc_ctl_mgr ==NULL ) { -wprintf (TEXT ("OpenSCManager failed - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("OpenSCManager failed - %ls\n" ),GetLastErrorText ());return 1 ; }
@@ -130,14 +130,14 @@ CmdStartService(openvpn_service_type type) }else { -wprintf (TEXT ("StartService failed - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("StartService failed - %ls\n" ),GetLastErrorText ()); }CloseServiceHandle (service); }else { -wprintf (TEXT ("OpenService failed - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("OpenService failed - %ls\n" ),GetLastErrorText ()); }CloseServiceHandle (svc_ctl_mgr);
@@ -156,7 +156,7 @@ CmdRemoveServices() svc_ctl_mgr =OpenSCManager (NULL ,NULL ,SC_MANAGER_CONNECT );if (svc_ctl_mgr ==NULL ) { -wprintf (TEXT ("OpenSCManager failed - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("OpenSCManager failed - %ls\n" ),GetLastErrorText ());return 1 ; }
@@ -167,14 +167,14 @@ CmdRemoveServices() DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);if (service ==NULL ) { -wprintf (TEXT ("OpenService failed - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("OpenService failed - %ls\n" ),GetLastErrorText ()); goto out; }/* try to stop the service */ if (ControlService (service,SERVICE_CONTROL_STOP , &status)) { -wprintf (TEXT ("Stopping %s." ), ovpn_svc->display_name); +wprintf (TEXT ("Stopping %ls." ), ovpn_svc->display_name);Sleep (1000 );while (QueryServiceStatus (service, &status))
@@ -192,23 +192,23 @@ CmdRemoveServices()if (status.dwCurrentState ==SERVICE_STOPPED ) { -wprintf (TEXT ("\n%s stopped.\n" ), ovpn_svc->display_name); +wprintf (TEXT ("\n%ls stopped.\n" ), ovpn_svc->display_name); }else { -wprintf (TEXT ("\n%s failed to stop.\n" ), ovpn_svc->display_name); +wprintf (TEXT ("\n%ls failed to stop.\n" ), ovpn_svc->display_name); } }/* now remove the service */ if (DeleteService (service)) { -wprintf (TEXT ("%s removed.\n" ), ovpn_svc->display_name); +wprintf (TEXT ("%ls removed.\n" ), ovpn_svc->display_name); --ret; }else { -wprintf (TEXT ("DeleteService failed - %s\n" ),GetLastErrorText ()); +wprintf (TEXT ("DeleteService failed - %ls\n" ),GetLastErrorText ()); }CloseServiceHandle (service);
@@ -274,9 +274,9 @@ _tmain(int argc, TCHAR *argv[]) }else { -wprintf (TEXT ("%s -install to install the interactive service\n" ),APPNAME ); -wprintf (TEXT ("%s -start [name] to start the service (name = \"interactive\" is optional)\n" ),APPNAME ); -wprintf (TEXT ("%s -remove to remove the service\n" ),APPNAME ); +wprintf (TEXT ("%ls -install to install the interactive service\n" ),APPNAME ); +wprintf (TEXT ("%ls -start [name] to start the service (name = \"interactive\" is optional)\n" ),APPNAME ); +wprintf (TEXT ("%ls -remove to remove the service\n" ),APPNAME );wprintf (TEXT ("\nService run-time parameters:\n" )); wprintf(TEXT("-instance interactive <id>\n")
src/openvpnserv/validate.c +3 -3
@@ -68,7 +68,7 @@ CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t *s)/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%s\\%s" , workdir, fname); +openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
@@ -182,7 +182,7 @@ IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admin_group) ret =IsUserInGroup (sid, token_groups, admin_group[i]);if (ret) { -MsgToEventLog (M_INFO ,TEXT ("Authorizing user '%s@%s' by virtue of membership in group '%s'" ), +MsgToEventLog (M_INFO ,TEXT ("Authorizing user '%ls@%ls' by virtue of membership in group '%ls'" ), username, domain, admin_group[i]); goto out; }
@@ -302,7 +302,7 @@ IsUserInGroup(PSID sid, const PTOKEN_GROUPS token_groups, const WCHAR *group_namif (err != NERR_Success && err != NERR_GroupNotFound) {SetLastError (err); -MsgToEventLog (M_SYSERR ,TEXT ("In NetLocalGroupGetMembers for group '%s'" ), group_name); +MsgToEventLog (M_SYSERR ,TEXT ("In NetLocalGroupGetMembers for group '%ls'" ), group_name); }return ret;
Signature · 1 line
2.20.1
PATCH 3/3 Print format spec changes for tapctl and openvpnmscia
In reply to [email protected]...From: Selva Nair <[email protected]...>
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.
--- src/openvpnmsica/openvpnmsica.c | 6 +++-- src/tapctl/main.c | 39 +++++++++++++++++++++------------ src/tapctl/tap.c | 3 ++- 3 files changed, 31 insertions(+), 17 deletions(-)
src/openvpnmsica/openvpnmsica.c +4 -2
@@ -108,7 +108,8 @@ _debug_popup(_In_z_ LPCTSTR szFunctionName)/* Compose pop-up title. The dialog title will contain function name to ease the process * locating. Mind that Visual Studio displays window titles on the process list. */ -_stprintf_s (szTitle,_countof (szTitle),TEXT ("%s v%s" ), szFunctionName,TEXT (PACKAGE_VERSION )); + _stprintf_s(szTitle, _countof(szTitle), TEXT("%") TEXT(PRIsLPTSTR) TEXT("v%") TEXT(PRIsLPTSTR), + szFunctionName,TEXT (PACKAGE_VERSION ));/* Get process name. */ GetModuleFileName (NULL , szProcessPath,_countof (szProcessPath));
@@ -118,7 +119,8 @@ _debug_popup(_In_z_ LPCTSTR szFunctionName)/* Compose the pop-up message. */ _stprintf_s( szMessage, _countof(szMessage), - TEXT("The %s process (PID: %u) has started to execute the %s custom action.\r\n") + TEXT("The %") TEXT(PRIsLPTSTR) TEXT(" process (PID: %u) has started to execute the %" + TEXT(PRIsLPTSTR) TEXT(" custom action.\r\n") TEXT("\r\n") 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") TEXT("\r\n")
src/tapctl/main.c +25 -14
@@ -49,7 +49,7 @@ const TCHAR title_string[] = ;static const TCHAR usage_message[] = - TEXT("%s\n") + TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n") TEXT("\n") TEXT("Usage:\n") TEXT("\n")
@@ -66,7 +66,7 @@ static const TCHAR usage_message[] = ;static const TCHAR usage_message_create[] = - TEXT("%s\n") + TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n") TEXT("\n") TEXT("Creates a new TUN/TAP adapter\n")TEXT ("\n" )
@@ -91,7 +91,7 @@ static const TCHAR usage_message_create[] = ;static const TCHAR usage_message_list[] = - TEXT("%s\n") + TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n") TEXT("\n") TEXT("Lists TUN/TAP adapters\n")TEXT ("\n" )
@@ -110,7 +110,7 @@ static const TCHAR usage_message_list[] = ;static const TCHAR usage_message_delete[] = - TEXT("%s\n") + TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n") TEXT("\n") TEXT("Deletes the specified network adapter\n")TEXT ("\n" )
@@ -170,7 +170,8 @@ _tmain(int argc, LPCTSTR argv[]) }else { -_ftprintf (stderr,TEXT ("Unknown command \"%s\". Please, use \"tapctl help\" to list supported commands.\n" ), argv[2 ]); + _ftprintf(stderr, TEXT("Unknown command \"%") TEXT(PRIsLPTSTR) +TEXT ("\". Please, use \"tapctl help\" to list supported commands.\n" ), argv[2 ]); }return 1 ;
@@ -194,7 +195,9 @@ _tmain(int argc, LPCTSTR argv[]) }else { -_ftprintf (stderr,TEXT ("Unknown option \"%s\". Please, use \"tapctl help create\" to list supported options. Ignored.\n" ), argv[i]); + _ftprintf(stderr, TEXT("Unknown option \"%") TEXT(PRIsLPTSTR) +TEXT ("\". Please, use \"tapctl help create\" to list supported options. Ignored.\n" ), + argv[i]); } }
@@ -230,7 +233,8 @@ _tmain(int argc, LPCTSTR argv[])if (_tcsicmp (szName, pAdapter->szName) ==0 ) {StringFromIID ((REFIID )&pAdapter->guid, &szAdapterId); - _ftprintf(stderr, TEXT("Adapter \"%s\" already exists (GUID %") TEXT(PRIsLPOLESTR) TEXT(").\n"), pAdapter->szName, szAdapterId); + _ftprintf(stderr, TEXT("Adapter \"%") TEXT(PRIsLPTSTR) TEXT("\" already exists (GUID %") + TEXT(PRIsLPOLESTR) TEXT(").\n"), pAdapter->szName, szAdapterId);CoTaskMemFree (szAdapterId); iResult =1 ; goto create_cleanup_pAdapterList; }
@@ -241,7 +245,9 @@ _tmain(int argc, LPCTSTR argv[])if (dwResult !=ERROR_SUCCESS ) {StringFromIID ((REFIID )&guidAdapter, &szAdapterId); - _ftprintf(stderr, TEXT("Renaming TUN/TAP adapter %") TEXT(PRIsLPOLESTR) TEXT(" to \"%s\" failed (error 0x%x).\n"), szAdapterId, szName, dwResult); + _ftprintf(stderr, TEXT("Renaming TUN/TAP adapter %") TEXT(PRIsLPOLESTR) + TEXT(" to \"%") TEXT(PRIsLPTSTR) TEXT("\" failed (error 0x%x).\n"), + szAdapterId, szName, dwResult);CoTaskMemFree (szAdapterId); iResult =1 ; goto quit; }
@@ -289,7 +295,9 @@ create_delete_adapter: }else { -_ftprintf (stderr,TEXT ("Unknown option \"%s\". Please, use \"tapctl help list\" to list supported options. Ignored.\n" ), argv[i]); + _ftprintf(stderr, TEXT("Unknown option \"%") TEXT(PRIsLPTSTR) +TEXT ("\". Please, use \"tapctl help list\" to list supported options. Ignored.\n" ), + argv[i]); } }
@@ -306,7 +314,8 @@ create_delete_adapter: {LPOLESTR szAdapterId =NULL ;StringFromIID ((REFIID )&pAdapter->guid, &szAdapterId); - _ftprintf(stdout, TEXT("%") TEXT(PRIsLPOLESTR) TEXT("\t%") TEXT(PRIsLPTSTR) TEXT("\n"), szAdapterId, pAdapter->szName); + _ftprintf(stdout, TEXT("%") TEXT(PRIsLPOLESTR) TEXT("\t%") + TEXT(PRIsLPTSTR) TEXT("\n"), szAdapterId, pAdapter->szName);CoTaskMemFree (szAdapterId); }
@@ -337,7 +346,7 @@ create_delete_adapter: {if (pAdapter ==NULL ) { -_ftprintf (stderr,TEXT ("\"%s\" adapter not found.\n" ), argv[2 ]); + _ftprintf(stderr, TEXT("\"%") TEXT(PRIsLPTSTR) TEXT("\" adapter not found.\n"), argv[2]); iResult =1 ; goto delete_cleanup_pAdapterList; }else if (_tcsicmp (argv[2 ], pAdapter->szName) ==0 )
@@ -364,7 +373,8 @@ delete_cleanup_pAdapterList: &bRebootRequired);if (dwResult !=ERROR_SUCCESS ) { -_ftprintf (stderr,TEXT ("Deleting adapter \"%s\" failed (error 0x%x).\n" ), argv[2 ], dwResult); + _ftprintf(stderr, TEXT("Deleting adapter \"%") TEXT(PRIsLPTSTR) +TEXT ("\" failed (error 0x%x).\n" ), argv[2 ], dwResult); iResult =1 ; goto quit; }
@@ -372,7 +382,8 @@ delete_cleanup_pAdapterList: }else { -_ftprintf (stderr,TEXT ("Unknown command \"%s\". Please, use \"tapctl help\" to list supported commands.\n" ), argv[1 ]); + _ftprintf(stderr, TEXT("Unknown command \"%") TEXT(PRIsLPTSTR) +TEXT ("\". Please, use \"tapctl help\" to list supported commands.\n" ), argv[1 ]);return 1 ; }
@@ -434,7 +445,7 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist) }/* Output error message. */ -_ftprintf (stderr,TEXT ("Error 0x%x: %s\n" ), dwResult, szErrMessage); + _ftprintf(stderr, TEXT("Error 0x%x: %") TEXT(PRIsLPTSTR) TEXT("\n"), dwResult, szErrMessage);LocalFree (szErrMessage); }
src/tapctl/tap.c +2 -1
@@ -1117,7 +1117,8 @@ tap_set_adapter_name( }/* rename adapter via netsh call */ -const TCHAR * szFmt =_T ("netsh interface set interface name=\"%s\" newname=\"%s\"" ); + const TCHAR* szFmt = TEXT("netsh interface set interface name=\"%") + TEXT(PRIsLPTSTR) TEXT("\" newname=\"%") TEXT(PRIsLPTSTR) TEXT("\"");size_t ncmdline =_tcslen (szFmt) +_tcslen (szOldName) +_tcslen (szName) +1 ;WCHAR * szCmdLine =malloc (ncmdline *sizeof (TCHAR ));_stprintf_s (szCmdLine, ncmdline, szFmt, szOldName, szName);
Signature · 1 line
2.20.1
Hi,
Change makes sense, indeed it was possible to at least try to build iservice in non-UNICODE setup. Which doesn't make much sense since we always build with UNICODE
for releases.
Built and smoke-tested with MSVC. Haven't noticed any issues.
Re: [Openvpn-devel] [PATCH 2/3] Use C standard compliant format specs in wprintf functions
In reply to [email protected]...Idea of this patch has been already discussed:
https://www.mail-archive.com/[email protected]/msg21509.html
Code looks good, built and smoke-tested with MSVC.
Re: [Openvpn-devel] [PATCH 3/3] Print format spec changes for tapctl and openvpnmscia
In reply to [email protected]...Hi,
I got compilation error:
2>openvpnmsica.c 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(140,1):
warning C4002: too many arguments for function-like macro invocation 'TEXT' 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(140,24):
error C2143: syntax error: missing ')' before ';' 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(132,9):
warning C4473: 'swprintf_s' : not enough arguments passed for format string 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(132,9):
message : placeholders and their parameters expect 3 variadic arguments, but 0 were provided 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(132,9):
message : the missing variadic argument 1 is required by format string '%ls'
OTOH it is easily fixed by this change:
src/openvpnmsica/openvpnmsica.c +0 -1
@@ -129,7 +129,7 @@ _debug_popup(_In_z_ LPCTSTR szFunctionName)/* Compose the pop-up message. */ _stprintf_s( szMessage, _countof(szMessage), - TEXT("The %") TEXT(PRIsLPTSTR) TEXT(" process (PID: %u) has
started to execute the %"
+ TEXT("The %") TEXT(PRIsLPTSTR) TEXT(" process (PID: %u) has
started to execute the %")
TEXT(PRIsLPTSTR) TEXT(" custom action.\r\n") TEXT("\r\n")
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")
A nit-pick:
Review
Quoted 3 lines
(quoted diff) +2
-1- _stprintf_s(szTitle, _countof(szTitle), TEXT("%s v%s"), szFunctionName, TEXT(PACKAGE_VERSION)); + _stprintf_s(szTitle, _countof(szTitle), TEXT("%") TEXT(PRIsLPTSTR) TEXT("v%") TEXT(PRIsLPTSTR), + szFunctionName, TEXT(PACKAGE_VERSION));
Otherwise looks good - compiled with MSVC and slightly tested. If Gert can fix abovementioned thigs (add a parenthesis and a whitespace) consider it as an ack.
Re: [Openvpn-devel] [PATCH 3/3] Print format spec changes for tapctl and openvpnmscia
Hi,
Thanks for the review.
Quoted 4 lines · Lev Stipakov
Hi,
I got compilation error:
Oops.. I did not test building with _DEBUG defined.
Quoted 28 lines
2>openvpnmsica.c 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(140,1):
warning C4002: too many arguments for function-like macro invocation 'TEXT' 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(140,24):
error C2143: syntax error: missing ')' before ';' 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(132,9):
warning C4473: 'swprintf_s' : not enough arguments passed for format string 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(132,9):
message : placeholders and their parameters expect 3 variadic arguments, but 0 were provided 2>C:\Users\lev\Projects\openvpn\src\openvpnmsica\openvpnmsica.c(132,9):
message : the missing variadic argument 1 is required by format string '%ls'OTOH it is easily fixed by this change:
src/openvpnmsica/openvpnmsica.c +0
-1@@ -129,7 +129,7 @@ _debug_popup(_In_z_ LPCTSTR szFunctionName)/* Compose the pop-up message. */ _stprintf_s( szMessage, _countof(szMessage), - TEXT("The %") TEXT(PRIsLPTSTR) TEXT(" process (PID: %u) has
Quoted 8 lines
started to execute the %"
+TEXT("The %")TEXT(PRIsLPTSTR) TEXT(" process (PID: %u) has
started to execute the %")
TEXT(PRIsLPTSTR)TEXT(" custom action.\r\n")TEXT("\r\n")
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")
Will submit a v2 with this one and the space below.
Selva
Quoted 10 lines
A nit-pick:
Review
Quoted 3 lines
(quoted diff) +2
-1- _stprintf_s(szTitle, _countof(szTitle), TEXT("%s v%s"), szFunctionName, TEXT(PACKAGE_VERSION)); + _stprintf_s(szTitle, _countof(szTitle), TEXT("%") TEXT(PRIsLPTSTR) TEXT("v%") TEXT(PRIsLPTSTR), + szFunctionName, TEXT(PACKAGE_VERSION));Otherwise looks good - compiled with MSVC and slightly tested. If Gert can fix abovementioned thigs (add a parenthesis and a whitespace) consider it as an ack.
PATCH v2 3/3 Print format spec changes for tapctl and openvpnmscia
In reply to [email protected]...From: Selva Nair <[email protected]...>
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
--- src/openvpnmsica/openvpnmsica.c | 6 +++-- src/tapctl/main.c | 39 +++++++++++++++++++++------------ src/tapctl/tap.c | 3 ++- 3 files changed, 31 insertions(+), 17 deletions(-)
src/openvpnmsica/openvpnmsica.c +4 -2
@@ -108,7 +108,8 @@ _debug_popup(_In_z_ LPCTSTR szFunctionName)/* Compose pop-up title. The dialog title will contain function name to ease the process * locating. Mind that Visual Studio displays window titles on the process list. */ -_stprintf_s (szTitle,_countof (szTitle),TEXT ("%s v%s" ), szFunctionName,TEXT (PACKAGE_VERSION )); + _stprintf_s(szTitle, _countof(szTitle), TEXT("%") TEXT(PRIsLPTSTR) TEXT("v%") TEXT(PRIsLPTSTR), + szFunctionName,TEXT (PACKAGE_VERSION ));/* Get process name. */ GetModuleFileName (NULL , szProcessPath,_countof (szProcessPath));
@@ -118,7 +119,8 @@ _debug_popup(_In_z_ LPCTSTR szFunctionName)/* Compose the pop-up message. */ _stprintf_s ( szMessage,_countof (szMessage), - TEXT("The %s process (PID: %u) has started to execute the %s custom action.\r\n") + TEXT("The %") TEXT(PRIsLPTSTR) TEXT(" process (PID: %u) has started to execute the %") + TEXT(PRIsLPTSTR) TEXT(" custom action.\r\n") TEXT("\r\n") 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") TEXT("\r\n")
src/tapctl/main.c +25 -14
@@ -49,7 +49,7 @@ const TCHAR title_string[] = ;static const TCHAR usage_message[] = - TEXT("%s\n") + TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n") TEXT("\n") TEXT("Usage:\n") TEXT("\n")
@@ -66,7 +66,7 @@ static const TCHAR usage_message[] = ;static const TCHAR usage_message_create[] = - TEXT("%s\n") + TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n") TEXT("\n") TEXT("Creates a new TUN/TAP adapter\n")TEXT ("\n" )
@@ -91,7 +91,7 @@ static const TCHAR usage_message_create[] = ;static const TCHAR usage_message_list[] = - TEXT("%s\n") + TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n") TEXT("\n") TEXT("Lists TUN/TAP adapters\n")TEXT ("\n" )
@@ -110,7 +110,7 @@ static const TCHAR usage_message_list[] = ;static const TCHAR usage_message_delete[] = - TEXT("%s\n") + TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n") TEXT("\n") TEXT("Deletes the specified network adapter\n")TEXT ("\n" )
@@ -170,7 +170,8 @@ _tmain(int argc, LPCTSTR argv[]) }else { -_ftprintf (stderr,TEXT ("Unknown command \"%s\". Please, use \"tapctl help\" to list supported commands.\n" ), argv[2 ]); + _ftprintf(stderr, TEXT("Unknown command \"%") TEXT(PRIsLPTSTR) +TEXT ("\". Please, use \"tapctl help\" to list supported commands.\n" ), argv[2 ]); }return 1 ;
@@ -194,7 +195,9 @@ _tmain(int argc, LPCTSTR argv[]) }else { -_ftprintf (stderr,TEXT ("Unknown option \"%s\". Please, use \"tapctl help create\" to list supported options. Ignored.\n" ), argv[i]); + _ftprintf(stderr, TEXT("Unknown option \"%") TEXT(PRIsLPTSTR) +TEXT ("\". Please, use \"tapctl help create\" to list supported options. Ignored.\n" ), + argv[i]); } }
@@ -230,7 +233,8 @@ _tmain(int argc, LPCTSTR argv[])if (_tcsicmp (szName, pAdapter->szName) ==0 ) {StringFromIID ((REFIID )&pAdapter->guid, &szAdapterId); - _ftprintf(stderr, TEXT("Adapter \"%s\" already exists (GUID %") TEXT(PRIsLPOLESTR) TEXT(").\n"), pAdapter->szName, szAdapterId); + _ftprintf(stderr, TEXT("Adapter \"%") TEXT(PRIsLPTSTR) TEXT("\" already exists (GUID %") + TEXT(PRIsLPOLESTR) TEXT(").\n"), pAdapter->szName, szAdapterId);CoTaskMemFree (szAdapterId); iResult =1 ; goto create_cleanup_pAdapterList; }
@@ -241,7 +245,9 @@ _tmain(int argc, LPCTSTR argv[])if (dwResult !=ERROR_SUCCESS ) {StringFromIID ((REFIID )&guidAdapter, &szAdapterId); - _ftprintf(stderr, TEXT("Renaming TUN/TAP adapter %") TEXT(PRIsLPOLESTR) TEXT(" to \"%s\" failed (error 0x%x).\n"), szAdapterId, szName, dwResult); + _ftprintf(stderr, TEXT("Renaming TUN/TAP adapter %") TEXT(PRIsLPOLESTR) + TEXT(" to \"%") TEXT(PRIsLPTSTR) TEXT("\" failed (error 0x%x).\n"), + szAdapterId, szName, dwResult);CoTaskMemFree (szAdapterId); iResult =1 ; goto quit; }
@@ -289,7 +295,9 @@ create_delete_adapter: }else { -_ftprintf (stderr,TEXT ("Unknown option \"%s\". Please, use \"tapctl help list\" to list supported options. Ignored.\n" ), argv[i]); + _ftprintf(stderr, TEXT("Unknown option \"%") TEXT(PRIsLPTSTR) +TEXT ("\". Please, use \"tapctl help list\" to list supported options. Ignored.\n" ), + argv[i]); } }
@@ -306,7 +314,8 @@ create_delete_adapter: {LPOLESTR szAdapterId =NULL ;StringFromIID ((REFIID )&pAdapter->guid, &szAdapterId); - _ftprintf(stdout, TEXT("%") TEXT(PRIsLPOLESTR) TEXT("\t%") TEXT(PRIsLPTSTR) TEXT("\n"), szAdapterId, pAdapter->szName); + _ftprintf(stdout, TEXT("%") TEXT(PRIsLPOLESTR) TEXT("\t%") + TEXT(PRIsLPTSTR) TEXT("\n"), szAdapterId, pAdapter->szName);CoTaskMemFree (szAdapterId); }
@@ -337,7 +346,7 @@ create_delete_adapter: {if (pAdapter ==NULL ) { -_ftprintf (stderr,TEXT ("\"%s\" adapter not found.\n" ), argv[2 ]); + _ftprintf(stderr, TEXT("\"%") TEXT(PRIsLPTSTR) TEXT("\" adapter not found.\n"), argv[2]); iResult =1 ; goto delete_cleanup_pAdapterList; }else if (_tcsicmp (argv[2 ], pAdapter->szName) ==0 )
@@ -364,7 +373,8 @@ delete_cleanup_pAdapterList: &bRebootRequired);if (dwResult !=ERROR_SUCCESS ) { -_ftprintf (stderr,TEXT ("Deleting adapter \"%s\" failed (error 0x%x).\n" ), argv[2 ], dwResult); + _ftprintf(stderr, TEXT("Deleting adapter \"%") TEXT(PRIsLPTSTR) +TEXT ("\" failed (error 0x%x).\n" ), argv[2 ], dwResult); iResult =1 ; goto quit; }
@@ -372,7 +382,8 @@ delete_cleanup_pAdapterList: }else { -_ftprintf (stderr,TEXT ("Unknown command \"%s\". Please, use \"tapctl help\" to list supported commands.\n" ), argv[1 ]); + _ftprintf(stderr, TEXT("Unknown command \"%") TEXT(PRIsLPTSTR) +TEXT ("\". Please, use \"tapctl help\" to list supported commands.\n" ), argv[1 ]);return 1 ; }
@@ -434,7 +445,7 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist) }/* Output error message. */ -_ftprintf (stderr,TEXT ("Error 0x%x: %s\n" ), dwResult, szErrMessage); + _ftprintf(stderr, TEXT("Error 0x%x: %") TEXT(PRIsLPTSTR) TEXT("\n"), dwResult, szErrMessage);LocalFree (szErrMessage); }
src/tapctl/tap.c +2 -1
@@ -1117,7 +1117,8 @@ tap_set_adapter_name( }/* rename adapter via netsh call */ -const TCHAR * szFmt =_T ("netsh interface set interface name=\"%s\" newname=\"%s\"" ); + const TCHAR* szFmt = TEXT("netsh interface set interface name=\"%") + TEXT(PRIsLPTSTR) TEXT("\" newname=\"%") TEXT(PRIsLPTSTR) TEXT("\"");size_t ncmdline =_tcslen (szFmt) +_tcslen (szOldName) +_tcslen (szName) +1 ;WCHAR * szCmdLine =malloc (ncmdline *sizeof (TCHAR ));_stprintf_s (szCmdLine, ncmdline, szFmt, szOldName, szName);
Signature · 1 line
2.20.1
Re: [Openvpn-devel] [PATCH 3/3] Print format spec changes for tapctl and openvpnmscia
In reply to Selva NairHi,
When _DEBUG is defined openvpnmsica builds okay using MSVC, but fails on mingw (before and after this patch) with errors like
openvpnmsica.c:410:17: error: ‘L__FUNCTION__’ undeclared (first use in this function); did you mean ‘NLS_FUNCTION’?
debug_popup(TEXT(__FUNCTION__));
I have left it to be handled by a separate patch.
On gcc (and mingw) __FUNCTION__ == function-name is not a macro and TEXT(__FUCNTION__) that expands to L__FUNCTION__ is undefined.
We do not really need to convert __FUNCTION__ to wide string for debug printing so I suggest to fix this by using it as is with %hs as the print spec for both UNICODE and ANSI builds. No TEXT() required.
If that's okay I'll submit a patch.
The alternative is to use __FUNCTIONW__ when UNICODE is defined, but it will complicate the logic for no reason.
We have no plans of using σ , µ and ℵₒ in function names any time soon, do we :)
Selva
Have not tested anything, just looked a bit at the changes. ACK from Lev is good enough :-) - and getting rid of #ifdef is even better.
Your patch has been applied to the master branch.
commit 455d0997931f968ed8c42812106c44941c4ca69b
Author: Selva Nair Date: Fri May 21 23:32:30 2021 -0400
Make it explicit that WIndows build requires UNICODE support
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22437.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Use C standard compliant format specs in wprintf functions
In reply to [email protected]...As with the last patch, I have not tested this - relying on Lev. I have looked at the changes a bit and "they do what it says on the tin" (though I have not explicitly verified each char/wchar <-> %hs/%ls mapping).
Your patch has been applied to the master branch.
commit ea2b153c35723fc2bbcf54ef191a6f0e0ee5371a
Author: Selva Nair Date: Fri May 21 23:32:31 2021 -0400
Use C standard compliant format specs in wprintf functions
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22436.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH 3/3 v2] Print format spec changes for tapctl and openvpnmscia
In reply to [email protected]...src/openvpnmsica/openvpnmsica.c _debug_popup(_In_z_ LPCTSTR szFunctionName) · line 111
Quoted 2 lines
src/openvpnmsica/openvpnmsica.c +1
-1-_stprintf_s (szTitle,_countof (szTitle),TEXT ("%s v%s" ), szFunctionName,TEXT (PACKAGE_VERSION )); + _stprintf_s(szTitle, _countof(szTitle), TEXT("%") TEXT(PRIsLPTSTR) TEXT("v%") TEXT(PRIsLPTSTR),
Just a note that a whitespace is (still) missing before "v%", but it is fixed in subsequent patch ("Replace TEXT(__FUNCTION__) by __FUNCTION__ in openvpnmscia.c").
Looks good - compared with v1, compiled/tested with MSVC.
[Openvpn-devel] [PATCH applied] Re: Print format spec changes for tapctl and openvpnmscia
In reply to [email protected]...Have not tested this, just stared a bit at the code. Did not "fix" the "%s v%s" issue Lev pointed out as this will be fixed in the next patch... thanks.
(I do wonder if "support ansi builds" is really something we want, if that makes the code so complicated - "always UNICODE" seems to be much simpler. What is the drawback of not supporting "ansi" builds?)
Your patch has been applied to the master branch.
commit a13f6b16b20d7cae7f1ff50d325e13e303c8d3b3
Author: Selva Nair Date: Tue May 25 13:38:38 2021 -0400
Print format spec changes for tapctl and openvpnmscia
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22453.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH applied] Re: Print format spec changes for tapctl and openvpnmscia
Hi
Quoted 8 lines · Gert Doering
Have not tested this, just stared a bit at the code. Did not "fix" the "%s v%s" issue Lev pointed out as this will be fixed in the next patch... thanks.
(I do wonder if "support ansi builds" is really something we want, if that makes the code so complicated - "always UNICODE" seems to be much simpler. What is the drawback of not supporting "ansi" builds?)
I prefer to write all new Windows code as unicode without any dependency on the defines UNICODE and _UNICODE --- i.e no TCHARs, explicit API calls, no _tprintfs.
For old code, an easy option would be to retain the TCHARs, but assume we only build with UNICODE (TCHAR=WCHAR) and going forward don't care to support ANSI builds. As we did with the service.
Even for this part of the code, I suspect ansi build is broken -- we never test it,
do we.
Selva
[Openvpn-devel] RfD: Windows code, UNICODE and ansi
Hi,
Quoted 11 lines · Selva Nair
Quoted 3 lines
(I do wonder if "support ansi builds" is really something we want, if that makes the code so complicated - "always UNICODE" seems to be much simpler. What is the drawback of not supporting "ansi" builds?)
I prefer to write all new Windows code as unicode without any dependency on the defines UNICODE and
_UNICODE--- i.e no TCHARs, explicit API calls, no_tprintfs.For old code, an easy option would be to retain the TCHARs, but assume we only build with UNICODE (TCHAR=WCHAR) and going forward don't care to support ANSI builds. As we did with the service.
I'm not the person who writes and debugs most of the windows code, I just see patches pass by, and some bits are "more readable" and others less so :-)
So my "vote" would be towards what you propose - always build unicode, and for older code, assume (or force-#define) UNICODE.
Plus, document this somewhere. On our styleguide page, maybe?
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] RfD: Windows code, UNICODE and ansi
Hi
Quoted 16 lines · Gert Doering
Hi,
Quoted 11 lines · Selva Nair
Quoted 3 lines
(I do wonder if "support ansi builds" is really something we want, if that makes the code so complicated - "always UNICODE" seems to be much simpler. What is the drawback of not supporting "ansi" builds?)
I prefer to write all new Windows code as unicode without any dependency on the defines UNICODE and
_UNICODE--- i.e no TCHARs, explicit API calls, no_tprintfs.For old code, an easy option would be to retain the TCHARs, but assume we only build with UNICODE (TCHAR=WCHAR) and going forward don't care to support ANSI builds. As we did with the service.
Quoted 8 lines
I'm not the person who writes and debugs most of the windows code, I just see patches pass by, and some bits are "more readable" and others less so :-)
So my "vote" would be towards what you propose - always build unicode, and for older code, assume (or force-#define) UNICODE.
Plus, document this somewhere. On our styleguide page, maybe?
I have added a section named "Windows specific" to the codestyle in the wiki. Not very polished -- please take a look and feel free to pull it apart.
https://community.openvpn.net/openvpn/wiki/CodeStyle#Windowsspecific
Selva
Re: [Openvpn-devel] RfD: Windows code, UNICODE and ansi
Hi,
Quoted 10 lines · Selva Nair
Quoted 4 lines
So my "vote" would be towards what you propose - always build unicode, and for older code, assume (or force-#define) UNICODE.
Plus, document this somewhere. On our styleguide page, maybe?
I have added a section named "Windows specific" to the codestyle in the wiki. Not very polished -- please take a look and feel free to pull it apart.
https://community.openvpn.net/openvpn/wiki/CodeStyle#Windowsspecific
This looks good to me. Short and concise. (One typo - WHCAR - fixed).
Lev, anything else we might want to add there?
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...