diff --git a/CHANGES b/CHANGES index 80ff4d7863..47f5b8aed5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,7 @@ + 895. [func] New function, isc_dir_current(), akin to POSIX's + getcwd(). + 894. [bug] When using the DNSSEC tools, a message intended to warn when the keyboard was being used because of the lack of a suitable random device was not being printed. diff --git a/lib/isc/unix/dir.c b/lib/isc/unix/dir.c index 25e2276f75..bb852885cd 100644 --- a/lib/isc/unix/dir.c +++ b/lib/isc/unix/dir.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dir.c,v 1.17 2001/06/04 19:33:32 tale Exp $ */ +/* $Id: dir.c,v 1.18 2001/06/08 23:50:31 tale Exp $ */ /* Principal Authors: DCL */ @@ -155,6 +155,34 @@ isc_dir_chroot(const char *dirname) { return (ISC_R_SUCCESS); } +isc_result_t +isc_dir_current(char *dirname, size_t length, isc_boolean_t end_sep) { + char *cwd; + isc_result_t result = ISC_R_SUCCESS; + + /* + * XXXDCL Could automatically allocate memory if dirname == NULL. + */ + REQUIRE(dirname != NULL); + REQUIRE(length > 0); + + cwd = getcwd(dirname, length); + + if (cwd == NULL) { + if (errno == ERANGE) + result = ISC_R_NOSPACE; + else + result = isc__errno2result(errno); + } else if (end_sep) { + if (strlen(dirname) + 1 == length) + result = ISC_R_NOSPACE; + else if (dirname[1] != '\0') + strcat(dirname, "/"); + } + + return (result); +} + isc_result_t isc_dir_createunique(char *templet) { isc_result_t result; diff --git a/lib/isc/unix/include/isc/dir.h b/lib/isc/unix/include/isc/dir.h index 29b7618a8b..77b9f318ea 100644 --- a/lib/isc/unix/include/isc/dir.h +++ b/lib/isc/unix/include/isc/dir.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dir.h,v 1.13 2001/01/29 03:17:45 marka Exp $ */ +/* $Id: dir.h,v 1.14 2001/06/08 23:50:32 tale Exp $ */ /* Principal Authors: DCL */ @@ -76,6 +76,16 @@ isc_dir_chdir(const char *dirname); isc_result_t isc_dir_chroot(const char *dirname); +isc_result_t +isc_dir_current(char *dirname, size_t length, isc_boolean_t end_sep); +/* + * Put the absolute name of the current directory into 'dirname', which is a + * buffer of at least 'length' characters. If 'end_sep' is true, end the + * string with the appropriate path separator, such that the final product + * could be concatenated with a relative pathname to make a valid pathname + * string. + */ + isc_result_t isc_dir_createunique(char *templet); /*