#define __SYSCOMMON_COMMON_H__
#include <stdbool.h>
+#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
*/
bool syscommon_is_mounted(const char *path);
+/**
+ * @brief Make directory including intermediate directories
+ *
+ * @return 0 on succes, otherwise negative error value
+ */
+int syscommon_mkdir(const char *path, mode_t mode);
+
#ifdef __cplusplus
}
#endif
#include <stdlib.h>
#include <unistd.h>
#include <mntent.h>
+#include <sys/stat.h>
#include <system_info.h>
#include "shared/log.h"
#include "libsyscommon/common.h"
#define FEATURE_MODEL_NAME_EMULATOR "Emulator"
#define CONTAINER_FILE_PATH "/run/systemd/container"
+#define PATH_MAX 256
+
bool syscommon_is_emulator(void)
{
int ret = 0;
endmntent(fp);
return ret;
}
+
+int syscommon_mkdir(const char *path, mode_t mode)
+{
+ char dir[PATH_MAX] = { 0, };
+ size_t sep, l;
+ int pos;
+ int ret;
+
+ if (!path)
+ return -EINVAL;
+
+ l = strlen(path);
+
+ for (pos = 0, sep = 0; pos < l; pos += sep + 1) {
+ sep = strcspn(path + pos, "/");
+ if (!sep)
+ continue;
+
+ ret = snprintf(dir, pos + sep + 1, "%s", path);
+ if (ret < 0)
+ return ret;
+
+ ret = mkdir(dir, mode);
+ if (ret < 0 && errno != EEXIST)
+ return -errno;
+ }
+
+ return 0;
+}