aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-stream-fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/camel-stream-fs.c')
-rw-r--r--camel/camel-stream-fs.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c
index 0a42e5062f..c7335f9821 100644
--- a/camel/camel-stream-fs.c
+++ b/camel/camel-stream-fs.c
@@ -27,6 +27,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
+#include "camel-log.h"
static CamelStreamClass *parent_class=NULL;
@@ -95,21 +96,27 @@ camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode)
int flags;
CamelStreamFs *stream_fs;
- if (!name) return NULL;
-
+ g_assert (name);
+ g_assert (name->str);
+ CAMEL_LOG (FULL_DEBUG, "Entering CamelStream::new_with_name, name=\"%s\", mode=%d\n", name->str, mode);
v = stat (name->str, &s);
-
+
if (mode & CAMEL_STREAM_FS_READ)
- if (mode & CAMEL_STREAM_FS_WRITE) flags = O_RDWR;
+ if (mode & CAMEL_STREAM_FS_WRITE) flags = O_RDWR | O_CREAT;
else flags = O_RDONLY;
else
- if (mode & CAMEL_STREAM_FS_WRITE) flags = O_WRONLY;
+ if (mode & CAMEL_STREAM_FS_WRITE) flags = O_WRONLY | O_CREAT;
else return NULL;
- if (mode & CAMEL_STREAM_FS_READ)
+ if ( (mode & CAMEL_STREAM_FS_READ) && !(mode & CAMEL_STREAM_FS_WRITE) )
if (v == -1) return NULL;
fd = open (name->str, flags);
+ if (fd==-1) {
+ CAMEL_LOG (FULL_DEBUG, "CamelStreamFs::new_with_name can not obtain fd for file \"%s\"\n", name->str);
+ CAMEL_LOG (FULL_DEBUG, " Full error text is : %s\n", strerror(errno));
+ return NULL;
+ }
stream_fs = CAMEL_STREAM_FS (camel_stream_fs_new_with_fd (fd));
stream_fs->name = name;
@@ -123,6 +130,7 @@ camel_stream_fs_new_with_fd (int fd)
{
CamelStreamFs *stream_fs;
+ CAMEL_LOG (FULL_DEBUG, "Entering CamelStream::new_with_fd fd=%d\n",fd);
stream_fs = gtk_type_new (camel_stream_fs_get_type ());
stream_fs->fd = fd;
return CAMEL_STREAM (stream_fs);
@@ -166,11 +174,19 @@ static gint
_write (CamelStream *stream, gchar *buffer, gint n)
{
int v;
-
+ g_assert (stream);
+ g_assert ((CAMEL_STREAM_FS (stream))->fd);
+ CAMEL_LOG (FULL_DEBUG, "CamelStreamFs:: entering write. n=%d\n", n);
do {
v = write ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
} while (v == -1 && errno == EINTR);
+#if HARD_LOG_LEVEL >= FULL_DEBUG
+ if (v==-1) {
+ perror("");
+ CAMEL_LOG (FULL_DEBUG, "CamelStreamFs::write could not write bytes in stream\n");
+ }
+#endif
return v;
}