From e438d7f1b37f2d8b29ae028b15f95442e48dd9e7 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 18 Nov 2019 12:40:39 +0100 Subject: Remove directory stack code Signed-off-by: David Oberhollenzer --- lib/common/dirstack.c | 78 --------------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 lib/common/dirstack.c (limited to 'lib/common/dirstack.c') 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 - */ -#include "common.h" -#include "util/compat.h" - -#include -#include -#include -#include -#include -#include - -#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; -} -- cgit v1.2.3