[PDH] Sync with Wine Staging 4.18. CORE-16441

This commit is contained in:
Amine Khaldi 2019-11-23 12:07:10 +01:00
parent 387183d627
commit 909d7a81e1
2 changed files with 36 additions and 30 deletions

View file

@ -30,11 +30,14 @@
#include "pdh.h" #include "pdh.h"
#include "pdhmsg.h" #include "pdhmsg.h"
#include "winperf.h" #include "winperf.h"
#ifdef __REACTOS__
#include <wchar.h>
#include <winnls.h>
#endif
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/heap.h" #include "wine/heap.h"
#include "wine/list.h" #include "wine/list.h"
#include "wine/unicode.h"
WINE_DEFAULT_DEBUG_CHANNEL(pdh); WINE_DEFAULT_DEBUG_CHANNEL(pdh);
@ -53,7 +56,7 @@ static inline WCHAR *pdh_strdup( const WCHAR *src )
WCHAR *dst; WCHAR *dst;
if (!src) return NULL; if (!src) return NULL;
if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src ); if ((dst = heap_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) ))) lstrcpyW( dst, src );
return dst; return dst;
} }
@ -178,6 +181,8 @@ struct source
static const WCHAR path_processor_time[] = static const WCHAR path_processor_time[] =
{'\\','P','r','o','c','e','s','s','o','r','(','_','T','o','t','a','l',')', {'\\','P','r','o','c','e','s','s','o','r','(','_','T','o','t','a','l',')',
'\\','%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0}; '\\','%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0};
static const WCHAR path_processor[] =
{'\\','P','r','o','c','e','s','s','o','r',0};
static const WCHAR path_uptime[] = static const WCHAR path_uptime[] =
{'\\','S','y','s','t','e','m', '\\', 'S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0}; {'\\','S','y','s','t','e','m', '\\', 'S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
@ -204,6 +209,7 @@ static void CALLBACK collect_uptime( struct counter *counter )
static const struct source counter_sources[] = static const struct source counter_sources[] =
{ {
{ 6, path_processor_time, collect_processor_time, TYPE_PROCESSOR_TIME, -5, 10000000 }, { 6, path_processor_time, collect_processor_time, TYPE_PROCESSOR_TIME, -5, 10000000 },
{ 238, path_processor, NULL, 0, 0, 0 },
{ 674, path_uptime, collect_uptime, TYPE_UPTIME, -3, 1000 } { 674, path_uptime, collect_uptime, TYPE_UPTIME, -3, 1000 }
}; };
@ -213,21 +219,21 @@ static BOOL is_local_machine( const WCHAR *name, DWORD len )
DWORD buflen = ARRAY_SIZE(buf); DWORD buflen = ARRAY_SIZE(buf);
if (!GetComputerNameW( buf, &buflen )) return FALSE; if (!GetComputerNameW( buf, &buflen )) return FALSE;
return len == buflen && !memicmpW( name, buf, buflen ); return len == buflen && !_wcsnicmp( name, buf, buflen );
} }
static BOOL pdh_match_path( LPCWSTR fullpath, LPCWSTR path ) static BOOL pdh_match_path( LPCWSTR fullpath, LPCWSTR path )
{ {
const WCHAR *p; const WCHAR *p;
if (path[0] == '\\' && path[1] == '\\' && (p = strchrW( path + 2, '\\' )) && if (path[0] == '\\' && path[1] == '\\' && (p = wcschr( path + 2, '\\' )) &&
is_local_machine( path + 2, p - path - 2 )) is_local_machine( path + 2, p - path - 2 ))
{ {
path += p - path; path += p - path;
} }
if (strchrW( path, '\\' )) p = fullpath; if (wcschr( path, '\\' )) p = fullpath;
else p = strrchrW( fullpath, '\\' ) + 1; else p = wcsrchr( fullpath, '\\' ) + 1;
return !strcmpW( p, path ); return !wcscmp( p, path );
} }
/*********************************************************************** /***********************************************************************
@ -898,9 +904,9 @@ PDH_STATUS WINAPI PdhLookupPerfNameByIndexA( LPCSTR machine, DWORD index, LPSTR
{ {
int required = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL ); int required = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
if (size && *size < required) ret = PDH_MORE_DATA; if (*size < required) ret = PDH_MORE_DATA;
else WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, required, NULL, NULL ); else WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, required, NULL, NULL );
if (size) *size = required; *size = required;
} }
heap_free( machineW ); heap_free( machineW );
return ret; return ret;
@ -929,13 +935,13 @@ PDH_STATUS WINAPI PdhLookupPerfNameByIndexW( LPCWSTR machine, DWORD index, LPWST
{ {
if (counter_sources[i].index == index) if (counter_sources[i].index == index)
{ {
WCHAR *p = strrchrW( counter_sources[i].path, '\\' ) + 1; WCHAR *p = wcsrchr( counter_sources[i].path, '\\' ) + 1;
unsigned int required = strlenW( p ) + 1; unsigned int required = lstrlenW( p ) + 1;
if (*size < required) ret = PDH_MORE_DATA; if (*size < required) ret = PDH_MORE_DATA;
else else
{ {
strcpyW( buffer, p ); lstrcpyW( buffer, p );
ret = ERROR_SUCCESS; ret = ERROR_SUCCESS;
} }
*size = required; *size = required;
@ -1061,7 +1067,7 @@ PDH_STATUS WINAPI PdhValidatePathA( LPCSTR path )
static PDH_STATUS validate_path( LPCWSTR path ) static PDH_STATUS validate_path( LPCWSTR path )
{ {
if (!path || !*path) return PDH_INVALID_ARGUMENT; if (!path || !*path) return PDH_INVALID_ARGUMENT;
if (*path++ != '\\' || !strchrW( path, '\\' )) return PDH_CSTATUS_BAD_COUNTERNAME; if (*path++ != '\\' || !wcschr( path, '\\' )) return PDH_CSTATUS_BAD_COUNTERNAME;
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
@ -1202,30 +1208,30 @@ PDH_STATUS WINAPI PdhMakeCounterPathW( PDH_COUNTER_PATH_ELEMENTS_W *e, LPWSTR bu
path[0] = 0; path[0] = 0;
if (e->szMachineName) if (e->szMachineName)
{ {
strcatW(path, bslash); lstrcatW(path, bslash);
strcatW(path, bslash); lstrcatW(path, bslash);
strcatW(path, e->szMachineName); lstrcatW(path, e->szMachineName);
} }
strcatW(path, bslash); lstrcatW(path, bslash);
strcatW(path, e->szObjectName); lstrcatW(path, e->szObjectName);
if (e->szInstanceName) if (e->szInstanceName)
{ {
strcatW(path, lparen); lstrcatW(path, lparen);
if (e->szParentInstance) if (e->szParentInstance)
{ {
strcatW(path, e->szParentInstance); lstrcatW(path, e->szParentInstance);
strcatW(path, fslash); lstrcatW(path, fslash);
} }
strcatW(path, e->szInstanceName); lstrcatW(path, e->szInstanceName);
sprintfW(instance, fmt, e->dwInstanceIndex); swprintf(instance, fmt, e->dwInstanceIndex);
strcatW(path, instance); lstrcatW(path, instance);
strcatW(path, rparen); lstrcatW(path, rparen);
} }
strcatW(path, bslash); lstrcatW(path, bslash);
strcatW(path, e->szCounterName); lstrcatW(path, e->szCounterName);
len = strlenW(path) + 1; len = lstrlenW(path) + 1;
if (*buflen >= len) strcpyW(buffer, path); if (*buflen >= len) lstrcpyW(buffer, path);
else ret = PDH_MORE_DATA; else ret = PDH_MORE_DATA;
*buflen = len; *buflen = len;
return ret; return ret;

View file

@ -148,7 +148,7 @@ dll/win32/oledlg # Synced to WineStaging-4.18
dll/win32/olepro32 # Synced to WineStaging-3.3 dll/win32/olepro32 # Synced to WineStaging-3.3
dll/win32/olesvr32 # Synced to WineStaging-4.18 dll/win32/olesvr32 # Synced to WineStaging-4.18
dll/win32/olethk32 # Synced to WineStaging-3.3 dll/win32/olethk32 # Synced to WineStaging-3.3
dll/win32/pdh # Synced to WineStaging-4.0 dll/win32/pdh # Synced to WineStaging-4.18
dll/win32/pidgen # Synced to WineStaging-4.0 dll/win32/pidgen # Synced to WineStaging-4.0
dll/win32/powrprof # Forked at Wine-1.0rc5 dll/win32/powrprof # Forked at Wine-1.0rc5
dll/win32/printui # Synced to WineStaging-3.3 dll/win32/printui # Synced to WineStaging-3.3