* Author: Alexander Larsson <alexl@redhat.com>
*/
-#include <config.h>
+#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
+#include "gcancellable.h"
#include "gioerror.h"
#include "glocalfileinputstream.h"
#include "glocalfileinfo.h"
#include "glibintl.h"
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
+
#include "gioalias.h"
#define g_local_file_input_stream_get_type _g_local_file_input_stream_get_type
struct _GLocalFileInputStreamPrivate {
int fd;
+ guint do_close : 1;
};
static gssize g_local_file_input_stream_read (GInputStream *stream,
GCancellable *cancellable,
GError **error);
static GFileInfo *g_local_file_input_stream_query_info (GFileInputStream *stream,
- char *attributes,
+ const char *attributes,
GCancellable *cancellable,
GError **error);
GLocalFileInputStream *file;
file = G_LOCAL_FILE_INPUT_STREAM (object);
-
- if (G_OBJECT_CLASS (g_local_file_input_stream_parent_class)->finalize)
- (*G_OBJECT_CLASS (g_local_file_input_stream_parent_class)->finalize) (object);
+
+ G_OBJECT_CLASS (g_local_file_input_stream_parent_class)->finalize (object);
+}
+
+void
+_g_local_file_input_stream_set_do_close (GLocalFileInputStream *in,
+ gboolean do_close)
+{
+ in->priv->do_close = do_close;
}
static void
gobject_class->finalize = g_local_file_input_stream_finalize;
- stream_class->read = g_local_file_input_stream_read;
+ stream_class->read_fn = g_local_file_input_stream_read;
stream_class->skip = g_local_file_input_stream_skip;
- stream_class->close = g_local_file_input_stream_close;
+ stream_class->close_fn = g_local_file_input_stream_close;
file_stream_class->tell = g_local_file_input_stream_tell;
file_stream_class->can_seek = g_local_file_input_stream_can_seek;
file_stream_class->seek = g_local_file_input_stream_seek;
info->priv = G_TYPE_INSTANCE_GET_PRIVATE (info,
G_TYPE_LOCAL_FILE_INPUT_STREAM,
GLocalFileInputStreamPrivate);
+ info->priv->do_close = TRUE;
}
/**
res = read (file->priv->fd, buffer, count);
if (res == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error reading from file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
start = lseek (file->priv->fd, 0, SEEK_CUR);
if (start == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return -1;
}
res = lseek (file->priv->fd, count, SEEK_CUR);
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return -1;
}
file = G_LOCAL_FILE_INPUT_STREAM (stream);
+ if (!file->priv->do_close)
+ return TRUE;
+
if (file->priv->fd == -1)
return TRUE;
{
res = close (file->priv->fd);
if (res == -1)
- g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
- _("Error closing file: %s"),
- g_strerror (errno));
+ {
+ int errsv = errno;
+
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ _("Error closing file: %s"),
+ g_strerror (errsv));
+ }
break;
}
pos = lseek (file->priv->fd, 0, SEEK_CUR);
- if (pos == (off_t)-1 &&
- errno == ESPIPE)
+ if (pos == (off_t)-1 && errno == ESPIPE)
return FALSE;
return TRUE;
if (pos == (off_t)-1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
static GFileInfo *
g_local_file_input_stream_query_info (GFileInputStream *stream,
- char *attributes,
+ const char *attributes,
GCancellable *cancellable,
GError **error)
{