r21900 - gnucash/trunk/src/backend/xml - Bug #668926: Fixes build on GNU/Hurd
Christian Stimming
cstim at code.gnucash.org
Sat Jan 28 17:05:51 EST 2012
Author: cstim
Date: 2012-01-28 17:05:50 -0500 (Sat, 28 Jan 2012)
New Revision: 21900
Trac: http://svn.gnucash.org/trac/changeset/21900
Modified:
gnucash/trunk/src/backend/xml/gnc-backend-xml.c
Log:
Bug #668926: Fixes build on GNU/Hurd
A buffer of fixed size PATH_MAX is created, but this constant is non-existent
on GNU/Hurd, so the package FTBFS on that architecture.
The fix consists in using a dynamically (re-)allocated buffer, as recommended
on: http://www.gnu.org/software/hurd/hurd/porting/guidelines.html
Modified: gnucash/trunk/src/backend/xml/gnc-backend-xml.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-backend-xml.c 2012-01-28 21:46:29 UTC (rev 21899)
+++ gnucash/trunk/src/backend/xml/gnc-backend-xml.c 2012-01-28 22:05:50 UTC (rev 21900)
@@ -117,8 +117,8 @@
{
struct stat statbuf;
#ifndef G_OS_WIN32
- char pathbuf[PATH_MAX];
- char *path = NULL;
+ char *pathbuf = NULL, *path = NULL;
+ size_t pathbuf_size = 0;
#endif
int rc;
QofBackendError be_err;
@@ -169,9 +169,16 @@
*/
#ifndef G_OS_WIN32
+ pathbuf_size = strlen (be->lockfile) + 100;
+ pathbuf = (char *) malloc (pathbuf_size);
strcpy (pathbuf, be->lockfile);
path = strrchr (pathbuf, '.');
- sprintf (path, ".%lx.%d.LNK", gethostid(), getpid());
+ while (snprintf (path, pathbuf_size - (path - pathbuf), ".%lx.%d.LNK", gethostid(), getpid())
+ >= pathbuf_size - (path - pathbuf))
+ {
+ pathbuf_size += 100;
+ pathbuf = (char *) realloc (pathbuf, pathbuf_size);
+ }
rc = link (be->lockfile, pathbuf);
if (rc)
@@ -187,12 +194,14 @@
)
{
be->linkfile = NULL;
+ free (pathbuf);
return TRUE;
}
/* Otherwise, something else is wrong. */
qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED);
g_unlink (pathbuf);
+ free (pathbuf);
close (be->lockfd);
g_unlink (be->lockfile);
return FALSE;
@@ -206,6 +215,7 @@
qof_backend_set_message ((QofBackend*)be, "Failed to stat lockfile %s",
be->lockfile );
g_unlink (pathbuf);
+ free (pathbuf);
close (be->lockfd);
g_unlink (be->lockfile);
return FALSE;
@@ -215,12 +225,14 @@
{
qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED);
g_unlink (pathbuf);
+ free (pathbuf);
close (be->lockfd);
g_unlink (be->lockfile);
return FALSE;
}
be->linkfile = g_strdup (pathbuf);
+ free (pathbuf);
return TRUE;
More information about the gnucash-changes
mailing list