Line data Source code
1 : #include "precizer.h"
2 :
3 : /**
4 : * @brief Removes trailing slashes from a given path.
5 : *
6 : * Modifies the input string in-place by removing any trailing '/' characters.
7 : * If the path consists only of slashes, it reduces it to a single '/'.
8 : *
9 : * @param path The string representing the path to be modified.
10 : */
11 905 : void remove_trailing_slash(char *path)
12 : {
13 905 : if(path == NULL || *path == '\0')
14 : {
15 1 : return;
16 : }
17 :
18 904 : size_t len = strlen(path);
19 :
20 : // Avoid modifying "/" (root path)
21 937 : while(len > 1 && path[len - 1] == '/')
22 : {
23 33 : path[--len] = '\0';
24 : }
25 : }
|