[evolution-patches] Trivial camel Win32 patches



I spent some time going through the current e-d-s Win32 diff, and split
out three trivial parts. Here is the first one, for camel. 

These changes fall into the following categories:
      * use the gstdio wrappers and g_dir* functions for full non-ASCII
        filename support. On Unix the gstdio wrapper are just #defines
        for the corresponding system calls, so no overhead there, and
        GDir is a thin wrapper around the dirent API, its effect should
        be negligeable.
      * Open files in binary mode. O_BINARY is defined as 0 on Unix.
      * As already changed in several other places, replace strcasecmp()
        with g_ascii_strcasecmp() for well-definedness and portability.
      * Use g_usleep() instead of usleep().
      * Use g_htons() and g_ntohs() instead of htons() and ntohs()

--tml

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/ChangeLog,v
retrieving revision 1.2490
diff -p -u -2 -r1.2490 ChangeLog
--- ChangeLog	25 Nov 2005 03:48:47 -0000	1.2490
+++ ChangeLog	30 Nov 2005 01:13:08 -0000
@@ -1,2 +1,57 @@
+2005-11-30  Tor Lillqvist  <tml novell com>
+
+	* camel-file-utils.h: Define O_BINARY as 0 on Unix. Add
+	declarations for camel_read_socket() and camel_write_socket(). (In
+	a not yet committed addition to camel-file-utils.c.)
+
+	* camel-block-file.c
+	* camel-certdb.c
+	* camel-data-cache.c
+	* camel-disco-diary.c
+	* camel-folder-summary.c
+	* camel-mime-parser.c
+	* camel-offline-journal.c
+	* camel-provider.c
+	* camel-session.c
+	* camel-store-summary.c
+	* camel-stream-fs.c
+	* camel-text-index.c
+	* camel-uid-cache.c
+	* camel-vee-store.c: Use gstdio wrappers for full non-ASCII
+	filename support on Windows.
+
+	* camel-block-file.c (key_file_use)
+	* camel-certdb.c (camel_certdb_save)
+	* camel-disco-diary.c (camel_disco_diary_new)
+	* camel-folder-summary.c (camel_folder_summary_load)
+	* camel-offline-journal.c (camel_offline_journal_construct)
+	* camel-store-summary.c (camel_store_summary_load,
+	camel_store_summary_save, camel_store_summary_header_load)
+	* camel-stream-fs.c (camel_stream_fs_new_with_name)
+	* camel-text-index.c (dump_raw)
+	* camel-uid-cache.c (camel_uid_cache_new, camel_uid_cache_save):
+	Open file in binary mode.
+
+	* camel-data-cache.c (data_cache_expire)
+	* camel-provider.c (camel_provider_init): Use GDir instead of
+	dirent API for portability and full non-ASCII filename support on
+	Windows.
+	
+	* camel-folder-summary.c (camel_folder_summary_load): On Win32
+	unlink destination before attempting a rename.
+
+	* camel-mime-parser.c: Drop unused includes. Use
+	g_ascii_strcasecmp() instead of strcasecmp() for well-definedness,
+	and the other string being compared is an ASCII literal anyway.
+
+	* camel-provider.c (camel_provider_init) Use G_MODULE_SUFFIX
+	instead of hardcoding .so.
+
+	* camel-session.c (session_thread_wait): Use g_usleep() instead of
+	usleep() for portability.
+
+	* camel-utf8.c: Use g_htons() and g_ntohs() instead of htons() and
+	ntohs() for portability.
+	
 2005-11-25  Tor Lillqvist  <tml novell com>
 
Index: camel-file-utils.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-file-utils.h,v
retrieving revision 1.9
diff -p -u -2 -r1.9 camel-file-utils.h
--- camel-file-utils.h	31 Aug 2005 04:21:56 -0000	1.9
+++ camel-file-utils.h	30 Nov 2005 01:13:08 -0000
@@ -37,4 +37,9 @@ extern "C" {
 #include <sys/types.h>
 #include <time.h>
+#include <fcntl.h>
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
 
 int camel_file_util_encode_fixed_int32 (FILE *out, gint32);
@@ -54,6 +59,16 @@ int camel_mkdir (const char *path, mode_
 char *camel_file_util_safe_filename (const char *name);
 
+/* Code that intends to be portable to Win32 should use camel_read()
+ * and camel_write() only on file descriptors returned from open(),
+ * creat(), pipe() or fileno(). On Win32 camel_read() and
+ * camel_write() calls will not be cancellable. For sockets, use
+ * camel_read_socket() and camel_write_socket(). These are cancellable
+ * also on Win32.
+ */
 ssize_t camel_read (int fd, char *buf, size_t n);
 ssize_t camel_write (int fd, const char *buf, size_t n);
+
+ssize_t camel_read_socket (int fd, char *buf, size_t n);
+ssize_t camel_write_socket (int fd, const char *buf, size_t n);
 
 char *camel_file_util_savename(const char *filename);
Index: camel-block-file.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-block-file.c,v
retrieving revision 1.20
diff -p -u -2 -r1.20 camel-block-file.c
--- camel-block-file.c	31 Aug 2005 04:21:56 -0000	1.20
+++ camel-block-file.c	30 Nov 2005 01:13:08 -0000
@@ -33,8 +33,11 @@
 #include <errno.h>
 
+#include <glib/gstdio.h>
+
 #include "libedataserver/e-msgport.h"
 
 #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))*/
@@ -283,5 +286,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 = g_open(bs->path, bs->flags|O_BINARY, 0600)) == -1) {
 		err = errno;
 		CAMEL_BLOCK_FILE_UNLOCK(bs, io_lock);
@@ -411,10 +414,10 @@ camel_block_file_rename(CamelBlockFile *
 	CAMEL_BLOCK_FILE_LOCK(bs, io_lock);
 
-	ret = rename(bs->path, path);
+	ret = g_rename(bs->path, path);
 	if (ret == -1) {
 		/* Maybe the rename actually worked */
 		err = errno;
-		if (stat(path, &st) == 0
-		    && stat(bs->path, &st) == -1
+		if (g_stat(path, &st) == 0
+		    && g_stat(bs->path, &st) == -1
 		    && errno == ENOENT)
 			ret = 0;
@@ -449,5 +452,5 @@ camel_block_file_delete(CamelBlockFile *
 
 	p->deleted = TRUE;
-	ret = unlink(bs->path);
+	ret = g_unlink(bs->path);
 
 	CAMEL_BLOCK_FILE_UNLOCK(bs, io_lock);
@@ -906,9 +909,9 @@ key_file_use(CamelKeyFile *bs)
 
 	if ((bs->flags & O_ACCMODE) == O_RDONLY)
-		flag = "r";
+		flag = "rb";
 	else
-		flag = "a+";
+		flag = "a+b";
 
-	if ((fd = open(bs->path, bs->flags, 0600)) == -1
+	if ((fd = g_open(bs->path, bs->flags|O_BINARY, 0600)) == -1
 	    || (bs->fp = fdopen(fd, flag)) == NULL) {
 		err = errno;
@@ -1024,10 +1027,10 @@ camel_key_file_rename(CamelKeyFile *kf, 
 	CAMEL_KEY_FILE_LOCK(kf, lock);
 
-	ret = rename(kf->path, path);
+	ret = g_rename(kf->path, path);
 	if (ret == -1) {
 		/* Maybe the rename actually worked */
 		err = errno;
-		if (stat(path, &st) == 0
-		    && stat(kf->path, &st) == -1
+		if (g_stat(path, &st) == 0
+		    && g_stat(kf->path, &st) == -1
 		    && errno == ENOENT)
 			ret = 0;
@@ -1062,5 +1065,5 @@ camel_key_file_delete(CamelKeyFile *kf)
 
 	p->deleted = TRUE;
-	ret = unlink(kf->path);
+	ret = g_unlink(kf->path);
 
 	CAMEL_KEY_FILE_UNLOCK(kf, lock);
Index: camel-certdb.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-certdb.c,v
retrieving revision 1.6
diff -p -u -2 -r1.6 camel-certdb.c
--- camel-certdb.c	31 Aug 2005 04:21:56 -0000	1.6
+++ camel-certdb.c	30 Nov 2005 01:13:09 -0000
@@ -36,11 +36,11 @@
 #include <errno.h>
 
+#include <glib/gstdio.h>
+
 #include "camel-certdb.h"
+#include "camel-file-utils.h"
 #include "camel-private.h"
 
-#include <camel/camel-file-utils.h>
-
-#include <libedataserver/e-memory.h>
-
+#include "libedataserver/e-memory.h"
 
 #define CAMEL_CERTDB_GET_CLASS(db)  ((CamelCertDBClass *) CAMEL_OBJECT_GET_CLASS (db))
@@ -262,5 +262,5 @@ camel_certdb_load (CamelCertDB *certdb)
 	g_return_val_if_fail (certdb->filename, -1);
 
-	in = fopen (certdb->filename, "r");
+	in = g_fopen (certdb->filename, "rb");
 	if (in == NULL)
 		return -1;
@@ -341,13 +341,13 @@ camel_certdb_save (CamelCertDB *certdb)
 	sprintf (filename, "%s~", certdb->filename);
 	
-	fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+	fd = g_open (filename, O_WRONLY | 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;
 		close (fd);
-		unlink (filename);
+		g_unlink (filename);
 		errno = i;
 		return -1;
@@ -372,5 +372,5 @@ camel_certdb_save (CamelCertDB *certdb)
 		i = errno;
 		fclose (out);
-		unlink (filename);
+		g_unlink (filename);
 		errno = i;
 		return -1;
@@ -379,12 +379,12 @@ camel_certdb_save (CamelCertDB *certdb)
 	if (fclose (out) != 0) {
 		i = errno;
-		unlink (filename);
+		g_unlink (filename);
 		errno = i;
 		return -1;
 	}
 	
-	if (rename (filename, certdb->filename) == -1) {
+	if (g_rename (filename, certdb->filename) == -1) {
 		i = errno;
-		unlink (filename);
+		g_unlink (filename);
 		errno = i;
 		return -1;
@@ -403,5 +403,5 @@ camel_certdb_save (CamelCertDB *certdb)
 	i = errno;
 	fclose (out);
-	unlink (filename);
+	g_unlink (filename);
 	errno = i;
 	
Index: camel-data-cache.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-data-cache.c,v
retrieving revision 1.17
diff -p -u -2 -r1.17 camel-data-cache.c
--- camel-data-cache.c	31 Aug 2005 04:21:56 -0000	1.17
+++ camel-data-cache.c	30 Nov 2005 01:13:09 -0000
@@ -27,5 +27,4 @@
 #include <sys/types.h>
 #include <ctype.h>
-#include <dirent.h>
 #include <errno.h>
 #include <string.h>
@@ -35,4 +34,6 @@
 #endif
 
+#include <glib/gstdio.h>
+
 #include "camel-i18n.h"
 #include "camel-data-cache.h"
@@ -191,27 +192,27 @@ static void
 data_cache_expire(CamelDataCache *cdc, const char *path, const char *keep, time_t now)
 {
-	DIR *dir;
-	struct dirent *d;
+	GDir *dir;
+	const char *dname;
 	GString *s;
 	struct stat st;
 	CamelStream *stream;
 
-	dir = opendir(path);
+	dir = g_dir_open(path, 0, NULL);
 	if (dir == NULL)
 		return;
 
 	s = g_string_new("");
-	while ( (d = readdir(dir)) ) {
-		if (strcmp(d->d_name, keep) == 0)
+	while ( (dname = g_dir_read_name(dir)) ) {
+		if (strcmp(dname, keep) == 0)
 			continue;
 		
-		g_string_printf (s, "%s/%s", path, d->d_name);
+		g_string_printf (s, "%s/%s", path, dname);
 		dd(printf("Checking '%s' for expiry\n", s->str));
-		if (stat(s->str, &st) == 0
+		if (g_stat(s->str, &st) == 0
 		    && S_ISREG(st.st_mode)
 		    && ((cdc->expire_age != -1 && st.st_mtime + cdc->expire_age < now)
 			|| (cdc->expire_access != -1 && st.st_atime + cdc->expire_access < now))) {
 			dd(printf("Has expired!  Removing!\n"));
-			unlink(s->str);
+			g_unlink(s->str);
 			stream = camel_object_bag_get(cdc->priv->busy_bag, s->str);
 			if (stream) {
@@ -222,5 +223,5 @@ data_cache_expire(CamelDataCache *cdc, c
 	}
 	g_string_free(s, TRUE);
-	closedir(dir);
+	g_dir_close(dir);
 }
 
@@ -239,5 +240,5 @@ data_cache_path(CamelDataCache *cdc, int
 	dir = alloca(strlen(cdc->path) + strlen(path) + 8);
 	sprintf(dir, "%s/%s/%02x", cdc->path, path, hash);
-	if (access(dir, F_OK) == -1) {
+	if (g_access(dir, F_OK) == -1) {
 		if (create)
 			camel_mkdir (dir, 0700);
@@ -295,5 +296,5 @@ camel_data_cache_add(CamelDataCache *cdc
 		stream = camel_object_bag_reserve(cdc->priv->busy_bag, real);
 		if (stream) {
-			unlink(real);
+			g_unlink(real);
 			camel_object_bag_remove(cdc->priv->busy_bag, stream);
 			camel_object_unref(stream);
@@ -372,5 +373,5 @@ camel_data_cache_remove(CamelDataCache *
 
 	/* maybe we were a mem stream */
-	if (unlink (real) == -1 && errno != ENOENT) {
+	if (g_unlink (real) == -1 && errno != ENOENT) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Could not remove cache entry: %s: %s"),
Index: camel-disco-diary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-disco-diary.c,v
retrieving revision 1.12
diff -p -u -2 -r1.12 camel-disco-diary.c
--- camel-disco-diary.c	31 Aug 2005 04:21:56 -0000	1.12
+++ camel-disco-diary.c	30 Nov 2005 01:13:09 -0000
@@ -30,4 +30,6 @@
 #include <errno.h>
 
+#include <glib/gstdio.h>
+
 #include "camel-i18n.h"
 #include "camel-disco-diary.h"
@@ -430,5 +432,5 @@ camel_disco_diary_new (CamelDiscoStore *
 	*/
 
-	diary->file = fopen (filename, "a+");
+	diary->file = g_fopen (filename, "a+b");
 	if (!diary->file) {
 		camel_object_unref (diary);
Index: camel-folder-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.c,v
retrieving revision 1.145
diff -p -u -2 -r1.145 camel-folder-summary.c
--- camel-folder-summary.c	11 Oct 2005 10:52:00 -0000	1.145
+++ camel-folder-summary.c	30 Nov 2005 01:13:12 -0000
@@ -34,31 +34,26 @@
 #include <ctype.h>
 
-#include <libedataserver/e-iconv.h>
+#include "libedataserver/e-iconv.h"
 
-#include "camel-folder-summary.h"
-
-/* for change events, perhaps we should just do them ourselves */
 #include "camel-folder.h"
-
-#include <camel/camel-file-utils.h>
-#include <camel/camel-mime-filter.h>
-#include <camel/camel-mime-filter-index.h>
-#include <camel/camel-mime-filter-charset.h>
-#include <camel/camel-mime-filter-basic.h>
-#include <camel/camel-mime-filter-html.h>
-#include <camel/camel-mime-message.h>
-#include <camel/camel-multipart.h>
-#include <camel/camel-stream-mem.h>
-
-#include <camel/camel-stream-null.h>
-#include <camel/camel-stream-filter.h>
-
-#include <camel/camel-string-utils.h>
+#include "camel-folder-summary.h"
+#include "camel-file-utils.h"
+#include "camel-mime-filter.h"
+#include "camel-mime-filter-index.h"
+#include "camel-mime-filter-charset.h"
+#include "camel-mime-filter-basic.h"
+#include "camel-mime-filter-html.h"
+#include "camel-mime-message.h"
+#include "camel-multipart.h"
+#include "camel-private.h"
+#include "camel-stream-mem.h"
+#include "camel-stream-null.h"
+#include "camel-stream-filter.h"
+#include "camel-string-utils.h"
 
 #include "libedataserver/md5-utils.h"
 #include "libedataserver/e-memory.h"
 
-#include "camel-private.h"
-
+#include <glib/gstdio.h>
 
 static pthread_mutex_t info_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -553,5 +548,5 @@ camel_folder_summary_load(CamelFolderSum
 		return 0;
 
-	in = fopen(s->summary_path, "r");
+	in = g_fopen(s->summary_path, "rb");
 	if (in == NULL)
 		return -1;
@@ -649,11 +644,11 @@ 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 = g_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;
-		unlink(path);
+		g_unlink(path);
 		close(fd);
 		errno = i;
@@ -689,7 +684,10 @@ camel_folder_summary_save(CamelFolderSum
 	CAMEL_SUMMARY_UNLOCK(s, io_lock);
 	
-	if (rename(path, s->summary_path) == -1) {
+#ifdef G_OS_WIN32
+	g_unlink(s->summary_path);
+#endif
+	if (g_rename(path, s->summary_path) == -1) {
 		i = errno;
-		unlink(path);
+		g_unlink(path);
 		errno = i;
 		return -1;
@@ -707,5 +705,5 @@ camel_folder_summary_save(CamelFolderSum
 	CAMEL_SUMMARY_UNLOCK(s, io_lock);
 	
-	unlink (path);
+	g_unlink (path);
 	errno = i;
 	
@@ -733,5 +731,5 @@ camel_folder_summary_header_load(CamelFo
 		return 0;
 
-	in = fopen(s->summary_path, "r");
+	in = g_fopen(s->summary_path, "rb");
 	if (in == NULL)
 		return -1;
Index: camel-mime-parser.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-mime-parser.c,v
retrieving revision 1.66
diff -p -u -2 -r1.66 camel-mime-parser.c
--- camel-mime-parser.c	31 Aug 2005 04:21:56 -0000	1.66
+++ camel-mime-parser.c	30 Nov 2005 01:13:13 -0000
@@ -29,5 +29,4 @@
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
 
@@ -37,15 +36,14 @@
 #include <errno.h>
 
-#include <regex.h>
-#include <ctype.h>
-
 #include <glib.h>
+
+#include "libedataserver/e-memory.h"
+
+#include "camel-mime-filter.h"
 #include "camel-mime-parser.h"
 #include "camel-mime-utils.h"
-#include "camel-mime-filter.h"
-#include "camel-stream.h"
+#include "camel-private.h"
 #include "camel-seekable-stream.h"
-
-#include "libedataserver/e-memory.h"
+#include "camel-stream.h"
 
 #define r(x) 
@@ -1629,7 +1627,7 @@ tail_recurse:
 					/*g_warning("Multipart with no boundary, treating as text/plain");*/
 				}
-			} else if (!strcasecmp(ct->type, "message")) {
-				if (!strcasecmp(ct->subtype, "rfc822")
-				    || !strcasecmp(ct->subtype, "news")
+			} else if (!g_ascii_strcasecmp(ct->type, "message")) {
+				if (!g_ascii_strcasecmp(ct->subtype, "rfc822")
+				    || !g_ascii_strcasecmp(ct->subtype, "news")
 				    /*|| !g_ascii_strcasecmp(ct->subtype, "partial")*/) {
 					type = CAMEL_MIME_PARSER_STATE_MESSAGE;
@@ -1834,5 +1832,5 @@ int main(int argc, char **argv)
 		printf("opening: %s", name);
 		
-		fd = open(name, O_RDONLY);
+		fd = g_open(name, O_RDONLY|O_BINARY, 0);
 		if (fd==-1) {
 			perror("Cannot open mailbox");
@@ -1867,5 +1865,5 @@ int main(int argc, char **argv)
 				encoding = camel_header_raw_find(&s->parts->headers, "Content-transfer-encoding", 0);
 				printf("encoding = '%s'\n", encoding);
-				if (encoding && !strncasecmp(encoding, " base64", 7)) {
+				if (encoding && !g_ascii_strncasecmp(encoding, " base64", 7)) {
 					printf("adding base64 filter\n");
 					attachname = g_strdup_printf("attach.%d.%d", i, attach++);
@@ -1878,5 +1876,5 @@ int main(int argc, char **argv)
 #endif
 				}
-				if (encoding && !strncasecmp(encoding, " quoted-printable", 17)) {
+				if (encoding && !g_ascii_strncasecmp(encoding, " quoted-printable", 17)) {
 					printf("adding quoted-printable filter\n");
 					attachname = g_strdup_printf("attach.%d.%d", i, attach++);
@@ -1896,5 +1894,5 @@ int main(int argc, char **argv)
 			case CAMEL_MIME_PARSER_STATE_BODY_END:
 				printf("end body %d '%.*s'\n",  len, len, data);
-				if (encoding && !strncasecmp(encoding, " base64", 7)) {
+				if (encoding && !g_ascii_strncasecmp(encoding, " base64", 7)) {
 					printf("removing filters\n");
 #if 0
@@ -1903,5 +1901,5 @@ int main(int argc, char **argv)
 #endif
 				}
-				if (encoding && !strncasecmp(encoding, " quoted-printable", 17)) {
+				if (encoding && !g_ascii_strncasecmp(encoding, " quoted-printable", 17)) {
 					printf("removing filters\n");
 #if 0
Index: camel-offline-journal.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-offline-journal.c,v
retrieving revision 1.5
diff -p -u -2 -r1.5 camel-offline-journal.c
--- camel-offline-journal.c	31 Aug 2005 04:21:56 -0000	1.5
+++ camel-offline-journal.c	30 Nov 2005 01:13:13 -0000
@@ -35,12 +35,13 @@
 #include <errno.h>
 
-#include <camel/camel-i18n.h>
-#include <camel/camel-folder.h>
-#include <camel/camel-file-utils.h>
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-data-cache.h>
+#include <glib/gstdio.h>
 
+#include "camel-data-cache.h"
+#include "camel-file-utils.h"
+#include "camel-folder-summary.h"
+#include "camel-folder.h"
+#include "camel-i18n.h"
 #include "camel-offline-journal.h"
-
+#include "camel-private.h"
 
 #define d(x) x
@@ -116,5 +117,5 @@ camel_offline_journal_construct (CamelOf
 	journal->folder = folder;
 	
-	if ((fp = fopen (filename, "r"))) {
+	if ((fp = g_fopen (filename, "rb"))) {
 		while ((entry = CAMEL_OFFLINE_JOURNAL_GET_CLASS (journal)->entry_load (journal, fp)))
 			e_dlist_addtail (&journal->queue, entry);
@@ -158,5 +159,5 @@ camel_offline_journal_write (CamelOfflin
 	int fd;
 	
-	if ((fd = open (journal->filename, O_CREAT | O_TRUNC | O_WRONLY, 0666)) == -1) {
+	if ((fd = g_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-provider.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-provider.c,v
retrieving revision 1.40
diff -p -u -2 -r1.40 camel-provider.c
--- camel-provider.c	15 Nov 2005 15:21:34 -0000	1.40
+++ camel-provider.c	30 Nov 2005 01:13:13 -0000
@@ -31,17 +31,20 @@
 
 #include <sys/types.h>
-#include <dirent.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
+#include <glib.h>
+#include <glib/gstdio.h>
 #include <gmodule.h>
 
-#include "camel-provider.h"
+#include "libedataserver/e-msgport.h"
+
 #include "camel-exception.h"
+#include "camel-i18n.h"
+#include "camel-provider.h"
 #include "camel-string-utils.h"
 #include "camel-vee-store.h"
-#include "libedataserver/e-msgport.h"
-#include "camel-i18n.h"
+#include "camel-private.h"
 
 /* table of CamelProviderModule's */
@@ -101,6 +104,6 @@ void
 camel_provider_init (void)
 {
-	DIR *dir;
-	struct dirent *d;
+	GDir *dir;
+	const char *entry;
 	char *p, *name, buf[80];
 	CamelProviderModule *m;
@@ -114,5 +117,5 @@ camel_provider_init (void)
 	loaded = 1;
 
-	dir = opendir (CAMEL_PROVIDERDIR);
+	dir = g_dir_open (CAMEL_PROVIDERDIR, 0, NULL);
 	if (!dir) {
 		g_warning("Could not open camel provider directory (%s): %s",
@@ -121,13 +124,13 @@ camel_provider_init (void)
 	}
 	
-	while ((d = readdir (dir))) {
+	while ((entry = g_dir_read_name (dir))) {
 		FILE *fp;
 		
-		p = strrchr (d->d_name, '.');
+		p = strrchr (entry, '.');
 		if (!p || strcmp (p, ".urls") != 0)
 			continue;
 		
-		name = g_strdup_printf ("%s/%s", CAMEL_PROVIDERDIR, d->d_name);
-		fp = fopen (name, "r");
+		name = g_strdup_printf ("%s/%s", CAMEL_PROVIDERDIR, entry);
+		fp = g_fopen (name, "r");
 		if (!fp) {
 			g_warning ("Could not read provider info file %s: %s",
@@ -138,5 +141,5 @@ camel_provider_init (void)
 		
 		p = strrchr (name, '.');
-		strcpy (p, ".so");
+		strcpy (p, "." G_MODULE_SUFFIX);
 
 		m = g_malloc0(sizeof(*m));
@@ -160,5 +163,5 @@ camel_provider_init (void)
 	}
 
-	closedir (dir);
+	g_dir_close (dir);
 }
 
Index: camel-session.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-session.c,v
retrieving revision 1.110
diff -p -u -2 -r1.110 camel-session.c
--- camel-session.c	31 Aug 2005 04:21:56 -0000	1.110
+++ camel-session.c	30 Nov 2005 01:13:14 -0000
@@ -35,14 +35,15 @@
 #include <errno.h>
 
-#include "camel-session.h"
-#include "camel-store.h"
-#include "camel-transport.h"
+#include <glib/gstdio.h>
+
 #include "camel-exception.h"
 #include "camel-file-utils.h"
-#include "camel-string-utils.h"
-#include "camel-url.h"
 #include "camel-i18n.h"
-
 #include "camel-private.h"
+#include "camel-session.h"
+#include "camel-store.h"
+#include "camel-string-utils.h"
+#include "camel-transport.h"
+#include "camel-url.h"
 
 #define d(x)
@@ -278,5 +279,5 @@ get_storage_path (CamelSession *session,
 	g_free (p);
 
-	if (access (path, F_OK) == 0)
+	if (g_access (path, F_OK) == 0)
 		return path;
 
@@ -555,5 +556,5 @@ static void session_thread_wait(CamelSes
 		CAMEL_SESSION_UNLOCK(session, thread_lock);
 		if (wait) {
-			usleep(20000);
+			g_usleep(20000);
 		}
 	} while (wait);
Index: camel-store-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-store-summary.c,v
retrieving revision 1.14
diff -p -u -2 -r1.14 camel-store-summary.c
--- camel-store-summary.c	31 Aug 2005 04:21:56 -0000	1.14
+++ camel-store-summary.c	30 Nov 2005 01:13:14 -0000
@@ -33,12 +33,12 @@
 #include <errno.h>
 
-#include "camel-store-summary.h"
-
-#include "camel-file-utils.h"
+#include <glib/gstdio.h>
 
 #include "libedataserver/md5-utils.h"
 #include "libedataserver/e-memory.h"
 
+#include "camel-file-utils.h"
 #include "camel-private.h"
+#include "camel-store-summary.h"
 #include "camel-url.h"
 
@@ -367,5 +367,5 @@ camel_store_summary_load(CamelStoreSumma
 	g_assert(s->summary_path);
 
-	in = fopen(s->summary_path, "r");
+	in = g_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 = g_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 = g_fopen(s->summary_path, "rb");
 	if (in == NULL)
 		return -1;
Index: camel-stream-fs.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-stream-fs.c,v
retrieving revision 1.69
diff -p -u -2 -r1.69 camel-stream-fs.c
--- camel-stream-fs.c	31 Aug 2005 04:21:56 -0000	1.69
+++ camel-stream-fs.c	30 Nov 2005 01:13:15 -0000
@@ -30,10 +30,12 @@
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 
+#include <glib/gstdio.h>
+
 #include "camel-file-utils.h"
 #include "camel-operation.h"
+#include "camel-private.h"
 #include "camel-stream-fs.h"
 
@@ -173,5 +175,5 @@ camel_stream_fs_new_with_name (const cha
 	int fd;
 
-	fd = open (name, flags, mode);
+	fd = g_open (name, flags|O_BINARY, mode);
 	if (fd == -1) {
 		return NULL;
Index: camel-text-index.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-text-index.c,v
retrieving revision 1.23
diff -p -u -2 -r1.23 camel-text-index.c
--- camel-text-index.c	31 Aug 2005 04:21:56 -0000	1.23
+++ camel-text-index.c	30 Nov 2005 01:13:16 -0000
@@ -34,14 +34,15 @@
 #include <ctype.h>
 
+#include <glib.h>
+#include <glib/gstdio.h>
+
 #include "libedataserver/e-msgport.h"
 #include "libedataserver/e-memory.h"
 
-#include "camel/camel-object.h"
-
-#include "camel-text-index.h"
 #include "camel-block-file.h"
+#include "camel-object.h"
 #include "camel-partition-table.h"
-
-#include <glib/gunicode.h>
+#include "camel-private.h"
+#include "camel-text-index.h"
 
 
@@ -514,7 +515,7 @@ fail:
 	/* clean up temp files always */
 	sprintf(savepath, "%s~.index", oldpath);
-	unlink(savepath);
+	g_unlink(savepath);
 	sprintf(newpath, "%s.data", savepath);
-	unlink(newpath);
+	g_unlink(newpath);
 
 	return ret;
@@ -933,5 +934,5 @@ camel_text_index_rename(const char *old,
 	sprintf(newname, "%s.index", new);
 
-	if (rename(oldname, newname) == -1 && errno != ENOENT)
+	if (g_rename(oldname, newname) == -1 && errno != ENOENT)
 		return -1;
 
@@ -939,9 +940,9 @@ camel_text_index_rename(const char *old,
 	sprintf(newname, "%s.index.data", new);
 
-	if (rename(oldname, newname) == -1 && errno != ENOENT) {
+	if (g_rename(oldname, newname) == -1 && errno != ENOENT) {
 		err = errno;
 		sprintf(oldname, "%s.index", old);
 		sprintf(newname, "%s.index", new);
-		rename(newname, oldname);
+		g_rename(newname, oldname);
 		errno = err;
 		return -1;
@@ -964,7 +965,7 @@ camel_text_index_remove(const char *old)
 	sprintf(key, "%s.index.data", old);
 
-	if (unlink(block) == -1 && errno != ENOENT)
+	if (g_unlink(block) == -1 && errno != ENOENT)
 		ret = -1;
-	if (unlink(key) == -1 && errno != ENOENT)
+	if (g_unlink(key) == -1 && errno != ENOENT)
 		ret = -1;
 
@@ -1091,5 +1092,5 @@ dump_raw(GHashTable *map, char *path)
 	camel_block_t id, total;
 
-	fd = open(path, O_RDONLY);
+	fd = g_open(path, O_RDONLY|O_BINARY, 0);
 	if (fd == -1)
 		return;
Index: camel-uid-cache.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-uid-cache.c,v
retrieving revision 1.15
diff -p -u -2 -r1.15 camel-uid-cache.c
--- camel-uid-cache.c	31 Aug 2005 04:21:56 -0000	1.15
+++ camel-uid-cache.c	30 Nov 2005 01:13:16 -0000
@@ -33,6 +33,9 @@
 #include <unistd.h>
 
-#include "camel-uid-cache.h"
+#include <glib/gstdio.h>
+
 #include "camel-file-utils.h"
+#include "camel-private.h"
+#include "camel-uid-cache.h"
 
 struct _uid_state {
@@ -68,5 +71,5 @@ camel_uid_cache_new (const char *filenam
 	g_free (dirname);
 	
-	if ((fd = open (filename, O_RDONLY | O_CREAT, 0666)) == -1)
+	if ((fd = g_open (filename, O_RDONLY | O_CREAT | O_BINARY, 0666)) == -1)
 		return NULL;
 	
@@ -154,5 +157,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 = g_open (filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666)) == -1) {
 		g_free (filename);
 		return FALSE;
@@ -173,5 +176,5 @@ camel_uid_cache_save (CamelUIDCache *cac
 	fd = -1;
 	
-	if (rename (filename, cache->filename) == -1)
+	if (g_rename (filename, cache->filename) == -1)
 		goto exception;
 	
@@ -201,5 +204,5 @@ camel_uid_cache_save (CamelUIDCache *cac
 		 **/
 		
-		if (stat (cache->filename, &st) == 0 &&
+		if (g_stat (cache->filename, &st) == 0 &&
 		    (cache->size > st.st_size || cache->size + cache->expired > st.st_size)) {
 			if (ftruncate (fd, (off_t) cache->size) != -1) {
@@ -214,5 +217,5 @@ camel_uid_cache_save (CamelUIDCache *cac
 #endif
 	
-	unlink (filename);
+	g_unlink (filename);
 	g_free (filename);
 	
Index: camel-vee-store.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-vee-store.c,v
retrieving revision 1.39
diff -p -u -2 -r1.39 camel-vee-store.c
--- camel-vee-store.c	31 Aug 2005 04:21:56 -0000	1.39
+++ camel-vee-store.c	30 Nov 2005 01:13:17 -0000
@@ -23,12 +23,13 @@
 #endif
 
-#include "camel-exception.h"
-#include "camel-vee-store.h"
-#include "camel-vee-folder.h"
+#include <string.h>
 
-#include "camel-private.h"
-#include "camel-i18n.h"
+#include <glib/gstdio.h>
 
-#include <string.h>
+#include "camel-exception.h"
+#include "camel-i18n.h"
+#include "camel-private.h"
+#include "camel-vee-folder.h"
+#include "camel-vee-store.h"
 
 #define d(x)
@@ -375,5 +376,5 @@ vee_delete_folder(CamelStore *store, con
 		camel_object_get(folder, NULL, CAMEL_OBJECT_STATE_FILE, &statefile, NULL);
 		if (statefile) {
-			unlink(statefile);
+			g_unlink(statefile);
 			camel_object_free(folder, CAMEL_OBJECT_STATE_FILE, statefile);
 			camel_object_set(folder, NULL, CAMEL_OBJECT_STATE_FILE, NULL, NULL);
Index: camel-utf8.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-utf8.c,v
retrieving revision 1.8
diff -p -u -2 -r1.8 camel-utf8.c
--- camel-utf8.c	31 Aug 2005 04:21:56 -0000	1.8
+++ camel-utf8.c	30 Nov 2005 01:13:17 -0000
@@ -30,7 +30,6 @@
 
 #include <glib.h>
-#include "camel-utf8.h"
 
-#include <netinet/in.h>
+#include "camel-utf8.h"
 
 /**
@@ -363,5 +362,5 @@ camel_utf8_ucs2(const char *ptr)
 
 	while ( (c = camel_utf8_getc((const unsigned char **)&ptr)) ) {
-		guint16 s = htons(c);
+		guint16 s = g_htons(c);
 
 		g_byte_array_append(work, (char *)&s, 2);
@@ -393,5 +392,5 @@ char *camel_ucs2_utf8(const char *ptr)
 
 	while ( (c = *ucs++) )
-		g_string_append_u(work, ntohs(c));
+		g_string_append_u(work, g_ntohs(c));
 
 	out = g_strdup(work->str);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]