home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n04
/
wqa0495.exe
/
FREESEL2.C
< prev
next >
Wrap
Text File
|
1995-04-01
|
2KB
|
44 lines
WORD __export _far _pascal GetFreeSelectorCount(void)
{
DESCRIPTOR FAR *lpDescriptor;
unsigned i, ldtSelectorCount, freeSelectorCount;
long LDTSize;
// get a pointer to the start of the LDT
lpDescriptor = MAKELP(GetLDTAlias(), 0);
// if NULL pointer, then can't get count, return 0
if (!lpDescriptor)
{
MessageBox(0, "Unable to find LDT", 0, MB_OK);
return 0;
}
// The alias selector that allows access to the LDT can have a limit
// of less than 64k to prevent poking around in the unused upper
// reaches. Therefore, we need to figure out how many DESCRIPTOR
// entries can fit within the memory limit of the LDT alias.
LDTSize = GetSelectorLimit(SELECTOROF(lpDescriptor))+ 1;
ldtSelectorCount = (WORD) (LDTSize / sizeof(DESCRIPTOR));
// We'll count all the selectors above the LDT alias limit as being
// available, since Windows will increase the limit of the LDT alias
// selector as necessary
freeSelectorCount = 8192 - ldtSelectorCount;
// Iterate through each descriptor of the LDT (or at least every selector
// that we're allowed to look at)
for ( i=0; i < ldtSelectorCount; i++ )
{
// Is it a free descriptor? Check for a value of 0 in the
// byte at offset 5 in the descriptor (the type field, and flags)
if ( lpDescriptor->type_and_flags == 0 )
freeSelectorCount++;
lpDescriptor++; // Advance to the next descriptor
}
return freeSelectorCount;
}