summaryrefslogtreecommitdiff
path: root/mesh/util.c
diff options
context:
space:
mode:
authorInga Stotland <inga.stotland@intel.com>2019-07-14 16:23:18 -0700
committerBrian Gix <brian.gix@intel.com>2019-07-15 14:48:04 -0700
commit7cafe5fd7cc86497c851e273550fb74fc52917d0 (patch)
tree63ee403213bff14c3b4cd6e749cdd494a46cd0d4 /mesh/util.c
parentd57524629036a4bbbe183b6a32afa02a87fe489d (diff)
downloadbluez-7cafe5fd7cc86497c851e273550fb74fc52917d0.tar.gz
mesh: Manage node config directory in mesh-config
This completely removes storage.c file. Instead, the handling of mesh node configuration storage is done completely in mesh-config layer by calling the following API functions: bool mesh_config_load_nodes(const char *cfg_dir, mesh_config_node_func_t cb, void *user_data) void mesh_config_release(struct mesh_config *cfg) void mesh_config_destroy(struct mesh_config *cfg) bool mesh_config_save(struct mesh_config *cfg, bool no_wait, mesh_config_status_func_t cb, void *user_data) struct mesh_config *mesh_config_create(const char *cfg_path, const uint8_t uuid[16], struct mesh_config_node *node)
Diffstat (limited to 'mesh/util.c')
-rw-r--r--mesh/util.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/mesh/util.c b/mesh/util.c
index 861232266..1455bdec3 100644
--- a/mesh/util.c
+++ b/mesh/util.c
@@ -22,7 +22,8 @@
#endif
#define _GNU_SOURCE
-
+#include <dirent.h>
+#include <ftw.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
@@ -91,3 +92,39 @@ size_t hex2str(uint8_t *in, size_t in_len, char *out, size_t out_len)
out[in_len * 2] = '\0';
return i;
}
+
+int create_dir(const char *dir_name)
+{
+ struct stat st;
+ char dir[PATH_MAX + 1], *prev, *next;
+ int err;
+
+ err = stat(dir_name, &st);
+ if (!err && S_ISREG(st.st_mode))
+ return 0;
+
+ memset(dir, 0, PATH_MAX + 1);
+ strcat(dir, "/");
+
+ prev = strchr(dir_name, '/');
+
+ while (prev) {
+ next = strchr(prev + 1, '/');
+ if (!next)
+ break;
+
+ if (next - prev == 1) {
+ prev = next;
+ continue;
+ }
+
+ strncat(dir, prev + 1, next - prev);
+ mkdir(dir, 0755);
+
+ prev = next;
+ }
+
+ mkdir(dir_name, 0755);
+
+ return 0;
+}