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 4cbfc42..4244629 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 999dcda..97eff8b 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 a07e913..0ad18cf 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 49db84c..fa787b7 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 3790636..c1906da 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 5533ba8..675576f 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 1e7345d..b5f1b2d 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 bd2cf0a..c864975 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 e3f684c..f554b8b 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 606da64..45acb6a 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 5f8ddb1..9ce01ba 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 53e43a5..f40bd87 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 df378f9..7f72b0e 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 c8e4b29..0674666 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 df66fa5..129339e 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 9bbb6cf..15e0bd9 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 5eadc4a..33307bf 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 5983495..eb95612 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 066dc9d..c609619 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 2c3aa88..0de5e72 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 8a8e991..ef7297a 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 6b2f665..bd13e31 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 6a12d18..84ec1da 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)