C H A P T E R 3
Working with Records
Listing 3-3 Setting 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