aboutsummaryrefslogtreecommitdiff
path: root/util.c
blob: 1f74ad5fd04c88734149137e8925b85dc75411f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "common.h"

/***
 * Strip whitespace from end of string
 * @param s string
 * @return count of characters stripped
 */
size_t rstrip(char *s) {
    char *ch;
    size_t i;

    i = 0;
    ch = &s[strlen(s)];
    if (ch) {
        while (isspace(*ch) || iscntrl(*ch)) {
            *ch = '\0';
            --ch;
            i++;
        }
    }
    return i;
}