From 23f854c962a161cc8ed982b23183600df376e818 Mon Sep 17 00:00:00 2001 From: Josh Bressers Date: Tue, 3 Jan 2006 01:08:33 +0000 Subject: [PATCH] Remove sbr/pwd.c file, moving the pwd() function into sbr/utils.c. --- ChangeLog | 4 ++ h/utils.h | 1 + sbr/Makefile.in | 2 +- sbr/pwd.c | 119 ------------------------------------------------------- sbr/utils.c | 23 ++++++++++- 5 files changed, 28 insertions(+), 121 deletions(-) delete mode 100644 sbr/pwd.c diff --git a/ChangeLog b/ChangeLog index 757d2eb..1c2fc9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-01-02 Josh Bressers + + * Remove sbr/pwd.c file, moving the pwd() function into sbr/utils.c. + 2006-01-01 Josh Bressers * patch #3967: Create a mh_xrealloc function to prevent mistakes when diff --git a/h/utils.h b/h/utils.h index 8648b3f..60e26e5 100644 --- a/h/utils.h +++ b/h/utils.h @@ -7,3 +7,4 @@ void *mh_xmalloc(size_t); void *mh_xrealloc(void *, size_t); +char *pwd(void); diff --git a/sbr/Makefile.in b/sbr/Makefile.in index 17d82e8..5f73e0f 100644 --- a/sbr/Makefile.in +++ b/sbr/Makefile.in @@ -68,7 +68,7 @@ SRCS = add.c addrsbr.c ambigsw.c atooi.c brkstring.c \ makedir.c mts.c norm_charmap.c \ path.c peekc.c pidwait.c pidstatus.c \ print_help.c print_sw.c print_version.c push.c \ - putenv.c pwd.c refile.c remdir.c r1bindex.c \ + putenv.c refile.c remdir.c r1bindex.c \ readconfig.c ruserpass.c seq_add.c seq_bits.c \ seq_del.c seq_getnum.c seq_list.c seq_nameok.c \ seq_print.c seq_read.c seq_save.c seq_setcur.c \ diff --git a/sbr/pwd.c b/sbr/pwd.c deleted file mode 100644 index 6a8b77f..0000000 --- a/sbr/pwd.c +++ /dev/null @@ -1,119 +0,0 @@ - -/* - * pwd.c -- return the current working directory - * - * $Id$ - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ - -#include - -static char curwd[PATH_MAX]; - - -char * -pwd(void) -{ - register char *cp; - - if (!getcwd (curwd, PATH_MAX)) { - admonish (NULL, "unable to determine working directory"); - if (!mypath || !*mypath - || (strcpy (curwd, mypath), chdir (curwd)) == -1) { - strcpy (curwd, "/"); - chdir (curwd); - } - return curwd; - } - - if ((cp = curwd + strlen (curwd) - 1) > curwd && *cp == '/') - *cp = '\0'; - - return curwd; -} - - -#if 0 - -/* - * Currently commented out. Everyone seems - * to have a native version these days. - */ - -/* - * getwd() - get the current working directory - */ - -int -getwd(char *cwd) -{ - int found; - char tmp1[BUFSIZ], tmp2[BUFSIZ]; - struct stat st1, st2, root; - register struct direct *dp; - register DIR *dd; - - strcpy (cwd, "/"); - stat ("/", &root); - - for (;;) { - if ((dd = opendir ("..")) == NULL) - return -1; - if (stat (".", &st2) == -1 || stat ("..", &st1) == -1) - goto out; - if (st2.st_ino == root.st_ino && st2.st_dev == root.st_dev) { - closedir (dd); - return chdir (cwd); - } - - if (st2.st_ino == st1.st_ino && st2.st_dev == st1.st_dev) { - closedir (dd); - chdir ("/"); - if ((dd = opendir (".")) == NULL) - return -1; - if (stat (".", &st1) < 0) - goto out; - if (st2.st_dev != st1.st_dev) - while (dp = readdir (dd)) { - if (stat (dp->d_name, &st1) == -1) - goto out; - if (st2.st_dev == st1.st_dev) { - snprintf (tmp1, sizeof(tmp1), "%s%s", dp->d_name, cwd); - strcpy (cwd + 1, tmp1); - closedir (dd); - return (chdir (cwd)); - } - } - else { - closedir (dd); - return (chdir (cwd)); - } - } - - found = 0; - while (dp = readdir (dd)) { - snprintf (tmp2, sizeof(tmp2), "../%s", dp->d_name); - if (stat (tmp2, &st1) != -1 - && st1.st_ino == st2.st_ino - && st1.st_dev == st2.st_dev) { - closedir (dd); - found++; - chdir (".."); - snprintf (tmp1, sizeof(tmp1), "%s%s", dp->d_name, cwd); - strcpy (cwd + 1, tmp1); - break; - } - } - if (!found) - goto out; - } - -out: ; - closedir (dd); - return -1; -} - -#endif diff --git a/sbr/utils.c b/sbr/utils.c index 7dfe900..c25e02d 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -9,7 +9,7 @@ * complete copyright information. */ -#include +#include #include #include @@ -42,3 +42,24 @@ mh_xrealloc(void *ptr, size_t size) return memory; } +char * +pwd(void) +{ + register char *cp; + static char curwd[PATH_MAX]; + + if (!getcwd (curwd, PATH_MAX)) { + admonish (NULL, "unable to determine working directory"); + if (!mypath || !*mypath + || (strcpy (curwd, mypath), chdir (curwd)) == -1) { + strcpy (curwd, "/"); + chdir (curwd); + } + return curwd; + } + + if ((cp = curwd + strlen (curwd) - 1) > curwd && *cp == '/') + *cp = '\0'; + + return curwd; +} -- 1.7.10.4