util: Don't compile couple of unused function for Windows.
authorGurucharan Shetty <gshetty@nicira.com>
Thu, 29 May 2014 17:19:19 +0000 (10:19 -0700)
committerGurucharan Shetty <gshetty@nicira.com>
Tue, 24 Jun 2014 16:50:43 +0000 (09:50 -0700)
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@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/util.c
lib/util.h
tests/.gitignore
tests/automake.mk
tests/file_name.at
tests/test-file_name.c [deleted file]
tests/test-util.c

index 830cf4f..60ec5bc 100644 (file)
@@ -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',
index 04b0328..b626c0b 100644 (file)
@@ -317,8 +317,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);
index 793258f..5b55a7d 100644 (file)
@@ -17,7 +17,6 @@
 /test-controller.8
 /test-controller
 /test-csum
-/test-file_name
 /test-flows
 /test-hash
 /test-heap
index 9354fad..c0d77f6 100644 (file)
@@ -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 \
index 3d48b85..0d19462 100644 (file)
@@ -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 (file)
index 9d2aca1..0000000
+++ /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);
index 202f8d0..a8060b0 100644 (file)
@@ -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 */
 \f
 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},
 };