Apple Network Setup manual Writing Preferences

Models: Network Setup

1 184
Download 184 pages 5.56 Kb
Page 39
Image 39
Writing Preferences

C H A P T E R 2

Using Network Setup

}

return err;

}

Writing Preferences

Listing 2-11 shows the routine MyWritePref, which demonstrates the basic mechanism for writing preferences. Writing a preference is similar to reading a preference, with the following exceptions:

When you open the entity, open the entity for writing by passing true in the

writer parameter of OTCfgOpenPrefs.

The entity that is opened must be in a writable temporary area. Attempting to open for writing an entity in a read-only area will result in an error.

Note

You don’t need provide the area identifier when you call OTCfgOpenPrefs because an entity “knows” the area to which it belongs.

Listing 2-11Writing a preference

static OSStatus MyWritePref(CfgDatabaseRef dbRef, const CfgEntityRef *entity, OSType prefType,

const void *buffer, ByteCount bufferSize)

{

OSStatus err;

OSStatus err2;

CfgEntityAccessID accessID;

assert(dbRef

!= nil);

assert(entity

!= nil);

assert(buffer

!= nil);

err = OTCfgOpenPrefs(dbRef, entity, true, &accessID); if (err == noErr) {

err = OTCfgSetPrefs(accessID, prefType, buffer, bufferSize);

Reading and Writing Preferences

39

Page 39
Image 39
Apple Network Setup manual Writing Preferences