gEDA-dev: glib 2.8.x functions in gschem/src/x_menu.c
Ivan Stankovic
ivan.stankovic at fer.hr
Wed May 9 11:28:36 EDT 2007
On Wed, May 09, 2007 at 01:24:48PM +0200, Bernd Jendrissek wrote:
> Why not just name it g_file_set_contents() and wrap its definition and
> declaration in #ifdef HAVE_G_SET_FILE_CONTENTS/#endif?
I agree, please see the patch below.
--
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 f8ebd63a277b1c11b38b5c1f6e046de38d7c81d0 Mon Sep 17 00:00:00 2001
From: Ivan Stankovic <ivan.stankovic at fer.hr>
Date: Wed, 9 May 2007 17:24:53 +0200
Subject: [PATCH] gschem: g_file_set_contents() exists only in glib >= 2.8
---
gschem/include/prototype.h | 4 ++++
gschem/src/x_menus.c | 28 ++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index db46ed6..54cc8cc 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -838,6 +838,10 @@ 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);
+#if !GLIB_CHECK_VERSION(2,8,0)
+gboolean g_file_set_contents(const gchar *filename, const gchar *contents,
+ gssize length, GError **error);
+#endif
/* 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..4765076 100644
--- a/gschem/src/x_menus.c
+++ b/gschem/src/x_menus.c
@@ -369,6 +369,34 @@ void x_menus_popup_sensitivity (TOPLEVEL* w_current, const char *buf, int flag)
}
}
+#if !GLIB_CHECK_VERSION(2,8,0)
+/* g_file_set_contents() exists only in glib >= 2.8 */
+gboolean g_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;
+}
+#endif /* !GLIB_CHECK_VERSION(2,8,0) */
+
#if !GLIB_CHECK_VERSION(2,6,0)
/* disable recent files support */
--
1.5.1
More information about the geda-dev
mailing list