Writing preferences, Listing 2-11, Writing preferences 2 – Apple Network Setup User Manual

Page 39

Advertising
background image

C H A P T E R 2

Using Network Setup

Reading and Writing Preferences

39

}

return err;

}

Writing Preferences

2

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-11

Writing 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);

Advertising