Fix implicit declaration of g_close()
[claws.git] / src / plugins / archive / libarchive_archive.c
index e7b32452242e3fe92ecc94a6fdce64cdca356cd8..32f75bfb9f73fc8fbc5595d29082b8b29a9e01fa 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2016 Michael Rasmussen and the Claws Mail Team
+ * Copyright (C) 1999-2018 Michael Rasmussen and the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 
 #include "libarchive_archive.h"
 
@@ -44,7 +45,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <dirent.h>
-#include <glib.h>
 #include <libgen.h>
 
 #define READ_BLOCK_SIZE 10240
@@ -441,14 +441,6 @@ const gchar* archive_extract(const char* archive_name, int flags) {
 const gchar* archive_create(const char* archive_name, GSList* files,
                        COMPRESS_METHOD method, ARCHIVE_FORMAT format) {
        struct archive* arch;
-       struct archive_entry* entry;
-       char* buf = NULL;
-       ssize_t len;
-       int fd;
-       struct stat st;
-       struct file_info* file;
-       gchar* filename = NULL;
-       gchar* msg = NULL;
 
 #ifndef _TEST
        gint num = 0;
@@ -565,6 +557,9 @@ const gchar* archive_create(const char* archive_name, GSList* files,
                return archive_error_string(arch);
 
        while (files && ! stop_action) {
+               struct file_info* file;
+               gchar* filename = NULL;
+
 #ifndef _TEST
                set_progress_print_all(num++, total, 30);
 #endif
@@ -580,28 +575,36 @@ const gchar* archive_create(const char* archive_name, GSList* files,
 #endif
                }
                else {
+                       struct archive_entry* entry;
+                       char* buf = NULL;
+                       ssize_t len;
+                       GError* err = NULL;
+                       GStatBuf st;
+                       int fd;
+                       gchar* msg = NULL;
+
 #ifndef _TEST
                        debug_print("Adding: %s\n", filename);
                        msg = g_strdup_printf("%s", filename);
                        set_progress_file_label(msg);
                        g_free(msg);
 #endif
-                       entry = archive_entry_new();
-                       if ((fd = open(filename, O_RDONLY)) == -1) {
-                               FILE_OP_ERROR(filename, "open");
+                       if ((fd = g_open(filename, O_RDONLY, 0)) == -1) {
+                               FILE_OP_ERROR(filename, "g_open");
                        }
                        else {
-                               if (lstat(filename, &st) == -1) {
-                                       FILE_OP_ERROR(filename, "lstat");
+                               if (g_stat(filename, &st) == -1) {
+                                       FILE_OP_ERROR(filename, "g_stat");
                                } else {
+                                       entry = archive_entry_new();
                                        archive_entry_copy_stat(entry, &st);
                                        archive_entry_set_pathname(entry, filename);
                                        if (S_ISLNK(st.st_mode)) {
-                                               if ((buf = malloc(PATH_MAX + 1)) != NULL) {
-                                                       if ((len = readlink(filename, buf, PATH_MAX)) < 0) {
-                                                               FILE_OP_ERROR(filename, "readlink");
-                                                       } else
-                                                               buf[len] = '\0';
+
+                                               buf = g_file_read_link(filename, &err);
+                                               if (err) {
+                                                       FILE_OP_ERROR(filename, "g_file_read_link");
+                                               } else {
                                                        archive_entry_set_symlink(entry, buf);
                                                        g_free(buf);
                                                        archive_entry_set_size(entry, 0);
@@ -622,9 +625,10 @@ const gchar* archive_create(const char* archive_name, GSList* files,
                                                        g_free(buf);
                                                }
                                        }
+                                       archive_entry_free(entry);
                                }
-                               close(fd);
-                               archive_entry_free(entry);
+                               if (!g_close(fd, &err) || err)
+                                       FILE_OP_ERROR(filename, "g_close");
                        }
                }
                g_free(filename);
@@ -665,7 +669,10 @@ void archive_scan_folder(const char* dir) {
        while ((ent = readdir(root)) != NULL) {
                if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0)
                        continue;
-               g_stat(ent->d_name, &st);
+               if (g_stat(ent->d_name, &st) == -1) {
+                       FILE_OP_ERROR(filename, "g_stat");
+                       continue;
+               }
                sprintf(path, "%s/%s", dir, ent->d_name);
                if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
                        archive_add_file(path);
@@ -747,3 +754,8 @@ int main(int argc, char** argv) {
        return EXIT_SUCCESS;
 }
 #endif
+
+void archiver_set_tooltip(GtkWidget* widget, gchar* text) {
+    gtk_widget_set_tooltip_text(widget, text);
+    g_free(text);
+}