Re: patch for linc on i386-gnu



On Sun, Oct 13, 2002 at 04:55:25PM +0200, Marcus Brinkmann wrote:
> 2002-10-13  Marcus Brinkmann  <marcus@gnu.org>
> 
> 	* src/linc-protocols.c (linc_tmpdir): Change type to char * and
> 	remove initializer.
> 	(linc_set_tmpdir): Dynamically allocate a large enough buffer for
> 	linc_tmpdir.
> 	(linc_get_tmpdir): Fall back to "" if linc_tmpdir is not set.
> 	(linc_protocol_get_sockaddr_unix): Likewise.

A slightly better version using g_strdup.

Thanks,
Marcus

--- linc-protocols.c.org	2002-10-13 18:46:47.000000000 +0200
+++ linc-protocols.c	2002-10-13 19:14:11.000000000 +0200
@@ -20,7 +20,7 @@
 
 #undef LOCAL_DEBUG
 
-static char linc_tmpdir [PATH_MAX] = "";
+static char *linc_tmpdir;
 
 /*
  * make_local_tmpdir:
@@ -82,9 +82,10 @@
 void
 linc_set_tmpdir (const char *dir)
 {
-	strncpy (linc_tmpdir, dir, PATH_MAX);
+	if (linc_tmpdir)
+		g_free (linc_tmpdir);
 
-	linc_tmpdir [PATH_MAX - 1] = '\0';
+	linc_tmpdir = g_strdup (dir);
 
 	make_local_tmpdir (linc_tmpdir);
 }
@@ -101,7 +102,7 @@
 char *
 linc_get_tmpdir (void)
 {
-	return g_strdup (linc_tmpdir);
+	return g_strdup (linc_tmpdir ? linc_tmpdir : "");
 }
 
 #ifdef HAVE_SOCKADDR_SA_LEN
@@ -400,7 +401,8 @@
 
 		gettimeofday (&t, NULL);
 		g_snprintf (buf, sizeof (buf),
-			    "%s/linc-%x-%x-%x%x", linc_tmpdir,
+			    "%s/linc-%x-%x-%x%x",
+			    linc_tmpdir ? linc_tmpdir : "",
 			    pid, idx++,
 			    (guint) (rand() ^ t.tv_sec),
 			    (guint) (idx ^ t.tv_usec));

-- 
`Rhubarb is no Egyptian god.' GNU      http://www.gnu.org    marcus@gnu.org
Marcus Brinkmann              The Hurd http://www.gnu.org/software/hurd/
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de/



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