summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a1bbc39)
raw | patch | inline | side by side (parent: a1bbc39)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 5 Jan 2012 10:53:19 +0000 (11:53 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 5 Jan 2012 10:53:19 +0000 (11:53 +0100) |
src/gtk-tpdfv.c | patch | blob | history |
diff --git a/src/gtk-tpdfv.c b/src/gtk-tpdfv.c
index d1a377ce4e44bd3d1204b259982f02ded02f533b..e17a4eb22073f252910f0ee96afe48e2b941b9fa 100644 (file)
--- a/src/gtk-tpdfv.c
+++ b/src/gtk-tpdfv.c
} tpdfv_zoommode_t;
typedef struct {
} tpdfv_zoommode_t;
typedef struct {
- char *filename;
+ gchar *filename;
time_t mtime;
time_t mtime;
static gboolean
tpdfv_init(gtk_tpdfv_t *pdf, const char *filename)
{
static gboolean
tpdfv_init(gtk_tpdfv_t *pdf, const char *filename)
{
- if (strstr(filename, "://"))
- pdf->filename = strdup(filename);
+ GError *err = NULL;
+
+ char *scheme;
+
+ if ((! pdf) || (! filename))
+ return FALSE;
+
+ scheme = g_uri_parse_scheme(filename);
+ if (scheme)
+ filename += strlen(scheme);
+
+ if (g_path_is_absolute(filename)) {
+ pdf->filename = g_filename_to_uri(filename,
+ /* hostname = */ NULL, &err);
+ }
else {
else {
- size_t len = strlen("file://") + strlen(filename);
- pdf->filename = (char *)malloc(len + 1);
- if (pdf->filename) {
- *pdf->filename = '\0';
- strncat(pdf->filename, "file://", len);
- strncat(pdf->filename, filename, len - strlen("file://"));
- }
+ gchar *tmp = g_build_filename(g_get_current_dir(), filename, NULL);
+ pdf->filename = g_filename_to_uri(tmp, /* hostname = */ NULL, &err);
+ g_free(tmp);
}
/* XXX: error reporting mechanism */
if (! pdf->filename) {
}
/* XXX: error reporting mechanism */
if (! pdf->filename) {
- char errbuf[1024];
- strerror_r(errno, errbuf, sizeof(errbuf));
- fprintf(stderr, "Failed to allocate string: %s.\n", errbuf);
+ if (err)
+ fprintf(stderr, "Failed to allocate string: %s.\n", err->message);
return FALSE;
}
return FALSE;
}
tpdfv_close(pdf);
pdf->current_page = NULL;
tpdfv_close(pdf);
pdf->current_page = NULL;
- free(pdf->filename);
+ g_free(pdf->filename);
pdf->filename = NULL;
return;
} /* tpdfv_clean */
pdf->filename = NULL;
return;
} /* tpdfv_clean */