HADOOP-9443. Port winutils static code analysis change to trunk. Contributed by Chuan Liu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1470224 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2013-04-20 20:20:44 +00:00
parent 794f9bb3e4
commit 7e122e1009
12 changed files with 80 additions and 58 deletions

View File

@ -516,6 +516,9 @@ Trunk (Unreleased)
HADOOP-9437. TestNativeIO#testRenameTo fails on Windows due to assumption HADOOP-9437. TestNativeIO#testRenameTo fails on Windows due to assumption
that POSIX errno is embedded in NativeIOException. (Chris Nauroth via that POSIX errno is embedded in NativeIOException. (Chris Nauroth via
suresh) suresh)
HADOOP-9443. Port winutils static code analysis change to trunk.
(Chuan Liu via suresh)
Release 2.0.5-beta - UNRELEASED Release 2.0.5-beta - UNRELEASED

View File

@ -74,18 +74,22 @@ static BOOL ParseMode(LPCWSTR modeString, PMODE_CHANGE_ACTION *actions);
static BOOL FreeActions(PMODE_CHANGE_ACTION actions); static BOOL FreeActions(PMODE_CHANGE_ACTION actions);
static BOOL ParseCommandLineArguments(__in int argc, __in wchar_t *argv[], static BOOL ParseCommandLineArguments(
__out BOOL *rec, __out_opt INT *mask, __in int argc,
__out_opt PMODE_CHANGE_ACTION *actions, __out LPCWSTR *path); __in_ecount(argc) wchar_t *argv[],
__out BOOL *rec,
__out_opt INT *mask,
__out_opt PMODE_CHANGE_ACTION *actions,
__out LPCWSTR *path);
static BOOL ChangeFileModeByActions(__in LPCWSTR path, static BOOL ChangeFileModeByActions(__in LPCWSTR path,
PMODE_CHANGE_ACTION actions); MODE_CHANGE_ACTION const *actions);
static BOOL ChangeFileMode(__in LPCWSTR path, __in_opt INT mode, static BOOL ChangeFileMode(__in LPCWSTR path, __in_opt INT mode,
__in_opt PMODE_CHANGE_ACTION actions); __in_opt MODE_CHANGE_ACTION const *actions);
static BOOL ChangeFileModeRecursively(__in LPCWSTR path, __in_opt INT mode, static BOOL ChangeFileModeRecursively(__in LPCWSTR path, __in_opt INT mode,
__in_opt PMODE_CHANGE_ACTION actions); __in_opt MODE_CHANGE_ACTION const *actions);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -99,7 +103,7 @@ static BOOL ChangeFileModeRecursively(__in LPCWSTR path, __in_opt INT mode,
// //
// Notes: // Notes:
// //
int Chmod(int argc, wchar_t *argv[]) int Chmod(__in int argc, __in_ecount(argc) wchar_t *argv[])
{ {
LPWSTR pathName = NULL; LPWSTR pathName = NULL;
LPWSTR longPathName = NULL; LPWSTR longPathName = NULL;
@ -169,7 +173,7 @@ ChmodEnd:
// Notes: // Notes:
// //
static BOOL ChangeFileMode(__in LPCWSTR path, __in_opt INT unixAccessMask, static BOOL ChangeFileMode(__in LPCWSTR path, __in_opt INT unixAccessMask,
__in_opt PMODE_CHANGE_ACTION actions) __in_opt MODE_CHANGE_ACTION const *actions)
{ {
if (actions != NULL) if (actions != NULL)
return ChangeFileModeByActions(path, actions); return ChangeFileModeByActions(path, actions);
@ -202,7 +206,7 @@ static BOOL ChangeFileMode(__in LPCWSTR path, __in_opt INT unixAccessMask,
// - Otherwise, call the method on all its children, then change its mode. // - Otherwise, call the method on all its children, then change its mode.
// //
static BOOL ChangeFileModeRecursively(__in LPCWSTR path, __in_opt INT mode, static BOOL ChangeFileModeRecursively(__in LPCWSTR path, __in_opt INT mode,
__in_opt PMODE_CHANGE_ACTION actions) __in_opt MODE_CHANGE_ACTION const *actions)
{ {
BOOL isDir = FALSE; BOOL isDir = FALSE;
BOOL isSymlink = FALSE; BOOL isSymlink = FALSE;
@ -335,7 +339,9 @@ ChangeFileModeRecursivelyEnd:
// 1. Recursive is only set on directories // 1. Recursive is only set on directories
// 2. 'actions' is NULL if the mode is octal // 2. 'actions' is NULL if the mode is octal
// //
static BOOL ParseCommandLineArguments(__in int argc, __in wchar_t *argv[], static BOOL ParseCommandLineArguments(
__in int argc,
__in_ecount(argc) wchar_t *argv[],
__out BOOL *rec, __out BOOL *rec,
__out_opt INT *mask, __out_opt INT *mask,
__out_opt PMODE_CHANGE_ACTION *actions, __out_opt PMODE_CHANGE_ACTION *actions,
@ -551,9 +557,9 @@ static INT ComputeNewMode(__in INT oldMode,
// none // none
// //
static BOOL ConvertActionsToMask(__in LPCWSTR path, static BOOL ConvertActionsToMask(__in LPCWSTR path,
__in PMODE_CHANGE_ACTION actions, __out PINT puMask) __in MODE_CHANGE_ACTION const *actions, __out PINT puMask)
{ {
PMODE_CHANGE_ACTION curr = NULL; MODE_CHANGE_ACTION const *curr = NULL;
BY_HANDLE_FILE_INFORMATION fileInformation; BY_HANDLE_FILE_INFORMATION fileInformation;
DWORD dwErrorCode = ERROR_SUCCESS; DWORD dwErrorCode = ERROR_SUCCESS;
@ -608,7 +614,7 @@ static BOOL ConvertActionsToMask(__in LPCWSTR path,
// none // none
// //
static BOOL ChangeFileModeByActions(__in LPCWSTR path, static BOOL ChangeFileModeByActions(__in LPCWSTR path,
PMODE_CHANGE_ACTION actions) MODE_CHANGE_ACTION const *actions)
{ {
INT mask = 0; INT mask = 0;
@ -769,10 +775,14 @@ static BOOL ParseMode(LPCWSTR modeString, PMODE_CHANGE_ACTION *pActions)
switch (c) switch (c)
{ {
case NULL: case NULL:
__fallthrough;
case L',': case L',':
i++; i++;
__fallthrough;
case L'+': case L'+':
__fallthrough;
case L'-': case L'-':
__fallthrough;
case L'=': case L'=':
state = PARSE_MODE_ACTION_WHO_STATE; state = PARSE_MODE_ACTION_WHO_STATE;

View File

@ -116,13 +116,13 @@ ChangeFileOwnerByNameEnd:
// Notes: // Notes:
// //
// //
int Chown(int argc, wchar_t *argv[]) int Chown(__in int argc, __in_ecount(argc) wchar_t *argv[])
{ {
LPWSTR pathName = NULL; LPWSTR pathName = NULL;
LPWSTR ownerInfo = NULL; LPWSTR ownerInfo = NULL;
LPWSTR colonPos = NULL; WCHAR const * colonPos = NULL;
LPWSTR userName = NULL; LPWSTR userName = NULL;
size_t userNameLen = 0; size_t userNameLen = 0;

View File

@ -32,12 +32,12 @@
// otherwise, space. // otherwise, space.
// //
static BOOL PrintGroups( static BOOL PrintGroups(
LPLOCALGROUP_USERS_INFO_0 groups, LOCALGROUP_USERS_INFO_0 const *groups,
DWORD entries, DWORD entries,
BOOL formatOutput) BOOL formatOutput)
{ {
BOOL ret = TRUE; BOOL ret = TRUE;
LPLOCALGROUP_USERS_INFO_0 pTmpBuf = groups; LOCALGROUP_USERS_INFO_0 const *pTmpBuf = groups;
DWORD i; DWORD i;
for (i = 0; i < entries; i++) for (i = 0; i < entries; i++)
@ -80,7 +80,10 @@ static BOOL PrintGroups(
// TRUE on the valid command line, FALSE otherwise // TRUE on the valid command line, FALSE otherwise
// //
static BOOL ParseCommandLine( static BOOL ParseCommandLine(
int argc, wchar_t *argv[], wchar_t **user, BOOL *formatOutput) __in int argc,
__in_ecount(argc) wchar_t *argv[],
__out PWSTR *user,
__out BOOL *formatOutput)
{ {
*formatOutput = FALSE; *formatOutput = FALSE;
@ -132,7 +135,7 @@ static BOOL ParseCommandLine(
// Notes: // Notes:
// //
// //
int Groups(int argc, wchar_t *argv[]) int Groups(__in int argc, __in_ecount(argc) wchar_t *argv[])
{ {
LPWSTR input = NULL; LPWSTR input = NULL;

View File

@ -37,7 +37,7 @@ typedef enum HardLinkCommandOptionType
// TRUE: If the command line is valid // TRUE: If the command line is valid
// FALSE: otherwise // FALSE: otherwise
static BOOL ParseCommandLine(__in int argc, static BOOL ParseCommandLine(__in int argc,
__in wchar_t *argv[], __in_ecount(argc) wchar_t *argv[],
__out HardLinkCommandOption *command) __out HardLinkCommandOption *command)
{ {
*command = HardLinkInvalid; *command = HardLinkInvalid;
@ -161,7 +161,7 @@ HardlinkCreateExit:
// Returns: // Returns:
// EXIT_SUCCESS: On success // EXIT_SUCCESS: On success
// EXIT_FAILURE: otherwise // EXIT_FAILURE: otherwise
int Hardlink(int argc, wchar_t *argv[]) int Hardlink(__in int argc, __in_ecount(argc) wchar_t *argv[])
{ {
DWORD dwErrorCode = ERROR_SUCCESS; DWORD dwErrorCode = ERROR_SUCCESS;
int ret = EXIT_FAILURE; int ret = EXIT_FAILURE;

View File

@ -20,13 +20,11 @@
#endif #endif
#pragma once #pragma once
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <windows.h> #include <windows.h>
#include <aclapi.h> #include <aclapi.h>
#include <accctrl.h> #include <accctrl.h>
#include <tchar.h>
#include <strsafe.h> #include <strsafe.h>
#include <lm.h> #include <lm.h>
@ -85,25 +83,25 @@ enum WindowsAclMask
extern const ACCESS_MASK WinMasks[]; extern const ACCESS_MASK WinMasks[];
int Ls(int argc, wchar_t *argv[]); int Ls(__in int argc, __in_ecount(argc) wchar_t *argv[]);
void LsUsage(LPCWSTR program); void LsUsage(LPCWSTR program);
int Chmod(int argc, wchar_t *argv[]); int Chmod(__in int argc, __in_ecount(argc) wchar_t *argv[]);
void ChmodUsage(LPCWSTR program); void ChmodUsage(LPCWSTR program);
int Chown(int argc, wchar_t *argv[]); int Chown(__in int argc, __in_ecount(argc) wchar_t *argv[]);
void ChownUsage(LPCWSTR program); void ChownUsage(LPCWSTR program);
int Groups(int argc, wchar_t *argv[]); int Groups(__in int argc, __in_ecount(argc) wchar_t *argv[]);
void GroupsUsage(LPCWSTR program); void GroupsUsage(LPCWSTR program);
int Hardlink(int argc, wchar_t *argv[]); int Hardlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
void HardlinkUsage(); void HardlinkUsage();
int Task(int argc, wchar_t *argv[]); int Task(__in int argc, __in_ecount(argc) wchar_t *argv[]);
void TaskUsage(); void TaskUsage();
int Symlink(int argc, wchar_t *argv[]); int Symlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
void SymlinkUsage(); void SymlinkUsage();
int SystemInfo(); int SystemInfo();
@ -114,9 +112,9 @@ DWORD GetFileInformationByName(__in LPCWSTR pathName, __in BOOL followLink,
DWORD ConvertToLongPath(__in PCWSTR path, __deref_out PWSTR *newPath); DWORD ConvertToLongPath(__in PCWSTR path, __deref_out PWSTR *newPath);
DWORD GetSidFromAcctNameW(LPCWSTR acctName, PSID* ppSid); DWORD GetSidFromAcctNameW(__in PCWSTR acctName, __out PSID* ppSid);
DWORD GetAccntNameFromSid(PSID pSid, LPWSTR *ppAcctName); DWORD GetAccntNameFromSid(__in PSID pSid, __out LPWSTR *ppAcctName);
void ReportErrorCode(LPCWSTR func, DWORD err); void ReportErrorCode(LPCWSTR func, DWORD err);

View File

@ -226,7 +226,6 @@ ConvertToLongPathExit:
if (dwErrorCode != ERROR_SUCCESS) if (dwErrorCode != ERROR_SUCCESS)
{ {
LocalFree(newPathValue); LocalFree(newPathValue);
*newPath = NULL;
} }
return dwErrorCode; return dwErrorCode;
@ -398,7 +397,7 @@ DWORD JunctionPointCheck(__in LPCWSTR pathName, __out PBOOL res)
// Notes: // Notes:
// Caller needs to destroy the memory of Sid by calling LocalFree() // Caller needs to destroy the memory of Sid by calling LocalFree()
// //
DWORD GetSidFromAcctNameW(LPCWSTR acctName, PSID *ppSid) DWORD GetSidFromAcctNameW(__in PCWSTR acctName, __out PSID *ppSid)
{ {
DWORD dwSidSize = 0; DWORD dwSidSize = 0;
DWORD cchDomainName = 0; DWORD cchDomainName = 0;
@ -545,7 +544,7 @@ static DWORD GetAccess(AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClient,
{ {
return GetLastError(); return GetLastError();
} }
*pAccessRights = (*(PACCESS_MASK)(AccessReply.GrantedAccessMask)); *pAccessRights = (*(const ACCESS_MASK *)(AccessReply.GrantedAccessMask));
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
@ -1088,6 +1087,7 @@ DWORD ChangeFileModeByMask(__in LPCWSTR path, INT mode)
DWORD revision = 0; DWORD revision = 0;
PSECURITY_DESCRIPTOR pAbsSD = NULL; PSECURITY_DESCRIPTOR pAbsSD = NULL;
PSECURITY_DESCRIPTOR pNonNullSD = NULL;
PACL pAbsDacl = NULL; PACL pAbsDacl = NULL;
PACL pAbsSacl = NULL; PACL pAbsSacl = NULL;
PSID pAbsOwner = NULL; PSID pAbsOwner = NULL;
@ -1200,7 +1200,8 @@ DWORD ChangeFileModeByMask(__in LPCWSTR path, INT mode)
// present in the security descriptor, the DACL is replaced. The security // present in the security descriptor, the DACL is replaced. The security
// descriptor is then used to set the security of a file or directory. // descriptor is then used to set the security of a file or directory.
// //
if (!SetSecurityDescriptorDacl(pAbsSD, TRUE, pNewDACL, FALSE)) pNonNullSD = (pAbsSD != NULL) ? pAbsSD : pSD;
if (!SetSecurityDescriptorDacl(pNonNullSD, TRUE, pNewDACL, FALSE))
{ {
ret = GetLastError(); ret = GetLastError();
goto ChangeFileModeByMaskEnd; goto ChangeFileModeByMaskEnd;
@ -1220,13 +1221,14 @@ DWORD ChangeFileModeByMask(__in LPCWSTR path, INT mode)
// its parent, and the child objects will not lose their inherited permissions // its parent, and the child objects will not lose their inherited permissions
// from the current object. // from the current object.
// //
if (!SetFileSecurity(longPathName, DACL_SECURITY_INFORMATION, pAbsSD)) if (!SetFileSecurity(longPathName, DACL_SECURITY_INFORMATION, pNonNullSD))
{ {
ret = GetLastError(); ret = GetLastError();
goto ChangeFileModeByMaskEnd; goto ChangeFileModeByMaskEnd;
} }
ChangeFileModeByMaskEnd: ChangeFileModeByMaskEnd:
pNonNullSD = NULL;
LocalFree(longPathName); LocalFree(longPathName);
LocalFree(pSD); LocalFree(pSD);
LocalFree(pNewDACL); LocalFree(pNewDACL);
@ -1252,7 +1254,7 @@ ChangeFileModeByMaskEnd:
// Notes: // Notes:
// Caller needs to destroy the memory of account name by calling LocalFree() // Caller needs to destroy the memory of account name by calling LocalFree()
// //
DWORD GetAccntNameFromSid(PSID pSid, LPWSTR *ppAcctName) DWORD GetAccntNameFromSid(__in PSID pSid, __out PWSTR *ppAcctName)
{ {
LPWSTR lpName = NULL; LPWSTR lpName = NULL;
DWORD cchName = 0; DWORD cchName = 0;

View File

@ -32,7 +32,7 @@
// altered. The caller need to initilize the mask string to be all '-' to get // altered. The caller need to initilize the mask string to be all '-' to get
// the correct mask string. // the correct mask string.
// //
static BOOL GetMaskString(INT accessMask, LPWSTR maskString) static BOOL GetMaskString(__in INT accessMask, __in_ecount(10) LPWSTR maskString)
{ {
if(wcslen(maskString) != 10) if(wcslen(maskString) != 10)
return FALSE; return FALSE;
@ -163,7 +163,10 @@ static wchar_t* CurrentDir = L".";
// TRUE on the valid command line, FALSE otherwise // TRUE on the valid command line, FALSE otherwise
// //
BOOL ParseCommandLine( BOOL ParseCommandLine(
int argc, wchar_t *argv[], wchar_t** path, int *optionsMask) __in int argc,
__in_ecount(argc) wchar_t *argv[],
__deref_out PWSTR *path,
__out int *optionsMask)
{ {
int MaxOptions = 2; // Should be equal to the number of elems in CmdLineOption int MaxOptions = 2; // Should be equal to the number of elems in CmdLineOption
int i = 0; int i = 0;
@ -236,7 +239,7 @@ BOOL ParseCommandLine(
// //
// Notes: // Notes:
// //
int Ls(int argc, wchar_t *argv[]) int Ls(__in int argc, __in_ecount(argc) wchar_t *argv[])
{ {
LPWSTR pathName = NULL; LPWSTR pathName = NULL;
LPWSTR longPathName = NULL; LPWSTR longPathName = NULL;

View File

@ -19,7 +19,7 @@
static void Usage(LPCWSTR program); static void Usage(LPCWSTR program);
int wmain(int argc, wchar_t* argv[]) int wmain(__in int argc, __in_ecount(argc) wchar_t* argv[])
{ {
LPCWSTR cmd = NULL; LPCWSTR cmd = NULL;

View File

@ -28,7 +28,7 @@
// //
// Notes: // Notes:
// //
int Symlink(int argc, wchar_t *argv[]) int Symlink(__in int argc, __in_ecount(argc) wchar_t *argv[])
{ {
PWSTR longLinkName = NULL; PWSTR longLinkName = NULL;
PWSTR longFileName = NULL; PWSTR longFileName = NULL;

View File

@ -51,8 +51,8 @@ int SystemInfo()
ULONGLONG cpuTimeMs; ULONGLONG cpuTimeMs;
size_t size; size_t size;
LPBYTE pBuffer; LPBYTE pBuffer;
PPROCESSOR_POWER_INFORMATION ppi; PROCESSOR_POWER_INFORMATION const *ppi;
long cpuFrequencyKhz; ULONGLONG cpuFrequencyKhz;
NTSTATUS status; NTSTATUS status;
ZeroMemory(&memInfo, sizeof(PERFORMANCE_INFORMATION)); ZeroMemory(&memInfo, sizeof(PERFORMANCE_INFORMATION));
@ -98,11 +98,12 @@ int SystemInfo()
LocalFree(pBuffer); LocalFree(pBuffer);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
ppi = (PPROCESSOR_POWER_INFORMATION)pBuffer; ppi = (PROCESSOR_POWER_INFORMATION const *)pBuffer;
cpuFrequencyKhz = ppi->MaxMhz*1000; cpuFrequencyKhz = ppi->MaxMhz*1000;
LocalFree(pBuffer); LocalFree(pBuffer);
fwprintf_s(stdout, L"%Iu,%Iu,%Iu,%Iu,%Iu,%Iu,%Iu\n", vmemSize, memSize, vmemFree, memFree, sysInfo.dwNumberOfProcessors, cpuFrequencyKhz, cpuTimeMs); fwprintf_s(stdout, L"%Iu,%Iu,%Iu,%Iu,%u,%I64u,%I64u\n", vmemSize, memSize,
vmemFree, memFree, sysInfo.dwNumberOfProcessors, cpuFrequencyKhz, cpuTimeMs);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -50,7 +50,7 @@ typedef enum TaskCommandOptionType
// TRUE: If the command line is valid // TRUE: If the command line is valid
// FALSE: otherwise // FALSE: otherwise
static BOOL ParseCommandLine(__in int argc, static BOOL ParseCommandLine(__in int argc,
__in wchar_t *argv[], __in_ecount(argc) wchar_t *argv[],
__out TaskCommandOption *command) __out TaskCommandOption *command)
{ {
*command = TaskInvalid; *command = TaskInvalid;
@ -99,7 +99,7 @@ static BOOL ParseCommandLine(__in int argc,
// Returns: // Returns:
// ERROR_SUCCESS: On success // ERROR_SUCCESS: On success
// GetLastError: otherwise // GetLastError: otherwise
DWORD createTask(_TCHAR* jobObjName, _TCHAR* cmdLine) DWORD createTask(__in PCWSTR jobObjName,__in PWSTR cmdLine)
{ {
DWORD err = ERROR_SUCCESS; DWORD err = ERROR_SUCCESS;
DWORD exitCode = EXIT_FAILURE; DWORD exitCode = EXIT_FAILURE;
@ -138,7 +138,7 @@ DWORD createTask(_TCHAR* jobObjName, _TCHAR* cmdLine)
// the child JVM uses this env var to send the task OS process identifier // the child JVM uses this env var to send the task OS process identifier
// to the TaskTracker. We pass the job object name. // to the TaskTracker. We pass the job object name.
if(SetEnvironmentVariable(_T("JVM_PID"), jobObjName) == 0) if(SetEnvironmentVariable(L"JVM_PID", jobObjName) == 0)
{ {
err = GetLastError(); err = GetLastError();
CloseHandle(jobObject); CloseHandle(jobObject);
@ -148,12 +148,14 @@ DWORD createTask(_TCHAR* jobObjName, _TCHAR* cmdLine)
ZeroMemory( &si, sizeof(si) ); ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si); si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) ); ZeroMemory( &pi, sizeof(pi) );
if(CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) == 0)
if (CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) == 0)
{ {
err = GetLastError(); err = GetLastError();
CloseHandle(jobObject); CloseHandle(jobObject);
return err; return err;
} }
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
// Wait until child process exits. // Wait until child process exits.
@ -194,7 +196,7 @@ DWORD createTask(_TCHAR* jobObjName, _TCHAR* cmdLine)
// Returns: // Returns:
// ERROR_SUCCESS: On success // ERROR_SUCCESS: On success
// GetLastError: otherwise // GetLastError: otherwise
DWORD isTaskAlive(const _TCHAR* jobObjName, int* isAlive, int* procsInJob) DWORD isTaskAlive(const WCHAR* jobObjName, int* isAlive, int* procsInJob)
{ {
PJOBOBJECT_BASIC_PROCESS_ID_LIST procList; PJOBOBJECT_BASIC_PROCESS_ID_LIST procList;
HANDLE jobObject = NULL; HANDLE jobObject = NULL;
@ -254,7 +256,7 @@ DWORD isTaskAlive(const _TCHAR* jobObjName, int* isAlive, int* procsInJob)
// Returns: // Returns:
// ERROR_SUCCESS: On success // ERROR_SUCCESS: On success
// GetLastError: otherwise // GetLastError: otherwise
DWORD killTask(_TCHAR* jobObjName) DWORD killTask(PCWSTR jobObjName)
{ {
HANDLE jobObject = OpenJobObject(JOB_OBJECT_TERMINATE, FALSE, jobObjName); HANDLE jobObject = OpenJobObject(JOB_OBJECT_TERMINATE, FALSE, jobObjName);
if(jobObject == NULL) if(jobObject == NULL)
@ -286,7 +288,7 @@ DWORD killTask(_TCHAR* jobObjName)
// Returns: // Returns:
// ERROR_SUCCESS: On success // ERROR_SUCCESS: On success
// GetLastError: otherwise // GetLastError: otherwise
DWORD printTaskProcessList(const _TCHAR* jobObjName) DWORD printTaskProcessList(const WCHAR* jobObjName)
{ {
DWORD i; DWORD i;
PJOBOBJECT_BASIC_PROCESS_ID_LIST procList; PJOBOBJECT_BASIC_PROCESS_ID_LIST procList;
@ -317,9 +319,9 @@ DWORD printTaskProcessList(const _TCHAR* jobObjName)
numProcs = procList->NumberOfAssignedProcesses; numProcs = procList->NumberOfAssignedProcesses;
LocalFree(procList); LocalFree(procList);
procList = (PJOBOBJECT_BASIC_PROCESS_ID_LIST) LocalAlloc(LPTR, sizeof (JOBOBJECT_BASIC_PROCESS_ID_LIST) + numProcs*32); procList = (PJOBOBJECT_BASIC_PROCESS_ID_LIST) LocalAlloc(LPTR, sizeof (JOBOBJECT_BASIC_PROCESS_ID_LIST) + numProcs*32);
if (!procList) if (procList == NULL)
{ {
DWORD err = GetLastError(); err = GetLastError();
CloseHandle(jobObject); CloseHandle(jobObject);
return err; return err;
} }
@ -343,7 +345,7 @@ DWORD printTaskProcessList(const _TCHAR* jobObjName)
userTime.HighPart = user.dwHighDateTime; userTime.HighPart = user.dwHighDateTime;
userTime.LowPart = user.dwLowDateTime; userTime.LowPart = user.dwLowDateTime;
cpuTimeMs = (kernelTime.QuadPart+userTime.QuadPart)/10000; cpuTimeMs = (kernelTime.QuadPart+userTime.QuadPart)/10000;
_ftprintf_s(stdout, TEXT("%u,%Iu,%Iu,%Iu\n"), procList->ProcessIdList[i], pmc.PrivateUsage, pmc.WorkingSetSize, cpuTimeMs); fwprintf_s(stdout, L"%Iu,%Iu,%Iu,%I64u\n", procList->ProcessIdList[i], pmc.PrivateUsage, pmc.WorkingSetSize, cpuTimeMs);
} }
} }
CloseHandle( hProcess ); CloseHandle( hProcess );
@ -366,7 +368,7 @@ DWORD printTaskProcessList(const _TCHAR* jobObjName)
// Returns: // Returns:
// ERROR_SUCCESS: On success // ERROR_SUCCESS: On success
// Error code otherwise: otherwise // Error code otherwise: otherwise
int Task(int argc, wchar_t *argv[]) int Task(__in int argc, __in_ecount(argc) wchar_t *argv[])
{ {
DWORD dwErrorCode = ERROR_SUCCESS; DWORD dwErrorCode = ERROR_SUCCESS;
TaskCommandOption command = TaskInvalid; TaskCommandOption command = TaskInvalid;