Apple OS X manual Opening and Closing a Node

Models: OS X

1 44
Download 44 pages 26.43 Kb
Page 28
Image 28

C H A P T E R 2

Working with Nodes

dirStatus = dsFindDirNodes( gDirRef, dataBuffer, nodeName, eDSContains, &bufferCount, &context );

if ( dirStatus == eDSNoErr )

{

for ( index = 1; index <= bufferCount; index++ )

{

dirStatus = dsGetDirNodeName( gDirRef, dataBuffer,

index, &nodeName );

if ( dirStatus == eDSNoErr )

{

printf( "#%4ld ", index ); PrintNodeName( nodeName ); //Deallocate the nodes.

dirStatus = dsDataListDeallocate( gDirRef, nodeName

);

free(nodeName);

}

else

{

printf("dsGetDirNodeName error = %ld\n", dirStatus

);

}

}

}

done = (context == NULL);

}

dirStatus = dsDataBufferDeAllocate( gDirRef, dataBuffer ); dataBuffer = NULL;

}

}

} // FindNodes

Opening and Closing a Node

The sample code in Listing 2-3 demonstrates how to open and close a node. The sample code opens an Open Directory session and gets an Open Directory reference. Then it calls its MyOpenDirNode routine and passes to it the address of the node reference (nodeRef) that it has allocated.

The MyOpenDirNode routine prints a prompt that solicits the entry of a node to open and calls scanf() to get the node’s name. It then calls dsBuildFromPath to build a data list containing the node name that was entered. It specifies the slash (/) character as the path delimiter. Then the MyOpenDirNode routine calls dsOpenDirNode to open the node. If the node can be opened, dsOpenDirNode stores in the node reference parameter a node reference that the application can use in subsequent calls to Open Directory functions that operate on the open node.

The MyOpenDirNode routine cleans up by calling dsCloseDirNode to close the node that was opened.

Listing 2-3Opening a node

void main ( )

{

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

28Opening and Closing a Node

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

Page 28
Image 28
Apple OS X manual Opening and Closing a Node