One kind of iteration call, RegistryEntryIterate, retrieves the next name entry in the Name Registry by moving in a specified direction.
OSStatus RegistryEntryIterate(
RegEntryIter *cookie,
RegEntryIterationOp relationship,
RegEntryID *foundEntry,
Boolean *done);
RegistryEntryIterate moves from entry to entry in the Name Registry, marking its position by changing the value of cookie. The direction of movement is indicated by relationship. RegistryEntryIterate returns the RegEntryID value that identifies the next name entry found in foundEntry, or true in done if all name entries have been found.
Listing 10-3 shows code using RegistryEntryIterate and RegistryEntryDelete that finds and removes all immediate child entries of a given parent entry. Deleting a name entry invalidates the iterator and RegEntryID for that name entry.
Listing 10-3 Finding and removing child entries
OSStatus
RemoveDevices(
constRegEntryID *parentEntry
)
{
RegEntryID entry;
RegEntryIter cookie;
RegEntryIterationOp iterOp;
Boolean done;
OSStatus err = noErr;
RegistryEntryIDInit(&entry);
err = RegistryEntryIterateCreate(&cookie);
if(err != noErr)
return err;
/* Reset iterator to point to the parent entry */
err = RegistryEntryIterateSet(&cookie, parentEntry);
if (err == noErr) {
/* Include just immediate chidren, not all descendants */
iterOp=kRegIterChildren;
do {
err=RegistryEntryIterate(&cookie, iterOp, &entry, &done);
if (!done && err == noErr) {
err = RegistryEntryDelete(&entry);
RegistryEntryIDDispose(&entry);
}
iterOp = kRegIterChildren;
} while (!done && err == noErr);
}
RegistryEntryIterateDispose(&cookie);
returnerr;
}