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;
}
}
}
}
+ 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;
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 );
}
/*
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;
addrharvest_readfile( harvester, msgNum, cache, listHdr );
node = g_list_next( node );
}
- closedir( dp );
}
/*
gint file_no;
GHashTable *wanted_files;
GSList *cur;
+ GError *error = NULL;
if (numberlist == NULL)
return 0;
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;
}
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)
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;
}
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;
}
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.
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 );
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.
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 );
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;
return;
if (mainWin) {
- GError *error;
+ GError *error = NULL;
gboolean online;
- error = NULL;
online = networkmanager_is_online(&error);
if(!error) {
if(online && went_offline_nm) {
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;
}
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;
{
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);
}
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;
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);
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",
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);
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;
g_free(utf8name);
}
-#ifdef G_OS_WIN32
g_dir_close(dir);
-#else
- closedir(dp);
-#endif
mh_set_mtime(folder, item);
}
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()
static void unbind_toggle_mainwindow()
{
- GError *error;
+ GError *error = NULL;
GtkHotkeyRegistry *registry;
/* clean up old hotkey */
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, ""))
{
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));
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");
gchar *path = NULL, *fname = NULL;
GDir *dp;
const gchar *d;
- GError *error;
+ GError *error = NULL;
gint num;
FeedItem *item = NULL;
RFeedCtx *ctx;
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);
gchar *path;
const char *f;
GDir *dp;
- GError *error;
+ GError *error = NULL;
gint max = 0;
gint num;
gchar *path;
GDir *dp;
const gchar *d;
- GError *error;
+ GError *error = NULL;
gint num, nummsgs = 0;
g_return_val_if_fail(item != NULL, -1);
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);
RFetchCtx *ctx = NULL;
GDir *dp;
const gchar *d;
- GError *error;
+ GError *error = NULL;
gint num;
gchar *path, *msg, *fname;
MainWindow *mainwin = mainwindow_get_mainwindow();
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);
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);
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;
}
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);
vcal_manager_free_event(event);
}
}
- closedir(dp);
+ g_dir_close(dp);
return g_slist_reverse(events);
}
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)
}
-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;
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;
}
-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;
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;
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);
g_free(fp);
row++;
}
- closedir(dir);
+ g_dir_close(dir);
g_free(path);
}
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)) {
} else
g_free(fullentry);
}
- closedir(dp);
+ g_dir_close(dp);
}
gchar *stock_pixmap_get_system_theme_dir_for_theme(const gchar *theme)