[evolution-patches] camel: Binary mode file opens
- From: Tor Lillqvist <tml novell com>
- To: evolution-patches lists ximian com
- Subject: [evolution-patches] camel: Binary mode file opens
- Date: Wed, 17 Aug 2005 03:31:42 +0300
This patch makes camel open files in binary mode on Win32. In open()
calls O_BINARY is used, and in fopen() calls "b" is used. (O_BINARY
is defined as 0 on Unix in camel-private.h.) OK to apply?
--tml
Index: camel/camel-block-file.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-block-file.c,v
retrieving revision 1.18
diff -p -u -2 -r1.18 camel-block-file.c
--- camel/camel-block-file.c 15 Aug 2005 03:23:09 -0000 1.18
+++ camel/camel-block-file.c 16 Aug 2005 23:09:38 -0000
@@ -28,5 +28,4 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/uio.h>
#include <pthread.h>
#include <unistd.h>
@@ -38,4 +37,5 @@
#include "camel-block-file.h"
#include "camel-file-utils.h"
+#include "camel-private.h"
#define d(x) /*(printf("%s(%d):%s: ", __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
@@ -284,5 +284,5 @@ block_file_use(CamelBlockFile *bs)
d(printf("Turning block file online: %s\n", bs->path));
- if ((bs->fd = open(bs->path, bs->flags, 0600)) == -1) {
+ if ((bs->fd = open(bs->path, bs->flags|O_BINARY, 0600)) == -1) {
err = errno;
CAMEL_BLOCK_FILE_UNLOCK(bs, io_lock);
@@ -911,5 +911,5 @@ key_file_use(CamelKeyFile *bs)
flag = "a+";
- if ((fd = open(bs->path, bs->flags, 0600)) == -1
+ if ((fd = open(bs->path, bs->flags|O_BINARY, 0600)) == -1
|| (bs->fp = fdopen(fd, flag)) == NULL) {
err = errno;
Index: camel/camel-disco-diary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-disco-diary.c,v
retrieving revision 1.11
diff -p -u -2 -r1.11 camel-disco-diary.c
--- camel/camel-disco-diary.c 20 Sep 2004 05:59:53 -0000 1.11
+++ camel/camel-disco-diary.c 16 Aug 2005 23:09:39 -0000
@@ -430,5 +430,5 @@ camel_disco_diary_new (CamelDiscoStore *
*/
- diary->file = fopen (filename, "a+");
+ diary->file = fopen (filename, "a+b");
if (!diary->file) {
camel_object_unref (diary);
Index: camel/camel-folder-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.c,v
retrieving revision 1.143
diff -p -u -2 -r1.143 camel-folder-summary.c
--- camel/camel-folder-summary.c 15 Aug 2005 03:23:09 -0000 1.143
+++ camel/camel-folder-summary.c 16 Aug 2005 23:09:43 -0000
@@ -553,5 +553,5 @@ camel_folder_summary_load(CamelFolderSum
return 0;
- in = fopen(s->summary_path, "r");
+ in = fopen(s->summary_path, "rb");
if (in == NULL)
return -1;
@@ -649,8 +649,8 @@ camel_folder_summary_save(CamelFolderSum
path = alloca(strlen(s->summary_path)+4);
sprintf(path, "%s~", s->summary_path);
- fd = open(path, O_RDWR|O_CREAT|O_TRUNC, 0600);
+ fd = open(path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
if (fd == -1)
return -1;
- out = fdopen(fd, "w");
+ out = fdopen(fd, "wb");
if (out == NULL) {
i = errno;
@@ -689,4 +689,7 @@ camel_folder_summary_save(CamelFolderSum
CAMEL_SUMMARY_UNLOCK(s, io_lock);
+#ifdef G_OS_WIN32
+ unlink(s->summary_path);
+#endif
if (rename(path, s->summary_path) == -1) {
i = errno;
@@ -733,5 +736,5 @@ camel_folder_summary_header_load(CamelFo
return 0;
- in = fopen(s->summary_path, "r");
+ in = fopen(s->summary_path, "rb");
if (in == NULL)
return -1;
Index: camel/camel-offline-journal.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-offline-journal.c,v
retrieving revision 1.3
diff -p -u -2 -r1.3 camel-offline-journal.c
--- camel/camel-offline-journal.c 13 May 2005 20:48:05 -0000 1.3
+++ camel/camel-offline-journal.c 16 Aug 2005 23:09:50 -0000
@@ -41,4 +42,5 @@
#include <camel/camel-data-cache.h>
+#include "camel-private.h"
#include "camel-offline-journal.h"
@@ -119,5 +121,5 @@ camel_offline_journal_construct (CamelOf
journal->folder = folder;
- if ((fp = fopen (filename, "r"))) {
+ if ((fp = fopen (filename, "rb"))) {
while ((entry = CAMEL_OFFLINE_JOURNAL_GET_CLASS (journal)->entry_load (journal, fp)))
e_dlist_addtail (&journal->queue, entry);
@@ -161,5 +163,5 @@ camel_offline_journal_write (CamelOfflin
int fd;
- if ((fd = open (journal->filename, O_CREAT | O_TRUNC | O_WRONLY, 0666)) == -1) {
+ if ((fd = open (journal->filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666)) == -1) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Cannot write offline journal for folder `%s': %s"),
Index: camel/camel-private.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-private.h,v
retrieving revision 1.31
diff -p -u -2 -r1.31 camel-private.h
--- camel/camel-private.h 2 Dec 2004 08:03:30 -0000 1.31
+++ camel/camel-private.h 16 Aug 2005 23:09:51 -0000
@@ -39,4 +39,10 @@ extern "C" {
#include <libedataserver/e-msgport.h>
+#include <fcntl.h>
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
struct _CamelFolderPrivate {
EMutex *lock;
@@ -160,4 +166,13 @@ struct _CamelCertDBPrivate {
#define CAMEL_CERTDB_LOCK(db, l) (g_mutex_lock (((CamelCertDB *) db)->priv->l))
#define CAMEL_CERTDB_UNLOCK(db, l) (g_mutex_unlock (((CamelCertDB *) db)->priv->l))
+
+#ifdef G_OS_WIN32
+int fsync (int fd);
+char *realpath(const char *path, char *resolved_path);
+#undef S_ISLNK
+#define S_ISLNK(m) 0
+#undef lstat
+#define lstat(path, statp) stat(path, statp)
+#endif
#ifdef __cplusplus
Index: camel/camel-store-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-store-summary.c,v
retrieving revision 1.13
diff -p -u -2 -r1.13 camel-store-summary.c
--- camel/camel-store-summary.c 21 Jul 2005 04:03:10 -0000 1.13
+++ camel/camel-store-summary.c 16 Aug 2005 23:09:53 -0000
@@ -367,5 +367,5 @@ camel_store_summary_load(CamelStoreSumma
g_assert(s->summary_path);
- in = fopen(s->summary_path, "r");
+ in = fopen(s->summary_path, "rb");
if (in == NULL)
return -1;
@@ -433,10 +433,10 @@ camel_store_summary_save(CamelStoreSumma
}
- fd = open(s->summary_path, O_RDWR|O_CREAT|O_TRUNC, 0600);
+ fd = open(s->summary_path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
if (fd == -1) {
io(printf("** open error: %s\n", strerror (errno)));
return -1;
}
- out = fdopen(fd, "w");
+ out = fdopen(fd, "wb");
if ( out == NULL ) {
i = errno;
@@ -504,5 +504,5 @@ camel_store_summary_header_load(CamelSto
g_assert(s->summary_path);
- in = fopen(s->summary_path, "r");
+ in = fopen(s->summary_path, "rb");
if (in == NULL)
return -1;
Index: camel/camel-stream-fs.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-stream-fs.c,v
retrieving revision 1.68
diff -p -u -2 -r1.68 camel-stream-fs.c
--- camel/camel-stream-fs.c 5 May 2005 18:38:48 -0000 1.68
+++ camel/camel-stream-fs.c 16 Aug 2005 23:09:53 -0000
@@ -30,8 +30,8 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <fcntl.h>
#include <errno.h>
#include <string.h>
+#include "camel-private.h"
#include "camel-file-utils.h"
#include "camel-operation.h"
@@ -173,5 +173,5 @@ camel_stream_fs_new_with_name (const cha
int fd;
- fd = open (name, flags, mode);
+ fd = open (name, flags|O_BINARY, mode);
if (fd == -1) {
return NULL;
Index: camel/camel-text-index.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-text-index.c,v
retrieving revision 1.20
diff -p -u -2 -r1.20 camel-text-index.c
--- camel/camel-text-index.c 2 Dec 2004 08:03:30 -0000 1.20
+++ camel/camel-text-index.c 16 Aug 2005 23:09:55 -0000
@@ -40,4 +39,5 @@
#include "camel/camel-object.h"
+#include "camel-private.h"
#include "camel-text-index.h"
#include "camel-block-file.h"
@@ -1092,5 +1092,5 @@ dump_raw(GHashTable *map, char *path)
camel_block_t id, total;
- fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY|O_BINARY);
if (fd == -1)
return;
Index: camel/camel-uid-cache.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-uid-cache.c,v
retrieving revision 1.14
diff -p -u -2 -r1.14 camel-uid-cache.c
--- camel/camel-uid-cache.c 27 Sep 2004 05:30:10 -0000 1.14
+++ camel/camel-uid-cache.c 16 Aug 2005 23:09:55 -0000
@@ -33,4 +33,5 @@
#include <unistd.h>
+#include "camel-private.h"
#include "camel-uid-cache.h"
#include "camel-file-utils.h"
@@ -68,5 +69,5 @@ camel_uid_cache_new (const char *filenam
g_free (dirname);
- if ((fd = open (filename, O_RDONLY | O_CREAT, 0666)) == -1)
+ if ((fd = open (filename, O_RDONLY | O_CREAT | O_BINARY, 0666)) == -1)
return NULL;
@@ -154,5 +155,5 @@ camel_uid_cache_save (CamelUIDCache *cac
filename = g_strdup_printf ("%s~", cache->filename);
- if ((fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1) {
+ if ((fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666)) == -1) {
g_free (filename);
return FALSE;
Index: camel/providers/imap/camel-imap-message-cache.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/imap/camel-imap-message-cache.c,v
retrieving revision 1.21
diff -p -u -2 -r1.21 camel-imap-message-cache.c
--- camel/providers/imap/camel-imap-message-cache.c 12 Nov 2004 05:53:12 -0000 1.21
+++ camel/providers/imap/camel-imap-message-cache.c 16 Aug 2005 23:10:00 -0000
@@ -248,5 +248,5 @@ insert_setup (CamelImapMessageCache *cac
camel_object_unref (CAMEL_OBJECT (stream));
- fd = open (*path, O_RDWR | O_CREAT | O_TRUNC, 0600);
+ fd = open (*path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0600);
if (fd == -1) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]