Apple Network Setup Network Card User Manual


 
CHAPTER 2
Using Network Setup
40 Reading and Writing Preferences
err2 = OTCfgClosePrefs(accessID);
if (err == noErr) {
err = err2;
}
}
return err;
}
Note
The sample shown in Listing 2-11, which opens and closes
the entity for each preference written, is implemented in an
inefficient manner for the sake of clarity. If you are writing
multiple preferences, it is more efficient to open the entity,
write your preferences by calling OTCfgSetPrefs multiple
times, and close the entity when you’re done.
Iterating the Preferences in an Entity 2
Network Setup provides functions for iterating all of the preferences in an
entity. You will rarely need to do this, but the code in Listing 2-12 gives an
example. The code first calls OTCfgGetPrefsTOCCount (TOC stands for “Table of
Contents”) to get a count of the number of preferences in the entity and then
calls OTCfgGetPrefsTOC to get an array of CfgPrefsHeader structures. Each
structure represents a preference in the entity, with fields for the preference’s
type and size.
Listing 2-12 Printing an entity’s table of contents
static void PrintPrefsTOC(CfgDatabaseRef dbRef, const CfgEntityRef *entity)
{
OSStatus err;
OSStatus err2;
CfgEntityAccessID accessID;
ItemCount prefsTOCCount;
ItemCount prefsTOCIndex;
CfgPrefsHeader *prefsTOC;
OSType prefType;
ByteCount prefSize;