]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
895. [func] New function, isc_dir_current(), akin to POSIX's
authorDavid Lawrence <source@isc.org>
Fri, 8 Jun 2001 23:50:32 +0000 (23:50 +0000)
committerDavid Lawrence <source@isc.org>
Fri, 8 Jun 2001 23:50:32 +0000 (23:50 +0000)
getcwd().

CHANGES
lib/isc/unix/dir.c
lib/isc/unix/include/isc/dir.h

diff --git a/CHANGES b/CHANGES
index 80ff4d7863e267a031c36e4eb36e791a3be74d12..47f5b8aed54dfa1b339425fabcf8eeabe26baed3 100644 (file)
--- 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.
index 25e2276f7560e357c9d4e6ab4ee98d2bcb4faa06..bb852885cdc35b58d05e7f1e8333eb084a3b5d23 100644 (file)
@@ -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;
index 29b7618a8b2509c40eade5a1ea9a40b058ba9e33..77b9f318eae7f923e0a4173f49f5134ae805501f 100644 (file)
@@ -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);
 /*