summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-07 14:56:09 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-07 14:59:03 +0200
commit145dfce5f04a3a74a49cc016f15b0aa6d9996662 (patch)
tree919357d5a18934222741732c8444db7711421aa3 /lib/util
parent7e1be3986b3b8229f0162431b6e02c24e04a5dba (diff)
Cleanup: move directory handling code to libcommon
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/Makemodule.am6
-rw-r--r--lib/util/dirstack.c79
-rw-r--r--lib/util/mkdir_p.c47
3 files changed, 2 insertions, 130 deletions
diff --git a/lib/util/Makemodule.am b/lib/util/Makemodule.am
index 5ba82bc..8dce70c 100644
--- a/lib/util/Makemodule.am
+++ b/lib/util/Makemodule.am
@@ -1,8 +1,6 @@
-libutil_la_SOURCES = lib/util/write_data.c include/util.h
-libutil_la_SOURCES += lib/util/mkdir_p.c include/compat.h
+libutil_la_SOURCES = lib/util/write_data.c include/util.h include/compat.h
libutil_la_SOURCES += lib/util/str_table.c include/str_table.h
-libutil_la_SOURCES += lib/util/dirstack.c lib/util/alloc.c
-libutil_la_SOURCES += lib/util/canonicalize_name.c
+libutil_la_SOURCES += lib/util/alloc.c lib/util/canonicalize_name.c
libutil_la_CFLAGS = $(AM_CFLAGS)
libutil_la_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/lib/util/dirstack.c b/lib/util/dirstack.c
deleted file mode 100644
index 20a89cc..0000000
--- a/lib/util/dirstack.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
-/*
- * dirstack.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <assert.h>
-#include <fcntl.h>
-#include <stdio.h>
-
-#include "util.h"
-
-#define STACK_DEPTH 128
-
-static int dirstack[STACK_DEPTH];
-static int stacktop = 0;
-
-int pushd(const char *path)
-{
- int fd;
-
- assert(stacktop < STACK_DEPTH);
-
- fd = open(".", O_DIRECTORY | O_PATH | O_RDONLY | O_CLOEXEC);
-
- if (fd < 0) {
- perror("open ./");
- return -1;
- }
-
- if (chdir(path)) {
- perror(path);
- close(fd);
- return -1;
- }
-
- dirstack[stacktop++] = fd;
- return 0;
-}
-
-int pushdn(const char *path, size_t len)
-{
- char *temp;
- int ret;
-
- temp = strndup(path, len);
- if (temp == NULL) {
- perror("pushd");
- return -1;
- }
-
- ret = pushd(temp);
-
- free(temp);
- return ret;
-}
-
-int popd(void)
-{
- int fd;
-
- assert(stacktop > 0);
-
- fd = dirstack[stacktop - 1];
-
- if (fchdir(fd)) {
- perror("popd");
- return -1;
- }
-
- --stacktop;
- close(fd);
- return 0;
-}
diff --git a/lib/util/mkdir_p.c b/lib/util/mkdir_p.c
deleted file mode 100644
index 93d0f59..0000000
--- a/lib/util/mkdir_p.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
-/*
- * mkdir_p.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include <string.h>
-#include <alloca.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include "util.h"
-
-int mkdir_p(const char *path)
-{
- size_t i, len;
- char *buffer;
-
- while (path[0] == '/' && path[1] == '/')
- ++path;
-
- if (*path == '\0' || (path[0] == '/' && path[1] == '\0'))
- return 0;
-
- len = strlen(path) + 1;
- buffer = alloca(len);
-
- for (i = 0; i < len; ++i) {
- if (i > 0 && (path[i] == '/' || path[i] == '\0')) {
- buffer[i] = '\0';
-
- if (mkdir(buffer, 0755) != 0) {
- if (errno != EEXIST) {
- fprintf(stderr, "mkdir %s: %s\n",
- buffer, strerror(errno));
- return -1;
- }
- }
- }
-
- buffer[i] = path[i];
- }
-
- return 0;
-}