From 2a3574f8d4cd7a72ccc51f47a55797d2f7fc1053 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Sun, 19 Jul 2009 05:26:05 +0000 Subject: [PATCH] windows portability fix (review by mgraff) --- bin/dnssec/dnssec-revoke.c | 10 +++++----- bin/dnssec/dnssec-settime.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/bin/dnssec/dnssec-revoke.c b/bin/dnssec/dnssec-revoke.c index a1bef44cd7..613ceec45d 100644 --- a/bin/dnssec/dnssec-revoke.c +++ b/bin/dnssec/dnssec-revoke.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dnssec-revoke.c,v 1.5 2009/07/19 04:18:04 each Exp $ */ +/* $Id: dnssec-revoke.c,v 1.6 2009/07/19 05:26:05 each Exp $ */ /*! \file */ @@ -133,6 +133,7 @@ main(int argc, char **argv) { #endif dir = strdup(argv[isc_commandline_index]); + filename = dir; /* Figure out the directory name from the key name */ slash = strrchr(dir, '/'); @@ -142,16 +143,15 @@ main(int argc, char **argv) { (slash == NULL && backslash != NULL)) slash = backslash; #endif - if (slash != NULL) + if (slash != NULL) { *slash++ = '\0'; - else { + filename = slash; + } else { free(dir); dir = strdup("."); } } - filename = argv[isc_commandline_index]; - if (ectx == NULL) setup_entropy(mctx, NULL, &ectx); result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE); diff --git a/bin/dnssec/dnssec-settime.c b/bin/dnssec/dnssec-settime.c index c1199c562b..26ba8656c5 100644 --- a/bin/dnssec/dnssec-settime.c +++ b/bin/dnssec/dnssec-settime.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dnssec-settime.c,v 1.3 2009/07/19 05:06:48 each Exp $ */ +/* $Id: dnssec-settime.c,v 1.4 2009/07/19 05:26:05 each Exp $ */ /*! \file */ @@ -179,9 +179,33 @@ main(int argc, char **argv) { if (argc > isc_commandline_index + 1) fatal("Extraneous arguments"); - if (directory == NULL) - directory = dirname(argv[isc_commandline_index]); - filename = basename(argv[isc_commandline_index]); + if (directory == NULL) { + char *slash; +#ifdef _WIN32 + char *backslash; +#endif + + directory = strdup(argv[isc_commandline_index]); + filename = directory; + + /* Figure out the directory name from the key name */ + slash = strrchr(directory, '/'); +#ifdef _WIN32 + backslash = strrchr(directory, '\\'); + if ((slash != NULL && backslash != NULL && backslash > slash) || + (slash == NULL && backslash != NULL)) + slash = backslash; +#endif + if (slash != NULL) { + *slash++ = '\0'; + filename = slash; + } else { + free(directory); + directory = strdup("."); + } + } + + filename = argv[isc_commandline_index]; if (ectx == NULL) setup_entropy(mctx, NULL, &ectx);