Commit 2fc159a7 authored by Ross Lagerwall's avatar Ross Lagerwall

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.

https://bugzilla.gnome.org/show_bug.cgi?id=738967
parent fcd88e9e
......@@ -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;
......
......@@ -876,18 +876,8 @@ 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"));
......@@ -1365,18 +1355,8 @@ 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"));
......
......@@ -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);
......
......@@ -215,3 +215,25 @@ gvfs_file_info_populate_content_types (GFileInfo *info,
g_free (free_mimetype);
}
/**
* 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;
}
}
......@@ -40,6 +40,8 @@ void gvfs_file_info_populate_content_types (GFileInfo *info,
const char *basename,
GFileType type);
int gvfs_seek_type_to_lseek (GSeekType type);
G_END_DECLS
#endif /* __G_VFS_DAEMON_UTILS_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment