Use g_dir_open() and friends instead of opendir() and friends.
authorAndrej Kacian <ticho@claws-mail.org>
Thu, 18 Jun 2015 11:22:06 +0000 (13:22 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Mon, 29 Jun 2015 09:35:13 +0000 (11:35 +0200)
This makes more things work on Windows, since Mingw
opendir() is kind of flakey, and breaks e.g. vcalendar or rssyl
being able to read contents of their folders.

I only left opendir() in archive plugin, since it is only found
in unused part of code (excluded by #ifdef _TEST, which is never
true for claws-mail compilations).

23 files changed:
src/addressbook.c
src/addrharvest.c
src/common/utils.c
src/exphtmldlg.c
src/expldifdlg.c
src/exporthtml.c
src/exporthtml.h
src/exportldif.c
src/exportldif.h
src/imap.c
src/main.c
src/mh.c
src/plugins/libravatar/libravatar_cache.c
src/plugins/notification/notification_hotkeys.c
src/plugins/pdf_viewer/poppler_viewer.c
src/plugins/rssyl/old_feeds.c
src/plugins/rssyl/parse822.c
src/plugins/rssyl/rssyl.c
src/plugins/rssyl/rssyl_update_comments.c
src/plugins/vcalendar/vcal_folder.c
src/prefs_themes.c
src/ssl_manager.c
src/stock_pixmap.c

index 4cbfc421b597455af6515fb266f11bf810fd6e4b..42446293b3f62f54043c094a31b0bd4b0dfa3543 100644 (file)
@@ -4085,22 +4085,26 @@ static gboolean addressbook_convert( AddressIndex *addrIndex ) {
 
 static gboolean migrate_addrbook(const gchar *origdir, const gchar *destdir)
 {
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *d;
        gboolean failed = FALSE;
+       GError *error = NULL;
 
-       if( ( dp = opendir( origdir ) ) == NULL ) {
+       if( ( dp = g_dir_open( origdir, 0, &error ) ) == NULL ) {
+               debug_print("opening '%s' failed: %d (%s)\n", origdir,
+                               error->code, error->message);
+               g_error_free(error);
                return FALSE;
        }
        
-       while( ( d = readdir( dp ) ) != NULL ) {
-               if (strncmp(d->d_name, "addrbook-", strlen("addrbook-")))
+       while( ( d = g_dir_read_name( dp ) ) != NULL ) {
+               if (strncmp(d, "addrbook-", strlen("addrbook-")))
                        continue;
                else {
                        gchar *orig_file = g_strconcat(origdir, G_DIR_SEPARATOR_S, 
-                                       d->d_name, NULL);
+                                       d, NULL);
                        gchar *dest_file = g_strconcat(destdir, G_DIR_SEPARATOR_S, 
-                                       d->d_name, NULL);
+                                       d, NULL);
                        if (copy_file(orig_file, dest_file, FALSE) < 0) {
                                failed = TRUE;
                        }
@@ -4111,24 +4115,27 @@ static gboolean migrate_addrbook(const gchar *origdir, const gchar *destdir)
                        }
                }
        }
+       g_dir_close( dp );
 
-       closedir( dp );
        if (!failed) {
                /* all copies succeeded, we can remove source files */
-               if( ( dp = opendir( origdir ) ) == NULL ) {
+               if( ( dp = g_dir_open( origdir, 0, &error ) ) == NULL ) {
+                       debug_print("opening '%s' failed: %d (%s)\n", origdir,
+                                       error->code, error->message);
+                       g_error_free(error);
                        return FALSE;
                }
-               while( ( d = readdir( dp ) ) != NULL ) {
-                       if (strncmp(d->d_name, "addrbook-", strlen("addrbook-")))
+               while( ( d = g_dir_read_name( dp ) ) != NULL ) {
+                       if (strncmp(d, "addrbook-", strlen("addrbook-")))
                                continue;
                        else {
                                gchar *orig_file = g_strconcat(origdir, G_DIR_SEPARATOR_S, 
-                                               d->d_name, NULL);
+                                               d, NULL);
                                claws_unlink(orig_file);
                                g_free(orig_file);
                        }
                }
-               closedir( dp );
+               g_dir_close( dp );
        }
        
        return !failed;
index 999dcda7a5fb4160a361d1290c36cb816634105a..97eff8bb77d296d91653e6cd51be64aafa238122 100644 (file)
@@ -763,37 +763,39 @@ static void addrharvest_harvest_dir(
        AddressHarvester *harvester, AddressCache *cache, GList *listHdr,
        gchar *dir )
 {
-       DIR *dp;
-       struct dirent *d;
-       GStatBuf s;
+       GDir *dp;
+       const gchar *d;
+       GError *error = NULL;
        gint num;
        int r;
 
-       if( ( dp = opendir( dir ) ) == NULL ) {
+       if( ( dp = g_dir_open( dir, 0, &error ) ) == NULL ) {
+               debug_print("opening '%s' failed: %d (%s)\n", dir,
+                               error->code, error->message);
+               g_error_free(error);
                return;
        }
 
        /* Process directory */
-       r = chdir( dir );
-       while( r == 0 && ( d = readdir( dp ) ) != NULL ) {
-               gint sr = g_stat( d->d_name, &s );
-               if(sr == 0 &&  S_ISDIR( s.st_mode ) ) {
+       r = g_chdir( dir );
+       while( r == 0 && ( d = g_dir_read_name( dp ) ) != NULL ) {
+               if( g_file_test(d, G_FILE_TEST_IS_DIR) ) {
                        if( harvester->folderRecurse ) {
-                               if( strstr( DIR_IGNORE, d->d_name ) != NULL )
+                               if( strstr( DIR_IGNORE, d ) != NULL )
                                        continue;
                                addrharvest_harvest_dir(
-                                       harvester, cache, listHdr, d->d_name );
+                                       harvester, cache, listHdr, (gchar *)d );
                        }
                }
-               if(sr == 0 && S_ISREG( s.st_mode ) ) {
-                       if( ( num = to_number( d->d_name ) ) >= 0 ) {
+               if( g_file_test(d, G_FILE_TEST_IS_REGULAR) ) {
+                       if( ( num = to_number( d ) ) >= 0 ) {
                                addrharvest_readfile(
-                                       harvester, d->d_name, cache, listHdr );
+                                       harvester, d, cache, listHdr );
                        }
                }
        }
-       r = chdir( ".." );
-       closedir( dp );
+       r = g_chdir( ".." );
+       g_dir_close( dp );
 }
 
 /*
@@ -806,22 +808,20 @@ static void addrharvest_harvest_list(
        AddressHarvester *harvester, AddressCache *cache, GList *listHdr,
        GList *msgList )
 {
-       DIR *dp;
        gint num;
        GList *node;
        gchar msgNum[ MSGNUM_BUFFSIZE ];
        int r;
 
-       if( ( dp = opendir( harvester->path ) ) == NULL ) {
-               g_message("cannot opendir %s\n", harvester->path);
+       if (!g_file_test(harvester->path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
+               debug_print("'%s' doesn't exist or is not a dir\n", harvester->path);
                return;
        }
 
        /* Process message list */
-       r = chdir( harvester->path );
+       r = g_chdir( harvester->path );
        if (r != 0) {
-               closedir( dp );
-               g_message("cannot chdir %s\n", harvester->path);
+               g_message("cannot g_chdir to '%s'\n", harvester->path);
                return;
        }
        node = msgList;
@@ -831,7 +831,6 @@ static void addrharvest_harvest_list(
                addrharvest_readfile( harvester, msgNum, cache, listHdr );
                node = g_list_next( node );
        }
-       closedir( dp );
 }
 
 /*
index a07e9136dd480049fe498b2b9048e0f2a03ce08f..0ad18cf86e932e7689a0577f9e0844d2a557c9ff 100644 (file)
@@ -2398,6 +2398,7 @@ gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist)
        gint file_no;
        GHashTable *wanted_files;
        GSList *cur;
+       GError *error = NULL;
 
        if (numberlist == NULL)
            return 0;
@@ -2410,8 +2411,10 @@ gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist)
                return -1;
        }
 
-       if ((dp = g_dir_open(".", 0, NULL)) == NULL) {
-               FILE_OP_ERROR(dir, "opendir");
+       if ((dp = g_dir_open(".", 0, &error)) == NULL) {
+               g_message("Couldn't open current directory: %s (%d).\n",
+                               error->message, error->code);
+               g_error_free(error);
                g_free(prev_dir);
                return -1;
        }
@@ -4863,7 +4866,7 @@ gint copy_dir(const gchar *src, const gchar *dst)
                    have something like this but the semantics might be
                    different.  Thus we don't use it under Windows. */
                 else if (g_file_test(old_file, G_FILE_TEST_IS_SYMLINK)) {
-                       GError *error;
+                       GError *error = NULL;
                        gint r = 0;
                        gchar *target = g_file_read_link(old_file, &error);
                        if (target)
index 49db84cf90858b6b13bcf2b6136744d308578752..fa787b7001e949c16949afcf065060f049c86122 100644 (file)
@@ -168,7 +168,8 @@ static gboolean exp_html_move_file( void ) {
        g_free( sFile );
 
        /* Test for directory */
-       if( exporthtml_test_dir( _exportCtl_ ) ) {
+       if( g_file_test(_exportCtl_->dirOutput,
+                               G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) {
                return TRUE;
        }
 
index 3790636b83e241cfdfe228b4803eebac53e5e02e..c1906da58299d69b55b716d38251f92b6e9a7d05 100644 (file)
@@ -178,7 +178,8 @@ static gboolean exp_ldif_move_file( void ) {
        if( errFlag ) return FALSE;
 
        /* Test for directory */
-       if( exportldif_test_dir( _exportCtl_ ) ) {
+       if( g_file_test(_exportCtl_->dirOutput,
+                               G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) {
                return TRUE;
        }
 
index 5533ba8e33b1bd5e4c00ac8452af8bb79327862d..675576f42ec8a132631c6ced437073962928b130 100644 (file)
@@ -1035,25 +1035,6 @@ void exporthtml_parse_filespec( ExportHtmlCtl *ctl, gchar *fileSpec ) {
        ctl->path = mgu_replace_string( ctl->path, fileSpec );
 }
 
-/*
- * ============================================================================
- * Test whether directory exists.
- * Enter:  ctl  Export control data.
- * Return: TRUE if exists.
- * ============================================================================
- */
-gboolean exporthtml_test_dir( ExportHtmlCtl *ctl ) {
-       gboolean retVal;
-       DIR *dp;
-
-       retVal = FALSE;
-       if((dp = opendir( ctl->dirOutput )) != NULL) {
-               retVal = TRUE;
-               closedir( dp );
-       }
-       return retVal;
-}
-
 /*
  * ============================================================================
  * Create output directory.
index 1e7345d5cf333364035e6295a37b5a9065fcb4d7..b5f1b2d953167e5e725e30d17605fc96b889d655 100644 (file)
@@ -73,7 +73,6 @@ void exporthtml_set_attributes        ( ExportHtmlCtl *ctl,
                                  const gboolean value );
 void exporthtml_process                ( ExportHtmlCtl *ctl,
                                  AddressCache *cache );
-gboolean exporthtml_test_dir   ( ExportHtmlCtl *ctl );
 gboolean exporthtml_create_dir ( ExportHtmlCtl *ctl );
 gchar *exporthtml_get_create_msg( ExportHtmlCtl *ctl );
 
index bd2cf0aa27c176ec18b938575c246a156622d659..c864975887ce2d714dc9b0064ef8be436aa8fa6f 100644 (file)
@@ -576,23 +576,6 @@ void exportldif_parse_filespec( ExportLdifCtl *ctl, gchar *fileSpec ) {
        ctl->path = mgu_replace_string( ctl->path, fileSpec );
 }
 
-/**
- * Test whether output directory exists.
- * \param  ctl Export control data.
- * \return TRUE if exists.
- */
-gboolean exportldif_test_dir( ExportLdifCtl *ctl ) {
-       gboolean retVal;
-       DIR *dp;
-
-       retVal = FALSE;
-       if((dp = opendir( ctl->dirOutput )) != NULL) {
-               retVal = TRUE;
-               closedir( dp );
-       }
-       return retVal;
-}
-
 /**
  * Create output directory.
  * \param  ctl Export control data.
index e3f684ca738c9ed07b6f151ff7d02d6c38d3969f..f554b8be88c66ba762c9c90c34da754019df0d78 100644 (file)
@@ -66,7 +66,6 @@ void exportldif_set_exclude_email     ( ExportLdifCtl *ctl,
                                          const gboolean value );
 void exportldif_process                        ( ExportLdifCtl *ctl,
                                          AddressCache *cache );
-gboolean exportldif_test_dir           ( ExportLdifCtl *ctl );
 gboolean exportldif_create_dir         ( ExportLdifCtl *ctl );
 gchar *exportldif_get_create_msg       ( ExportLdifCtl *ctl );
 
index 606da6413d7154766329027a0b48e73ffe4ccceb..45acb6afe7c3369fcb09c12c551591acd70317da 100644 (file)
@@ -5915,11 +5915,8 @@ void imap_disconnect_all(gboolean have_connectivity)
        GList *list;
        gboolean short_timeout;
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
-       GError *error;
-#endif
+       GError *error = NULL;
 
-#ifdef HAVE_NETWORKMANAGER_SUPPORT
-       error = NULL;
        short_timeout = !networkmanager_is_online(&error);
        if(error) {
                short_timeout = TRUE;
index 5f8ddb1d3dacedb2e96d9f6aaa766836dace35e0..9ce01bac42c1de43eea67c80906f0d6add38e185 100644 (file)
@@ -2830,10 +2830,9 @@ static void networkmanager_state_change_cb(DBusGProxy *proxy, gchar *dev,
                return;
 
        if (mainWin) {
-               GError *error;
+               GError *error = NULL;
                gboolean online;
 
-               error = NULL;           
                online = networkmanager_is_online(&error);
                if(!error) {
                        if(online && went_offline_nm) {
index 53e43a5ea58ab8d5c81ea9ae5dfd7dd50b20217e..f40bd870fb9d54236ea00965fa8a2dc557460275 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -244,8 +244,9 @@ gboolean mh_scan_required(Folder *folder, FolderItem *item)
 static void mh_get_last_num(Folder *folder, FolderItem *item)
 {
        gchar *path;
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *d;
+       GError *error = NULL;
        gint max = 0;
        gint num;
 
@@ -261,21 +262,23 @@ static void mh_get_last_num(Folder *folder, FolderItem *item)
        }
        g_free(path);
 
-       if ((dp = opendir(".")) == NULL) {
-               FILE_OP_ERROR(item->path, "opendir");
+       if ((dp = g_dir_open(".", 0, &error)) == NULL) {
+               g_message("Couldn't open current directory: %s (%d).\n",
+                               error->message, error->code);
+               g_error_free(error);
                return;
        }
 
-       while ((d = readdir(dp)) != NULL) {
-               if ((num = to_number(d->d_name)) > 0 &&
-                   dirent_is_regular_file(d)) {
+       while ((d = g_dir_read_name(dp)) != NULL) {
+               if ((num = to_number(d)) > 0 &&
+                   g_file_test(d, G_FILE_TEST_IS_REGULAR)) {
                        if (max < num)
                                max = num;
                }
                if (num % 2000 == 0)
                        GTK_EVENTS_FLUSH();
        }
-       closedir(dp);
+       g_dir_close(dp);
 
        debug_print("Last number in dir %s = %d\n", item->path?item->path:"(null)", max);
        item->last_num = max;
@@ -285,8 +288,9 @@ gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean *
 {
 
        gchar *path;
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *d;
+       GError *error = NULL;
        gint num, nummsgs = 0;
 
        cm_return_val_if_fail(item != NULL, -1);
@@ -303,18 +307,20 @@ gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean *
        }
        g_free(path);
 
-       if ((dp = opendir(".")) == NULL) {
-               FILE_OP_ERROR(item->path, "opendir");
+       if ((dp = g_dir_open(".", 0, &error)) == NULL) {
+               g_message("Couldn't open current directory: %s (%d).\n",
+                               error->message, error->code);
+               g_error_free(error);
                return -1;
        }
 
-       while ((d = readdir(dp)) != NULL) {
-               if ((num = to_number(d->d_name)) > 0) {
+       while ((d = g_dir_read_name(dp)) != NULL) {
+               if ((num = to_number(d)) > 0) {
                        *list = g_slist_prepend(*list, GINT_TO_POINTER(num));
                        nummsgs++;
                }
        }
-       closedir(dp);
+       g_dir_close(dp);
 
        mh_set_mtime(folder, item);
        return nummsgs;
@@ -1097,16 +1103,11 @@ static void mh_remove_missing_folder_items(Folder *folder)
 static void mh_scan_tree_recursive(FolderItem *item)
 {
        Folder *folder;
-#ifdef G_OS_WIN32
        GDir *dir;
-#else
-       DIR *dp;
-       struct dirent *d;
-#endif
        const gchar *dir_name;
-       GStatBuf s;
        gchar *real_path, *entry, *utf8entry, *utf8name;
        gint n_msg = 0;
+       GError *error = NULL;
 
        cm_return_if_fail(item != NULL);
        cm_return_if_fail(item->folder != NULL);
@@ -1114,20 +1115,14 @@ static void mh_scan_tree_recursive(FolderItem *item)
        folder = item->folder;
 
        real_path = item->path ? mh_filename_from_utf8(item->path) : g_strdup(".");
-#ifdef G_OS_WIN32
-       dir = g_dir_open(real_path, 0, NULL);
+       dir = g_dir_open(real_path, 0, &error);
        if (!dir) {
-               g_warning("failed to open directory: %s\n", real_path);
+               g_warning("failed to open directory '%s': %s (%d)\n",
+                               real_path, error->message, error->code);
+               g_error_free(error);
                g_free(real_path);
                return;
        }
-#else
-       dp = opendir(real_path);
-       if (!dp) {
-               FILE_OP_ERROR(real_path, "opendir");
-               return;
-       }
-#endif
        g_free(real_path);
 
        debug_print("scanning %s ...\n",
@@ -1136,12 +1131,7 @@ static void mh_scan_tree_recursive(FolderItem *item)
        if (folder->ui_func)
                folder->ui_func(folder, item, folder->ui_func_data);
 
-#ifdef G_OS_WIN32
        while ((dir_name = g_dir_read_name(dir)) != NULL) {
-#else
-       while ((d = readdir(dp)) != NULL) {
-               dir_name = d->d_name;
-#endif
                if (dir_name[0] == '.') continue;
 
                utf8name = mh_filename_to_utf8(dir_name);
@@ -1152,16 +1142,7 @@ static void mh_scan_tree_recursive(FolderItem *item)
                        utf8entry = g_strdup(utf8name);
                entry = mh_filename_from_utf8(utf8entry);
 
-               if (
-#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
-                       d->d_type == DT_DIR ||
-                       (d->d_type == DT_UNKNOWN &&
-#endif
-                       g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
-#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
-                       )
-#endif
-                  ) {
+               if (g_file_test(entry, G_FILE_TEST_IS_DIR)) {
                        FolderItem *new_item = NULL;
                        GNode *node;
 
@@ -1214,11 +1195,7 @@ static void mh_scan_tree_recursive(FolderItem *item)
                g_free(utf8name);
        }
 
-#ifdef G_OS_WIN32
        g_dir_close(dir);
-#else
-       closedir(dp);
-#endif
 
        mh_set_mtime(folder, item);
 }
index df378f90f4d0a0c5f6897bd49d5330fc737b9887..7f72b0ed0f6dfd42d71d35e3f54c723337d6da27 100644 (file)
@@ -78,29 +78,31 @@ static void cache_stat_item(gpointer filename, gpointer data)
 
 static void cache_items_deep_first(const gchar *dir, GSList **items, guint *failed)
 {
-       struct dirent   *d;
-       DIR             *dp;
+       const gchar     *d;
+       GDir            *dp;
+       GError          *error = NULL;
 
        cm_return_if_fail(dir != NULL);
 
-       if ((dp = opendir(dir)) == NULL) {
-               g_warning("cannot open directory %s\n", dir);
+       if ((dp = g_dir_open(dir, 0, &error)) == NULL) {
+               g_warning("cannot open directory '%s': %s (%d)\n",
+                               dir, error->message, error->code);
+               g_error_free(error);
                (*failed)++;
                return;
        }
-       while ((d = readdir(dp)) != NULL) {
-               if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) {
+       while ((d = g_dir_read_name(dp)) != NULL) {
+               if (strcmp(d, ".") == 0 || strcmp(d, "..") == 0) {
                        continue;
                }
                else {
-                       const gchar *fname = g_strconcat(dir, G_DIR_SEPARATOR_S,
-                                                  d->d_name, NULL);
+                       const gchar *fname = g_strconcat(dir, G_DIR_SEPARATOR_S, d, NULL);
                        if (is_dir_exist(fname))
                                cache_items_deep_first(fname, items, failed);
                        *items = g_slist_append(*items, (gpointer) fname);
                }
        }
-       closedir(dp);
+       g_dir_close(dp);
 }
 
 AvatarCacheStats *libravatar_cache_stats()
index c8e4b299195ff014caad5bb95191f74dd82165da..067466677b6fb225de7c5632f47fcab069196efc 100644 (file)
@@ -42,7 +42,7 @@ static void hotkey_toggle_mainwindow_activated(GtkHotkeyInfo *hotkey, guint even
 
 static void unbind_toggle_mainwindow()
 {
-  GError *error;
+  GError *error = NULL;
   GtkHotkeyRegistry *registry;
 
   /* clean up old hotkey */
@@ -73,7 +73,7 @@ static void unbind_toggle_mainwindow()
 
 static void update_hotkey_binding_toggle_mainwindow()
 {
-  GError *error;
+  GError *error = NULL;
 
   /* don't do anything if no signature is given */
   if(!notify_config.hotkeys_toggle_mainwindow || !strcmp(notify_config.hotkeys_toggle_mainwindow, ""))
index df66fa5d508a29a1297e59072beac09ca96686e9..129339ed156e255fb46a3384b6b035ea4b0b9cf5 100644 (file)
@@ -1239,13 +1239,12 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
 {
 
        PdfViewer *viewer = (PdfViewer *) _viewer;
-       GError *error;
+       GError *error = NULL;
        gchar *tmpfile = NULL;
        gchar *tmp;
 
        debug_print("pdf_viewer_update\n");
 
-       error = NULL;
        if (reload_file) {
                if (viewer->pdf_doc) {
                        g_object_unref(G_OBJECT(viewer->pdf_doc));
index 9bbb6cfff9a42a12009578b0d76e499a495ab8b2..15e0bd98352a21e0eb66d4de6ce232bc95a08ad2 100644 (file)
@@ -80,7 +80,7 @@ GSList *rssyl_old_feed_metadata_parse(gchar *filepath)
        GSList *oldfeeds = NULL;
        gchar *contents = NULL;
        gsize length;
-       GError *error;
+       GError *error = NULL;
        struct _oldrssyl_ctx *ctx;
 
        debug_print("RSSyl: Starting to parse old feeds.xml\n");
index 5eadc4a924f5c7e5169420594fc4e20d1aeadc74..33307bfb4679b89488b14170c35795e44936ca8b 100644 (file)
@@ -245,7 +245,7 @@ static void rssyl_folder_read_existing_real(RFolderItem *ritem)
        gchar *path = NULL, *fname = NULL;
        GDir *dp;
        const gchar *d;
-       GError *error;
+       GError *error = NULL;
        gint num;
        FeedItem *item = NULL;
        RFeedCtx *ctx;
@@ -266,7 +266,6 @@ static void rssyl_folder_read_existing_real(RFolderItem *ritem)
        ritem->last_update = 0;
 
        if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
-               FILE_OP_ERROR(path, "g_dir_open");
                debug_print("g_dir_open on \"%s\" failed with error %d (%s)\n",
                                path, error->code, error->message);
                g_error_free(error);
index 5983495f5ad231a2aae53a195fbaf74e5f390419..eb9561227f91190840e7d6773c9bb283ddaa80c8 100644 (file)
@@ -205,7 +205,7 @@ static void rssyl_get_last_num(Folder *folder, FolderItem *item)
        gchar *path;
        const char *f;
        GDir *dp;
-       GError *error;
+       GError *error = NULL;
        gint max = 0;
        gint num;
 
@@ -657,7 +657,7 @@ static gint rssyl_get_num_list(Folder *folder, FolderItem *item,
        gchar *path;
        GDir *dp;
        const gchar *d;
-       GError *error;
+       GError *error = NULL;
        gint num, nummsgs = 0;
 
        g_return_val_if_fail(item != NULL, -1);
@@ -670,7 +670,6 @@ static gint rssyl_get_num_list(Folder *folder, FolderItem *item,
        g_return_val_if_fail(path != NULL, -1);
 
        if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
-               FILE_OP_ERROR(item->path, "opendir");
                debug_print("g_dir_open() failed on \"%s\", error %d (%s).\n",
                                path, error->code, error->message);
                g_error_free(error);
index 066dc9da2930e87e7ef472837699a485261e461d..c6096190866993472cbaec103014c7d645935490 100644 (file)
@@ -58,7 +58,7 @@ void rssyl_update_comments(RFolderItem *ritem)
        RFetchCtx *ctx = NULL;
        GDir *dp;
        const gchar *d;
-       GError *error;
+       GError *error = NULL;
        gint num;
        gchar *path, *msg, *fname;
        MainWindow *mainwin = mainwindow_get_mainwindow();
@@ -74,7 +74,6 @@ void rssyl_update_comments(RFolderItem *ritem)
        debug_print("RSSyl: starting to parse comments, path is '%s'\n", path);
 
        if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
-               FILE_OP_ERROR(item->path, "g_dir_open");
                debug_print("g_dir_open on \"%s\" failed with error %d (%s)\n",
                                path, error->code, error->message);
                g_error_free(error);
index 2c3aa8850e6b0bc92aad6ecb6aa6726e6f5ce716..0de5e7234b1d1b2aa6bdc8528a524037418a19c4 100644 (file)
@@ -705,9 +705,10 @@ add_new:
 
 GSList *vcal_get_events_list(FolderItem *item)
 {
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *d;
        GSList *events = NULL;
+       GError *error = NULL;
 
        if (item != item->folder->inbox) {
                GSList *subs = vcal_folder_get_webcal_events_for_folder(item);
@@ -724,27 +725,29 @@ GSList *vcal_get_events_list(FolderItem *item)
                return events;
        }
 
-       dp = opendir(vcal_manager_get_event_path());
+       dp = g_dir_open(vcal_manager_get_event_path(), 0, &error);
        
        if (!dp) {
-               FILE_OP_ERROR(vcal_manager_get_event_path(), "opendir");
+               debug_print("couldn't open dir '%s': %s (%d)\n",
+                               vcal_manager_get_event_path(), error->message, error->code);
+               g_error_free(error);
                return 0;
        }
 
-       while ((d = readdir(dp)) != NULL) {
+       while ((d = g_dir_read_name(dp)) != NULL) {
                VCalEvent *event = NULL;
-               if (d->d_name[0] == '.' || strstr(d->d_name, ".bak")
-               ||  !strcmp(d->d_name, "internal.ics")
-               ||  !strcmp(d->d_name, "internal.ifb")
-               ||  !strcmp(d->d_name, "multisync")) 
+               if (d[0] == '.' || strstr(d, ".bak")
+               ||  !strcmp(d, "internal.ics")
+               ||  !strcmp(d, "internal.ifb")
+               ||  !strcmp(d, "multisync")) 
                        continue;
 
-               event = vcal_manager_load_event(d->d_name);
+               event = vcal_manager_load_event(d);
                if (!event)
                        continue;
                if (event->rec_occurence) {
                        vcal_manager_free_event(event);
-                       claws_unlink(d->d_name);
+                       claws_unlink(d);
                        continue;
                }
 
@@ -770,7 +773,7 @@ GSList *vcal_get_events_list(FolderItem *item)
                                struct icaldurationtype ical_dur;
                                int i = 0;
 
-                               debug_print("dumping recurring events from main event %s\n", d->d_name);
+                               debug_print("dumping recurring events from main event %s\n", d);
                                recur = icalrecurrencetype_from_string(event->recur);
                                dtstart = icaltime_from_string(event->dtstart);
 
@@ -821,7 +824,7 @@ GSList *vcal_get_events_list(FolderItem *item)
                        vcal_manager_free_event(event);
                }
        }
-       closedir(dp);
+       g_dir_close(dp);
        return g_slist_reverse(events);
 }
 
index 8a8e9915cb5d84f0542e65fb6eca6a4913462461..ef7297a5a6aa732d53e8a9cc932fd247bc12f453 100644 (file)
@@ -221,29 +221,30 @@ static void prefs_themes_file_install(const gchar *filename, gpointer data)
 
 static void prefs_themes_foreach_file(const gchar *dirname, const FileFunc func, gpointer data)
 {
-       struct dirent *d;
-       DIR           *dp;
+       const gchar *entry;
+       gchar *fullentry;
+       GDir *dp;
+       GError *error = NULL;
 
        cm_return_if_fail(dirname != NULL);
        cm_return_if_fail(func != NULL);
 
-       if ((dp = opendir(dirname)) == NULL) {
-               debug_print("directory %s not found\n", dirname);
+       if ((dp = g_dir_open(dirname, 0, &error)) == NULL) {
+               debug_print("couldn't open dir '%s': %s (%d)\n", dirname,
+                               error->message, error->code);
+               g_error_free(error);
                return;
        }
 
-       while ((d = readdir(dp)) != NULL) {
-               gchar *entry;
-               gchar *fullentry;
+       while ((entry = g_dir_read_name(dp)) != NULL) {
 
-               entry     = d->d_name;
                fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
 
                (*func)(fullentry, data);
 
                g_free(fullentry);
        }
-       closedir(dp);
+       g_dir_close(dp);
 }
 
 static gboolean prefs_themes_is_system_theme(const gchar *dirname)
index 6b2f6650078d9e92e3c0c64a727035a83e47092e..bd13e312a4c87c0f6c0888ec2004a9ff87b9267f 100644 (file)
@@ -208,7 +208,7 @@ void ssl_manager_create(void)
                
 }
 
-static char *get_server(char *str)
+static char *get_server(const char *str)
 {
        char *ret = NULL, *tmp = g_strdup(str);
        char *first_pos = NULL, *last_pos = NULL;
@@ -237,7 +237,7 @@ static char *get_server(char *str)
        return ret;
 }
 
-static char *get_port(char *str)
+static char *get_port(const char *str)
 {
        char *ret = NULL, *tmp = g_strdup(str);
        char *last_pos = NULL;
@@ -264,7 +264,7 @@ static char *get_port(char *str)
        
 }
 
-static char *get_fingerprint(char *str)
+static char *get_fingerprint(const char *str)
 {
        char *ret = NULL, *tmp = g_strdup(str);
        char *previous_pos = NULL, *last_pos = NULL;
@@ -318,8 +318,9 @@ static void ssl_manager_list_view_insert_cert(GtkWidget *list_view,
 
 static void ssl_manager_load_certs (void) 
 {
-       DIR *dir;
-       struct dirent *d;
+       GDir *dir;
+       const gchar *d;
+       GError *error = NULL;
        gchar *path;
        int row = 0;
        GtkListStore *store;
@@ -332,21 +333,23 @@ static void ssl_manager_load_certs (void)
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, 
                          "certs", G_DIR_SEPARATOR_S, NULL);
 
-       if((dir = opendir(path)) == NULL) {
-               perror("opendir");
+       if((dir = g_dir_open(path, 0, &error)) == NULL) {
+               debug_print("couldn't open dir '%s': %s (%d)\n", path,
+                               error->message, error->code);
+               g_error_free(error);
                return;
        }
        
-       while ((d = readdir(dir)) != NULL) {
+       while ((d = g_dir_read_name(dir)) != NULL) {
                gchar *server, *port, *fp;
                SSLCertificate *cert;
 
-               if(strstr(d->d_name, ".cert") != d->d_name + (strlen(d->d_name) - strlen(".cert"))) 
+               if(strstr(d, ".cert") != d + (strlen(d) - strlen(".cert"))) 
                        continue;
 
-               server = get_server(d->d_name);
-               port = get_port(d->d_name);
-               fp = get_fingerprint(d->d_name);
+               server = get_server(d);
+               port = get_port(d);
+               fp = get_fingerprint(d);
                
                cert = ssl_certificate_find(server, atoi(port), fp);
 
@@ -358,7 +361,7 @@ static void ssl_manager_load_certs (void)
                g_free(fp);
                row++;
        }
-       closedir(dir);
+       g_dir_close(dir);
        g_free(path);
 }
 
index 6a12d189a271df3d654a6b7a5a9e3e63f9d88948..84ec1da66d1757b69d286a35ffe41c482726b1d5 100644 (file)
@@ -491,20 +491,20 @@ try_next_extension:
 
 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
 {
-       struct dirent *d;
-       DIR *dp;
+       const gchar *entry;
+       gchar *fullentry;
+       GDir *dp;
+       GError *error = NULL;
        static const char *extension[]={".png", ".xpm", NULL};
        
-       if ((dp = opendir(dirname)) == NULL) {
-               debug_print("dir %s not found, skipping theme scan\n", dirname?dirname:"(null)");
+       if ((dp = g_dir_open(dirname, 0, &error)) == NULL) {
+               debug_print("skipping theme scan, dir %s could not be opened: %s (%d)\n",
+                               dirname ? dirname : "(null)", error->message, error->code);
+               g_error_free(error);
                return;
        }
        
-       while ((d = readdir(dp)) != NULL) {
-               gchar *entry;
-               gchar *fullentry;
-
-               entry     = d->d_name;
+       while ((entry = g_dir_read_name(dp)) != NULL) {
                fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
                
                if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
@@ -527,7 +527,7 @@ static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
                } else 
                        g_free(fullentry);
        }
-       closedir(dp);
+       g_dir_close(dp);
 }
 
 gchar *stock_pixmap_get_system_theme_dir_for_theme(const gchar *theme)