Apple OS X manual Working with Records Listing 3-3Setting the name of a record

Models: OS X

1 44
Download 44 pages 26.43 Kb
Page 38
Image 38

C H A P T E R 3

Working with Records

Listing 3-3Setting the name of a record

void main ( )

{

long dirStatus = eDSNoErr; tDirNodeReference nodeRef = NULL; dirStatus = dsOpenDirService( &gDirRef ); if ( dirStatus == eDSNoErr )

{

dirStatus = MyOpenDirNode( &nodeRef ); if ( dirStatus == eDSNoErr )

{

SetRecordName( nodeRef ); dsCloseDirNode( nodeRef );

}

}

if ( gDirRef != NULL )

{

dirStatus = dsCloseDirService( gDirRef );

}

}

void SetRecordName ( const tDirNodeReference nodeRef )

{

long dirStatus = eDSNoErr; tRecordReference recRef = NULL; tDataNodePtr recName = NULL; tDataNodePtr newRecName = NULL; tDataNodePtr recType = NULL;

recName = dsDataNodeAllocateString( gDirRef, "testuser" ); if ( recName != NULL )

{

recType = dsDataNodeAllocateString( gDirRef, kDSStdRecordTypeUsers ); if ( recType != NULL )

{

dirStatus = dsOpenRecord( nodeRef, recType, recName, &recRef ); if ( dirStatus == eDSNoErr )

{

newRecName = dsDataNodeAllocateString(gDirRef, "newtestname"

);

if ( newRecName != NULL )

{

dirStatus = dsSetRecordName( recRef, newRecName ); dsDataNodeDeAllocate( gDirRef, newRecName ); newRecName = NULL;

}

dirStatus = dsCloseRecord( recRef ); recRef = NULL;

}

dsDataNodeDeAllocate( gDirRef, recType ); recType = NULL;

}

dsDataNodeDeAllocate( gDirRef, recName ); recName = NULL;

}

} // SetRecordName

38Setting the Name of a Record

2007-01-08 © 2007 Apple Inc. All Rights Reserved.

Page 38
Image 38
Apple OS X manual Working with Records Listing 3-3Setting the name of a record