aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-18 12:40:39 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-18 12:49:42 +0100
commite438d7f1b37f2d8b29ae028b15f95442e48dd9e7 (patch)
tree0d7f5078dbb5b0bfa886c8f9aa0d5512566098ee
parent1c88fa83a4699b153d5c920cb0e18e23307b82a9 (diff)
Remove directory stack code
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/common.h9
-rw-r--r--include/util/compat.h4
-rw-r--r--lib/common/Makemodule.am3
-rw-r--r--lib/common/dirstack.c78
4 files changed, 1 insertions, 93 deletions
diff --git a/include/common.h b/include/common.h
index 93bbb26..b8fe6e4 100644
--- a/include/common.h
+++ b/include/common.h
@@ -148,15 +148,6 @@ bool is_filename_sane(const char *name);
*/
int mkdir_p(const char *path);
-/* Returns 0 on success. On failure, prints error message to stderr. */
-int pushd(const char *path);
-
-/* Same as pushd, but the string doesn't have to be null-terminated. */
-int pushdn(const char *path, size_t len);
-
-/* Returns 0 on success. On failure, prints error message to stderr. */
-int popd(void);
-
/* A common implementation of the '--version' command line flag. */
void print_version(const char *progname);
diff --git a/include/util/compat.h b/include/util/compat.h
index 76ede23..fae9d92 100644
--- a/include/util/compat.h
+++ b/include/util/compat.h
@@ -7,10 +7,6 @@
#ifndef COMPAT_H
#define COMPAT_H
-#ifndef __linux__
-#define O_PATH 0
-#endif
-
#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
diff --git a/lib/common/Makemodule.am b/lib/common/Makemodule.am
index 4f4562b..2e5a812 100644
--- a/lib/common/Makemodule.am
+++ b/lib/common/Makemodule.am
@@ -5,7 +5,6 @@ libcommon_a_SOURCES += lib/common/compress.c lib/common/comp_opt.c
libcommon_a_SOURCES += lib/common/data_writer.c include/common.h
libcommon_a_SOURCES += lib/common/get_path.c lib/common/io_stdin.c
libcommon_a_SOURCES += lib/common/writer.c lib/common/perror.c
-libcommon_a_SOURCES += lib/common/dirstack.c lib/common/mkdir_p.c
-libcommon_a_SOURCES += lib/common/filename_sane.c
+libcommon_a_SOURCES += lib/common/mkdir_p.c lib/common/filename_sane.c
noinst_LIBRARIES += libcommon.a
diff --git a/lib/common/dirstack.c b/lib/common/dirstack.c
deleted file mode 100644
index f8d1278..0000000
--- a/lib/common/dirstack.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * dirstack.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "common.h"
-#include "util/compat.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <assert.h>
-#include <fcntl.h>
-#include <stdio.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;
-}