--------------------------------------------------------------------------* * Accessors * *--------------------------------------------------------------------------*/ ! * \brief lqueueAdd() * * \param[in] lq lqueue * \param[in] item to be added to the tail of the queue * \return 0 if OK, 1 on error * * * Notes
| 184 | * </pre> |
| 185 | */ |
| 186 | l_int32 |
| 187 | lqueueAdd(L_QUEUE *lq, |
| 188 | void *item) |
| 189 | { |
| 190 | PROCNAME("lqueueAdd"); |
| 191 | |
| 192 | if (!lq) |
| 193 | return ERROR_INT("lq not defined", procName, 1); |
| 194 | if (!item) |
| 195 | return ERROR_INT("item not defined", procName, 1); |
| 196 | |
| 197 | /* If filled to the end and the ptrs can be shifted to the left, |
| 198 | * shift them. */ |
| 199 | if ((lq->nhead + lq->nelem >= lq->nalloc) && (lq->nhead != 0)) { |
| 200 | memmove(lq->array, lq->array + lq->nhead, sizeof(void *) * lq->nelem); |
| 201 | lq->nhead = 0; |
| 202 | } |
| 203 | |
| 204 | /* If necessary, expand the allocated array by a factor of 2 */ |
| 205 | if (lq->nelem > 0.75 * lq->nalloc) |
| 206 | lqueueExtendArray(lq); |
| 207 | |
| 208 | /* Now add the item */ |
| 209 | lq->array[lq->nhead + lq->nelem] = (void *)item; |
| 210 | lq->nelem++; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | |
| 216 | /*! |
no test coverage detected