[gmime/gmime-2-4] fixed text translation mode on Windows
- From: Jeffrey Stedfast <fejj src gnome org>
- To: svn-commits-list gnome org
- Subject: [gmime/gmime-2-4] fixed text translation mode on Windows
- Date: Thu, 7 May 2009 23:20:24 -0400 (EDT)
commit 6da297a0fe570584d905dc74f7416a52714806f7
Author: Jeffrey Stedfast <fejj gnome org>
Date: Thu May 7 23:20:28 2009 -0400
fixed text translation mode on Windows
2009-05-07 Jeffrey Stedfast <fejj novell com>
* gmime/gmime-stream-fs.c (stream_read): Removed gross hack.
(stream_write): Same.
(g_mime_stream_fs_new): On Windows systems, set the translation
mode to BINARY.
(g_mime_stream_fs_new_with_bounds): Same.
* gmime/gmime-stream-file.c: Same as GMimeStreamFs
---
ChangeLog | 10 ++++++++++
gmime/gmime-stream-file.c | 43 +++++++++++++++++--------------------------
gmime/gmime-stream-fs.c | 30 ++++++++----------------------
3 files changed, 35 insertions(+), 48 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c227c7c..835760c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-05-07 Jeffrey Stedfast <fejj novell com>
+
+ * gmime/gmime-stream-fs.c (stream_read): Removed gross hack.
+ (stream_write): Same.
+ (g_mime_stream_fs_new): On Windows systems, set the translation
+ mode to BINARY.
+ (g_mime_stream_fs_new_with_bounds): Same.
+
+ * gmime/gmime-stream-file.c: Same as GMimeStreamFs
+
2009-05-02 Jeffrey Stedfast <fejj novell com>
* gmime/gmime-stream-buffer.c (stream_seek_cache_read): Fixed a
diff --git a/gmime/gmime-stream-file.c b/gmime/gmime-stream-file.c
index 4dc3a03..070d3d1 100644
--- a/gmime/gmime-stream-file.c
+++ b/gmime/gmime-stream-file.c
@@ -23,6 +23,13 @@
#include <config.h>
#endif
+#include <glib.h>
+
+#ifdef G_OS_WIN32
+#include <fcntl.h>
+#include <io.h>
+#endif
+
#include <errno.h>
#include "gmime-stream-file.h"
@@ -149,20 +156,8 @@ stream_read (GMimeStream *stream, char *buf, size_t len)
/* make sure we are at the right position */
fseek (fstream->fp, (long) stream->position, SEEK_SET);
- if ((nread = fread (buf, 1, len, fstream->fp)) > 0) {
-#ifdef G_OS_WIN32
- /* fucking Windows... sigh. Since it might decide to translate \r\n into \n,
- * we need to query the real position rather than using simple math. */
- long pos;
-
- if ((pos = ftell (fstream->fp)) == -1)
- stream->position += nread;
- else
- stream->position = pos;
-#else
+ if ((nread = fread (buf, 1, len, fstream->fp)) > 0)
stream->position += nread;
-#endif
- }
return (ssize_t) nread;
}
@@ -189,20 +184,8 @@ stream_write (GMimeStream *stream, const char *buf, size_t len)
/* make sure we are at the right position */
fseek (fstream->fp, (long) stream->position, SEEK_SET);
- if ((nwritten = fwrite (buf, 1, len, fstream->fp)) > 0) {
-#ifdef G_OS_WIN32
- /* fucking Windows... sigh. Since it might decide to translate \n into \r\n,
- * we need to query the real position rather than using simple math. */
- long pos;
-
- if ((pos = ftell (fstream->fp)) == -1)
- stream->position += nwritten;
- else
- stream->position = pos;
-#else
+ if ((nwritten = fwrite (buf, 1, len, fstream->fp)) > 0)
stream->position += nwritten;
-#endif
- }
return (ssize_t) nwritten;
}
@@ -388,6 +371,10 @@ g_mime_stream_file_new (FILE *fp)
GMimeStreamFile *fstream;
gint64 start;
+#ifdef G_OS_WIN32
+ _setmode (_fileno (fp), O_BINARY);
+#endif
+
if ((start = ftell (fp)) == -1)
start = 0;
@@ -419,6 +406,10 @@ g_mime_stream_file_new_with_bounds (FILE *fp, gint64 start, gint64 end)
{
GMimeStreamFile *fstream;
+#ifdef G_OS_WIN32
+ _setmode (_fileno (fp), O_BINARY);
+#endif
+
fstream = g_object_newv (GMIME_TYPE_STREAM_FILE, 0, NULL);
g_mime_stream_construct (GMIME_STREAM (fstream), start, end);
fstream->owner = TRUE;
diff --git a/gmime/gmime-stream-fs.c b/gmime/gmime-stream-fs.c
index 7857986..93fb730 100644
--- a/gmime/gmime-stream-fs.c
+++ b/gmime/gmime-stream-fs.c
@@ -172,18 +172,7 @@ stream_read (GMimeStream *stream, char *buf, size_t len)
} while (nread == -1 && errno == EINTR);
if (nread > 0) {
-#ifdef G_OS_WIN32
- /* fucking Windows... sigh. Since it might decide to translate \r\n into \n,
- * we need to query the real position rather than using simple math. */
- off_t pos;
-
- if ((pos = lseek (fs->fd, 0, SEEK_CUR)) == -1)
- stream->position += nread;
- else
- stream->position = pos;
-#else
stream->position += nread;
-#endif
} else if (nread == 0) {
fs->eos = TRUE;
}
@@ -227,18 +216,7 @@ stream_write (GMimeStream *stream, const char *buf, size_t len)
fs->eos = TRUE;
if (nwritten > 0) {
-#ifdef G_OS_WIN32
- /* fucking Windows... sigh. Since it might decide to translate \n into \r\n,
- * we need to query the real position rather than using simple math. */
- off_t pos;
-
- if ((pos = lseek (fs->fd, 0, SEEK_CUR)) == -1)
- stream->position += nwritten;
- else
- stream->position = pos;
-#else
stream->position += nwritten;
-#endif
} else if (n == -1) {
/* error and nothing written */
return -1;
@@ -443,6 +421,10 @@ g_mime_stream_fs_new (int fd)
GMimeStreamFs *fs;
gint64 start;
+#ifdef G_OS_WIN32
+ _setmode (fd, O_BINARY);
+#endif
+
if ((start = lseek (fd, (off_t) 0, SEEK_CUR)) == -1)
start = 0;
@@ -472,6 +454,10 @@ g_mime_stream_fs_new_with_bounds (int fd, gint64 start, gint64 end)
{
GMimeStreamFs *fs;
+#ifdef G_OS_WIN32
+ _setmode (fd, O_BINARY);
+#endif
+
fs = g_object_newv (GMIME_TYPE_STREAM_FS, 0, NULL);
g_mime_stream_construct (GMIME_STREAM (fs), start, end);
fs->owner = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]