* Trim whitespace characters from end of an sbuf. */
| 769 | * Trim whitespace characters from end of an sbuf. |
| 770 | */ |
| 771 | int |
| 772 | sbuf_trim(struct sbuf *s) |
| 773 | { |
| 774 | |
| 775 | assert_sbuf_integrity(s); |
| 776 | assert_sbuf_state(s, 0); |
| 777 | KASSERT(s->s_drain_func == NULL, |
| 778 | ("%s makes no sense on sbuf %p with drain", __func__, s)); |
| 779 | |
| 780 | if (s->s_error != 0) |
| 781 | return (-1); |
| 782 | |
| 783 | while (s->s_len > 0 && isspace(s->s_buf[s->s_len-1])) { |
| 784 | --s->s_len; |
| 785 | if (SBUF_ISSECTION(s)) |
| 786 | s->s_sect_len--; |
| 787 | } |
| 788 | |
| 789 | return (0); |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * Check if an sbuf has an error. |
no test coverage detected