Author: dcreager
Date: Mon Jun 18 21:43:20 2012
New Revision: 1351499
URL: http://svn.apache.org/viewvc?rev=1351499&view=rev
Log:
AVRO-1117. C: avro_file_writer_create{_with_codec}_fp functions
Contributed by Lucas Martin-King.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/c/src/avro/io.h
avro/trunk/lang/c/src/datafile.c
Modified: avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1351499&r1=1351498&r2=1351499&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Jun 18 21:43:20 2012
@@ -15,6 +15,10 @@ Avro 1.7.1 (unreleased)
AVRO-1104. C: avroappend utility. (Lucas Martin-King via dcreager)
+ AVRO-1117. C: avro_file_writer_create_with_codec_fp and
+ avro_file_writer_create_with_fp functions.
+ (Lucas Martin-King via dcreager)
+
IMPROVEMENTS
BUG FIXES
Modified: avro/trunk/lang/c/src/avro/io.h
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c/src/avro/io.h?rev=1351499&r1=1351498&r2=1351499&view=diff
==============================================================================
--- avro/trunk/lang/c/src/avro/io.h (original)
+++ avro/trunk/lang/c/src/avro/io.h Mon Jun 18 21:43:20 2012
@@ -99,9 +99,14 @@ typedef struct avro_file_writer_t_ *avro
int avro_file_writer_create(const char *path, avro_schema_t schema,
avro_file_writer_t * writer);
+int avro_file_writer_create_fp(FILE *fp, const char *path, avro_schema_t
schema,
+ avro_file_writer_t * writer);
int avro_file_writer_create_with_codec(const char *path,
avro_schema_t schema, avro_file_writer_t *
writer,
const char *codec, size_t block_size);
+int avro_file_writer_create_with_codec_fp(FILE *fp, const char *path,
+ avro_schema_t schema, avro_file_writer_t *
writer,
+ const char *codec, size_t block_size);
int avro_file_writer_open(const char *path, avro_file_writer_t * writer);
int avro_file_reader(const char *path, avro_file_reader_t * reader);
int avro_file_reader_fp(FILE *fp, const char *path, int should_close,
Modified: avro/trunk/lang/c/src/datafile.c
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datafile.c?rev=1351499&r1=1351498&r2=1351499&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datafile.c (original)
+++ avro/trunk/lang/c/src/datafile.c Mon Jun 18 21:43:20 2012
@@ -108,9 +108,12 @@ static int write_header(avro_file_writer
}
static int
-file_writer_init_fp(const char *path, const char *mode, avro_file_writer_t w)
+file_writer_init_fp(FILE *fp, const char *path, const char *mode,
avro_file_writer_t w)
{
- FILE *fp = fopen(path, mode);
+ if (!fp) {
+ fp = fopen(path, mode);
+ }
+
if (!fp) {
avro_set_error("Cannot open file for %s", path);
return ENOMEM;
@@ -135,14 +138,14 @@ file_writer_init_fp(const char *path, co
#endif
static int
-file_writer_create(const char *path, avro_schema_t schema, avro_file_writer_t
w, size_t block_size)
+file_writer_create(FILE *fp, const char *path, avro_schema_t schema,
avro_file_writer_t w, size_t block_size)
{
int rval;
w->block_count = 0;
- rval = file_writer_init_fp(path, EXCLUSIVE_WRITE_MODE, w);
+ rval = file_writer_init_fp(fp, path, EXCLUSIVE_WRITE_MODE, w);
if (rval) {
- check(rval, file_writer_init_fp(path, "wb", w));
+ check(rval, file_writer_init_fp(fp, path, "wb", w));
}
w->datum_buffer_size = block_size;
@@ -171,13 +174,27 @@ int
avro_file_writer_create(const char *path, avro_schema_t schema,
avro_file_writer_t * writer)
{
- return avro_file_writer_create_with_codec(path, schema, writer, "null",
0);
+ return avro_file_writer_create_with_codec_fp(NULL, path, schema,
writer, "null", 0);
+}
+
+int
+avro_file_writer_create_fp(FILE *fp, const char *path, avro_schema_t schema,
+ avro_file_writer_t * writer)
+{
+ return avro_file_writer_create_with_codec_fp(fp, path, schema, writer,
"null", 0);
}
int avro_file_writer_create_with_codec(const char *path,
avro_schema_t schema, avro_file_writer_t * writer,
const char *codec, size_t block_size)
{
+ return avro_file_writer_create_with_codec_fp(NULL, path, schema,
writer, codec, block_size);
+}
+
+int avro_file_writer_create_with_codec_fp(FILE *fp, const char *path,
+ avro_schema_t schema, avro_file_writer_t * writer,
+ const char *codec, size_t block_size)
+{
avro_file_writer_t w;
int rval;
check_param(EINVAL, path, "path");
@@ -207,7 +224,7 @@ int avro_file_writer_create_with_codec(c
avro_freet(struct avro_file_writer_t_, w);
return rval;
}
- rval = file_writer_create(path, schema, w, block_size);
+ rval = file_writer_create(fp, path, schema, w, block_size);
if (rval) {
avro_codec_reset(w->codec);
avro_freet(struct avro_codec_t_, w->codec);