[dia/neduard/meson_fixes: 20/26] Code cleanup: for_each_in_dir and custom.c.
- From: Eduard <neduard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/neduard/meson_fixes: 20/26] Code cleanup: for_each_in_dir and custom.c.
- Date: Fri, 15 Feb 2019 14:29:40 +0000 (UTC)
commit 3c32a9260863465024717d8e6192db0d7e8e0adc
Author: Eduard <eddnicodei gmail com>
Date: Fri Feb 1 00:42:27 2019 +0000
Code cleanup: for_each_in_dir and custom.c.
lib/plug-ins.c | 17 +++++++++++------
objects/custom/custom.c | 7 +++----
2 files changed, 14 insertions(+), 10 deletions(-)
---
diff --git a/lib/plug-ins.c b/lib/plug-ins.c
index c07cd359..415e8f57 100644
--- a/lib/plug-ins.c
+++ b/lib/plug-ins.c
@@ -290,26 +290,31 @@ for_each_in_dir(const gchar *directory, ForEachInDirDoFunc dofunc,
ForEachInDirFilterFunc filter)
{
GStatBuf statbuf;
- const char *dentry;
+ const gchar *dentry;
GDir *dp;
GError *error = NULL;
- if (g_stat(directory, &statbuf) < 0)
+ if (g_stat(directory, &statbuf) < 0) {
return;
+ }
dp = g_dir_open(directory, 0, &error);
if (dp == NULL) {
g_warning("Could not open `%s'\n`%s'", directory, error->message);
- g_error_free (error);
+ g_error_free(error);
return;
}
- while ((dentry = g_dir_read_name(dp)) != NULL) {
- gchar *name = g_build_filename(directory,dentry,NULL);
+ while ( (dentry = g_dir_read_name(dp)) ) {
+ gchar *name = g_build_filename(directory, dentry, NULL);
+
+ if (filter(name)) {
+ dofunc(name);
+ }
- if (filter(name)) dofunc(name);
g_free(name);
}
+
g_dir_close(dp);
}
diff --git a/objects/custom/custom.c b/objects/custom/custom.c
index 5de009dd..c21310a2 100644
--- a/objects/custom/custom.c
+++ b/objects/custom/custom.c
@@ -35,9 +35,8 @@
#include "dia_dirs.h"
#include "intl.h"
#include "plug-ins.h"
+#include "custom_object.h"
-void custom_object_new (ShapeInfo *info,
- DiaObjectType **otype);
G_MODULE_EXPORT gboolean custom_object_load(gchar *filename,
DiaObjectType **otype);
@@ -95,9 +94,9 @@ load_shapes_from_tree(const gchar *directory)
if (dp == NULL) {
return;
}
+
while ( (dentry = g_dir_read_name(dp)) ) {
- gchar *filename = g_strconcat(directory, G_DIR_SEPARATOR_S,
- dentry, NULL);
+ gchar *filename = g_build_filename(directory, dentry, NULL);
const gchar *p;
if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]