aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-08-24 16:49:30 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-08-24 17:07:16 +0200
commit8450ece27de10881edde04c844e60366268816f8 (patch)
tree82c18c7940bbad0b719543433bcd38869cc12a4b
parent2e021242cbc7bf22681b33038ee61a9d2df5f945 (diff)
downloadhardware_replicant_libsamsung-ipc-patches-todo/mkdir-p.tar.gz
hardware_replicant_libsamsung-ipc-patches-todo/mkdir-p.tar.bz2
hardware_replicant_libsamsung-ipc-patches-todo/mkdir-p.zip
move mkdir -p in its own filepatches-todo/mkdir-p
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--samsung-ipc/Makefile.am1
-rw-r--r--samsung-ipc/path_utils.c163
-rw-r--r--samsung-ipc/tests/partitions/android.c5
-rw-r--r--samsung-ipc/utils.c134
4 files changed, 168 insertions, 135 deletions
diff --git a/samsung-ipc/Makefile.am b/samsung-ipc/Makefile.am
index 47484e5..7772398 100644
--- a/samsung-ipc/Makefile.am
+++ b/samsung-ipc/Makefile.am
@@ -27,6 +27,7 @@ libsamsung_ipc_la_SOURCES = \
ipc.h \
ipc_strings.c \
ipc_utils.c \
+ path_utils.c \
utils.c \
call.c \
sms.c \
diff --git a/samsung-ipc/path_utils.c b/samsung-ipc/path_utils.c
new file mode 100644
index 0000000..9cfc640
--- /dev/null
+++ b/samsung-ipc/path_utils.c
@@ -0,0 +1,163 @@
+/*
+ * This file is part of libsamsung-ipc.
+ *
+ * Copyright (C) 2013-2014 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * libsamsung-ipc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * libsamsung-ipc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/stat.h>
+
+#include <samsung-ipc.h>
+
+#include "path_utils.h"
+
+int rmdir_p(struct ipc_client *client,
+ const char * const path, struct dir_infos *infos)
+{
+#if 0
+ char *_path;
+ char *startp;
+ char *endp;
+ uint64_t created_dirs = 0;
+ uint64_t dirs_depth = 0;
+ int rc;
+
+ /* We want to be able to modify the path string to replace '/'
+ * with '\0' to avoid having to copy again and again string
+ * parts */
+ _path = malloc(strlen(path) + 1);
+ if (_path == NULL) {
+ rc = errno;
+ ipc_client_log(client,
+ "%s: malloc _path failed with error %d: %s",
+ __func__, rc, strerror(rc));
+ errno = rc;
+ return -1;
+ }
+
+ memcpy(_path, path, strlen(path) + 1);
+
+ startp = _path;
+ while (true) {
+ endp = strchr(startp + 1, '/');
+ if (endp != NULL)
+ *endp = '\0';
+
+ //rc = mkdir(_path, mode);
+ if (rc == -1) {
+ rc = errno;
+ if (rc == EEXIST) {
+ dirs_depth++;
+ } else {
+ ipc_client_log(client,
+ "%s: mkdir %s failed with error %d: %s",
+ __func__, _path, rc, strerror(rc));
+ rc = rmdir_p(client, _path, dirs_depth, created_dirs);
+ if (rc == -1) {
+ ipc_client_log(client,
+ "%s: rmdir_p %s failed",
+ __func__, _path);
+ }
+ return -1;
+ }
+ } else {
+ created_dirs |= (DIR_CREATED << dirs_depth);
+ dirs_depth++;
+ }
+
+ if (endp == NULL)
+ break;
+
+ startp = endp;
+ *endp = '/';
+ }
+#endif
+ return 0;
+}
+
+int mkdir_p(struct ipc_client *client,
+ const char * const path, mode_t mode, struct dir_infos *infos)
+{
+ char *_path;
+ char *startp;
+ char *endp;
+ /* In case of errors we want to be able to remove (only) the
+ * directories we created, so we need to store what was
+ * already there and what we created. */
+ uint64_t created_dirs = 0;
+ uint64_t dirs_depth = 0;
+ int rc;
+
+ /* We want to be able to modify the path string to replace '/'
+ * with '\0' to avoid having to copy again and again string
+ * parts */
+ _path = malloc(strlen(path) + 1);
+ if (_path == NULL) {
+ rc = errno;
+ ipc_client_log(client,
+ "%s: malloc _path failed with error %d: %s",
+ __func__, rc, strerror(rc));
+ errno = rc;
+ return -1;
+ }
+
+ memcpy(_path, path, strlen(path) + 1);
+
+ startp = _path;
+ while (true) {
+ endp = strchr(startp + 1, '/');
+ if (endp != NULL)
+ *endp = '\0';
+
+ rc = mkdir(_path, mode);
+ if (rc == -1) {
+ rc = errno;
+ if (rc == EEXIST) {
+ dirs_depth++;
+ } else {
+ ipc_client_log(client,
+ "%s: mkdir %s failed with error %d: %s",
+ __func__, _path, rc, strerror(rc));
+ rc = rmdir_p(client, _path, infos);
+ if (rc == -1) {
+ ipc_client_log(client,
+ "%s: rmdir_p %s failed",
+ __func__, _path);
+ }
+ free(_path);
+ return -1;
+ }
+ } else {
+ created_dirs |= (DIR_CREATED << dirs_depth);
+ dirs_depth++;
+ }
+
+ if (endp == NULL)
+ break;
+
+ startp = endp;
+ *endp = '/';
+ }
+
+ free(_path);
+ return 0;
+}
diff --git a/samsung-ipc/tests/partitions/android.c b/samsung-ipc/tests/partitions/android.c
index 8c64661..16f7c19 100644
--- a/samsung-ipc/tests/partitions/android.c
+++ b/samsung-ipc/tests/partitions/android.c
@@ -31,7 +31,9 @@
#include <samsung-ipc.h>
#include <partitions/android/android.h>
+
#include "android.h"
+#include "path_utils.h"
static char const * const dummy_modem_image_paths[] = {
/* We can't use mktemp here since everything is const
@@ -102,8 +104,9 @@ int create_dummy_modem_image(struct ipc_client *client,
int fd;
int rc;
char *startp;
+ struct dir_infos infos;
- mkdir_p(client, path, 0775);
+ mkdir_p(client, path, 0775, &infos);
startp = strchr(path, '/');
diff --git a/samsung-ipc/utils.c b/samsung-ipc/utils.c
index e606cad..726f65c 100644
--- a/samsung-ipc/utils.c
+++ b/samsung-ipc/utils.c
@@ -594,137 +594,3 @@ void *string2data(const char *string)
return data;
}
-
-#define DIR_EEXIST 0
-#define DIR_CREATED 1
-
-int rmdir_p(struct ipc_client *client, const char * const path,
- uint64_t dirs_depth, uint64_t created_dirs)
-{
-#if 0
- char *_path;
- char *startp;
- char *endp;
- uint64_t created_dirs = 0;
- uint64_t dirs_depth = 0;
- int rc;
-
- /* We want to be able to modify the path string to replace '/'
- * with '\0' to avoid having to copy again and again string
- * parts */
- _path = malloc(strlen(path) + 1);
- if (_path == NULL) {
- rc = errno;
- ipc_client_log(client,
- "%s: malloc _path failed with error %d: %s",
- __func__, rc, strerror(rc));
- errno = rc;
- return -1;
- }
-
- memcpy(_path, path, strlen(path) + 1);
-
- startp = _path;
- while (true) {
- endp = strchr(startp + 1, '/');
- if (endp != NULL)
- *endp = '\0';
-
- //rc = mkdir(_path, mode);
- if (rc == -1) {
- rc = errno;
- if (rc == EEXIST) {
- dirs_depth++;
- } else {
- ipc_client_log(client,
- "%s: mkdir %s failed with error %d: %s",
- __func__, _path, rc, strerror(rc));
- rc = rmdir_p(client, _path, dirs_depth, created_dirs);
- if (rc == -1) {
- ipc_client_log(client,
- "%s: rmdir_p %s failed",
- __func__, _path);
- }
- return -1;
- }
- } else {
- created_dirs |= (DIR_CREATED << dirs_depth);
- dirs_depth++;
- }
-
- if (endp == NULL)
- break;
-
- startp = endp;
- *endp = '/';
- }
-#endif
- return 0;
-}
-
-int mkdir_p(struct ipc_client *client, const char * const path, mode_t mode)
-{
- char *_path;
- char *startp;
- char *endp;
- /* In case of errors we want to be able to remove (only) the
- * directories we created, so we need to store what was
- * already there and what we created. */
- uint64_t created_dirs = 0;
- uint64_t dirs_depth = 0;
- int rc;
-
- /* We want to be able to modify the path string to replace '/'
- * with '\0' to avoid having to copy again and again string
- * parts */
- _path = malloc(strlen(path) + 1);
- if (_path == NULL) {
- rc = errno;
- ipc_client_log(client,
- "%s: malloc _path failed with error %d: %s",
- __func__, rc, strerror(rc));
- errno = rc;
- return -1;
- }
-
- memcpy(_path, path, strlen(path) + 1);
-
- startp = _path;
- while (true) {
- endp = strchr(startp + 1, '/');
- if (endp != NULL)
- *endp = '\0';
-
- rc = mkdir(_path, mode);
- if (rc == -1) {
- rc = errno;
- if (rc == EEXIST) {
- dirs_depth++;
- } else {
- ipc_client_log(client,
- "%s: mkdir %s failed with error %d: %s",
- __func__, _path, rc, strerror(rc));
- rc = rmdir_p(client, _path, dirs_depth, created_dirs);
- if (rc == -1) {
- ipc_client_log(client,
- "%s: rmdir_p %s failed",
- __func__, _path);
- }
- free(_path);
- return -1;
- }
- } else {
- created_dirs |= (DIR_CREATED << dirs_depth);
- dirs_depth++;
- }
-
- if (endp == NULL)
- break;
-
- startp = endp;
- *endp = '/';
- }
-
- free(_path);
- return 0;
-}