]> git.street.me.uk Git - andy/viking.git/blobdiff - src/curl_download.c
Portability: reduce unistd.h dependency
[andy/viking.git] / src / curl_download.c
index ba89a275f9343a2e38baa4fcd386bc1b9fdba214..526b9fcb87fb1393bee4db9500b9b55207484fe7 100644 (file)
  *
  */
 
-#include <unistd.h>
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
 #include <curl/curl.h>
@@ -42,14 +43,14 @@ static gchar *get_cookie_file(gboolean init)
     static gchar *cookie_fn = "cookies.txt";
     const gchar *viking_dir = a_get_viking_dir();
     cookie_file = g_build_filename(viking_dir, cookie_fn, NULL);
-    unlink(cookie_file);
+    g_unlink(cookie_file);
     return NULL;
   }
 
   g_assert(cookie_file != NULL);
 
   g_mutex_lock(mutex);
-  if (access(cookie_file, F_OK)) {  /* file not there */
+  if (g_file_test(cookie_file, G_FILE_TEST_EXISTS) == FALSE) {  /* file not there */
     FILE * out_file = fopen("/dev/null", "w");
     CURLcode res;
     CURL *curl = curl_easy_init();
@@ -58,9 +59,9 @@ static gchar *get_cookie_file(gboolean init)
     curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookie_file);
     res = curl_easy_perform(curl);
     if (res != CURLE_OK) {
-      g_warning("%s() Curl perform failed: %s\n", __PRETTY_FUNCTION__,
+      g_warning(_("%s() Curl perform failed: %s"), __PRETTY_FUNCTION__,
           curl_easy_strerror(res));
-      unlink(cookie_file);
+      g_unlink(cookie_file);
     }
     curl_easy_cleanup(curl);
   }
@@ -104,13 +105,13 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadOptions *options )
   return(res);
 }
 
-int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadOptions *options )
+int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadOptions *options, gboolean ftp )
 {
   int ret;
   gchar *full = NULL;
 
   /* Compose the full url */
-  full = g_strdup_printf ( "http://%s%s", hostname, uri );
+  full = g_strdup_printf ( "%s://%s%s", (ftp?"ftp":"http"), hostname, uri );
   ret = curl_download_uri ( full, f, options );
   g_free ( full );
   full = NULL;