[lttng-dev] [Babeltrace PATCH 23/23] Open files as binary under Windows

Ikaheimonen, JP jp_ikaheimonen at mentor.com
Wed May 22 04:08:31 EDT 2013


When opening files with open() or fdopen(), use the "b" flag to
avoid CR/LF transformations under Windows.
---
 formats/ctf/ctf.c                     | 2 +-
 include/babeltrace/compat/memstream.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
index ffa5387..5a7779f 100644
--- a/formats/ctf/ctf.c
+++ b/formats/ctf/ctf.c
@@ -1105,7 +1105,7 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td,
 			goto end_free;
 		}
 
-		fp = fdopen(metadata_stream->pos.fd, "r");
+		fp = fdopen(metadata_stream->pos.fd, "rb");
 		if (!fp) {
 			fprintf(stderr, "[error] Unable to open metadata stream.\n");
 			perror("Metadata stream open");
diff --git a/include/babeltrace/compat/memstream.h b/include/babeltrace/compat/memstream.h
index fb24ad9..cc5328d 100644
--- a/include/babeltrace/compat/memstream.h
+++ b/include/babeltrace/compat/memstream.h
@@ -70,7 +70,7 @@ FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
 	/*
 	 * We need to write to the file.
 	 */
-	fp = fdopen(ret, "w+");
+	fp = fdopen(ret, "w+b");
 	if (!fp) {
 		goto error_unlink;
 	}
@@ -149,7 +149,7 @@ FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
 	if (ret < 0) {
 		return NULL;
 	}
-	fp = fdopen(ret, "w+");
+	fp = fdopen(ret, "w+b");
 	if (!fp) {
 		goto error_unlink;
 	}
-- 
1.8.1.msysgit.1




More information about the lttng-dev mailing list