gEDA-dev: glib 2.8.x functions in gschem/src/x_menu.c
Ivan Stankovic
ivan.stankovic at fer.hr
Wed May 9 04:34:10 EDT 2007
On Wed, May 09, 2007 at 06:39:52AM +0100, Peter TB Brett wrote:
> Hi Ales -- my bad, I assumed that Ivan had used functions in 2.6 or under
> inside a check for GTK 2.6!
>
> However, the recent file loading **is** completely disabled in GTK < 2.6. I
> don't imagine it'll be too difficult to fix it to work in 2.6 --
> g_file_set_contents() is a utility function, and it shouldn't take more than
> an explicit fopen(), fwrite(), fclose() to replace it.
Sorry about this, I don't know how I missed that function. The attached patch
should fix this.
--
Ivan Stankovic, ivan.stankovic at fer.hr
"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"
-------------- next part --------------
>From 14fe3fe4846a9d18033be5482243ec00ec02a954 Mon Sep 17 00:00:00 2001
From: Ivan Stankovic <ivan.stankovic at fer.hr>
Date: Wed, 9 May 2007 10:27:53 +0200
Subject: [PATCH] gschem: g_file_set_contents() exists only in glib >= 2.8
---
gschem/include/prototype.h | 2 ++
gschem/src/x_menus.c | 30 ++++++++++++++++++++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index db46ed6..3eae8d0 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -838,6 +838,8 @@ void x_menu_attach_recent_files_submenu(TOPLEVEL *w_current);
void recent_files_load();
void recent_files_save();
void recent_files_add(const char *filename);
+gboolean file_set_contents(const gchar *filename, const gchar *contents,
+ gssize length, GError **error);
/* x_multiattrib.c */
void x_multiattrib_open (TOPLEVEL *toplevel, OBJECT *object);
/* x_multimulti.c */
diff --git a/gschem/src/x_menus.c b/gschem/src/x_menus.c
index 3a022f3..06df21a 100644
--- a/gschem/src/x_menus.c
+++ b/gschem/src/x_menus.c
@@ -392,6 +392,32 @@ static GList *recent_files = NULL;
#define RECENT_FILES_STORE ".gEDA/gschem-recent-files"
+/* g_file_set_contents() exists only in glib >= 2.8 */
+gboolean file_set_contents(const gchar *filename, const gchar *contents,
+ gssize length, GError **error)
+{
+ FILE *fp;
+ gboolean ret = FALSE;
+
+ fp = fopen(filename, "w");
+ if(fp == NULL)
+ return FALSE;
+
+ if(length == -1) {
+ /* It's a null-terminated string. */
+ if(fputs(contents, fp) == EOF)
+ goto out;
+ } else {
+ if(fwrite(contents, length, 1, fp) != 1)
+ goto out;
+ }
+
+ ret = TRUE;
+out:
+ fclose(fp);
+ return ret;
+}
+
static void recent_file_clicked(gpointer filename)
{
PAGE *page;
@@ -509,7 +535,7 @@ static void recent_files_create_empty()
c = g_key_file_to_data(kf, NULL, NULL);
g_key_file_free(kf);
- g_file_set_contents(file, c, -1, NULL);
+ file_set_contents(file, c, -1, NULL);
g_free(c);
g_free(file);
}
@@ -538,7 +564,7 @@ void recent_files_save()
g_key_file_set_string_list(kf, "Recent files", "Files",
(const gchar **)files, num);
c = g_key_file_to_data(kf, NULL, NULL);
- g_file_set_contents(file, c, -1, NULL);
+ file_set_contents(file, c, -1, NULL);
g_free(c);
g_free(file);
--
1.5.1
More information about the geda-dev
mailing list