librnr/dlistvoid.c
DListVoidNode_T *DListVoidInsert(DListVoid_T *pHead, int iIndex, void *pData)
{
  DListVoidNode_T  *pNext;
  DListVoidNode_T  *pNode;

  LOGDIAG4CALL(_TPTR(pHead), _TINT(iIndex), _TPTR(pData));

  CHKPTR(pHead, NULL);

  if( iIndex == 0 )
  {
    return DListVoidPrepend(pHead, pData);
  }
  else if( (iIndex == DLIST_INSERT_AT_END)  || 
           (iIndex == DListVoidCount(pHead)) )
  {
    return DListVoidAppend(pHead, pData);
  }

  // get insertion point
  if( (pNext = DListVoidGetNodeAt(pHead, iIndex)) == NULL )
  {
    return NULL;
  }

  // allocate node
  pNode = NEW(DListVoidNode_T);

  // attach data
  pNode->m_pData = pData;

  // insert into list
  _dlist_add(&pNode->m_dnode, pNext->m_dnode.prev, &pNext->m_dnode);

  pHead->m_nNumNodes++;

  LOGDIAG4(_TPTR(pNode));

  return pNode;
}
/*!
 * \brief Attach the user data to a new node and insert before the dlist index.
 *
 * The special index value DLIST_INSERT_AT_END will insert at end-of-list
 * (append).
 *
 * \param pHead   Pointer to dlist (head).
 * \param iIndex  Index to dlist entry where insertion occurs.
 * \param pData   Pointer to user (allocated) data.
 *
 * \return Returns pointer to new node on success, NULL on failure.
 */
\brief Attach the user data to a new node and insert before the dlist index.
The special index value DLIST_INSERT_AT_END will insert at end-of-list
(append).

\param pHead   Pointer to dlist (head).
\param iIndex  Index to dlist entry where insertion occurs.
\param pData   Pointer to user (allocated) data.

\return Returns pointer to new node on success, NULL on failure.
\ brief Attach the user data to a new node and insert before the dlist index . The special index value DLIST_INSERT_AT_END will insert at end - of - list ( append ) . \ param pHead Pointer to dlist ( head ) . \ param iIndex Index to dlist entry where insertion occurs . \ param pData Pointer to user ( allocated ) data . \ return Returns pointer to new node on success NULL on failure .
DListVoidNode_T *DListVoidInsert(DListVoid_T *pHead, int iIndex, void *pData)
{
  DListVoidNode_T  *pNext;
  DListVoidNode_T  *pNode;
  LOGDIAG4CALL(_TPTR(pHead), _TINT(iIndex), _TPTR(pData));
  CHKPTR(pHead, NULL);
  if( iIndex == 0 )
  {
    return DListVoidPrepend(pHead, pData);
  }
  else if( (iIndex == DLIST_INSERT_AT_END)  || 
           (iIndex == DListVoidCount(pHead)) )
  {
    return DListVoidAppend(pHead, pData);
  }
  if( (pNext = DListVoidGetNodeAt(pHead, iIndex)) == NULL )
  {
    return NULL;
  }
  pNode = NEW(DListVoidNode_T);
  pNode->m_pData = pData;
  _dlist_add(&pNode->m_dnode, pNext->m_dnode.prev, &pNext->m_dnode);
  pHead->m_nNumNodes++;
  LOGDIAG4(_TPTR(pNode));
  return pNode;
}
DListVoidNode_T * DListVoidInsert ( DListVoid_T * pHead , int iIndex , void * pData ) { DListVoidNode_T * pNext ; DListVoidNode_T * pNode ; LOGDIAG4CALL ( _TPTR ( pHead ) , _TINT ( iIndex ) , _TPTR ( pData ) ) ; CHKPTR ( pHead , NULL ) ; if ( iIndex == 0 ) { return DListVoidPrepend ( pHead , pData ) ; } else if ( ( iIndex == DLIST_INSERT_AT_END ) || ( iIndex == DListVoidCount ( pHead ) ) ) { return DListVoidAppend ( pHead , pData ) ; } if ( ( pNext = DListVoidGetNodeAt ( pHead , iIndex ) ) == NULL ) { return NULL ; } pNode = NEW ( DListVoidNode_T ) ; pNode -> m_pData = pData ; _dlist_add ( & pNode -> m_dnode , pNext -> m_dnode . prev , & pNext -> m_dnode ) ; pHead -> m_nNumNodes ++ ; LOGDIAG4 ( _TPTR ( pNode ) ) ; return pNode ; }
\brief Attach the user data to a new node and insert before the dlist index.
\ brief Attach the user data to a new node and insert before the dlist index .
// get insertion point // allocate node // attach data // insert into list