[ovs-dev] [PATCH v2 5/7] util: Don't compile couple of unused function for Windows.

Gurucharan Shetty shettyg at nicira.com
Fri Jun 13 14:40:04 UTC 2014


basename() and dir_name() are not used for Windows and won't work well if
used.  So put a '#ifndef _WIN32' around them to prevent future calls.

test-file_name.c tests the above 2 functions. It makes sense to merge
this single function file with test-util.c and then not compile it for
Windows.

Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
v1-v2:
 * Don't compile basename() and dir_name() for Windows.
 * Merge test-file_name.c with test-util.c
---
 lib/util.c             |    2 ++
 lib/util.h             |    2 ++
 tests/.gitignore       |    1 -
 tests/automake.mk      |    2 --
 tests/file_name.at     |    3 ++-
 tests/test-file_name.c |   40 ----------------------------------------
 tests/test-util.c      |   23 +++++++++++++++++++++++
 7 files changed, 29 insertions(+), 44 deletions(-)
 delete mode 100644 tests/test-file_name.c

diff --git a/lib/util.c b/lib/util.c
index 830cf4f..60ec5bc 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -772,6 +772,7 @@ all_slashes_name(const char *s)
                    : ".");
 }
 
+#ifndef _WIN32
 /* Returns the directory name portion of 'file_name' as a malloc()'d string,
  * similar to the POSIX dirname() function but thread-safe. */
 char *
@@ -813,6 +814,7 @@ base_name(const char *file_name)
 
     return xmemdup0(file_name + start, end - start);
 }
+#endif /* _WIN32 */
 
 /* If 'file_name' starts with '/', returns a copy of 'file_name'.  Otherwise,
  * returns an absolute path to 'file_name' considering it relative to 'dir',
diff --git a/lib/util.h b/lib/util.h
index 4d0ba76..8ec6742 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -313,8 +313,10 @@ unsigned int hexits_value(const char *s, size_t n, bool *ok);
 const char *english_list_delimiter(size_t index, size_t total);
 
 char *get_cwd(void);
+#ifndef _WIN32
 char *dir_name(const char *file_name);
 char *base_name(const char *file_name);
+#endif
 char *abs_file_name(const char *dir, const char *file_name);
 
 char *follow_symlinks(const char *filename);
diff --git a/tests/.gitignore b/tests/.gitignore
index 793258f..5b55a7d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -17,7 +17,6 @@
 /test-controller.8
 /test-controller
 /test-csum
-/test-file_name
 /test-flows
 /test-hash
 /test-heap
diff --git a/tests/automake.mk b/tests/automake.mk
index 9354fad..c0d77f6 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -109,7 +109,6 @@ valgrind_wrappers = \
 	tests/valgrind/test-classifier \
 	tests/valgrind/test-cmap \
 	tests/valgrind/test-csum \
-	tests/valgrind/test-file_name \
 	tests/valgrind/test-flows \
 	tests/valgrind/test-hash \
 	tests/valgrind/test-hindex \
@@ -218,7 +217,6 @@ tests_ovstest_SOURCES = \
 	tests/test-classifier.c \
 	tests/test-cmap.c \
 	tests/test-csum.c \
-	tests/test-file_name.c \
 	tests/test-flows.c \
 	tests/test-hash.c \
 	tests/test-heap.c \
diff --git a/tests/file_name.at b/tests/file_name.at
index 3d48b85..0d19462 100644
--- a/tests/file_name.at
+++ b/tests/file_name.at
@@ -2,8 +2,9 @@ AT_BANNER([test dir_name and base_name functions])
 
 m4_define([CHECK_FILE_NAME],
   [AT_SETUP([components of "$1" are "$2", "$3"])
+   AT_SKIP_IF([test "$IS_WIN32" = "yes"])
    AT_KEYWORDS([dir_name base_name])
-   AT_CHECK([ovstest test-file_name "AS_ESCAPE($1)"], [0], [$2
+   AT_CHECK([ovstest test-util file_name "AS_ESCAPE($1)"], [0], [$2
 $3
 ])
    AT_CLEANUP])
diff --git a/tests/test-file_name.c b/tests/test-file_name.c
deleted file mode 100644
index 9d2aca1..0000000
--- a/tests/test-file_name.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2009, 2010, 2014 Nicira, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <config.h>
-#include "util.h"
-#include <stdlib.h>
-#include "ovstest.h"
-
-static void
-test_filename_main(int argc, char *argv[])
-{
-    int i;
-
-    for (i = 1; i < argc; i++) {
-        char *dir, *base;
-
-        dir = dir_name(argv[i]);
-        puts(dir);
-        free(dir);
-
-        base = base_name(argv[i]);
-        puts(base);
-        free(base);
-    }
-}
-
-OVSTEST_REGISTER("test-file_name", test_filename_main);
diff --git a/tests/test-util.c b/tests/test-util.c
index 093ee9c..486f3ba 100644
--- a/tests/test-util.c
+++ b/tests/test-util.c
@@ -1031,6 +1031,26 @@ test_snprintf(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 
     ovs_assert(snprintf(NULL, 0, "abcde") == 5);
 }
+
+#ifndef _WIN32
+static void
+test_file_name(int argc, char *argv[])
+{
+    int i;
+
+    for (i = 1; i < argc; i++) {
+        char *dir, *base;
+
+        dir = dir_name(argv[i]);
+        puts(dir);
+        free(dir);
+
+        base = base_name(argv[i]);
+        puts(base);
+        free(base);
+    }
+}
+#endif /* _WIN32 */
 
 static const struct command commands[] = {
     {"ctz", 0, 0, test_ctz},
@@ -1047,6 +1067,9 @@ static const struct command commands[] = {
     {"assert", 0, 0, test_assert},
     {"ovs_scan", 0, 0, test_ovs_scan},
     {"snprintf", 0, 0, test_snprintf},
+#ifndef _WIN32
+    {"file_name", 1, INT_MAX, test_file_name},
+#endif
     {NULL, 0, 0, NULL},
 };
 
-- 
1.7.9.5




More information about the dev mailing list