* Peek at the full contents of a message buffer without marking any * data as read. `seqp' should point to an unsigned integer that * msgbuf_peekbytes() can use to retain state between calls so that * the whole message buffer can be read in multiple short reads. * To initialise this variable to the start of the message buffer, * call msgbuf_peekbytes() with a NULL `buf' parameter. * * Retur
| 355 | * Returns the number of characters that were placed in `buf'. |
| 356 | */ |
| 357 | int |
| 358 | msgbuf_peekbytes(struct msgbuf *mbp, char *buf, int buflen, u_int *seqp) |
| 359 | { |
| 360 | u_int len, pos, wseq; |
| 361 | |
| 362 | mtx_lock_spin(&mbp->msg_lock); |
| 363 | |
| 364 | if (buf == NULL) { |
| 365 | /* Just initialise *seqp. */ |
| 366 | *seqp = MSGBUF_SEQNORM(mbp, mbp->msg_wseq - mbp->msg_size); |
| 367 | mtx_unlock_spin(&mbp->msg_lock); |
| 368 | return (0); |
| 369 | } |
| 370 | |
| 371 | wseq = mbp->msg_wseq; |
| 372 | len = MSGBUF_SEQSUB(mbp, wseq, *seqp); |
| 373 | if (len == 0) { |
| 374 | mtx_unlock_spin(&mbp->msg_lock); |
| 375 | return (0); |
| 376 | } |
| 377 | if (len > mbp->msg_size) { |
| 378 | *seqp = MSGBUF_SEQNORM(mbp, wseq - mbp->msg_size); |
| 379 | len = mbp->msg_size; |
| 380 | } |
| 381 | pos = MSGBUF_SEQ_TO_POS(mbp, *seqp); |
| 382 | len = min(len, mbp->msg_size - pos); |
| 383 | len = min(len, (u_int)buflen); |
| 384 | bcopy(&mbp->msg_ptr[MSGBUF_SEQ_TO_POS(mbp, *seqp)], buf, len); |
| 385 | *seqp = MSGBUF_SEQNORM(mbp, *seqp + len); |
| 386 | |
| 387 | mtx_unlock_spin(&mbp->msg_lock); |
| 388 | |
| 389 | return (len); |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Compute the checksum for the complete message buffer contents. |
no test coverage detected