Author: brucem
Date: Tue May 25 08:40:25 2010
New Revision: 947962
URL: http://svn.apache.org/viewvc?rev=947962&view=rev
Log:
AVRO-552: Fix build issues for Windows. Still needs Jansson to be fixed or replaced.
Added:
avro/trunk/lang/c/src/config.h
avro/trunk/lang/c/src/types.h
avro/trunk/lang/c/tests/dir_iterator.h
- copied, changed from r947795, avro/trunk/lang/c/src/dump.h
avro/trunk/lang/c/tests/linux/
avro/trunk/lang/c/tests/linux/dir_iterator.c
avro/trunk/lang/c/tests/windows/
avro/trunk/lang/c/tests/windows/dir_iterator.c
Modified:
avro/trunk/lang/c/CMakeLists.txt
avro/trunk/lang/c/examples/quickstop.c
avro/trunk/lang/c/src/CMakeLists.txt
avro/trunk/lang/c/src/avro.h
avro/trunk/lang/c/src/datafile.c
avro/trunk/lang/c/src/datum.c
avro/trunk/lang/c/src/dump.h
avro/trunk/lang/c/src/encoding_binary.c
avro/trunk/lang/c/src/io.c
avro/trunk/lang/c/src/schema.c
avro/trunk/lang/c/src/st.h
avro/trunk/lang/c/tests/CMakeLists.txt
avro/trunk/lang/c/tests/generate_interop_data.c
avro/trunk/lang/c/tests/test_avro_data.c
avro/trunk/lang/c/tests/test_avro_schema.c
Modified: avro/trunk/lang/c/CMakeLists.txt
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/CMakeLists.txt?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/CMakeLists.txt (original)
+++ avro/trunk/lang/c/CMakeLists.txt Tue May 25 08:40:25 2010
@@ -36,6 +36,8 @@ add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(tests)
+if(NOT WIN32)
add_custom_target(pretty
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake_pretty.cmake")
+endif()
Modified: avro/trunk/lang/c/examples/quickstop.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/examples/quickstop.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/examples/quickstop.c (original)
+++ avro/trunk/lang/c/examples/quickstop.c Tue May 25 08:40:25 2010
@@ -19,7 +19,9 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
+#ifndef WIN32
#include <unistd.h>
+#endif
avro_schema_t person_schema;
int64_t id = 0;
Modified: avro/trunk/lang/c/src/CMakeLists.txt
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/CMakeLists.txt?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/CMakeLists.txt (original)
+++ avro/trunk/lang/c/src/CMakeLists.txt Tue May 25 08:40:25 2010
@@ -26,6 +26,7 @@ set(AVRO_SRC
avro.c
avro.h
avro_private.h
+ config.h
datafile.c
datum.c
datum.h
@@ -45,6 +46,7 @@ set(AVRO_SRC
schema_equal.c
st.c
st.h
+ types.h
)
set(JANSSON_SRC
@@ -67,15 +69,24 @@ source_group(Jansson FILES ${JANSSON_SRC
add_library(avro-static STATIC ${AVRO_SRC} ${JANSSON_SRC})
set_target_properties(avro-static PROPERTIES OUTPUT_NAME avro)
+
add_library(avro-shared SHARED ${AVRO_SRC} ${JANSSON_SRC})
set_target_properties(avro-shared PROPERTIES
- OUTPUT_NAME avro
- SOVERSION ${AVRO_VERSION})
+ OUTPUT_NAME avro
+ SOVERSION ${AVRO_VERSION}
+)
+if(MSVC)
+ set_target_properties(avro-static avro-shared PROPERTIES
+ COMPILE_DEFINITIONS "_CRT_SECURE_NO_WARNINGS"
+ )
+endif()
+
+if(NOT WIN32)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/avro.h DESTINATION include)
install(TARGETS avro-static avro-shared
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
-
+endif()
Modified: avro/trunk/lang/c/src/avro.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/avro.h?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/avro.h (original)
+++ avro/trunk/lang/c/src/avro.h Tue May 25 08:40:25 2010
@@ -24,7 +24,7 @@ extern "C" {
#endif
#include <stdio.h>
-#include <stdint.h>
+#include "types.h"
typedef int32_t avro_atom_t;
@@ -201,7 +201,7 @@ avro_datum_t avro_givefixed(const char *
const int64_t size);
avro_datum_t avro_map(void);
avro_datum_t avro_array(void);
-avro_datum_t avro_union(int64_t discriminant, const avro_datum_t datum);
+avro_datum_t avro_union(int64_t discriminant, avro_datum_t datum);
/* getters */
int avro_string_get(avro_datum_t datum, char **p);
@@ -255,7 +255,7 @@ void avro_datum_decref(avro_datum_t valu
void avro_datum_print(avro_datum_t value, FILE * fp);
-int avro_datum_equal(avro_datum_t a, avro_datum_t b);
+int avro_datum_equal(const avro_datum_t a, const avro_datum_t b);
int avro_schema_match(avro_schema_t writers_schema,
avro_schema_t readers_schema);
Added: avro/trunk/lang/c/src/config.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/config.h?rev=947962&view=auto
==============================================================================
--- avro/trunk/lang/c/src/config.h (added)
+++ avro/trunk/lang/c/src/config.h Tue May 25 08:40:25 2010
@@ -0,0 +1,14 @@
+#ifndef AVRO_CONFIG_H
+#define AVRO_CONFIG_H
+
+#ifdef WIN32
+
+// MSVC doesn't support C99, hence inline is not recognized as a keyword,
+// so we need to use the MSVC specific __inline instead.
+#define inline __inline
+
+#define snprintf _snprintf
+
+#endif // WIN32
+
+#endif // AVRO_CONFIG_H
Modified: avro/trunk/lang/c/src/datafile.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datafile.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datafile.c (original)
+++ avro/trunk/lang/c/src/datafile.c Tue May 25 08:40:25 2010
@@ -109,7 +109,11 @@ file_writer_init_fp(const char *path, co
static int
file_writer_create(const char *path, avro_schema_t schema, avro_file_writer_t w)
{
+#ifdef WIN32
+ int rval = file_writer_init_fp(path, "w", w);
+#else
int rval = file_writer_init_fp(path, "wx", w);
+#endif
if (rval) {
check(rval, file_writer_init_fp(path, "w", w));
}
Modified: avro/trunk/lang/c/src/datum.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum.c (original)
+++ avro/trunk/lang/c/src/datum.c Tue May 25 08:40:25 2010
@@ -379,9 +379,9 @@ int avro_boolean_get(avro_datum_t datum,
avro_datum_t avro_null(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_NULL,
- .class_type = AVRO_DATUM,
- .refcount = 1
+ AVRO_NULL, // type
+ AVRO_DATUM, // class_type
+ 1 // refcount
};
return &obj;
}
Modified: avro/trunk/lang/c/src/dump.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/dump.h?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/dump.h (original)
+++ avro/trunk/lang/c/src/dump.h Tue May 25 08:40:25 2010
@@ -19,7 +19,7 @@
#define DUMP_H
#include <stdio.h>
-#include <sys/types.h>
+#include "types.h"
void dump(FILE * out, const caddr_t addr, const long len);
Modified: avro/trunk/lang/c/src/encoding_binary.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/encoding_binary.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/encoding_binary.c (original)
+++ avro/trunk/lang/c/src/encoding_binary.c Tue May 25 08:40:25 2010
@@ -22,7 +22,7 @@
#include <limits.h>
#include <errno.h>
#include <string.h>
-#include <sys/types.h>
+#include "types.h"
#define MAX_VARINT_BUF_SIZE 10
@@ -78,8 +78,6 @@ static int write_long(avro_writer_t writ
static int64_t size_long(avro_writer_t writer, int64_t l)
{
- AVRO_UNUSED(writer);
-
int64_t len = 0;
uint64_t n = (l << 1) ^ (l >> 63);
while (n & ~0x7F) {
@@ -87,6 +85,9 @@ static int64_t size_long(avro_writer_t w
n >>= 7;
}
len++;
+
+ AVRO_UNUSED(writer);
+
return len;
}
@@ -372,61 +373,61 @@ static int64_t size_null(avro_writer_t w
}
const avro_encoding_t avro_binary_encoding = {
- .description = "BINARY FORMAT",
+ "BINARY FORMAT",
/*
* string
*/
- .read_string = read_string,
- .skip_string = skip_string,
- .write_string = write_string,
- .size_string = size_string,
+ read_string,
+ skip_string,
+ write_string,
+ size_string,
/*
* bytes
*/
- .read_bytes = read_bytes,
- .skip_bytes = skip_bytes,
- .write_bytes = write_bytes,
- .size_bytes = size_bytes,
+ read_bytes,
+ skip_bytes,
+ write_bytes,
+ size_bytes,
/*
* int
*/
- .read_int = read_int,
- .skip_int = skip_int,
- .write_int = write_int,
- .size_int = size_int,
+ read_int,
+ skip_int,
+ write_int,
+ size_int,
/*
* long
*/
- .read_long = read_long,
- .skip_long = skip_long,
- .write_long = write_long,
- .size_long = size_long,
+ read_long,
+ skip_long,
+ write_long,
+ size_long,
/*
* float
*/
- .read_float = read_float,
- .skip_float = skip_float,
- .write_float = write_float,
- .size_float = size_float,
+ read_float,
+ skip_float,
+ write_float,
+ size_float,
/*
* double
*/
- .read_double = read_double,
- .skip_double = skip_double,
- .write_double = write_double,
- .size_double = size_double,
+ read_double,
+ skip_double,
+ write_double,
+ size_double,
/*
* boolean
*/
- .read_boolean = read_boolean,
- .skip_boolean = skip_boolean,
- .write_boolean = write_boolean,
- .size_boolean = size_boolean,
+ read_boolean,
+ skip_boolean,
+ write_boolean,
+ size_boolean,
/*
* null
*/
- .read_null = read_skip_null,
- .skip_null = read_skip_null,
- .write_null = write_null,
- .size_null = size_null
+ read_skip_null,
+ read_skip_null,
+ write_null,
+ size_null
};
Modified: avro/trunk/lang/c/src/io.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/io.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/io.c (original)
+++ avro/trunk/lang/c/src/io.c Tue May 25 08:40:25 2010
@@ -160,7 +160,7 @@ static int
avro_read_file(struct _avro_reader_file_t *reader, void *buf, int64_t len)
{
int64_t needed = len;
- void *p = buf;
+ char *p = buf;
int rval;
if (len == 0) {
Modified: avro/trunk/lang/c/src/schema.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/schema.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/schema.c (original)
+++ avro/trunk/lang/c/src/schema.c Tue May 25 08:40:25 2010
@@ -15,6 +15,7 @@
* permissions and limitations under the License.
*/
+#include "config.h"
#include "avro_private.h"
#include <inttypes.h>
#include <stdlib.h>
@@ -198,9 +199,9 @@ void avro_schema_decref(avro_schema_t sc
avro_schema_t avro_schema_string(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_STRING,
- .class_type = AVRO_SCHEMA,
- .refcount = 1
+ AVRO_STRING, // type
+ AVRO_SCHEMA, // class_type
+ 1 // refcount
};
return &obj;
}
@@ -208,9 +209,9 @@ avro_schema_t avro_schema_string(void)
avro_schema_t avro_schema_bytes(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_BYTES,
- .class_type = AVRO_SCHEMA,
- .refcount = 1
+ AVRO_BYTES, // type
+ AVRO_SCHEMA, // class_type
+ 1 // refcount
};
return &obj;
}
@@ -218,9 +219,9 @@ avro_schema_t avro_schema_bytes(void)
avro_schema_t avro_schema_int(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_INT32,
- .class_type = AVRO_SCHEMA,
- .refcount = 1
+ AVRO_INT32, // type
+ AVRO_SCHEMA, // class_type
+ 1 // refcount
};
return &obj;
}
@@ -228,9 +229,9 @@ avro_schema_t avro_schema_int(void)
avro_schema_t avro_schema_long(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_INT64,
- .class_type = AVRO_SCHEMA,
- .refcount = 1
+ AVRO_INT64, // type
+ AVRO_SCHEMA, // class_type
+ 1 // refcount
};
return &obj;
}
@@ -238,9 +239,9 @@ avro_schema_t avro_schema_long(void)
avro_schema_t avro_schema_float(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_FLOAT,
- .class_type = AVRO_SCHEMA,
- .refcount = 1
+ AVRO_FLOAT, // type
+ AVRO_SCHEMA, // class_type
+ 1 // refcount
};
return &obj;
}
@@ -248,9 +249,9 @@ avro_schema_t avro_schema_float(void)
avro_schema_t avro_schema_double(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_DOUBLE,
- .class_type = AVRO_SCHEMA,
- .refcount = 1
+ AVRO_DOUBLE, // type
+ AVRO_SCHEMA, // class_type
+ 1 // refcount
};
return &obj;
}
@@ -258,9 +259,9 @@ avro_schema_t avro_schema_double(void)
avro_schema_t avro_schema_boolean(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_BOOLEAN,
- .class_type = AVRO_SCHEMA,
- .refcount = 1
+ AVRO_BOOLEAN, // type
+ AVRO_SCHEMA, // class_type
+ 1 // refcount
};
return &obj;
}
@@ -268,9 +269,9 @@ avro_schema_t avro_schema_boolean(void)
avro_schema_t avro_schema_null(void)
{
static struct avro_obj_t obj = {
- .type = AVRO_NULL,
- .class_type = AVRO_SCHEMA,
- .refcount = 1
+ AVRO_NULL, // type
+ AVRO_SCHEMA, // class_type
+ 1 // refcount
};
return &obj;
}
@@ -921,9 +922,9 @@ avro_schema_t avro_schema_copy(avro_sche
st_data_t data;
struct avro_record_field_t *field;
} val;
+ avro_schema_t type_copy;
st_lookup(record_schema->fields, i, &val.data);
- avro_schema_t type_copy =
- avro_schema_copy(val.field->type);
+ type_copy = avro_schema_copy(val.field->type);
// FIXME: Remove avro_atom_to_string() here.
avro_schema_record_field_append(new_schema,
avro_atom_to_string(val.field->name),
Modified: avro/trunk/lang/c/src/st.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/st.h?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/st.h (original)
+++ avro/trunk/lang/c/src/st.h Tue May 25 08:40:25 2010
@@ -10,7 +10,7 @@
#ifndef ST_INCLUDED
#define ST_INCLUDED
-#include <stdint.h> /* for uintptr_t */
+#include "types.h" /* for uintptr_t */
typedef uintptr_t st_data_t;
typedef struct st_table st_table;
Added: avro/trunk/lang/c/src/types.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/types.h?rev=947962&view=auto
==============================================================================
--- avro/trunk/lang/c/src/types.h (added)
+++ avro/trunk/lang/c/src/types.h Tue May 25 08:40:25 2010
@@ -0,0 +1,24 @@
+#ifndef AVRO_TYPES_H
+#define AVRO_TYPES_H
+
+#ifdef WIN32
+
+typedef signed __int8 int8_t;
+typedef signed __int16 int16_t;
+typedef signed __int32 int32_t;
+typedef signed __int64 int64_t;
+
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+
+typedef char* caddr_t;
+
+#else // if not WIN32
+#include <stdint.h>
+#include <sys/types.h>
+#endif // WIN32
+
+#endif // AVRO_TYPES_H
+
Modified: avro/trunk/lang/c/tests/CMakeLists.txt
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/CMakeLists.txt?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/CMakeLists.txt (original)
+++ avro/trunk/lang/c/tests/CMakeLists.txt Tue May 25 08:40:25 2010
@@ -22,7 +22,19 @@ target_link_libraries(generate_interop_d
add_executable(test_interop_data test_interop_data.c)
target_link_libraries(test_interop_data avro-static)
-add_executable(test_avro_schema test_avro_schema.c)
+if(WIN32)
+ add_executable(test_avro_schema
+ test_avro_schema.c
+ dir_iterator.h
+ windows/dir_iterator.c
+ )
+else()
+ add_executable(test_avro_schema
+ test_avro_schema.c
+ dir_iterator.h
+ linux/dir_iterator.c
+ )
+endif()
target_link_libraries(test_avro_schema avro-static)
add_test(test_avro_schema ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/test_avro_schema)
Copied: avro/trunk/lang/c/tests/dir_iterator.h (from r947795, avro/trunk/lang/c/src/dump.h)
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/dir_iterator.h?p2=avro/trunk/lang/c/tests/dir_iterator.h&p1=avro/trunk/lang/c/src/dump.h&r1=947795&r2=947962&rev=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/src/dump.h (original)
+++ avro/trunk/lang/c/tests/dir_iterator.h Tue May 25 08:40:25 2010
@@ -15,12 +15,9 @@
* permissions and limitations under the License.
*/
-#ifndef DUMP_H
-#define DUMP_H
+typedef struct dir_iterator_t_* dir_iterator_t;
-#include <stdio.h>
-#include <sys/types.h>
-
-void dump(FILE * out, const caddr_t addr, const long len);
-
-#endif
+dir_iterator_t dir_iterator_new(char *dir_path);
+void dir_iterator_destroy(dir_iterator_t dir);
+int dir_iterator_next(dir_iterator_t dir);
+const char* dir_iterator_value(dir_iterator_t dir);
Modified: avro/trunk/lang/c/tests/generate_interop_data.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/generate_interop_data.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/generate_interop_data.c (original)
+++ avro/trunk/lang/c/tests/generate_interop_data.c Tue May 25 08:40:25 2010
@@ -18,7 +18,7 @@
#include "avro_private.h"
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
+#include "config.h"
struct atom_holder {
avro_atom_t arrayField;
Added: avro/trunk/lang/c/tests/linux/dir_iterator.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/linux/dir_iterator.c?rev=947962&view=auto
==============================================================================
--- avro/trunk/lang/c/tests/linux/dir_iterator.c (added)
+++ avro/trunk/lang/c/tests/linux/dir_iterator.c Tue May 25 08:40:25 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 "avro_private.h"
+#include "../dir_iterator.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+struct dir_iterator_t_
+{
+ DIR *dir;
+ struct dirent *dent;
+};
+
+dir_iterator_t dir_iterator_new(char *dir_path)
+{
+ dir_iterator_t dir = (dir_iterator_t)malloc(sizeof(struct dir_iterator_t_));
+ if (dir)
+ {
+ dir->dir = opendir(dir_path);
+ }
+ return dir;
+}
+
+void dir_iterator_destroy(dir_iterator_t dir)
+{
+ free(dir);
+}
+
+int dir_iterator_next(dir_iterator_t dir)
+{
+ dir->dent = readdir(dir->dir);
+ if (!dir->dent)
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}
+
+const char* dir_iterator_value(dir_iterator_t dir)
+{
+ return dir->dent->d_name;
+}
Modified: avro/trunk/lang/c/tests/test_avro_data.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/test_avro_data.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/test_avro_data.c (original)
+++ avro/trunk/lang/c/tests/test_avro_data.c Tue May 25 08:40:25 2010
@@ -55,6 +55,7 @@ write_read_check(avro_schema_t writers_s
{
avro_datum_t datum_out;
int validate;
+ int64_t size;
for (validate = 0; validate <= 1; validate++) {
@@ -68,7 +69,7 @@ write_read_check(avro_schema_t writers_s
type, validate);
exit(EXIT_FAILURE);
}
- int64_t size =
+ size =
avro_size_data(writer, validate ? writers_schema : NULL,
datum);
if (size != avro_writer_tell(writer)) {
Modified: avro/trunk/lang/c/tests/test_avro_schema.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/test_avro_schema.c?rev=947962&r1=947961&r2=947962&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/test_avro_schema.c (original)
+++ avro/trunk/lang/c/tests/test_avro_schema.c Tue May 25 08:40:25 2010
@@ -16,10 +16,11 @@
*/
#include "avro_private.h"
+#include "config.h"
+#include "dir_iterator.h"
#include <stdio.h>
#include <stdlib.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <stdio.h>
int test_cases = 0;
avro_writer_t avro_stderr;
@@ -29,23 +30,23 @@ static void run_tests(char *dirpath, int
char jsontext[4096];
size_t jsonlen, rval;
char filepath[1024];
- DIR *dir;
- struct dirent *dent;
+ dir_iterator_t dir;
+ const char *dent;
FILE *fp;
avro_schema_t schema;
avro_schema_error_t avro_schema_error;
- dir = opendir(dirpath);
+ dir = dir_iterator_new(dirpath);
if (dir == NULL) {
fprintf(stderr, "Unable to open '%s'\n", dirpath);
exit(EXIT_FAILURE);
}
- do {
- dent = readdir(dir);
- if (dent && dent->d_name[0] != '.') {
+ while (dir_iterator_next(dir)) {
+ dent = dir_iterator_value(dir);
+ if (dent && dent[0] != '.') {
int test_rval;
snprintf(filepath, sizeof(filepath), "%s/%s", dirpath,
- dent->d_name);
+ dent);
fprintf(stderr, "TEST %s...", filepath);
jsonlen = 0;
fp = fopen(filepath, "r");
@@ -94,7 +95,10 @@ static void run_tests(char *dirpath, int
}
}
}
- while (dent != NULL);
+ if (NULL != dir)
+ {
+ dir_iterator_destroy(dir);
+ }
}
int main(int argc, char *argv[])
Added: avro/trunk/lang/c/tests/windows/dir_iterator.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/windows/dir_iterator.c?rev=947962&view=auto
==============================================================================
--- avro/trunk/lang/c/tests/windows/dir_iterator.c (added)
+++ avro/trunk/lang/c/tests/windows/dir_iterator.c Tue May 25 08:40:25 2010
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 "../dir_iterator.h"
+#include "config.h"
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <Windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+struct dir_iterator_t_
+{
+ HANDLE handle;
+ WIN32_FIND_DATA find_data;
+ char dir_path[MAX_PATH + 1];
+};
+
+dir_iterator_t dir_iterator_new(char *dir_path)
+{
+ dir_iterator_t dir = (dir_iterator_t)malloc(sizeof(struct dir_iterator_t_));
+ if (dir)
+ {
+ dir->handle = INVALID_HANDLE_VALUE;
+ strcpy(dir->dir_path, dir_path);
+ }
+ return dir;
+}
+
+void dir_iterator_destroy(dir_iterator_t dir)
+{
+ if (INVALID_HANDLE_VALUE != dir->handle)
+ {
+ FindClose(dir->handle);
+ }
+ free(dir);
+}
+
+int dir_iterator_next(dir_iterator_t dir)
+{
+ if (INVALID_HANDLE_VALUE == dir->handle)
+ {
+ char search_path[MAX_PATH + 1];
+ snprintf(search_path, sizeof(search_path), "%s/*", dir->dir_path);
+ dir->handle = FindFirstFile(search_path, &dir->find_data);
+ if (INVALID_HANDLE_VALUE == dir->handle)
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ if (!FindNextFile(dir->handle, &dir->find_data))
+ {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+const char* dir_iterator_value(dir_iterator_t dir)
+{
+ return dir->find_data.cFileName;
+}
|