[gvfs/nfs: 2/3] daemon: Move seek type conversion to shared library
- From: Ross Lagerwall <rossl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/nfs: 2/3] daemon: Move seek type conversion to shared library
- Date: Tue, 21 Oct 2014 21:37:32 +0000 (UTC)
commit 3218e1f843efbab5564d468c38409491f38e80a7
Author: Ross Lagerwall <rosslagerwall gmail com>
Date: Sun Oct 19 09:26:02 2014 +0100
daemon: Move seek type conversion to shared library
Since converting a GSeekType into an lseek type is repeated in a few
places, move it into shared code.
daemon/gvfsbackendafc.c | 12 +-----------
daemon/gvfsbackendsmb.c | 32 ++++++--------------------------
daemon/gvfsbackendtest.c | 17 +++--------------
daemon/gvfsdaemonutils.c | 22 ++++++++++++++++++++++
daemon/gvfsdaemonutils.h | 2 ++
5 files changed, 34 insertions(+), 51 deletions(-)
---
diff --git a/daemon/gvfsbackendafc.c b/daemon/gvfsbackendafc.c
index 3c0b787..8cd8401 100644
--- a/daemon/gvfsbackendafc.c
+++ b/daemon/gvfsbackendafc.c
@@ -1341,18 +1341,8 @@ g_vfs_backend_afc_seek (GVfsBackendAfc *self,
int afc_seek_type;
FileHandle *fh;
- switch (type)
+ if ((afc_seek_type = gvfs_seek_type_to_lseek (type)) == -1)
{
- case G_SEEK_SET:
- afc_seek_type = SEEK_SET;
- break;
- case G_SEEK_CUR:
- afc_seek_type = SEEK_CUR;
- break;
- case G_SEEK_END:
- afc_seek_type = SEEK_END;
- break;
- default:
g_vfs_job_failed(job, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
_("Invalid seek type"));
return 1;
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
index ac338d7..7334ddf 100644
--- a/daemon/gvfsbackendsmb.c
+++ b/daemon/gvfsbackendsmb.c
@@ -857,21 +857,11 @@ do_seek_on_read (GVfsBackend *backend,
off_t res;
smbc_lseek_fn smbc_lseek;
- switch (type)
+ if ((whence = gvfs_seek_type_to_lseek (type)) == -1)
{
- case G_SEEK_SET:
- whence = SEEK_SET;
- break;
- case G_SEEK_CUR:
- whence = SEEK_CUR;
- break;
- case G_SEEK_END:
- whence = SEEK_END;
- break;
- default:
g_vfs_job_failed (G_VFS_JOB (job),
- G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("Unsupported seek type"));
+ G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("Unsupported seek type"));
return;
}
@@ -1346,21 +1336,11 @@ do_seek_on_write (GVfsBackend *backend,
off_t res;
smbc_lseek_fn smbc_lseek;
- switch (type)
+ if ((whence = gvfs_seek_type_to_lseek (type)) == -1)
{
- case G_SEEK_SET:
- whence = SEEK_SET;
- break;
- case G_SEEK_CUR:
- whence = SEEK_CUR;
- break;
- case G_SEEK_END:
- whence = SEEK_END;
- break;
- default:
g_vfs_job_failed (G_VFS_JOB (job),
- G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("Unsupported seek type"));
+ G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("Unsupported seek type"));
return;
}
diff --git a/daemon/gvfsbackendtest.c b/daemon/gvfsbackendtest.c
index 6a7d18e..f657766 100644
--- a/daemon/gvfsbackendtest.c
+++ b/daemon/gvfsbackendtest.c
@@ -43,6 +43,7 @@
#include "gvfsjobopenforwrite.h"
#include "gvfsjobclosewrite.h"
#include "gvfsjobqueryinfowrite.h"
+#include "gvfsdaemonutils.h"
G_DEFINE_TYPE (GVfsBackendTest, g_vfs_backend_test, G_VFS_TYPE_BACKEND)
@@ -218,20 +219,8 @@ do_seek_on_read (GVfsBackend *backend,
g_print ("seek_on_read (%d, %u)\n", (int)offset, type);
- switch (type)
- {
- default:
- case G_SEEK_SET:
- whence = SEEK_SET;
- break;
- case G_SEEK_CUR:
- whence = SEEK_CUR;
- break;
- case G_SEEK_END:
- whence = SEEK_END;
- break;
- }
-
+ if ((whence = gvfs_seek_type_to_lseek (type)) == -1)
+ whence = SEEK_SET;
fd = GPOINTER_TO_INT (handle);
diff --git a/daemon/gvfsdaemonutils.c b/daemon/gvfsdaemonutils.c
index a5f635f..50f861d 100644
--- a/daemon/gvfsdaemonutils.c
+++ b/daemon/gvfsdaemonutils.c
@@ -232,3 +232,25 @@ gvfs_randomize_string (char *str, int len)
for (i = 0; i < len; i++)
str[i] = chars[g_random_int_range (0, strlen(chars))];
}
+
+/**
+ * gvfs_seek_type_to_lseek:
+ * @type: the seek type
+ *
+ * Takes a GSeekType and converts it to an lseek type.
+ **/
+int
+gvfs_seek_type_to_lseek (GSeekType type)
+{
+ switch (type)
+ {
+ case G_SEEK_CUR:
+ return SEEK_CUR;
+ case G_SEEK_SET:
+ return SEEK_SET;
+ case G_SEEK_END:
+ return SEEK_END;
+ default:
+ return -1;
+ }
+}
diff --git a/daemon/gvfsdaemonutils.h b/daemon/gvfsdaemonutils.h
index b08d794..a586a6a 100644
--- a/daemon/gvfsdaemonutils.h
+++ b/daemon/gvfsdaemonutils.h
@@ -42,6 +42,8 @@ void gvfs_file_info_populate_content_types (GFileInfo *info,
void gvfs_randomize_string (char *str, int len);
+int gvfs_seek_type_to_lseek (GSeekType type);
+
G_END_DECLS
#endif /* __G_VFS_DAEMON_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]