Source: tofrodos
Version: 1.7.8.debian.1-2
Author: Guillem Jover <guillem@debian.org>
Status: applied
Debbug: 622365
Description:
 Fix FTBFS on GNU/Hurd.


diff --git a/debian/patches/FTBFS_kfreebsd.diff b/debian/patches/FTBFS_kfreebsd.diff
deleted file mode 100644
index 0cd31b6..0000000
--- a/debian/patches/FTBFS_kfreebsd.diff
+++ /dev/null
@@ -1,16 +0,0 @@
-## 02_FTBFS_kfreebsd.dpatch by Florian Ernst <florian@debian.org>
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: Fix FTBFS on GNU/kFreeBSD, patch by Robert Millan, see bug#351417
-
-diff -urNad tofrodos-1.7.6~/src/config.h tofrodos-1.7.6/src/config.h
---- tofrodos-1.7.6~/src/config.h	2005-03-15 16:01:02.000000000 +0100
-+++ tofrodos-1.7.6/src/config.h	2006-02-07 12:01:04.000000000 +0100
-@@ -95,7 +95,7 @@
- #endif
- 
- /* define the systems */
--#if defined(__linux__)	/* (predefined) */
-+#if defined(__linux__) || defined(__GLIBC__)	/* (predefined) */
- #if !defined(LINUX)
- #define	LINUX
- #endif
diff --git a/debian/patches/FTBFS_non-linux.diff b/debian/patches/FTBFS_non-linux.diff
new file mode 100644
index 0000000..ef3db9a
--- /dev/null
+++ b/debian/patches/FTBFS_non-linux.diff
@@ -0,0 +1,59 @@
+## 02_FTBFS_non-linux.dpatch by Guillem Jover <guillem@debian.org>
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: Fix FTBFS on non Linux systems
+
+---
+ src/config.h   |    4 +++-
+ src/tofrodos.c |   13 ++++++++++---
+ 2 files changed, 13 insertions(+), 4 deletions(-)
+
+--- a/src/config.h
++++ b/src/config.h
+@@ -102,7 +102,9 @@ extern "C" {
+ #endif
+ #endif
+ 
+-#if defined(__FreeBSD__) || defined(__OpenBSD__)	/* seems to work like Linux... */
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
++    defined(__OpenBSD__) || defined(__NetBSD__) || \
++    defined(__GNU__) /* seems to work like Linux... */
+ #if !defined(LINUX)
+ #define	LINUX
+ #endif
+--- a/src/tofrodos.c
++++ b/src/tofrodos.c
+@@ -443,7 +443,7 @@ static int convert ( FILE * infp, FILE *
+ static int openandconvert_preamble ( char * filename )
+ {
+ 	struct stat statbuf ;
+-	char		realfilepath[MAXPATHLEN+1] ;
++	char		*realfilepath ;
+ 	int			len ;
+ 
+ 	/* get the file information */
+@@ -461,16 +461,23 @@ static int openandconvert_preamble ( cha
+ 		/* eg, #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK) */
+ 		/* or something like that. */
+ 
+-		if ((len = readlink( filename, realfilepath, (sizeof(realfilepath) - 1) )) != -1) {
++		realfilepath = xmalloc( statbuf.st_size + 1 );
++
++		if ((len = readlink( filename, realfilepath, statbuf.st_size )) != -1) {
++			int	ret ;
++
+ 			/* got to null terminate the string - there is always space because */
+ 			/* we passed readlink() the size of the buffer less 1. */
+ 			realfilepath[len] = '\0' ;
+ 			if (verbose) {
+ 				emsg( VERBOSE_SYMLINKSRC, filename, realfilepath );
+ 			}
+-			return openandconvert( realfilepath );
++			ret = openandconvert( realfilepath );
++			free( realfilepath );
++			return ret;
+ 		}
+ 		emsg( EMSG_SYMLINK, filename );
++		free( realfilepath );
+ 		return -1 ;
+ 	}
+ 	/* If we reach here, "filename" is not a symbolic link */
diff --git a/debian/patches/series b/debian/patches/series
index 7252415..5b0a355 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1 @@
-FTBFS_kfreebsd.diff
+FTBFS_non-linux.diff
