Apple Network Setup Network Card User Manual


 
CHAPTER 2
Using Network Setup
Reading and Writing Preferences 35
write the desired preferences, and close the entity. This section describes this
process for reading variable-length and fixed-size preferences and for writing
preferences.
Reading Fixed-size Preferences 2
Many Network Setup preferences are of a fixed size. Reading a fixed size
preference is easy because you simply read it into the C structure that
corresponds to the preference. The code in Listing 2-7 shows a simple wrapper
routine you can use to read a fixed size preference from an entity within the
database. The prefType parameter controls the preference that is read. The
preference data is put in the buffer described by buffer and bufferSize.
Listing 2-7 Reading a fixed-size preference
static OSStatus MyReadFixedSizePref(CfgDatabaseRef dbRef,
const CfgEntityRef *entity,
OSType prefType,
void *buffer,
ByteCount bufferSize)
{
OSStatus err;
OSStatus err2;
CfgEntityAccessID accessID;
assert(dbRef != nil);
assert(entity != nil);
assert(buffer != nil);
err = OTCfgOpenPrefs(dbRef, entity, false, &accessID);
if (err == noErr) {
err = OTCfgGetPrefs(accessID, prefType, buffer, bufferSize);
err2 = OTCfgClosePrefs(accessID);
if (err == noErr) {
err = err2;
}
}
return err;
}