Re: control-center-1.2.1: Why does it use getline()?



Paul Barnfather <plb@clanger9.demon.co.uk> writes:

> The new control-center does not compile on Solaris, AIX (and presumably
> other !Linux systems?)
> 
> It makes a call to getline(), which I can't find anywhere.
> 
> Is this an essential "feature"? If so, where can I get the necessary
> library?

Essential feature? No... the getline() usage began as a Red Hat Linux
specific patch to bulletproof the gtkrc editing code, and I used this
convenient GNU libc function. Then it got incorporated into the
standard control-center without being properly portabilized.

Could you try the following patch ... (to test the configure.in
bit, you need to rerun autoconf)

Regards,
                                        Owen

Index: configure.in
===================================================================
RCS file: /cvs/gnome/control-center/configure.in,v
retrieving revision 1.170.2.10
diff -u -r1.170.2.10 configure.in
--- configure.in	2000/08/04 08:42:14	1.170.2.10
+++ configure.in	2000/08/05 16:51:44
@@ -56,7 +56,7 @@
 ])])
 AC_SUBST(DL_LIB)
 
-AC_CHECK_FUNCS(usleep)
+AC_CHECK_FUNCS(usleep flockfile getline)
 
 dnl keyboard-properties-capplet
 AC_CHECK_HEADERS(X11/extensions/xf86misc.h, XF86MISC_LIBS="-lXxf86misc")
Index: capplets/theme-switcher/lister.c
===================================================================
RCS file: /cvs/gnome/control-center/capplets/theme-switcher/lister.c,v
retrieving revision 1.5.2.1
diff -u -r1.5.2.1 lister.c
--- capplets/theme-switcher/lister.c	2000/08/01 23:55:17	1.5.2.1
+++ capplets/theme-switcher/lister.c	2000/08/05 16:51:46
@@ -4,6 +4,91 @@
 #include <sys/types.h>
 #include <utime.h>
 #include <errno.h>
+#include <config.h>
+
+#ifndef HAVE_GETLINE
+/* The interface here is that of GNU libc's getline */
+static ssize_t
+getline (char **lineptr, size_t *n, FILE *stream)
+{
+#define EXPAND_CHUNK 16
+
+  int n_read = 0;
+  char *line = *lineptr;
+
+  g_return_val_if_fail (lineptr != NULL, -1);
+  g_return_val_if_fail (n != NULL, -1);
+  g_return_val_if_fail (stream != NULL, -1);
+  g_return_val_if_fail (*lineptr != NULL || *n == 0, -1);
+  
+#ifdef HAVE_FLOCKFILE
+  flockfile (stream);
+#endif  
+  
+  while (1)
+    {
+      int c;
+      
+#ifdef HAVE_FLOCKFILE
+      c = getc_unlocked (stream);
+#else
+      c = getc (stream);
+#endif      
+
+      if (c == EOF)
+        {
+          if (n_read > 0)
+	    line[n_read] = '\0';
+          break;
+        }
+
+      if (n_read + 2 >= *n)
+        {
+	  size_t new_size;
+
+	  if (*n == 0)
+	    new_size = 16;
+	  else
+	    new_size = *n * 2;
+
+	  if (*n >= new_size)    /* Overflowed size_t */
+	    line = NULL;
+	  else
+	    line = *lineptr ? realloc (*lineptr, new_size) : malloc (new_size);
+
+	  if (line)
+	    {
+	      *lineptr = line;
+	      *n = new_size;
+	    }
+	  else
+	    {
+	      if (*n > 0)
+		{
+		  (*lineptr)[*n - 1] = '\0';
+		  n_read = *n - 2;
+		}
+	      break;
+	    }
+        }
+
+      line[n_read] = c;
+      n_read++;
+
+      if (c == '\n')
+        {
+          line[n_read] = '\0';
+          break;
+        }
+    }
+
+#ifdef HAVE_FLOCKFILE
+  funlockfile (stream);
+#endif
+
+  return n_read - 1;
+}
+#endif /* ! HAVE_GETLINE */
 
 #define MARK_STRING "# -- THEME AUTO-WRITTEN DO NOT EDIT\n"
 static void




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]