From f28a4cc671f161db2698a7e17a8e7b662dbf6d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 13 May 2014 19:51:34 +0100 Subject: [PATCH] elements: don't depend on libgio just for g_io_error_from_errno() https://bugzilla.gnome.org/show_bug.cgi?id=729949 --- plugins/elements/gstdownloadbuffer.c | 13 +- plugins/elements/gstsparsefile.c | 216 ++++++++++++++++++++++++++- plugins/elements/gstsparsefile.h | 49 ++++++ 3 files changed, 268 insertions(+), 10 deletions(-) diff --git a/plugins/elements/gstdownloadbuffer.c b/plugins/elements/gstdownloadbuffer.c index a349e148b9..9b155fca83 100644 --- a/plugins/elements/gstdownloadbuffer.c +++ b/plugins/elements/gstdownloadbuffer.c @@ -60,13 +60,22 @@ #include "gstdownloadbuffer.h" #include -#include #include "gst/gst-i18n-lib.h" #include "gst/glib-compat-private.h" #include +#ifdef G_OS_WIN32 +#include /* lseek, open, close, read */ +#undef lseek +#define lseek _lseeki64 +#undef off_t +#define off_t guint64 +#else +#include +#endif + static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, @@ -778,7 +787,7 @@ gst_download_buffer_read_buffer (GstDownloadBuffer * dlbuf, guint64 offset, &remaining, &error); if (G_UNLIKELY (res == 0)) { switch (error->code) { - case G_IO_ERROR_WOULD_BLOCK: + case GST_SPARSE_FILE_IO_ERROR_WOULD_BLOCK: /* we don't have the requested data in the file, decide what to * do next. */ ret = gst_download_buffer_wait_for_data (dlbuf, offset, length); diff --git a/plugins/elements/gstsparsefile.c b/plugins/elements/gstsparsefile.c index 6941121e27..fb9b26cfe2 100644 --- a/plugins/elements/gstsparsefile.c +++ b/plugins/elements/gstsparsefile.c @@ -23,7 +23,6 @@ #include #include -#include #include "gstsparsefile.h" @@ -45,6 +44,11 @@ #define FSEEK_FILE(file,offset) (fseek (file, offset, SEEK_SET) != 0) #endif +#define GST_SPARSE_FILE_IO_ERROR \ + g_quark_from_static_string("gst-sparse-file-io-error-quark") + +static GstSparseFileIOErrorEnum +gst_sparse_file_io_error_from_errno (gint err_no); typedef struct _GstSparseRange GstSparseRange; @@ -290,8 +294,9 @@ gst_sparse_file_write (GstSparseFile * file, gsize offset, gconstpointer data, /* ERRORS */ error: { - g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - "Error writing file: %s", g_strerror (errno)); + g_set_error (error, GST_SPARSE_FILE_IO_ERROR, + gst_sparse_file_io_error_from_errno (errno), "Error writing file: %s", + g_strerror (errno)); return 0; } } @@ -308,7 +313,7 @@ error: * Read @count bytes from @file at @offset into @data. * * On error, @error will be set. If there are no @count bytes available - * at @offset, %G_IO_ERROR_WOULD_BLOCK is returned. + * at @offset, %GST_SPARSE_FILE_IO_ERROR_WOULD_BLOCK is returned. * * @remaining will be set to the amount of bytes remaining in the read * range. @@ -353,15 +358,16 @@ gst_sparse_file_read (GstSparseFile * file, gsize offset, gpointer data, /* ERRORS */ no_range: { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK, - "Offset not written to file yet"); + g_set_error_literal (error, GST_SPARSE_FILE_IO_ERROR, + GST_SPARSE_FILE_IO_ERROR_WOULD_BLOCK, "Offset not written to file yet"); return 0; } error: { if (ferror (file->file)) { - g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - "Error reading file: %s", g_strerror (errno)); + g_set_error (error, GST_SPARSE_FILE_IO_ERROR, + gst_sparse_file_io_error_from_errno (errno), "Error reading file: %s", + g_strerror (errno)); } else if (feof (file->file)) { return res; } @@ -466,3 +472,197 @@ gst_sparse_file_get_range_after (GstSparseFile * file, gsize offset, } return result != NULL; } + +/* we don't want to rely on libgio just for g_io_error_from_errno() */ +static GstSparseFileIOErrorEnum +gst_sparse_file_io_error_from_errno (gint err_no) +{ + switch (err_no) { +#ifdef EEXIST + case EEXIST: + return GST_SPARSE_FILE_IO_ERROR_EXISTS; + break; +#endif + +#ifdef EISDIR + case EISDIR: + return GST_SPARSE_FILE_IO_ERROR_IS_DIRECTORY; + break; +#endif + +#ifdef EACCES + case EACCES: + return GST_SPARSE_FILE_IO_ERROR_PERMISSION_DENIED; + break; +#endif + +#ifdef ENAMETOOLONG + case ENAMETOOLONG: + return GST_SPARSE_FILE_IO_ERROR_FILENAME_TOO_LONG; + break; +#endif + +#ifdef ENOENT + case ENOENT: + return GST_SPARSE_FILE_IO_ERROR_NOT_FOUND; + break; +#endif + +#ifdef ENOTDIR + case ENOTDIR: + return GST_SPARSE_FILE_IO_ERROR_NOT_DIRECTORY; + break; +#endif + +#ifdef EROFS + case EROFS: + return GST_SPARSE_FILE_IO_ERROR_READ_ONLY; + break; +#endif + +#ifdef ELOOP + case ELOOP: + return GST_SPARSE_FILE_IO_ERROR_TOO_MANY_LINKS; + break; +#endif + +#ifdef ENOSPC + case ENOSPC: + return GST_SPARSE_FILE_IO_ERROR_NO_SPACE; + break; +#endif + +#ifdef ENOMEM + case ENOMEM: + return GST_SPARSE_FILE_IO_ERROR_NO_SPACE; + break; +#endif + +#ifdef EINVAL + case EINVAL: + return GST_SPARSE_FILE_IO_ERROR_INVALID_ARGUMENT; + break; +#endif + +#ifdef EPERM + case EPERM: + return GST_SPARSE_FILE_IO_ERROR_PERMISSION_DENIED; + break; +#endif + +#ifdef ECANCELED + case ECANCELED: + return GST_SPARSE_FILE_IO_ERROR_CANCELLED; + break; +#endif + + /* ENOTEMPTY == EEXIST on AIX for backward compatibility reasons */ +#if defined (ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST)) + case ENOTEMPTY: + return GST_SPARSE_FILE_IO_ERROR_NOT_EMPTY; + break; +#endif + +#ifdef ENOTSUP + case ENOTSUP: + return GST_SPARSE_FILE_IO_ERROR_NOT_SUPPORTED; + break; +#endif + + /* EOPNOTSUPP == ENOTSUP on Linux, but POSIX considers them distinct */ +#if defined (EOPNOTSUPP) && (!defined (ENOTSUP) || (EOPNOTSUPP != ENOTSUP)) + case EOPNOTSUPP: + return GST_SPARSE_FILE_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef EPROTONOSUPPORT + case EPROTONOSUPPORT: + return GST_SPARSE_FILE_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef ESOCKTNOSUPPORT + case ESOCKTNOSUPPORT: + return GST_SPARSE_FILE_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef EPFNOSUPPORT + case EPFNOSUPPORT: + return GST_SPARSE_FILE_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef EAFNOSUPPORT + case EAFNOSUPPORT: + return GST_SPARSE_FILE_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef ETIMEDOUT + case ETIMEDOUT: + return GST_SPARSE_FILE_IO_ERROR_TIMED_OUT; + break; +#endif + +#ifdef EBUSY + case EBUSY: + return GST_SPARSE_FILE_IO_ERROR_BUSY; + break; +#endif + +#ifdef EWOULDBLOCK + case EWOULDBLOCK: + return GST_SPARSE_FILE_IO_ERROR_WOULD_BLOCK; + break; +#endif + + /* EWOULDBLOCK == EAGAIN on most systems, but POSIX considers them distinct */ +#if defined (EAGAIN) && (!defined (EWOULDBLOCK) || (EWOULDBLOCK != EAGAIN)) + case EAGAIN: + return GST_SPARSE_FILE_IO_ERROR_WOULD_BLOCK; + break; +#endif + +#ifdef EMFILE + case EMFILE: + return GST_SPARSE_FILE_IO_ERROR_TOO_MANY_OPEN_FILES; + break; +#endif + +#ifdef EADDRINUSE + case EADDRINUSE: + return GST_SPARSE_FILE_IO_ERROR_ADDRESS_IN_USE; + break; +#endif + +#ifdef EHOSTUNREACH + case EHOSTUNREACH: + return GST_SPARSE_FILE_IO_ERROR_HOST_UNREACHABLE; + break; +#endif + +#ifdef ENETUNREACH + case ENETUNREACH: + return GST_SPARSE_FILE_IO_ERROR_NETWORK_UNREACHABLE; + break; +#endif + +#ifdef ECONNREFUSED + case ECONNREFUSED: + return GST_SPARSE_FILE_IO_ERROR_CONNECTION_REFUSED; + break; +#endif + +#ifdef EPIPE + case EPIPE: + return GST_SPARSE_FILE_IO_ERROR_BROKEN_PIPE; + break; +#endif + + default: + return GST_SPARSE_FILE_IO_ERROR_FAILED; + break; + } +} diff --git a/plugins/elements/gstsparsefile.h b/plugins/elements/gstsparsefile.h index 68dd8a7841..76f73d38ea 100644 --- a/plugins/elements/gstsparsefile.h +++ b/plugins/elements/gstsparsefile.h @@ -26,6 +26,55 @@ G_BEGIN_DECLS typedef struct _GstSparseFile GstSparseFile; +/* NOTE: Remove this before making this public API again! */ +typedef enum { + GST_SPARSE_FILE_IO_ERROR_FAILED, + GST_SPARSE_FILE_IO_ERROR_NOT_FOUND, + GST_SPARSE_FILE_IO_ERROR_EXISTS, + GST_SPARSE_FILE_IO_ERROR_IS_DIRECTORY, + GST_SPARSE_FILE_IO_ERROR_NOT_DIRECTORY, + GST_SPARSE_FILE_IO_ERROR_NOT_EMPTY, + GST_SPARSE_FILE_IO_ERROR_NOT_REGULAR_FILE, + GST_SPARSE_FILE_IO_ERROR_NOT_SYMBOLIC_LINK, + GST_SPARSE_FILE_IO_ERROR_NOT_MOUNTABLE_FILE, + GST_SPARSE_FILE_IO_ERROR_FILENAME_TOO_LONG, + GST_SPARSE_FILE_IO_ERROR_INVALID_FILENAME, + GST_SPARSE_FILE_IO_ERROR_TOO_MANY_LINKS, + GST_SPARSE_FILE_IO_ERROR_NO_SPACE, + GST_SPARSE_FILE_IO_ERROR_INVALID_ARGUMENT, + GST_SPARSE_FILE_IO_ERROR_PERMISSION_DENIED, + GST_SPARSE_FILE_IO_ERROR_NOT_SUPPORTED, + GST_SPARSE_FILE_IO_ERROR_NOT_MOUNTED, + GST_SPARSE_FILE_IO_ERROR_ALREADY_MOUNTED, + GST_SPARSE_FILE_IO_ERROR_CLOSED, + GST_SPARSE_FILE_IO_ERROR_CANCELLED, + GST_SPARSE_FILE_IO_ERROR_PENDING, + GST_SPARSE_FILE_IO_ERROR_READ_ONLY, + GST_SPARSE_FILE_IO_ERROR_CANT_CREATE_BACKUP, + GST_SPARSE_FILE_IO_ERROR_WRONG_ETAG, + GST_SPARSE_FILE_IO_ERROR_TIMED_OUT, + GST_SPARSE_FILE_IO_ERROR_WOULD_RECURSE, + GST_SPARSE_FILE_IO_ERROR_BUSY, + GST_SPARSE_FILE_IO_ERROR_WOULD_BLOCK, + GST_SPARSE_FILE_IO_ERROR_HOST_NOT_FOUND, + GST_SPARSE_FILE_IO_ERROR_WOULD_MERGE, + GST_SPARSE_FILE_IO_ERROR_FAILED_HANDLED, + GST_SPARSE_FILE_IO_ERROR_TOO_MANY_OPEN_FILES, + GST_SPARSE_FILE_IO_ERROR_NOT_INITIALIZED, + GST_SPARSE_FILE_IO_ERROR_ADDRESS_IN_USE, + GST_SPARSE_FILE_IO_ERROR_PARTIAL_INPUT, + GST_SPARSE_FILE_IO_ERROR_INVALID_DATA, + GST_SPARSE_FILE_IO_ERROR_DBUS_ERROR, + GST_SPARSE_FILE_IO_ERROR_HOST_UNREACHABLE, + GST_SPARSE_FILE_IO_ERROR_NETWORK_UNREACHABLE, + GST_SPARSE_FILE_IO_ERROR_CONNECTION_REFUSED, + GST_SPARSE_FILE_IO_ERROR_PROXY_FAILED, + GST_SPARSE_FILE_IO_ERROR_PROXY_AUTH_FAILED, + GST_SPARSE_FILE_IO_ERROR_PROXY_NEED_AUTH, + GST_SPARSE_FILE_IO_ERROR_PROXY_NOT_ALLOWED, + GST_SPARSE_FILE_IO_ERROR_BROKEN_PIPE +} GstSparseFileIOErrorEnum; + GstSparseFile * gst_sparse_file_new (void); void gst_sparse_file_free (GstSparseFile *file);