From: Balbir Singh Date: Fri, 9 Oct 2009 14:45:34 +0000 (+0530) Subject: Minor improvements and refactoring of lscgroups X-Git-Tag: v0.35~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=797a53825f0f9c1678f231cd16735e31436513ec;p=thirdparty%2Flibcgroup.git Minor improvements and refactoring of lscgroups This patch removes the excess "/"'s and makes the output more readable. Please test on your systems as well. Signed-off-by: Balbir Singh Signed-off-by: Dhaval Giani --- diff --git a/src/tools/lscgroup.c b/src/tools/lscgroup.c index 5e3e80b3..5164d353 100644 --- a/src/tools/lscgroup.c +++ b/src/tools/lscgroup.c @@ -28,6 +28,16 @@ enum flag{ FL_LIST = 1 }; +static inline void trim_filepath(char *path) +{ + int len; + len = strlen(path) - 1; + while (path[len] == '/') + len--; + + path[len + 1] = '\0'; +} + void usage(int status, char *program_name) { if (status != 0) { @@ -86,22 +96,13 @@ int display_controller_data(char *input_path, char *controller, char *name) strncpy(cgroup_dir_path, info.full_path, FILENAME_MAX); /* remove problematic '/' characters from cgroup directory path*/ - len = strlen(cgroup_dir_path)-1; - while (cgroup_dir_path[len] == '/') - len--; - - cgroup_dir_path[len+1] = '\0'; + trim_filepath(cgroup_dir_path); strncpy(input_dir_path, input_path, FILENAME_MAX); /* remove problematic '/' characters from input path*/ - len = strlen(input_dir_path)-1; - while (input_dir_path[len] == '/') - len--; - - input_dir_path[len+1] = '\0'; - - len = strlen(cgroup_dir_path) - strlen(input_dir_path); + trim_filepath(cgroup_dir_path); + len = strlen(cgroup_dir_path) - strlen(input_dir_path) + 1; print_info(&info, name, len); while ((ret = cgroup_walk_tree_next(0, &handle, &info, lvl)) == 0) print_info(&info, name, len);