Opening the database for writing, Opening the database for writing 2 – Apple Network Setup User Manual

Page 26

Advertising
background image

C H A P T E R 2

Using Network Setup

26

Opening and Closing the Network Setup Database

Listing 2-1

Opening the database for reading

static OSStatus MyOpenDatabaseForReading(CfgDatabaseRef *dbRef,

CfgAreaID *readArea)

{

OSStatus err;

assert(dbRef != nil);

assert(readArea != nil);

err = OTCfgOpenDatabase(dbRef);

if (err == noErr) {

err = OTCfgGetCurrentArea(*dbRef, readArea);

if (err == noErr) {

err = OTCfgOpenArea(*dbRef, *readArea);

}

if (err != noErr) {

(void) OTCfgCloseDatabase(dbRef);

}

}

if (err != noErr) {

*dbRef = nil;

*readArea = kInvalidCfgAreaID;

}

return err;

}

Opening the Database for Writing

2

The

MyOpenDatabaseForWriting

routine shown in Listing 2-2 shows how to open

the default (or current) area in the Network Setup database for writing. The
approach is similar to that used for opening the database for reading except that
instead of calling

OTCfgOpenArea

to open the area for reading, the routine calls

OTCfgBeginAreaModifications

to open the area for writing.

The

OTCfgBeginAreaModifications

function returns another area identifier that

references a writable temporary area. The

MyOpenDatabaseForWriting

routine

returns both the original default area identifier and the writable temporary area
identifier. You must keep both of these area identifiers because you need them
both in order to close the database. You can only make changes to the writable

Advertising