* Read and mark as read a character from a message buffer. * Returns the character, or -1 if no characters are available. */
| 288 | * Returns the character, or -1 if no characters are available. |
| 289 | */ |
| 290 | int |
| 291 | msgbuf_getchar(struct msgbuf *mbp) |
| 292 | { |
| 293 | u_int len, wseq; |
| 294 | int c; |
| 295 | |
| 296 | mtx_lock_spin(&mbp->msg_lock); |
| 297 | |
| 298 | wseq = mbp->msg_wseq; |
| 299 | len = MSGBUF_SEQSUB(mbp, wseq, mbp->msg_rseq); |
| 300 | if (len == 0) { |
| 301 | mtx_unlock_spin(&mbp->msg_lock); |
| 302 | return (-1); |
| 303 | } |
| 304 | if (len > mbp->msg_size) |
| 305 | mbp->msg_rseq = MSGBUF_SEQNORM(mbp, wseq - mbp->msg_size); |
| 306 | c = (u_char)mbp->msg_ptr[MSGBUF_SEQ_TO_POS(mbp, mbp->msg_rseq)]; |
| 307 | mbp->msg_rseq = MSGBUF_SEQNORM(mbp, mbp->msg_rseq + 1); |
| 308 | |
| 309 | mtx_unlock_spin(&mbp->msg_lock); |
| 310 | |
| 311 | return (c); |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | * Read and mark as read a number of characters from a message buffer. |
no outgoing calls
no test coverage detected