From 6d828a1b309685ad7f5d74abc0162c59fbbd3304 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Tue, 3 Dec 2019 17:16:19 +0100 Subject: Add 'GetRunningBindingDirPath' function Add 'GetRunningBindingDirPath' function that returns the binding directory path (the path to the directory that contains the binding). FYI: - 'Binding directory path' is the path to the directory that contains a binding binding launched by the binder. - 'Binder root directory path' is the path specified at binder launch using '--rootdir' option. If no option is specified, binder root directory is set to the current directory. SPEC-AGL: SPEC-3009 Change-Id: I34b3d17710ebc2bf06541a00ca7f8d7189f6aa18 Signed-off-by: Jonathan Aillet --- filescan-utils.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'filescan-utils.c') diff --git a/filescan-utils.c b/filescan-utils.c index 236e192..6ac90fe 100644 --- a/filescan-utils.c +++ b/filescan-utils.c @@ -179,7 +179,33 @@ char *GetAFBRootDirPath(afb_api_t apiHandle) return GetAFBRootDirPathUsingFd(fd); } +char *GetRunningBindingDirPath(afb_api_t apiHandle) +{ + int ret; + + char *lastSlashInPath, *bindingDirectoryPath; + const char *bindingPath; + + json_object *settingsJ, *bindingPathJ = NULL; + + settingsJ = afb_api_settings(apiHandle); + if(!settingsJ) + return NULL; + + ret = json_object_object_get_ex(settingsJ, "binding-path", &bindingPathJ); + if(!ret || !bindingPathJ || !json_object_is_type(bindingPathJ, json_type_string)) + return NULL; + + bindingPath = json_object_get_string(bindingPathJ); + + lastSlashInPath = rindex(bindingPath, '/'); + if(!lastSlashInPath) + return NULL; + + bindingDirectoryPath = strndup(bindingPath, lastSlashInPath - bindingPath); + return bindingDirectoryPath; +} /** -- cgit 1.2.3-korg