>From 49d5cf131be213bbbfe52e756e7a2461df784f72 Mon Sep 17 00:00:00 2001
From: Nils Goroll <nils.goroll@uplex.de>
Date: Tue, 20 Aug 2013 12:27:53 +0200
Subject: [PATCH] use liblongpath if available

---
 configure.ac |    8 ++++++++
 flist.c      |    3 +++
 rsync.h      |    8 ++++++++
 syscall.c    |    4 ++++
 xattrs.c     |    4 ++++
 5 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index 633aa5c..562dc87 100644
--- a/configure.ac
+++ b/configure.ac
@@ -487,6 +487,14 @@ AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
 
 dnl AC_MSG_NOTICE([Looking in libraries: $LIBS])
 
+# longpath support - see https://code.uplex.de/liblongpath/liblongpath
+# as long as rsync is single threaded, we can use _unsafe
+# NOTE: CHANGE THIS WHEN GOING MULTI-THREADED!
+AC_LIB_HAVE_LINKFLAGS([longpath_unsafe], [], [#include <longpath/longpath.h>])
+if test x$HAVE_LIBLONGPATH_UNSAFE = xyes; then
+   LIBS="$LIBS $LIBLONGPATH_UNSAFE"
+fi
+
 AC_CHECK_FUNCS(inet_ntop, , [AC_LIBOBJ(lib/inet_ntop)])
 AC_CHECK_FUNCS(inet_pton, , [AC_LIBOBJ(lib/inet_pton)])
 
diff --git a/flist.c b/flist.c
index bf8d124..7b7b812 100644
--- a/flist.c
+++ b/flist.c
@@ -25,6 +25,9 @@
 #include "rounding.h"
 #include "inums.h"
 #include "io.h"
+#if defined HAVE_LIBLONGPATH_UNSAFE
+#include <longpath/longpath_redefine_defs.h>
+#endif
 
 extern int am_root;
 extern int am_server;
diff --git a/rsync.h b/rsync.h
index 714906a..7c24df1 100644
--- a/rsync.h
+++ b/rsync.h
@@ -280,6 +280,10 @@ enum delret {
 
 #include "config.h"
 
+#if defined HAVE_LIBLONGPATH_UNSAFE
+#include <longpath/longpath_redefine_pre.h>
+#endif
+
 /* The default RSYNC_RSH is always set in config.h. */
 
 #include <stdio.h>
@@ -1289,3 +1293,7 @@ char *getpass(const char *prompt);
 #ifdef MAINTAINER_MODE
 const char *get_panic_action(void);
 #endif
+
+#if defined HAVE_LIBLONGPATH_UNSAFE
+#include <longpath/longpath_redefine_post.h>
+#endif
diff --git a/syscall.c b/syscall.c
index fd23d15..169a631 100644
--- a/syscall.c
+++ b/syscall.c
@@ -33,6 +33,10 @@
 #include <sys/syscall.h>
 #endif
 
+#if defined HAVE_LIBLONGPATH_UNSAFE
+#include <longpath/longpath_redefine_post.h>
+#endif
+
 extern int dry_run;
 extern int am_root;
 extern int am_sender;
diff --git a/xattrs.c b/xattrs.c
index df2ea82..8391147 100644
--- a/xattrs.c
+++ b/xattrs.c
@@ -26,6 +26,10 @@
 
 #ifdef SUPPORT_XATTRS
 
+#if defined HAVE_LIBLONGPATH_UNSAFE
+#include <longpath/longpath_redefine_post.h>
+#endif
+
 extern int dry_run;
 extern int am_root;
 extern int am_sender;
-- 
1.5.6.5

