*
*/
#include <dirent.h>
+#include <fcntl.h>
#include <ftw.h>
#include <unistd.h>
#include <stdio.h>
int i;
line = g_malloc(strlen(prefix) + (16 * 3) + 2);
- sprintf(line, "%s ", prefix);
+ snprintf(line, strlen(prefix), "%s ", prefix);
bytes = line + strlen(prefix) + 1;
for (i = 0; i < len; ++i) {
- sprintf(bytes, "%2.2x ", data[i]);
+ snprintf(bytes, 4, "%2.2x ", data[i]);
if ((i + 1) % 16) {
bytes += 3;
} else {
buf[0] = (opcode >> 16) & 0xff;
l_put_be16(opcode, buf + 1);
return 3;
- } else
+ } else {
return 0;
+ }
}
bool _bt_mesh_util_opcode_get(const uint8_t *buf,
return true;
}
+bool _bt_mesh_util_delete_file(const char *filename)
+{
+ struct stat st;
+ int fd;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ BT_ERR("Mesh: Failed to open [%s]", filename);
+ return false;
+ }
+
+ if (fstat(fd, &st) < 0) {
+ BT_ERR("Mesh: Failed to stat [%s]", filename);
+ close(fd);
+ return false;
+ }
+
+ if (S_ISREG(st.st_mode)) {
+ BT_INFO("Mesh: Failed stat: success [%s]", filename);
+ close(fd);
+ remove(filename);
+ return true;
+ } else {
+ BT_ERR("Mesh: [%s] Is not a regular file", filename);
+ }
+
+ BT_INFO("Mesh: File [%s] deleted", filename);
+ close(fd);
+ return false;
+}
+
bool _bt_mesh_util_is_directory_exists(const char *dir_path)
{
struct stat st;