windows trial: Replacement of link(2)?

Christian Stimming stimming at tuhh.de
Tue Mar 14 10:29:16 EST 2006


Hi,

Windows/mingw32 doesn't have link(2) and I think this is because vfat et
al don't support hard links anyway. We use this function only in one
file, src/backend/file/gnc-backend-file.c. I'd need some input as for
how to replace that function. My own proposed patch is attached. Please
comment whether this seems fine or not.

The file locking on windows can be a bit less strict than on Unix
because on Windows, the OS will not allow different processes to open
the same file for editing anyway.

Christian
-------------- next part --------------
Index: src/backend/file/gnc-backend-file.c
===================================================================
--- src/backend/file/gnc-backend-file.c	(revision 13630)
+++ src/backend/file/gnc-backend-file.c	(working copy)
@@ -123,17 +123,31 @@
 
     strcpy (pathbuf, be->lockfile);
     path = strrchr (pathbuf, '.');
-    sprintf (path, ".%lx.%d.LNK", gethostid(), getpid());
+    sprintf (path, ".%lx.%d.LNK", 
+#ifdef HAVE_GETHOSTID
+	     gethostid(),
+#else
+	     0,
+#endif
+	     getpid());
 
-    rc = link (be->lockfile, pathbuf);
+    rc = 
+#ifdef HAVE_LINK
+      link (be->lockfile, pathbuf)
+#else
+      -1
+#endif
+      ;
     if (rc)
     {
+#ifdef HAVE_LINK
         /* If hard links aren't supported, just allow the lock. */
         if (errno == EPERM
-#ifdef EOPNOTSUPP
+# ifdef EOPNOTSUPP
 	    || errno == EOPNOTSUPP
+# endif
+	    )
 #endif
-	    )
         {
             be->linkfile = NULL;
             return TRUE;
@@ -337,14 +351,22 @@
 static gboolean
 gnc_int_link_or_make_backup(FileBackend *be, const char *orig, const char *bkup)
 {
-    int err_ret = link(orig, bkup);
+    int err_ret = 
+#ifdef HAVE_LINK
+      link (orig, bkup)
+#else
+      -1
+#endif
+      ;
     if(err_ret != 0)
     {
+#ifdef HAVE_LINK
         if(errno == EPERM
-#ifdef EOPNOTSUPP
+# ifdef EOPNOTSUPP
 	   || errno == EOPNOTSUPP
+# endif
+	   )
 #endif
-	   )
         {
             err_ret = copy_file(orig, bkup);
         }


More information about the gnucash-devel mailing list