Changeset: 80e6748ab8cc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=80e6748ab8cc
Modified Files:
common/stream/stream.c
Branch: Jan2014
Log Message:
On Windows, when reading from compressed file, convert line endings.
If in text mode, we should not return \r\n line endings. In stead, we
must convert them to just \n.
diffs (57 lines):
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -784,6 +784,26 @@ stream_gzread(stream *s, void *buf, size
s->errnr = MNSTR_READ_ERROR;
return -1;
}
+#ifdef WIN32
+ /* on Windows when in text mode, convert \r\n line
+ * endings to \n */
+ if (s->type == ST_ASCII) {
+ char *p1, *p2, *pe;
+
+ p1 = buf;
+ pe = p1 + size;
+ while (p1 < pe && *p1 != '\r')
+ p1++;
+ p2 = p1;
+ while (p1 < pe) {
+ if (*p1 == '\r' && p1[1] == '\n')
+ size--;
+ else
+ *p2++ = *p1;
+ p1++;
+ }
+ }
+#endif
return (ssize_t) (size / elmsize);
}
return 0;
@@ -999,6 +1019,26 @@ stream_bzread(stream *s, void *buf, size
s->errnr = MNSTR_READ_ERROR;
return -1;
}
+#ifdef WIN32
+ /* on Windows when in text mode, convert \r\n line endings to
+ * \n */
+ if (s->type == ST_ASCII) {
+ char *p1, *p2, *pe;
+
+ p1 = buf;
+ pe = p1 + size;
+ while (p1 < pe && *p1 != '\r')
+ p1++;
+ p2 = p1;
+ while (p1 < pe) {
+ if (*p1 == '\r' && p1[1] == '\n')
+ size--;
+ else
+ *p2++ = *p1;
+ p1++;
+ }
+ }
+#endif
return size / elmsize;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list