C H A P T E R 2

Using Network Setup

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

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-7Reading 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;

}

Reading and Writing Preferences

35

Page 35
Image 35
Apple Network Setup manual Reading Fixed-size Preferences, Listing 2-7Reading a fixed-size preference