remove-extraneous-code-20040312
[openafs.git] / src / WINNT / client_config / pagesize.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include <windows.h>
16 #include <stdlib.h>
17 #include "pagesize.h"
18
19
20 ULONG ExtractPageSize (LPCTSTR psz)
21 {
22    LPCTSTR pch = &psz[ lstrlen(psz) ];
23    while ((pch > psz) && (isdigit(pch[-1])))
24       pch--;
25    return atol(pch);
26 }
27
28
29 ULONG GetPagingSpace (void)
30 {
31    ULONG ckPageSpace = 0;
32
33    HKEY hk;
34    if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management"), 0, KEY_QUERY_VALUE, &hk) == ERROR_SUCCESS)
35       {
36       TCHAR mszData[1024] = TEXT("");
37       DWORD dwSize = sizeof(mszData);
38       DWORD dwType = REG_MULTI_SZ;
39
40       if (RegQueryValueEx (hk, TEXT("PagingFiles"), 0, &dwType, (PBYTE)mszData, &dwSize) == ERROR_SUCCESS)
41          {
42          for (LPTSTR psz = mszData; *psz; psz += 1+lstrlen(psz))
43             {
44             ckPageSpace += ExtractPageSize (psz);
45             }
46          }
47
48       RegCloseKey (hk);
49       }
50
51    return ckPageSpace * 1024;
52 }
53