I have a rudimentary plugin variable function
@DU[dir[,flag(s)]] = disk use; flags: R = recurse, A = allocated
It works, for example,
v:\> echo %@du[c:\,r]
7790035966
But when I change wsprintf() to Sprintf() in two locations in ProcessDirectory() (code below), it gives garbage, like
v:\> echo %@du[c:\,r]
8971340599845407408
Sprintf() has always been good to me and this kind squirrely error is usually my fault. But I can't find anything wrong! Help! Code below (DU.CPP attached as DU.TXT). It says you can't attach CPPfiles!!!!!!!!
// globals
DWORD dwClusterSize = 0;
ULONGLONG ullTotalClusters = 0, ullTotalBytes = 0;
VOID ProcessDirectory( WCHAR *pDirName, BOOL bRecurse )
{
ULONGLONG ullFileSize;
WIN32_FIND_DATA wfd;
WCHAR szFindRoot[MAX_PATH];
Sprintf(szFindRoot, L"%s*", pDirName);
HANDLE hFind = FindFirstFile(szFindRoot, &wfd);
if ( !hFind ) return;
do
{
if ( bRecurse && wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
if ( wfd.cFileName[0] != L'.' && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) )
{
Sprintf(szFindRoot, L"%s%s\\", pDirName, wfd.cFileName);
ProcessDirectory(szFindRoot, bRecurse);
}
}
else // not a directory
{
ullFileSize = (ULONGLONG) wfd.nFileSizeHigh * 0x100000000I64 + wfd.nFileSizeLow;
ullTotalBytes += ullFileSize;
ullTotalClusters += ( (ullFileSize + dwClusterSize - 1) / dwClusterSize );
}
}
while ( FindNextFile(hFind, &wfd) );
FindClose(hFind);
}
@DU[dir[,flag(s)]] = disk use; flags: R = recurse, A = allocated
It works, for example,
v:\> echo %@du[c:\,r]
7790035966
But when I change wsprintf() to Sprintf() in two locations in ProcessDirectory() (code below), it gives garbage, like
v:\> echo %@du[c:\,r]
8971340599845407408
Sprintf() has always been good to me and this kind squirrely error is usually my fault. But I can't find anything wrong! Help! Code below (DU.CPP attached as DU.TXT). It says you can't attach CPPfiles!!!!!!!!
// globals
DWORD dwClusterSize = 0;
ULONGLONG ullTotalClusters = 0, ullTotalBytes = 0;
VOID ProcessDirectory( WCHAR *pDirName, BOOL bRecurse )
{
ULONGLONG ullFileSize;
WIN32_FIND_DATA wfd;
WCHAR szFindRoot[MAX_PATH];
Sprintf(szFindRoot, L"%s*", pDirName);
HANDLE hFind = FindFirstFile(szFindRoot, &wfd);
if ( !hFind ) return;
do
{
if ( bRecurse && wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
if ( wfd.cFileName[0] != L'.' && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) )
{
Sprintf(szFindRoot, L"%s%s\\", pDirName, wfd.cFileName);
ProcessDirectory(szFindRoot, bRecurse);
}
}
else // not a directory
{
ullFileSize = (ULONGLONG) wfd.nFileSizeHigh * 0x100000000I64 + wfd.nFileSizeLow;
ullTotalBytes += ullFileSize;
ullTotalClusters += ( (ullFileSize + dwClusterSize - 1) / dwClusterSize );
}
}
while ( FindNextFile(hFind, &wfd) );
FindClose(hFind);
}