All functions should receive const pointer arguments, except in the cases when the argument object itself needs to be modified. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- include/tracefs.h | 15 ++++++++------- src/tracefs-instance.c | 17 +++++++++-------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/tracefs.h b/include/tracefs.h index f3eec62..e54f791 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -25,12 +25,13 @@ struct tracefs_instance *tracefs_instance_create(const char *name); struct tracefs_instance *tracefs_instance_alloc(const char *tracing_dir, const char *name); int tracefs_instance_destroy(struct tracefs_instance *instance); -bool tracefs_instance_is_new(struct tracefs_instance *instance); -const char *tracefs_instance_get_name(struct tracefs_instance *instance); -const char *tracefs_instance_get_trace_dir(struct tracefs_instance *instance); +bool tracefs_instance_is_new(const struct tracefs_instance *instance); +const char *tracefs_instance_get_name(const struct tracefs_instance *instance); +const char *tracefs_instance_get_trace_dir(const struct tracefs_instance *instance); char * -tracefs_instance_get_file(struct tracefs_instance *instance, const char *file); -char *tracefs_instance_get_dir(struct tracefs_instance *instance); +tracefs_instance_get_file(const struct tracefs_instance *instance, + const char *file); +char *tracefs_instance_get_dir(const struct tracefs_instance *instance); int tracefs_instance_file_write(struct tracefs_instance *instance, const char *file, const char *str); char *tracefs_instance_file_read(struct tracefs_instance *instance, @@ -42,8 +43,8 @@ int tracefs_instance_file_open(struct tracefs_instance *instance, int tracefs_instances_walk(int (*callback)(const char *, void *), void *context); bool tracefs_instance_exists(const char *name); -bool tracefs_file_exists(struct tracefs_instance *instance, char *name); -bool tracefs_dir_exists(struct tracefs_instance *instance, char *name); +bool tracefs_file_exists(struct tracefs_instance *instance, const char *name); +bool tracefs_dir_exists(struct tracefs_instance *instance, const char *name); int tracefs_trace_is_on(struct tracefs_instance *instance); int tracefs_trace_on(struct tracefs_instance *instance); diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c index 0df4e13..ba467a8 100644 --- a/src/tracefs-instance.c +++ b/src/tracefs-instance.c @@ -100,7 +100,7 @@ out: * Returns true, if the ftrace instance is newly created by the library or * false otherwise. */ -bool tracefs_instance_is_new(struct tracefs_instance *instance) +bool tracefs_instance_is_new(const struct tracefs_instance *instance) { if (instance && (instance->flags & FLAG_INSTANCE_NEWLY_CREATED)) return true; @@ -229,7 +229,8 @@ int tracefs_instance_destroy(struct tracefs_instance *instance) * Must use tracefs_put_tracing_file() to free the returned string. */ char * -tracefs_instance_get_file(struct tracefs_instance *instance, const char *file) +tracefs_instance_get_file(const struct tracefs_instance *instance, + const char *file) { char *path = NULL; int ret; @@ -255,7 +256,7 @@ tracefs_instance_get_file(struct tracefs_instance *instance, const char *file) * * Must use tracefs_put_tracing_file() to free the returned string. */ -char *tracefs_instance_get_dir(struct tracefs_instance *instance) +char *tracefs_instance_get_dir(const struct tracefs_instance *instance) { char *path = NULL; int ret; @@ -283,7 +284,7 @@ char *tracefs_instance_get_dir(struct tracefs_instance *instance) * Returns the name of the given @instance. * The returned string must *not* be freed. */ -const char *tracefs_instance_get_name(struct tracefs_instance *instance) +const char *tracefs_instance_get_name(const struct tracefs_instance *instance) { if (instance) return instance->name; @@ -297,7 +298,7 @@ const char *tracefs_instance_get_name(struct tracefs_instance *instance) * Returns the top trace directory where the given @instance is configured. * The returned string must *not* be freed. */ -const char *tracefs_instance_get_trace_dir(struct tracefs_instance *instance) +const char *tracefs_instance_get_trace_dir(const struct tracefs_instance *instance) { if (instance) return instance->trace_dir; @@ -436,7 +437,7 @@ int tracefs_instance_file_open(struct tracefs_instance *instance, } static bool check_file_exists(struct tracefs_instance *instance, - char *name, bool dir) + const char *name, bool dir) { char file[PATH_MAX]; struct stat st; @@ -482,7 +483,7 @@ bool tracefs_instance_exists(const char *name) * * If a directory with the given name exists, false is returned. */ -bool tracefs_file_exists(struct tracefs_instance *instance, char *name) +bool tracefs_file_exists(struct tracefs_instance *instance, const char *name) { return check_file_exists(instance, name, false); } @@ -494,7 +495,7 @@ bool tracefs_file_exists(struct tracefs_instance *instance, char *name) * * Returns true if the directory exists, false otherwise */ -bool tracefs_dir_exists(struct tracefs_instance *instance, char *name) +bool tracefs_dir_exists(struct tracefs_instance *instance, const char *name) { return check_file_exists(instance, name, true); } -- 2.25.1