2007-11-26 17:13:05 +01:00
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
2014-01-23 12:58:29 +01:00
|
|
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Author: Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-06-22 17:10:51 +02:00
|
|
|
#include "config.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gstdio.h>
|
2008-07-01 08:32:35 +02:00
|
|
|
#include "gcancellable.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
#include "gioerror.h"
|
|
|
|
#include "glocalfileinputstream.h"
|
|
|
|
#include "glocalfileinfo.h"
|
|
|
|
#include "glibintl.h"
|
|
|
|
|
2010-05-20 16:51:00 +02:00
|
|
|
#ifdef G_OS_UNIX
|
Replace #ifdef HAVE_UNISTD_H checks with #ifdef G_OS_UNIX
In Windows development environments that have it, <unistd.h> is mostly
just a wrapper around several other native headers (in particular,
<io.h>, which contains read(), close(), etc, and <process.h>, which
contains getpid()). But given that some Windows dev environments don't
have <unistd.h>, everything that uses those functions on Windows
already needed to include the correct Windows header as well, and so
there is never any point to including <unistd.h> on Windows.
Also, remove some <unistd.h> includes (and a few others) that were
unnecessary even on unix.
https://bugzilla.gnome.org/show_bug.cgi?id=710519
2013-10-19 19:04:00 +02:00
|
|
|
#include <unistd.h>
|
2013-01-25 18:05:26 +01:00
|
|
|
#include "glib-unix.h"
|
2010-05-20 16:51:00 +02:00
|
|
|
#include "gfiledescriptorbased.h"
|
|
|
|
#endif
|
|
|
|
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
2013-06-11 01:29:58 +02:00
|
|
|
struct _GLocalFileInputStreamPrivate {
|
|
|
|
int fd;
|
|
|
|
guint do_close : 1;
|
|
|
|
};
|
2010-02-07 17:17:44 +01:00
|
|
|
|
2010-05-20 16:51:00 +02:00
|
|
|
#ifdef G_OS_UNIX
|
2010-02-07 17:17:44 +01:00
|
|
|
static void g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface);
|
2010-05-20 16:51:00 +02:00
|
|
|
#endif
|
|
|
|
|
2007-11-28 17:01:59 +01:00
|
|
|
#define g_local_file_input_stream_get_type _g_local_file_input_stream_get_type
|
2010-05-20 16:51:00 +02:00
|
|
|
#ifdef G_OS_UNIX
|
2010-06-22 11:13:21 +02:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GLocalFileInputStream, g_local_file_input_stream, G_TYPE_FILE_INPUT_STREAM,
|
2013-06-11 01:29:58 +02:00
|
|
|
G_ADD_PRIVATE (GLocalFileInputStream)
|
2010-02-07 17:17:44 +01:00
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED,
|
2013-06-11 01:29:58 +02:00
|
|
|
g_file_descriptor_based_iface_init))
|
2010-06-22 11:13:21 +02:00
|
|
|
#else
|
2013-06-11 01:29:58 +02:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GLocalFileInputStream, g_local_file_input_stream, G_TYPE_FILE_INPUT_STREAM,
|
|
|
|
G_ADD_PRIVATE (GLocalFileInputStream))
|
2010-06-22 11:13:21 +02:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
static gssize g_local_file_input_stream_read (GInputStream *stream,
|
|
|
|
void *buffer,
|
|
|
|
gsize count,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error);
|
|
|
|
static gssize g_local_file_input_stream_skip (GInputStream *stream,
|
|
|
|
gsize count,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error);
|
|
|
|
static gboolean g_local_file_input_stream_close (GInputStream *stream,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error);
|
|
|
|
static goffset g_local_file_input_stream_tell (GFileInputStream *stream);
|
|
|
|
static gboolean g_local_file_input_stream_can_seek (GFileInputStream *stream);
|
|
|
|
static gboolean g_local_file_input_stream_seek (GFileInputStream *stream,
|
|
|
|
goffset offset,
|
|
|
|
GSeekType type,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error);
|
|
|
|
static GFileInfo *g_local_file_input_stream_query_info (GFileInputStream *stream,
|
2009-03-17 12:21:37 +01:00
|
|
|
const char *attributes,
|
2007-11-26 17:13:05 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error);
|
2010-05-20 16:51:00 +02:00
|
|
|
#ifdef G_OS_UNIX
|
2010-02-07 17:17:44 +01:00
|
|
|
static int g_local_file_input_stream_get_fd (GFileDescriptorBased *stream);
|
2010-05-20 16:51:00 +02:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2009-05-13 13:03:47 +02:00
|
|
|
void
|
|
|
|
_g_local_file_input_stream_set_do_close (GLocalFileInputStream *in,
|
|
|
|
gboolean do_close)
|
|
|
|
{
|
|
|
|
in->priv->do_close = do_close;
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static void
|
|
|
|
g_local_file_input_stream_class_init (GLocalFileInputStreamClass *klass)
|
|
|
|
{
|
|
|
|
GInputStreamClass *stream_class = G_INPUT_STREAM_CLASS (klass);
|
|
|
|
GFileInputStreamClass *file_stream_class = G_FILE_INPUT_STREAM_CLASS (klass);
|
|
|
|
|
2007-12-05 11:38:03 +01:00
|
|
|
stream_class->read_fn = g_local_file_input_stream_read;
|
2007-11-26 17:13:05 +01:00
|
|
|
stream_class->skip = g_local_file_input_stream_skip;
|
2007-12-05 11:38:03 +01:00
|
|
|
stream_class->close_fn = g_local_file_input_stream_close;
|
2007-11-26 17:13:05 +01:00
|
|
|
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;
|
|
|
|
file_stream_class->query_info = g_local_file_input_stream_query_info;
|
|
|
|
}
|
|
|
|
|
2010-05-20 16:51:00 +02:00
|
|
|
#ifdef G_OS_UNIX
|
2010-02-07 17:17:44 +01:00
|
|
|
static void
|
|
|
|
g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_fd = g_local_file_input_stream_get_fd;
|
|
|
|
}
|
2010-05-20 16:51:00 +02:00
|
|
|
#endif
|
2010-02-07 17:17:44 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static void
|
|
|
|
g_local_file_input_stream_init (GLocalFileInputStream *info)
|
|
|
|
{
|
2013-06-24 16:43:04 +02:00
|
|
|
info->priv = g_local_file_input_stream_get_instance_private (info);
|
2009-05-13 13:03:47 +02:00
|
|
|
info->priv->do_close = TRUE;
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GFileInputStream *
|
2007-11-28 17:01:59 +01:00
|
|
|
_g_local_file_input_stream_new (int fd)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GLocalFileInputStream *stream;
|
|
|
|
|
|
|
|
stream = g_object_new (G_TYPE_LOCAL_FILE_INPUT_STREAM, NULL);
|
|
|
|
stream->priv->fd = fd;
|
|
|
|
|
|
|
|
return G_FILE_INPUT_STREAM (stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gssize
|
2007-11-30 06:11:25 +01:00
|
|
|
g_local_file_input_stream_read (GInputStream *stream,
|
|
|
|
void *buffer,
|
|
|
|
gsize count,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GLocalFileInputStream *file;
|
|
|
|
gssize res;
|
|
|
|
|
|
|
|
file = G_LOCAL_FILE_INPUT_STREAM (stream);
|
|
|
|
|
|
|
|
res = -1;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
break;
|
|
|
|
res = read (file->priv->fd, buffer, count);
|
|
|
|
if (res == -1)
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
|
|
|
if (errsv == EINTR)
|
2007-11-26 17:13:05 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error reading from file: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gssize
|
2007-11-30 06:11:25 +01:00
|
|
|
g_local_file_input_stream_skip (GInputStream *stream,
|
|
|
|
gsize count,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2013-10-29 05:02:59 +01:00
|
|
|
off_t start, end;
|
2007-11-26 17:13:05 +01:00
|
|
|
GLocalFileInputStream *file;
|
|
|
|
|
|
|
|
file = G_LOCAL_FILE_INPUT_STREAM (stream);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
start = lseek (file->priv->fd, 0, SEEK_CUR);
|
|
|
|
if (start == -1)
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error seeking in file: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-29 05:02:59 +01:00
|
|
|
end = lseek (file->priv->fd, 0, SEEK_END);
|
|
|
|
if (end == -1)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error seeking in file: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-29 05:02:59 +01:00
|
|
|
if (end - start > count)
|
|
|
|
{
|
|
|
|
end = lseek (file->priv->fd, count - (end - start), SEEK_CUR);
|
|
|
|
if (end == -1)
|
|
|
|
{
|
|
|
|
int errsv = errno;
|
|
|
|
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
g_io_error_from_errno (errsv),
|
|
|
|
_("Error seeking in file: %s"),
|
|
|
|
g_strerror (errsv));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return end - start;
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
g_local_file_input_stream_close (GInputStream *stream,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GLocalFileInputStream *file;
|
|
|
|
|
|
|
|
file = G_LOCAL_FILE_INPUT_STREAM (stream);
|
|
|
|
|
2009-05-13 13:03:47 +02:00
|
|
|
if (!file->priv->do_close)
|
|
|
|
return TRUE;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (file->priv->fd == -1)
|
|
|
|
return TRUE;
|
|
|
|
|
2013-01-25 18:05:26 +01:00
|
|
|
if (!g_close (file->priv->fd, NULL))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2013-01-25 18:05:26 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
g_io_error_from_errno (errsv),
|
|
|
|
_("Error closing file: %s"),
|
|
|
|
g_strerror (errsv));
|
|
|
|
return FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
2013-01-25 18:05:26 +01:00
|
|
|
return TRUE;
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static goffset
|
|
|
|
g_local_file_input_stream_tell (GFileInputStream *stream)
|
|
|
|
{
|
|
|
|
GLocalFileInputStream *file;
|
|
|
|
off_t pos;
|
|
|
|
|
|
|
|
file = G_LOCAL_FILE_INPUT_STREAM (stream);
|
|
|
|
|
|
|
|
pos = lseek (file->priv->fd, 0, SEEK_CUR);
|
|
|
|
|
|
|
|
if (pos == (off_t)-1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_local_file_input_stream_can_seek (GFileInputStream *stream)
|
|
|
|
{
|
|
|
|
GLocalFileInputStream *file;
|
|
|
|
off_t pos;
|
|
|
|
|
|
|
|
file = G_LOCAL_FILE_INPUT_STREAM (stream);
|
|
|
|
|
|
|
|
pos = lseek (file->priv->fd, 0, SEEK_CUR);
|
|
|
|
|
2008-01-21 15:02:19 +01:00
|
|
|
if (pos == (off_t)-1 && errno == ESPIPE)
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
seek_type_to_lseek (GSeekType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case G_SEEK_CUR:
|
|
|
|
return SEEK_CUR;
|
|
|
|
|
|
|
|
case G_SEEK_SET:
|
|
|
|
return SEEK_SET;
|
|
|
|
|
|
|
|
case G_SEEK_END:
|
|
|
|
return SEEK_END;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
g_local_file_input_stream_seek (GFileInputStream *stream,
|
|
|
|
goffset offset,
|
|
|
|
GSeekType type,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GLocalFileInputStream *file;
|
|
|
|
off_t pos;
|
|
|
|
|
|
|
|
file = G_LOCAL_FILE_INPUT_STREAM (stream);
|
|
|
|
|
|
|
|
pos = lseek (file->priv->fd, offset, seek_type_to_lseek (type));
|
|
|
|
|
|
|
|
if (pos == (off_t)-1)
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error seeking in file: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileInfo *
|
2007-11-30 06:11:25 +01:00
|
|
|
g_local_file_input_stream_query_info (GFileInputStream *stream,
|
2009-03-17 12:21:37 +01:00
|
|
|
const char *attributes,
|
2007-11-30 06:11:25 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GLocalFileInputStream *file;
|
|
|
|
|
|
|
|
file = G_LOCAL_FILE_INPUT_STREAM (stream);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return _g_local_file_info_get_from_fd (file->priv->fd,
|
|
|
|
attributes,
|
|
|
|
error);
|
|
|
|
}
|
2010-02-07 17:17:44 +01:00
|
|
|
|
2010-05-20 16:51:00 +02:00
|
|
|
#ifdef G_OS_UNIX
|
2010-02-07 17:17:44 +01:00
|
|
|
static int
|
|
|
|
g_local_file_input_stream_get_fd (GFileDescriptorBased *fd_based)
|
|
|
|
{
|
|
|
|
GLocalFileInputStream *stream = G_LOCAL_FILE_INPUT_STREAM (fd_based);
|
|
|
|
return stream->priv->fd;
|
|
|
|
}
|
2010-05-20 16:51:00 +02:00
|
|
|
#endif
|