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
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
void main ( )
{
long dirStatus = eDSNoErr; tDirNodeReference nodeRef = NULL; dirStatus = dsOpenDirService( &gDirRef );
28Opening and Closing a Node