diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-10-19 09:26:02 +0100 |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-10-21 22:36:42 +0100 |
commit | 3218e1f843efbab5564d468c38409491f38e80a7 (patch) | |
tree | 7cff1bfbd22615a6743f5cf7eb4dd72a098e78cd | |
parent | ca883e6a2d156c3a9cb46cc2064448ed2a06693e (diff) | |
download | gvfs-3218e1f843efbab5564d468c38409491f38e80a7.tar.gz |
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.
-rw-r--r-- | daemon/gvfsbackendafc.c | 12 | ||||
-rw-r--r-- | daemon/gvfsbackendsmb.c | 32 | ||||
-rw-r--r-- | daemon/gvfsbackendtest.c | 17 | ||||
-rw-r--r-- | daemon/gvfsdaemonutils.c | 22 | ||||
-rw-r--r-- | daemon/gvfsdaemonutils.h | 2 |
5 files changed, 34 insertions, 51 deletions
diff --git a/daemon/gvfsbackendafc.c b/daemon/gvfsbackendafc.c index 3c0b7874..8cd84011 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 ac338d76..7334ddf7 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 6a7d18e5..f6577665 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 a5f635fe..50f861da 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 b08d7946..a586a6a9 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__ */ |