code:
diff -ru a//include/llvm/Target/TargetLibraryInfo.h b//include/llvm/Target/TargetLibraryInfo.h
--- a//include/llvm/Target/TargetLibraryInfo.h	2013-11-03 06:48:38.000000000 +0000
+++ b//include/llvm/Target/TargetLibraryInfo.h	2014-01-13 05:10:56.127944508 +0000
@@ -259,8 +259,6 @@
       fmodl,
       /// FILE *fopen(const char *filename, const char *mode);
       fopen,
-      /// FILE *fopen64(const char *filename, const char *opentype)
-      fopen64,
       /// int fprintf(FILE *stream, const char *format, ...);
       fprintf,
       /// int fputc(int c, FILE *stream);
@@ -283,8 +281,6 @@
       fseek,
       /// int fseeko(FILE *stream, off_t offset, int whence);
       fseeko,
-      /// int fseeko64(FILE *stream, off64_t offset, int whence)
-      fseeko64,
       /// int fsetpos(FILE *stream, const fpos_t *pos);
       fsetpos,
       /// int fstat(int fildes, struct stat *buf);
@@ -299,8 +295,6 @@
       ftell,
       /// off_t ftello(FILE *stream);
       ftello,
-      /// off64_t ftello64(FILE *stream)
-      ftello64,
       /// int ftrylockfile(FILE *file);
       ftrylockfile,
       /// void funlockfile(FILE *file);
@@ -606,8 +600,6 @@
       times,
       /// FILE *tmpfile(void);
       tmpfile,
-      /// FILE *tmpfile64(void)
-      tmpfile64,
       /// int toascii(int c);
       toascii,
       /// double trunc(double x);
diff -ru a//lib/ExecutionEngine/RTDyldMemoryManager.cpp b//lib/ExecutionEngine/RTDyldMemoryManager.cpp
--- a//lib/ExecutionEngine/RTDyldMemoryManager.cpp	2013-12-24 06:50:45.000000000 +0000
+++ b//lib/ExecutionEngine/RTDyldMemoryManager.cpp	2014-01-13 05:13:00.116944627 +0000
@@ -33,7 +33,7 @@
 RTDyldMemoryManager::~RTDyldMemoryManager() {}

 // Determine whether we can register EH tables.
-#if (defined(__GNUC__) && !defined(__ARM_EABI__) && !defined(__ia64__) && \
+#if (defined(__GLIBC__) && !defined(__ARM_EABI__) && !defined(__ia64__) && \
      !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__))
 #define HAVE_EHTABLE_SUPPORT 1
 #else
diff -ru a//lib/Support/DynamicLibrary.cpp b//lib/Support/DynamicLibrary.cpp
--- a//lib/Support/DynamicLibrary.cpp	2013-11-13 15:35:13.000000000 +0000
+++ b//lib/Support/DynamicLibrary.cpp	2014-01-13 05:13:52.530944677 +0000
@@ -143,7 +143,7 @@
 // On linux we have a weird situation. The stderr/out/in symbols are both
 // macros and global variables because of standards requirements. So, we
 // boldly use the EXPLICIT_SYMBOL macro without checking for a #define first.
-#if defined(__linux__) and !defined(__ANDROID__)
+#if defined(__GLIBC__)
   {
     EXPLICIT_SYMBOL(stderr);
     EXPLICIT_SYMBOL(stdout);
diff -ru a//lib/Support/Unix/Signals.inc b//lib/Support/Unix/Signals.inc
--- a//lib/Support/Unix/Signals.inc	2013-08-30 20:39:21.000000000 +0000
+++ b//lib/Support/Unix/Signals.inc	2014-01-13 05:14:59.285944741 +0000
@@ -266,7 +266,7 @@
 // On glibc systems we have the 'backtrace' function, which works nicely, but
 // doesn't demangle symbols.
 void llvm::sys::PrintStackTrace(FILE *FD) {
-#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
+#if defined(__GLIBC__) && defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
   static void* StackTrace[256];
   // Use backtrace() to output a backtrace on Linux systems with glibc.
   int depth = backtrace(StackTrace,
diff -ru a//lib/Target/TargetLibraryInfo.cpp b//lib/Target/TargetLibraryInfo.cpp
--- a//lib/Target/TargetLibraryInfo.cpp	2013-11-03 06:48:38.000000000 +0000
+++ b//lib/Target/TargetLibraryInfo.cpp	2014-01-13 05:16:07.928944807 +0000
@@ -144,7 +144,6 @@
     "fmodf",
     "fmodl",
     "fopen",
-    "fopen64",
     "fprintf",
     "fputc",
     "fputs",
@@ -156,7 +155,6 @@
     "fscanf",
     "fseek",
     "fseeko",
-    "fseeko64",
     "fsetpos",
     "fstat",
     "fstat64",
@@ -164,7 +162,6 @@
     "fstatvfs64",
     "ftell",
     "ftello",
-    "ftello64",
     "ftrylockfile",
     "funlockfile",
     "fwrite",
@@ -315,7 +312,6 @@
     "tanl",
     "times",
     "tmpfile",
-    "tmpfile64",
     "toascii",
     "trunc",
     "truncf",
@@ -603,16 +599,12 @@
     TLI.setUnavailable(LibFunc::under_IO_getc);
     TLI.setUnavailable(LibFunc::under_IO_putc);
     TLI.setUnavailable(LibFunc::memalign);
-    TLI.setUnavailable(LibFunc::fopen64);
-    TLI.setUnavailable(LibFunc::fseeko64);
     TLI.setUnavailable(LibFunc::fstat64);
     TLI.setUnavailable(LibFunc::fstatvfs64);
-    TLI.setUnavailable(LibFunc::ftello64);
     TLI.setUnavailable(LibFunc::lstat64);
     TLI.setUnavailable(LibFunc::open64);
     TLI.setUnavailable(LibFunc::stat64);
     TLI.setUnavailable(LibFunc::statvfs64);
-    TLI.setUnavailable(LibFunc::tmpfile64);
   }
 }

diff -ru a//lib/Transforms/IPO/FunctionAttrs.cpp b//lib/Transforms/IPO/FunctionAttrs.cpp
--- a//lib/Transforms/IPO/FunctionAttrs.cpp	2013-10-31 03:03:55.000000000 +0000
+++ b//lib/Transforms/IPO/FunctionAttrs.cpp	2014-01-13 05:16:39.776944837 +0000
@@ -1599,32 +1599,6 @@
     setOnlyReadsMemory(F, 1);
     setOnlyReadsMemory(F, 2);
     break;
-  case LibFunc::fopen64:
-    if (FTy->getNumParams() != 2 ||
-        !FTy->getReturnType()->isPointerTy() ||
-        !FTy->getParamType(0)->isPointerTy() ||
-        !FTy->getParamType(1)->isPointerTy())
-      return false;
-    setDoesNotThrow(F);
-    setDoesNotAlias(F, 0);
-    setDoesNotCapture(F, 1);
-    setDoesNotCapture(F, 2);
-    setOnlyReadsMemory(F, 1);
-    setOnlyReadsMemory(F, 2);
-    break;
-  case LibFunc::fseeko64:
-  case LibFunc::ftello64:
-    if (FTy->getNumParams() == 0 || !FTy->getParamType(0)->isPointerTy())
-      return false;
-    setDoesNotThrow(F);
-    setDoesNotCapture(F, 1);
-    break;
-  case LibFunc::tmpfile64:
-    if (!FTy->getReturnType()->isPointerTy())
-      return false;
-    setDoesNotThrow(F);
-    setDoesNotAlias(F, 0);
-    break;
   case LibFunc::fstat64:
   case LibFunc::fstatvfs64:
     if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
diff -ru a//projects/compiler-rt/lib/Makefile.mk b//projects/compiler-rt/lib/Makefile.mk
--- a//projects/compiler-rt/lib/Makefile.mk	2013-08-07 22:47:26.000000000 +0000
+++ b//projects/compiler-rt/lib/Makefile.mk	2014-01-13 05:19:22.742944993 +0000
@@ -14,15 +14,15 @@
 SubDirs += i386 ppc x86_64 arm

 # Add other submodules.
-SubDirs += asan
+#SubDirs += asan
 SubDirs += interception
 SubDirs += profile
-SubDirs += sanitizer_common
-SubDirs += tsan
-SubDirs += msan
-SubDirs += ubsan
-SubDirs += lsan
-SubDirs += dfsan
+#SubDirs += sanitizer_common
+#SubDirs += tsan
+#SubDirs += msan
+#SubDirs += ubsan
+#SubDirs += lsan
+#SubDirs += dfsan

 # Define the variables for this specific directory.
 Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file)))
diff -ru a//projects/compiler-rt/lib/interception/interception_linux.cc b//projects/compiler-rt/lib/interception/interception_linux.cc
--- a//projects/compiler-rt/lib/interception/interception_linux.cc	2013-09-03 07:53:49.000000000 +0000
+++ b//projects/compiler-rt/lib/interception/interception_linux.cc	2014-01-13 05:20:27.936945056 +0000
@@ -24,12 +24,6 @@
   return real == wrapper;
 }

-#if !defined(__ANDROID__)  // android does not have dlvsym
-void *GetFuncAddrVer(const char *func_name, const char *ver) {
-  return dlvsym(RTLD_NEXT, func_name, ver);
-}
-#endif  // !defined(__ANDROID__)
-
 }  // namespace __interception

diff -ru a//projects/compiler-rt/lib/interception/interception_linux.h b//projects/compiler-rt/lib/interception/interception_linux.h
--- a//projects/compiler-rt/lib/interception/interception_linux.h	2013-11-12 10:21:52.000000000 +0000
+++ b//projects/compiler-rt/lib/interception/interception_linux.h	2014-01-13 05:20:19.617945048 +0000
@@ -34,14 +34,8 @@
           (::__interception::uptr)&(func), \
           (::__interception::uptr)&WRAP(func))

-#if !defined(__ANDROID__)  // android does not have dlvsym
-# define INTERCEPT_FUNCTION_VER_LINUX(func, symver) \
-     ::__interception::real_##func = (func##_f)(unsigned long) \
-         ::__interception::GetFuncAddrVer(#func, symver)
-#else
 # define INTERCEPT_FUNCTION_VER_LINUX(func, symver) \
      INTERCEPT_FUNCTION_LINUX(func)
-#endif  // !defined(__ANDROID__)

 #endif  // INTERCEPTION_LINUX_H
 #endif  // __linux__
diff -ru a//utils/unittest/googletest/src/gtest.cc b//utils/unittest/googletest/src/gtest.cc
--- a//utils/unittest/googletest/src/gtest.cc	2013-11-19 00:57:56.000000000 +0000
+++ b//utils/unittest/googletest/src/gtest.cc	2014-01-13 05:17:31.868944887 +0000
@@ -120,6 +120,7 @@

 #if GTEST_CAN_STREAM_RESULTS_
 # include <arpa/inet.h>  // NOLINT
+# include <sys/socket.h>
 # include <netdb.h>  // NOLINT
 #endif


code:
--- lsof_4.87_src.org/dialects/linux/Makefile
+++ lsof_4.87_src/dialects/linux/Makefile
@@ -43,7 +43,7 @@
 all: ${PROG}

 ${PROG}: ${P} ${LIB} ${OBJ}
-	${CC} -o $@ ${OBJ} ${CFGL}
+	${CC} -o $@ ${OBJ} ${CFLAGS} ${CFGL} ${LDFLAGS}

 clean: FRC
 	rm -f Makefile.bak ${PROG} a.out core errs lint.out tags *.o version.h ${CFGDN}

repo_name: aarf/bkauler

license: unknown


code:
--- lsof_4.87_src.org/dialects/linux/dsock.c
+++ lsof_4.87_src/dialects/linux/dsock.c
@@ -35,10 +35,9 @@
 static char *rcsid = "$Id: dsock.c,v 1.39 2013/01/02 17:02:36 abe Exp $";
 #endif

-
+#include <netinet/tcp.h>
 #include "lsof.h"
 #include <sys/xattr.h>
-

 /*
  * Local definitions


code:
--- lsof_4.87_src.org/Configure
+++ lsof_4.87_src/Configure
@@ -5370,6 +5370,21 @@
 fi	# }
 rm -f ${LSOF_TMPC}.[cox]

+cat > $LSOF_TMPC.c << .LSOF_END_HERE_DOC2
+#include <rpc/pmap_prot.h>
+int main(){return 0;}
+.LSOF_END_HERE_DOC2
+echo $EO "Testing for rpc/pmap_prot.h, using $LSOF_CC ... $EC"
+$LSOF_CC ${LSOF_TMPC}.c -o ${LSOF_TMPC}.x > /dev/null 2>&1
+if test -x ${LSOF_TMPC}.x	# {
+then
+  echo "present"
+else
+  echo "missing"
+  LSOF_CFGF="$LSOF_CFGF -DHASNORPC_H"
+fi	# }
+rm -f ${LSOF_TMPC}.[cox]
+
 # Make the dialect sources.

 if test "X$LSOF_MKC" = "X"	# {


code:
--- ./conf/example.conf.in.orig
+++ ./conf/example.conf.in
@@ -694,6 +694,7 @@
 	# Configuration option global/library_dir.
 	# Search this directory first for shared libraries.
 	# This configuration option does not have a default value defined.
+	library_dir="/lib/device-mapper"

 	# Configuration option global/locking_library.
 	# The external locking library to use for locking_type 2.


code:
--- ./lib/mm/memlock.c.orig	2015-03-09 11:18:41.560028850 -0100
+++ ./lib/mm/memlock.c	2015-03-09 11:19:54.504373309 -0100
@@ -137,7 +137,7 @@

 static void _allocate_memory(void)
 {
-#ifndef VALGRIND_POOL
+#if !defined(VALGRIND_POOL) && defined(__GLIBC__)
 	void *stack_mem;
 	struct rlimit limit;
 	int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;


code:
--- ./conf/example.conf.in.orig
+++ ./conf/example.conf.in
@@ -1352,7 +1352,7 @@
 	# Use the old behavior of mlockall to pin all memory.
 	# Prior to version 2.02.62, LVM used mlockall() to pin the whole
 	# process's memory while activating devices.
-	use_mlockall = 0
+	use_mlockall = 1

 	# Configuration option activation/monitoring.
 	# Monitor LVs that are activated.
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index 8ab1fde..57b2443 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -53,7 +53,7 @@
 #define DEFAULT_WAIT_FOR_LOCKS 1
 #define DEFAULT_LVMLOCKD_LOCK_RETRIES 3
 #define DEFAULT_PRIORITISE_WRITE_LOCKS 1
-#define DEFAULT_USE_MLOCKALL 0
+#define DEFAULT_USE_MLOCKALL 1
 #define DEFAULT_METADATA_READ_ONLY 0
 #define DEFAULT_LVDISPLAY_SHOWS_FULL_DEVICE_PATH 0


code:
--- LVM2.2.02.103.orig/lib/commands/toolcontext.c
+++ LVM2.2.02.103/lib/commands/toolcontext.c
@@ -1336,7 +1336,10 @@
 /*
  * Close and reopen stream on file descriptor fd.
  */
-static int _reopen_stream(FILE *stream, int fd, const char *mode, const char *name, FILE **new_stream)
+#ifdef __GLIBC__
+#define _reopen_stream(stream, fd, mode, name) __reopen_stream(stream, fd, mode, name, &stream)
+
+static int __reopen_stream(FILE *stream, int fd, const char *mode, const char *name, FILE **new_stream)
 {
 	int fd_copy, new_fd;

@@ -1363,6 +1366,9 @@

 	return 1;
 }
+#else
+#define _reopen_stream(stream, fd, mode, name) (freopen(NULL, mode, stream) != NULL)
+#endif

 /* Entry point */
 struct cmd_context *create_toolcontext(unsigned is_long_lived,
@@ -1371,7 +1377,6 @@
 				       unsigned threaded)
 {
 	struct cmd_context *cmd;
-	FILE *new_stream;
 	int flags;

 #ifdef M_MMAP_MAX
@@ -1421,9 +1426,8 @@
 		if (is_valid_fd(STDIN_FILENO) &&
 		    ((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) &&
 		    (flags & O_ACCMODE) != O_WRONLY) {
-			if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream))
+			if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin"))
 				goto_out;
-			stdin = new_stream;
 			if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) {
 				log_sys_error("setvbuf", "");
 				goto out;
@@ -1433,9 +1437,8 @@
 		if (is_valid_fd(STDOUT_FILENO) &&
 		    ((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) &&
 		    (flags & O_ACCMODE) != O_RDONLY) {
-			if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream))
+			if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout"))
 				goto_out;
-			stdout = new_stream;
 			if (setvbuf(stdout, cmd->linebuffer + linebuffer_size,
 				     _IOLBF, linebuffer_size)) {
 				log_sys_error("setvbuf", "");
@@ -1715,7 +1718,6 @@
 void destroy_toolcontext(struct cmd_context *cmd)
 {
 	struct dm_config_tree *cft_cmdline;
-	FILE *new_stream;
 	int flags;

 	if (cmd->dump_filter && cmd->filter && cmd->filter->dump &&
@@ -1752,8 +1754,7 @@
 		if (is_valid_fd(STDIN_FILENO) &&
 		    ((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) &&
 		    (flags & O_ACCMODE) != O_WRONLY) {
-			if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) {
-				stdin = new_stream;
+			if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin")) {
 				setlinebuf(stdin);
 			} else
 				cmd->linebuffer = NULL;	/* Leave buffer in place (deliberate leak) */
@@ -1762,8 +1763,7 @@
 		if (is_valid_fd(STDOUT_FILENO) &&
 		    ((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) &&
 		    (flags & O_ACCMODE) != O_RDONLY) {
-			if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) {
-				stdout = new_stream;
+			if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout")) {
 				setlinebuf(stdout);
 			} else
 				cmd->linebuffer = NULL;	/* Leave buffer in place (deliberate leak) */
--- LVM2.2.02.103.orig/tools/lvmcmdline.c
+++ LVM2.2.02.103/tools/lvmcmdline.c
@@ -1252,7 +1252,7 @@
 	int err = is_valid_fd(STDERR_FILENO);

 	if (!is_valid_fd(STDIN_FILENO) &&
-	    !(stdin = fopen(_PATH_DEVNULL, "r"))) {
+	    !freopen(_PATH_DEVNULL, "r", stdin)) {
 		if (err)
 			perror("stdin stream open");
 		else
@@ -1262,7 +1262,7 @@
 	}

 	if (!is_valid_fd(STDOUT_FILENO) &&
-	    !(stdout = fopen(_PATH_DEVNULL, "w"))) {
+	    !freopen(_PATH_DEVNULL, "w", stdout)) {
 		if (err)
 			perror("stdout stream open");
 		/* else no stdout */
@@ -1270,7 +1270,7 @@
 	}

 	if (!is_valid_fd(STDERR_FILENO) &&
-	    !(stderr = fopen(_PATH_DEVNULL, "w"))) {
+	    !freopen(_PATH_DEVNULL, "w", stderr)) {
 		printf("stderr stream open: %s\n",
 		       strerror(errno));
 		return 0;


code:
#!/bin/sh

cd ${LXC_ROOTFS_MOUNT}/dev
mkdir -p input/ dri/ snd/ shm/

mknoddir() {
  dir=$1
  ls -l /dev/$dir* |sed 's#,# #g; s#/dev/##g;' \
    |awk '{print $1 " " $5 " " $6 " " $10}' \
    |while read perms major minor name; do
      type=$(echo $perms |sed -r 's,^(.).+$,\1,g')
      echo "mknod -m 666 $name $type $major $minor"
  done
}
mknoddir input/
mknoddir dri/
mknoddir snd/

mknod -m 666 mem c 1 1
mknod -m 666 input/event0 c 13 64
mknod -m 666 input/event1 c 13 65
mknod -m 666 input/event2 c 13 66
mknod -m 666 input/event3 c 13 67
mknod -m 666 input/event4 c 13 68
mknod -m 666 input/event5 c 13 69
mknod -m 666 input/event6 c 13 70
mknod -m 666 input/event7 c 13 71
mknod -m 666 input/mice c 13 63
mknod -m 666 input/mouse0 c 13 32
mknod -m 666 dri/card0 c 226 0
mknod -m 666 dri/controlD64 c 226 64
mknod -m 666 snd/controlC0 c 116 6
mknod -m 666 snd/controlC1 c 116 9
mknod -m 666 snd/controlD64 c 226 64
mknod -m 666 snd/midiC0D0 c 116 5
mknod -m 666 snd/midiC0D1 c 116 4
mknod -m 666 snd/midiC0D2 c 116 3
mknod -m 666 snd/midiC0D3 c 116 2
mknod -m 666 snd/pcmC1D0c c 116 8
mknod -m 666 snd/pcmC1D0p c 116 7
mknod -m 666 snd/seq c 116 1
mknod -m 666 snd/timer c 116 33

mknod -m 666 fb0 c 29 0
mknod -m 666 tty7 c 4 7
mknod -m 666 tty8 c 4 8
mknod -m 666 psaux c 10 1
mknod -m 666 hidraw0 c 248 0
mknod -m 666 hidraw1 c 248 1
mknod -m 666 vga_arbiter c 10 63
exit 0

path: KEEP/lxc-autodev-X


code:
lxc.include = /share/lxc/config/debian.common.conf

##For X support
#dri
lxc.cgroup.devices.allow = c 226:* rwm
#tty7-8
lxc.cgroup.devices.allow = c 4:7 rwm
lxc.cgroup.devices.allow = c 4:8 rwm
# fb0
lxc.cgroup.devices.allow = c 29:0 rwm
# input
lxc.cgroup.devices.allow = c 13:* rwm
# snd
lxc.cgroup.devices.allow = c 116:* rwm
# psaux
lxc.cgroup.devices.allow = c 10:1 rwm
# hidraw[01]
lxc.cgroup.devices.allow = c 248:0 rwm
lxc.cgroup.devices.allow = c 248:1 rwm
#mem
lxc.cgroup.devices.allow = c 1:1 rwm
#vga-arbiter
lxc.cgroup.devices.allow = c 10:63 rwm
lxc.autodev = 1
lxc.hook.autodev = /share/lxc/hooks/autodev-debian.X


code:
--- lxdm-0.4.1.org/src/lxdm.c
+++ lxdm-0.4.1/src/lxdm.c
@@ -52,7 +52,6 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>

-#include <execinfo.h>

 #ifdef HAVE_UTMPX_H
 #include <utmpx.h>
@@ -1578,7 +1577,7 @@

 static void log_sigsegv(void)
 {
-	void *array[40];
+/*	void *array[40];
 	size_t size;
 	char **bt_strs;
 	size_t i;
@@ -1589,7 +1588,7 @@
 	for (i=0; i<size; i++)
 	    fprintf(stderr, "%s\n", bt_strs[i]);

-	free(bt_strs);
+	free(bt_strs); */
 }

 static void sigsegv_handler(int sig)


code:
--- lxmusic-0.4.5.org/src/lxmusic.c	2012-11-05 00:29:47.000000000 +0000
+++ lxmusic-0.4.5/src/lxmusic.c	2012-11-05 00:29:53.000000000 +0000
@@ -1900,8 +1900,8 @@
                     gtk_list_store_set(list_store, &it, COL_WEIGHT, PANGO_WEIGHT_BOLD, -1);

 		    /* update id of currently played track */
-		    xmmsv_dict_get( val, "id", &int_value );
-		    xmmsv_get_int( int_value, &cur_track_id );
+		    if(xmmsv_dict_get( val, "id", &int_value ))
+			    xmmsv_get_int( int_value, &cur_track_id );
                 }
 		/* scroll to currently played song */
 		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(playlist_view), path, NULL, FALSE, 0.0, 0.0 );


code:
--- lxpanel-0.5.10.org/src/plugins/netstat/devproc.c
+++ lxpanel-0.5.10/src/plugins/netstat/devproc.c
@@ -26,14 +26,24 @@
 #include <net/if_arp.h>
 #include <arpa/inet.h>
 #include <linux/sockios.h>
-#include <linux/types.h>
-#include <linux/ethtool.h>
+//#include <linux/types.h>
+//#include <linux/ethtool.h>
 #include <iwlib.h>
 #include "nsconfig.h"
 #include "netstat.h"
 #include "statusicon.h"
 #include "devproc.h"
 #include "dbg.h"
+
+/* for requesting NIC test and getting results*/
+struct ethtool_test {
+        uint32_t   cmd;            /* ETHTOOL_TEST */
+        uint32_t   flags;          /* ETH_TEST_FL_xxx */
+        uint32_t   reserved;
+        uint32_t   len;            /* result length, in number of u64 elements */
+        uint64_t   data[0];
+};
+

 /* network device list */
 static void netproc_netdevlist_add(NETDEVLIST_PTR *netdev_list,


code:
From 886cbf679e41cf23509131ad79119a664e40f608 Mon Sep 17 00:00:00 2001
From: rofl0r <retnyg@gmx.net>
Date: Thu, 2 Aug 2012 09:25:37 +0200
Subject: [PATCH] cumulative fix

---
 src/interface.c              |    8 +++---
 src/main.c                   |    4 +-
 src/types.h                  |    7 +++--
 src/xfce-taskmanager-linux.c |   57 ++++++++++++++++++++++++++++++++++-------
 4 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/src/interface.c b/src/interface.c
index 76c41e8..c68c00a 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -346,7 +346,7 @@ GtkWidget* create_mainmenu (void)
     gtk_widget_show(preferences1);
     gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), preferences1);

-    g_signal_connect ((gpointer) show_user_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)own_uid);
+    g_signal_connect ((gpointer) show_user_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *) (size_t) own_uid);
     g_signal_connect ((gpointer) show_root_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)0);
     g_signal_connect ((gpointer) show_other_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)-1);
     g_signal_connect ((gpointer) show_cached_as_free1, "toggled", G_CALLBACK (on_show_cached_as_free_toggled), (void *)0);
@@ -422,11 +422,11 @@ void fill_list_item(gint i, GtkTreeIter *iter)
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PPID, buf, -1);
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_STATE, task->state, -1);

-        /* size */
-        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_MEM, size_to_string(buf, task->size * 1024), -1);
+        /* vm size */
+        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_MEM, size_to_string(buf, task->size), -1);

         /* rss */
-        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_RSS, size_to_string(buf, task->rss*1024), -1);
+        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_RSS, size_to_string(buf, task->rss), -1);

         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_UNAME, task->uname, -1);
         sprintf(buf,"%0d%%", (guint)task->time_percentage);
diff --git a/src/main.c b/src/main.c
index 2fbe20b..8ed4489 100644
--- a/src/main.c
+++ b/src/main.c
@@ -56,7 +56,7 @@ guint win_height;
 guint refresh_interval;
 guint rID;

-int PAGE_SIZE;
+int page_size;

 int main (int argc, char *argv[])
 {
@@ -72,7 +72,7 @@ int main (int argc, char *argv[])
 #endif
     gtk_init (&argc, &argv);

-    PAGE_SIZE=sysconf(_SC_PAGESIZE)>>10;
+    page_size = sysconf(_SC_PAGESIZE);
     own_uid = getuid();

     config_file = g_build_filename(g_get_user_config_dir(), "lxtask.conf", NULL);
diff --git a/src/types.h b/src/types.h
index 7a9e812..d57567e 100644
--- a/src/types.h
+++ b/src/types.h
@@ -21,6 +21,7 @@
 #define TYPES_H

 #include <gtk/gtk.h>
+#include <stddef.h>

 #define REFRESH_INTERVAL 1000

@@ -32,8 +33,8 @@ struct task
     gchar uname[64];
     gchar name[64];
     gchar state[16];
-    gint size;
-    gint rss;
+    size_t size;
+    size_t rss;
     gboolean checked;
     gint time;
     gint old_time;
@@ -79,6 +80,6 @@ extern guint win_height;
 const gchar *custom_signal_0;
 const gchar *custom_signal_1;

-extern int PAGE_SIZE;
+extern int page_size;

 #endif
diff --git a/src/xfce-taskmanager-linux.c b/src/xfce-taskmanager-linux.c
index 858ea30..e7923e5 100644
--- a/src/xfce-taskmanager-linux.c
+++ b/src/xfce-taskmanager-linux.c
@@ -35,6 +35,7 @@ void get_task_details(gint pid,struct task *task)
 {
 	int fd;
 	gchar line[256];
+	ssize_t ret;

 	task->pid=-1;
 	task->checked=FALSE;
@@ -43,12 +44,13 @@ void get_task_details(gint pid,struct task *task)
 	sprintf(line,"/proc/%d/statm",pid);
         fd=open(line,O_RDONLY);
         if(fd==-1) return;
-        read(fd,line,256);
-        sscanf(line,"%d %d",&task->size,&task->rss);
-        close(fd);
-        if(!task->size) return;
-	task->size*=PAGE_SIZE;
-	task->rss*=PAGE_SIZE;
+        ret = read(fd,line,sizeof(line));
+	if(!ret || ret == -1) goto err;
+	sscanf(line,"%zu %zu",&task->size,&task->rss);
+	close(fd);
+	if(!task->size) return;
+	task->size *= page_size;
+	task->rss *= page_size;

 	sprintf(line,"/proc/%d/stat",pid);
 	fd=open(line,O_RDONLY);
@@ -63,11 +65,46 @@ void get_task_details(gint pid,struct task *task)

 		task->pid=pid;

-		read(fd,buf,2048);
-		p=strchr(buf,'(');p++;
+		ret = read(fd,buf,sizeof(buf));
+		if(!ret || ret == -1) {
+			err:
+			close(fd);
+			return;
+		}
+
+		p=strchr(buf,'(');
+		if(!p) goto err;
+		p++;
 		for(len=0;*p!=')';len++) task->name[len]=*p++;
-		task->name[len]=0;p++;
-		if(len>=15)
+		task->name[len]=0;
+		p++;
+		if(0)
+		{
+			FILE *fp;
+			sprintf(line,"/proc/%d/cmdline",pid);
+			fp=fopen(line,"r");
+			if(fp)
+			{
+				size_t size;
+				size=fread(task->name,1,sizeof(task->name)-1,fp);
+				if(size>0)
+				{
+					int i;
+					task->name[size]=0;
+					for(i=0;i<size;i++)
+					{
+						if(task->name[i]=='\0')
+						{
+							if(task->name[i+1]=='\n')
+								break;
+							task->name[i]=' ';
+						}
+					}
+				}
+				fclose(fp);
+			}
+		}
+		else if(len>=15)
 		{
 			FILE *fp;
 			sprintf(line,"/proc/%d/cmdline",pid);
--
1.7.3.4


code:
--- lynx2.8.9dev.8.org/src/HTFWriter.c
+++ lynx2.8.9dev.8/src/HTFWriter.c
@@ -1052,7 +1052,7 @@
 		     * It's compressed with the modern gzip.  - FM
 		     */
 		    StrAllocCopy(uncompress_mask, program);
-		    StrAllocCat(uncompress_mask, " -d --no-name %s");
+		    StrAllocCat(uncompress_mask, " -d -n %s");
 		    compress_suffix = "gz";
 		}
 		break;


code:
--- make-3.82.org/make.h
+++ make-3.82/make.h
@@ -342,9 +342,10 @@
 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
 # define SET_STACK_SIZE
 #endif
-#ifdef SET_STACK_SIZE
+#undef SET_STACK_SIZE
+#if 0
 # include <sys/resource.h>
-struct rlimit stack_limit;
+extern struct rlimit stack_limit;
 #endif

 struct floc


code:
Submitted By:            Armin K. <krejzi at email dot com>
Date:                    2012-09-19
Initial Package Version: 3.82
Upstream Status:         Fixed Upstream
Origin:                  Upstream
Description:             Several bug fixes from upstream cvs.

--- make.orig/expand.c	2010-07-13 03:20:39.000000000 +0200
+++ make/expand.c	2012-09-19 17:25:52.496989738 +0200
@@ -197,7 +197,7 @@
 {
   struct variable *v;
   const char *p, *p1;
-  char *abuf = NULL;
+  char *save;
   char *o;
   unsigned int line_offset;

@@ -212,16 +212,11 @@
       return (variable_buffer);
     }

-  /* If we want a subset of the string, allocate a temporary buffer for it.
-     Most of the functions we use here don't work with length limits.  */
-  if (length > 0 && string[length] != '\0')
-    {
-      abuf = xmalloc(length+1);
-      memcpy(abuf, string, length);
-      abuf[length] = '\0';
-      string = abuf;
-    }
-  p = string;
+  /* We need a copy of STRING: due to eval, it's possible that it will get
+     freed as we process it (it might be the value of a variable that's reset
+     for example).  Also having a nil-terminated string is handy.  */
+  save = length < 0 ? xstrdup (string) : xstrndup (string, length);
+  p = save;

   while (1)
     {
@@ -411,8 +406,7 @@
       ++p;
     }

-  if (abuf)
-    free (abuf);
+  free (save);

   variable_buffer_output (o, "", 1);
   return (variable_buffer + line_offset);
--- make.orig/function.c	2010-07-13 03:20:39.000000000 +0200
+++ make/function.c	2012-09-19 17:25:52.509989959 +0200
@@ -706,7 +706,7 @@
   const char *word_iterator = argv[0];
   char buf[20];

-  while (find_next_token (&word_iterator, (unsigned int *) 0) != 0)
+  while (find_next_token (&word_iterator, NULL) != 0)
     ++i;

   sprintf (buf, "%d", i);
@@ -1133,21 +1133,14 @@

   /* Find the maximum number of words we'll have.  */
   t = argv[0];
-  wordi = 1;
-  while (*t != '\0')
+  wordi = 0;
+  while ((p = find_next_token (&t, NULL)) != 0)
     {
-      char c = *(t++);
-
-      if (! isspace ((unsigned char)c))
-        continue;
-
+      ++t;
       ++wordi;
-
-      while (isspace ((unsigned char)*t))
-        ++t;
     }

-  words = xmalloc (wordi * sizeof (char *));
+  words = xmalloc ((wordi == 0 ? 1 : wordi) * sizeof (char *));

   /* Now assign pointers to each string in the array.  */
   t = argv[0];
--- make.orig/job.c	2010-07-24 10:27:50.000000000 +0200
+++ make/job.c	2012-09-19 17:25:52.509989959 +0200
@@ -29,6 +29,15 @@

 #include <string.h>

+#if defined(__linux__) /* defined (HAVE_LINUX_BINFMTS_H) && defined (HAVE_SYS_USER_H) */
+#include <sys/user.h>
+#include <unistd.h>
+#ifndef PAGE_SIZE
+#define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
+#endif
+#include <linux/binfmts.h>
+#endif
+
 /* Default shell to use.  */
 #ifdef WINDOWS32
 #include <windows.h>
@@ -2791,6 +2800,15 @@
        argument list.  */

     unsigned int shell_len = strlen (shell);
+#ifdef MAX_ARG_STRLEN
+    static char eval_line[] = "eval\\ \\\"set\\ x\\;\\ shift\\;\\ ";
+#define ARG_NUMBER_DIGITS 5
+#define EVAL_LEN (sizeof(eval_line)-1 + shell_len + 4 \
+                 + (7 + ARG_NUMBER_DIGITS) * 2 * line_len / (MAX_ARG_STRLEN - 2))
+#else
+#define EVAL_LEN 0
+#endif
+    char *args_ptr;
     unsigned int line_len = strlen (line);
     unsigned int sflags_len = strlen (shellflags);
     char *command_ptr = NULL; /* used for batch_mode_shell mode */
@@ -2866,7 +2884,7 @@
       }

     new_line = alloca (shell_len + 1 + sflags_len + 1
-                             + (line_len*2) + 1);
+                             + (line_len*2) + 1 + EVAL_LEN);
     ap = new_line;
     memcpy (ap, shell, shell_len);
     ap += shell_len;
@@ -2875,6 +2893,30 @@
     ap += sflags_len;
     *(ap++) = ' ';
     command_ptr = ap;
+
+#if !defined (WINDOWS32) && defined (MAX_ARG_STRLEN)
+    if (unixy_shell && line_len > MAX_ARG_STRLEN)
+      {
+	unsigned j;
+	memcpy (ap, eval_line, sizeof (eval_line) - 1);
+	ap += sizeof (eval_line) - 1;
+	for (j = 1; j <= 2 * line_len / (MAX_ARG_STRLEN - 2); j++)
+	  ap += sprintf (ap, "\\$\\{%u\\}", j);
+	*ap++ = '\\';
+	*ap++ = '"';
+	*ap++ = ' ';
+	/* Copy only the first word of SHELL to $0.  */
+	for (p = shell; *p != '\0'; ++p)
+	  {
+	    if (isspace ((unsigned char)*p))
+	      break;
+	    *ap++ = *p;
+	  }
+	*ap++ = ' ';
+      }
+#endif
+    args_ptr = ap;
+
     for (p = line; *p != '\0'; ++p)
       {
 	if (restp != NULL && *p == '\n')
@@ -2922,6 +2964,14 @@
           }
 #endif
 	*ap++ = *p;
+
+#if !defined (WINDOWS32) && defined (MAX_ARG_STRLEN)
+	if (unixy_shell && line_len > MAX_ARG_STRLEN && (ap - args_ptr > MAX_ARG_STRLEN - 2))
+	  {
+	    *ap++ = ' ';
+	    args_ptr = ap;
+	  }
+#endif
       }
     if (ap == new_line + shell_len + sflags_len + 2)
       /* Line was empty.  */
--- make.orig/main.c	2010-07-19 09:10:53.000000000 +0200
+++ make/main.c	2012-09-19 17:25:52.510989976 +0200
@@ -1138,7 +1138,7 @@
      a macro and some compilers (MSVC) don't like conditionals in macros.  */
   {
     const char *features = "target-specific order-only second-expansion"
-                           " else-if shortest-stem undefine"
+                           " else-if shortest-stem undefine oneshell"
 #ifndef NO_ARCHIVES
                            " archives"
 #endif
@@ -2088,12 +2088,17 @@

           ++restarts;

+          /* If we're re-exec'ing the first make, put back the number of
+             job slots so define_makefiles() will get it right.  */
+          if (master_job_slots)
+            job_slots = master_job_slots;
+
           /* Reset makeflags in case they were changed.  */
           {
             const char *pv = define_makeflags (1, 1);
             char *p = alloca (sizeof ("MAKEFLAGS=") + strlen (pv) + 1);
             sprintf (p, "MAKEFLAGS=%s", pv);
-            putenv (p);
+            putenv (allocated_variable_expand (p));
           }

 	  if (ISDB (DB_BASIC))
@@ -2824,9 +2829,6 @@
 		       && (*(unsigned int *) cs->value_ptr ==
 			   *(unsigned int *) cs->noarg_value))
 		ADD_FLAG ("", 0); /* Optional value omitted; see below.  */
-	      else if (cs->c == 'j')
-		/* Special case for `-j'.  */
-		ADD_FLAG ("1", 1);
 	      else
 		{
 		  char *buf = alloca (30);
--- make.orig/read.c	2010-07-13 03:20:42.000000000 +0200
+++ make/read.c	2012-09-19 17:25:52.511989993 +0200
@@ -2904,6 +2904,7 @@
       const char *name;
       const char **nlist = 0;
       char *tildep = 0;
+      int globme = 1;
 #ifndef NO_ARCHIVES
       char *arname = 0;
       char *memname = 0;
@@ -3028,7 +3029,7 @@
             {
               /* This looks like the first element in an open archive group.
                  A valid group MUST have ')' as the last character.  */
-              const char *e = p + nlen;
+              const char *e = p;
               do
                 {
                   e = next_token (e);
@@ -3084,19 +3085,19 @@
          Go to the next item in the string.  */
       if (flags & PARSEFS_NOGLOB)
         {
-          NEWELT (concat (2, prefix, tp));
+          NEWELT (concat (2, prefix, tmpbuf));
           continue;
         }

       /* If we get here we know we're doing glob expansion.
          TP is a string in tmpbuf.  NLEN is no longer used.
          We may need to do more work: after this NAME will be set.  */
-      name = tp;
+      name = tmpbuf;

       /* Expand tilde if applicable.  */
-      if (tp[0] == '~')
+      if (tmpbuf[0] == '~')
 	{
-	  tildep = tilde_expand (tp);
+	  tildep = tilde_expand (tmpbuf);
 	  if (tildep != 0)
             name = tildep;
 	}
@@ -3112,32 +3113,40 @@
 	}
 #endif /* !NO_ARCHIVES */

-      switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
-	{
-	case GLOB_NOSPACE:
-	  fatal (NILF, _("virtual memory exhausted"));
-
-	case 0:
-          /* Success.  */
-          i = gl.gl_pathc;
-          nlist = (const char **)gl.gl_pathv;
-          break;
-
-        case GLOB_NOMATCH:
-          /* If we want only existing items, skip this one.  */
-          if (flags & PARSEFS_EXISTS)
-            {
-              i = 0;
-              break;
-            }
-          /* FALLTHROUGH */
-
-	default:
-          /* By default keep this name.  */
+      /* glob() is expensive: don't call it unless we need to.  */
+      if (!(flags & PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
+        {
+          globme = 0;
           i = 1;
           nlist = &name;
-          break;
-	}
+        }
+      else
+        switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
+          {
+          case GLOB_NOSPACE:
+            fatal (NILF, _("virtual memory exhausted"));
+
+          case 0:
+            /* Success.  */
+            i = gl.gl_pathc;
+            nlist = (const char **)gl.gl_pathv;
+            break;
+
+          case GLOB_NOMATCH:
+            /* If we want only existing items, skip this one.  */
+            if (flags & PARSEFS_EXISTS)
+              {
+                i = 0;
+                break;
+              }
+            /* FALLTHROUGH */
+
+          default:
+            /* By default keep this name.  */
+            i = 1;
+            nlist = &name;
+            break;
+          }

       /* For each matched element, add it to the list.  */
       while (i-- > 0)
@@ -3152,7 +3161,10 @@
             else
               {
                 /* We got a chain of items.  Attach them.  */
-                (*newp)->next = found;
+                if (*newp)
+                  (*newp)->next = found;
+                else
+                  *newp = found;

                 /* Find and set the new end.  Massage names if necessary.  */
                 while (1)
@@ -3174,7 +3186,8 @@
 #endif /* !NO_ARCHIVES */
           NEWELT (concat (2, prefix, nlist[i]));

-      globfree (&gl);
+      if (globme)
+        globfree (&gl);

 #ifndef NO_ARCHIVES
       if (arname)
--- make.orig/remake.c	2010-07-13 03:20:42.000000000 +0200
+++ make/remake.c	2012-09-19 17:26:09.116270849 +0200
@@ -614,6 +614,10 @@
                 d->file->dontcare = file->dontcare;
               }

+            /* We may have already considered this file, when we didn't know
+               we'd need to update it.  Force update_file() to consider it and
+               not prune it.  */
+            d->file->considered = !considered;

 	    dep_status |= update_file (d->file, depth);


code:
/* (C) 1997 Robert de Bath
 * (C) 2013 rofl0r
 * under the terms of the GPL.
 *
 * This is a manual pager program, it will search for and format manual
 * pages which it then pipes to more.
 *
 * The program understands manual pages that have been compressed with
 * either 'compress' or 'gzip' and will decompress them on the fly.
 *
 * The environment is checked for these variables:
 *   MANSECT=1:2:3:4:5:6:7:8:9		# Manual section search order.
 *   MANPATH=/usr/local/man:/usr/man	# Directorys to search for man tree.
 *   PAGER=more				# pager progam to use.
 *   PATH=...				# Search for gzip/uncompress
 *
 * The program will display documents that are either in it's own "nroff -man"
 * like format or in "catman" format, it will not correctly display pages in
 * the BSD '-mdoc' format.
 *
 * Neither nroff nor any similar program is needed as this program has it's
 * own built in _man_ _page_ _formatter_. This is NOT an nroff clone and will
 * not (for instance) understand macros or tbl constructs.
 *
 * Unlike groff this is small, fast and picky!
 */

#define DONT_SPLATTER		/* Lots of messages out */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <sys/ioctl.h>

static FILE *ofd, *ifd;
static int *line_ptr;

static int keep_nl;		/* How many nl to keep til eof */
static int optional_keep;		/* Is the next keep optional ? */
static int pending_nl;		/* Is there a pending newline on output? */
static int no_fill;		/* Disable 'filling' of lines */
static int left_indent;		/* Current step of left margin */
static int old_para_indent;	/* Indent to go back to after this paragraph */
static int is_tty;
static int current_line;		/* Line number = ? */
static int gaps_on_line;		/* Gaps on line for adjustments */
static int flg_w;

static int line[256];			/* Buffer for building output line */
static char whitespace[256];
static char line_header[256];	/* Page header line */
static char doc_footer[256];	/* Document footer line */
static char man_file[256];
static char word[80];			/* Current word */

static int right_margin = 65;		/* Don't print past this column */
static int verbose = 1;		/* print warnings about unknown macros */
static int no_nl = 1;			/* Next NL in input file is ignored */
static int catmode = 1;		/* Have we seen a '.XX' command ? */
static int cur_font = 0x100;		/* Current font, 1 == Roman */
static int next_line_indent = -1;	/* Indent after next line_break */
static int input_tab = 8;		/* Tab width in input file */
static int right_adjust = 1;		/* Adjust right margin */
static int standard_tab = 5;		/* Amount left margin stepped by */

static int find_page(char *name, char *sect);
static void step(char **pcurr, char **pnext);
static int open_page(char *name);
static void close_page(void);
static void do_file(void);
static int fetch_word(void);
static int do_command(void);
static void do_skipeol(void);
static int do_fontwords(int this_font, int other_font, int early_exit);
static int do_noargs(int cmd_id);
static int do_argvcmd(int cmd_id);
static void build_headers(void);
static void print_word(char *pword);
static void line_break(void);
static void page_break(void);
static void print_header(void);
static void print_doc_footer(void);

static void usage(void)
{
	fprintf(stderr, "man [-w] [-v|-q] [section-number] page\n"
	"-w\tonly print the location of matching manpages\n"
	"-v\tForce verbose output. (default)\n"
	"-q\tForce quiet output.\n");
	exit(1);
}

/****************************************************************************
 * Main routine, hunt down the manpage.
 */
int main(int argc, char **argv) {
	ofd = 0;
	ifd = stdin;
	int do_pclose_ofd = 0;
	int ar;
	char *mansect = 0;
	char *manname = 0;

	for(ar = 1; ar < argc; ar++)
		if(argv[ar][0] == '-') {
			char *p;
			for(p = argv[ar] + 1; *p; p++)
				switch (*p) {
					case 'w':
						flg_w = 1;
						break;
					case 'v':
						verbose = 1;
						break;
					case 'q':
						verbose = 0;
						break;
				}
		} else if(isdigit(argv[ar][0]))
			mansect = argv[ar];
		else if(manname == 0)
			manname = argv[ar];
		else if(mansect == 0) {
			mansect = manname;
			manname = argv[ar];
		} else {
			fprintf(stderr, "Ignoring argument %s\n", argv[ar]);
			break;
		}

	if(manname == 0) usage();

	if(find_page(manname, mansect) < 0) {
		if(mansect)
			fprintf(stderr, "No entry for %s in section %s of the manual.\n", manname, mansect);
		else
			fprintf(stderr, "No manual entry for %s\n", manname);
		exit(1);
	}
	if(flg_w)
		exit(0);

	/* ifd is now the file - display it */
	if(isatty(1)) {		/* If writing to a tty do it to a pager */
		is_tty = 1;
		char *pager = getenv("PAGER");
		if(pager) ofd = popen(pager, "w");
		if(!ofd) ofd = popen("less", "w");
		if(!ofd) ofd = popen("more", "w");
		if(!ofd) ofd = stdout;
		else {
			do_pclose_ofd = 1;
#ifdef TIOCGWINSZ
			struct winsize ws;
			if(!ioctl(0, TIOCGWINSZ, &ws))
				right_margin = ws.ws_col>251 ? 250 : ws.ws_col-2;
			else
#endif
			right_margin = 78;
		}
	} else
		ofd = stdout;

	do_file();

	/* Close files */
	if(do_pclose_ofd)
		pclose(ofd);
	close_page();
	exit(0);
}

static int find_page(char *name, char *sect) {
	static char defpath[] = "/usr/local/share/man:/usr/share/man";
	static char defsect[] = "1p:1:1perl:2:3p:3:3perl:4:5:6:7:8:9:0p";
	static char defsuff[] = ":.gz:.Z";
	static char manorcat[] = "man:cat";

	char fbuf[256];
	char *manpath;
	char *mansect = sect;
	char *mansuff;
	char *mc, *mp, *ms, *su, *nmc, *nmp, *nms, *nsu;
	int rv = -1;

	manpath = getenv("MANPATH");
	if(!manpath)
		manpath = defpath;
	if(!mansect)
		mansect = getenv("MANSECT");
	if(!mansect)
		mansect = defsect;
	mansuff = defsuff;

	if(strchr(name, '/')) {
		for(su = nsu = mansuff, step(&su, &nsu); su; step(&su, &nsu)) {
			snprintf(fbuf, sizeof(fbuf), "%s%s", name, su);
			if((rv = open_page(fbuf)) >= 0)
				break;
		}
		*man_file = 0;
		return rv;
	}

	/* SEARCH!! */
	for(mc = nmc = manorcat, step(&mc, &nmc); mc; step(&mc, &nmc))
		for(ms = nms = mansect, step(&ms, &nms); ms; step(&ms, &nms))
			for(mp = nmp = manpath, step(&mp, &nmp); mp; step(&mp, &nmp))
				for(su = nsu = mansuff, step(&su, &nsu); su; step(&su, &nsu)) {
					snprintf(fbuf, sizeof fbuf, "%s/%s%s/%s.%s%s", mp, mc, ms, name, ms, su);

					/* Got it ? */
					if(access(fbuf, 0) < 0)
						continue;
					if(flg_w) {
						printf("%s\n", fbuf);
						rv = 0;
						continue;
					}

					/* Try it ! */
					if((rv = open_page(fbuf)) >= 0) {
						char *p;
						snprintf(man_file, sizeof man_file, "%s", fbuf);
						p = strrchr(man_file, '/');
						if(p)
							*p = 0;
						p = strrchr(man_file, '/');
						if(p)
							p[1] = 0;
						return 0;
					}
				}

	return rv;
}

static void step(char **pcurr, char **pnext) {
	char *curr = *pcurr;
	char *next = *pnext;

	if(curr == 0)
		return;
	if(curr == next) {
		next = strchr(curr, ':');
		if(next)
			*next++ = 0;
	} else {
		curr = next;
		if(curr) {
			curr[-1] = ':';
			next = strchr(curr, ':');
			if(next)
				*next++ = 0;
		}
	}

	*pcurr = curr;
	*pnext = next;
}

static char* which(const char* prog, char* buf, size_t buf_size) {
	char* path = getenv("PATH");
	if(!path) return 0;
	while(1) {
		path += strspn(path, ":");
		size_t l = strcspn(path, ":");
		if(!l) break;
		if (snprintf(buf, buf_size, "%.*s/%s", (int)l, path, prog) >= (ssize_t) buf_size)
                        continue;
		if(!access(buf, X_OK)) return buf;
		path += l;
	}
	return 0;
}

static int program_exists_in_path(const char* prog) {
	char buf[256];
	return !!which(prog, buf, sizeof buf);
}

#define PREPROC "manpp"
static int preprocessor_exists(void) {
	return program_exists_in_path(PREPROC);
}

static int open_page(char *name) {
	char *p, *command = 0;
	char buf[256];

	if(access(name, 0) < 0)
		return -1;

	if((p = strrchr(name, '.'))) {
		if(!strcmp(p, ".gz")) command = "gzip -dc ";
		else if(!strcmp(p, ".Z")) command = "uncompress -c ";
	}
	if(!command) command = "cat ";

	snprintf(buf, sizeof buf, "%s%s%s", command, name, preprocessor_exists() ? " | " PREPROC : "");
	if(!(ifd = popen(buf, "r"))) return -1;
	return 0;
}

static void close_page(void) {
	if(ifd) {
		pclose(ifd);
		ifd = 0;
	}
}

/****************************************************************************
 * ifd is the manual page, ofd is the 'output' file or pipe, format it!
 */
static void do_file(void) {
	int nl;
	ungetc('\r', ifd);

	while((nl = fetch_word()) >= 0) {
#ifdef SPLATTER
		fprintf(ofd, ">WS='%s',", whitespace);
		fprintf(ofd, "catmode=%d,", catmode);
		fprintf(ofd, "nl=%d,", nl);
		fprintf(ofd, "no_nl=%d,", no_nl);
		fprintf(ofd, "no_fill=%d,", no_fill);
		fprintf(ofd, "keep_nl=%d,", keep_nl);
		fprintf(ofd, "opt_keep=%d,", optional_keep);
		fprintf(ofd, "WD='%s',", word);
		fprintf(ofd, "\n");
#endif

		if(catmode) {
			if(strcmp(word, "'\\\"") == 0 || strcmp(word, "'''") == 0) {
				/* This is a marker sometimes used for opening subprocesses like
				 * tbl and equ; this program ignores it.
				 */
				do_skipeol();
			} else if(*whitespace == '\r')
				fprintf(ofd, "%s%s", whitespace + 1, word);
			else
				fprintf(ofd, "%s%s", whitespace, word);
		} else {
			if(keep_nl && nl && !no_nl) {
				if(optional_keep) {
					optional_keep = 0;
					if(line_ptr == 0 || next_line_indent < 0 ||
					   left_indent + (line_ptr - line) + 1 > next_line_indent)
						line_break();
					else if(line_ptr != 0 && next_line_indent > 0) {
						while(left_indent + (line_ptr - line) + 1 <= next_line_indent)
							*line_ptr++ = cur_font + ' ';
					}
				} else
					line_break();
				if(keep_nl > 0)
					keep_nl--;
			}

			if(nl == 1 && (word[0] == '.' ||
				       (word[0] == '\'' && strcmp(word, "'\\\"") == 0) ||
				       (word[0] == '\'' && strcmp(word, "'''") == 0)
			   )) {
				no_nl = 1;
				if(do_command() < 0)
					break;
			} else {
				if(nl == 1 && no_fill)
					line_break();
				if(*whitespace)
					print_word(whitespace);
				print_word(word);
				no_nl = 0;
			}
		}
	}

	print_doc_footer();
}

static int fetch_word(void) {
	static int col = 0;
	char *p;
	int ch, nl;

	nl = 0;
	*(p = whitespace) = 0;

	if(!catmode && !no_fill)
		p++;

	while((ch = fgetc(ifd)) != EOF && isspace(ch)) {
		if(nl && no_fill && ch != '.' && ch != '\n')
			break;
		if(nl && !catmode && ch == '\n') {
			*whitespace = 0;
			strcpy(word, ".sp");
			ungetc(ch, ifd);
			return 1;
		}
		nl = (ch == '\n' || ch == '\r');
		if(nl)
			col = 0;
		else
			col++;

		if(no_fill && nl && *whitespace) {
			*word = 0;
			ungetc(ch, ifd);
			return 0;
		}

		if(p < whitespace + sizeof(whitespace) - 1 && (!nl || catmode))
			*p++ = ch;

		if(ch == '\t' && !catmode) {
			p[-1] = ' ';
			while(col % input_tab) {
				if(p < whitespace + sizeof(whitespace) - 1)
					*p++ = ' ';
				col++;
			}
		}

		if(!catmode && !no_fill && nl)
			*(p = whitespace) = 0;
	}
	*p = 0;

	if(catmode && ch == '.' && nl)
		catmode = 0;

	*(p = word) = 0;
	if(ch == EOF || p > word + sizeof(word) / 2) {
		if(p != word) {
			ungetc(ch, ifd);
			*p = 0;
			return nl;
		}
		return -1;
	}
	ungetc(ch, ifd);

	while((ch = fgetc(ifd)) != EOF && !isspace(ch)) {
		if(p < word + sizeof(word) - 1)
			*p++ = ch;
		col++;
		if(ch == '\\') {
			if((ch = fgetc(ifd)) == EOF)
				break;
			// if( ch == ' ' ) ch = ' ' + 0x80;    /* XXX Is this line needed? */
			if(p < word + sizeof(word) - 1)
				*p++ = ch;
			col++;
		}
	}
	*p = 0;
	ungetc(ch, ifd);

	return (nl != 0);
}

/****************************************************************************
 * Accepted nroff commands and executors.
 */

const struct cmd_list_s {
	char cmd[3];
	char class;
	char id;
} cmd_list[] = {
	{"\\\"", 0, 0},
	{"nh", 0, 0},		/* This program never inserts hyphens */
	{"hy", 0, 0},		/* This program never inserts hyphens */
	{"PD", 0, 0},		/* Inter-para distance is 1 line */
	{"DT", 0, 0},		/* Default tabs, they can't be non-default! */
	{"IX", 0, 0},		/* Indexing for some weird package */
	{"Id", 0, 0},		/* Line for RCS tokens */
	{"BY", 0, 0},		/* I wonder where this should go ? */
	{"nf", 0, 1},		/* Line break, Turn line fill off */
	{"fi", 0, 2},		/* Line break, Turn line fill on */
	{"sp", 0, 3},		/* Line break, line space (arg for Nr lines) */
	{"br", 0, 4},		/* Line break */
	{"bp", 0, 5},		/* Page break */
	{"PP", 0, 6},
	{"LP", 0, 6},
	{"P", 0, 6},		/* Paragraph */
	{"RS", 0, 7},		/* New Para + Indent start */
	{"RE", 0, 8},		/* New Para + Indent end */
	{"HP", 0, 9},		/* Begin hanging indent (TP without arg?) */
	{"ad", 0, 10},		/* Line up right margin */
	{"na", 0, 11},		/* Leave right margin unaligned */
	{"ta", 0, 12},		/* Changes _input_ tab spacing, right? */
	{"TH", 1, 1},		/* Title and headers */
	{"SH", 1, 2},		/* Section */
	{"SS", 1, 3},		/* Subsection */
	{"IP", 1, 4},		/* New para, indent except argument 1 */
	{"TP", 1, 5},		/* New para, indent except line 1 */
	{"B", 2, 22},		/* Various font fiddles */
	{"BI", 2, 23},
	{"BR", 2, 21},
	{"I", 2, 33},
	{"IB", 2, 32},
	{"IR", 2, 31},
	{"RB", 2, 12},
	{"RI", 2, 13},
	{"SB", 2, 42},
	{"SM", 2, 44},
	{"C", 2, 22},		/* PH-UX manual pages! */
	{"CI", 2, 23},
	{"CR", 2, 21},
	{"IC", 2, 32},
	{"RC", 2, 12},
	{"so", 3, 0},
	{"\0\0", 0, 0}
};

static int do_command(void) {
	char *cmd;
	int i;
	char lbuf[10];

	cmd = word + 1;

	/* Comments don't need the space */
	if(strncmp(cmd, "\\\"", 2) == 0)
		cmd = "\\\"";

	for(i = 0; cmd_list[i].cmd[0]; i++) {
		if(strcmp(cmd_list[i].cmd, cmd) == 0)
			break;
	}

	if(cmd_list[i].cmd[0] == 0) {
		if(verbose) {
			strncpy(lbuf, cmd, 3);
			lbuf[3] = 0;
			line_break();
			i = left_indent;
			left_indent = 0;
			snprintf(word, sizeof word, "**** Unknown formatter command: .%s", lbuf);
			print_word(word);
			line_break();
			left_indent = i;
		}

		i = 0;		/* Treat as comment */
	}

	switch (cmd_list[i].class) {
		case 1:	/* Parametered commands */
			return do_argvcmd(cmd_list[i].id);

		case 2:	/* Font changers */
			return do_fontwords(cmd_list[i].id / 10, cmd_list[i].id % 10, 0);

		case 3:	/* .so */
			fetch_word();
			if(strlen(man_file) + 4 < sizeof man_file)
				strcat(man_file, word);
			close_page();
			if(find_page(man_file, (char *) 0) < 0) {
				fprintf(stderr, "Cannot open .so file %s\n", word);
				return -1;
			}
			ungetc('\r', ifd);
			break;

		default:
			do_skipeol();
			if(cmd_list[i].id)
				return do_noargs(cmd_list[i].id);
	}
	return 0;
}

static void do_skipeol(void) {
	int ch;
	char *p = word;

	while((ch = fgetc(ifd)) != EOF && ch != '\n')
		if(p < word + sizeof(word) - 1)
			*p++ = ch;;
	*p = 0;
	ungetc(ch, ifd);
}

static void flush_word(char **p) {
	memcpy(*p, "\\fR", 4);
	print_word(word);
	*p = word;
}

static void insert_font(char **p, int font) {
	const char ftab[] = " RBIS";
	memcpy(*p, "\\f", 2);
	(*p)[2] = ftab[font];
	*p += 3;
}

static int do_fontwords(int this_font, int other_font, int early_exit) {
	char *p = word;
	int ch;
	int in_quote = 0;

	no_nl = 0; /* Line is effectivly been reprocessed so NL is visible */
	for(;;) {
		if(p == word) insert_font(&p, this_font);
		/* at each turn, at most 5 bytes are appended to word
		 * in order to flush the buffer, 4 more bytes are required to stay free */
		if(p+5+4 >= word+sizeof word) {
			assert(p+4<word+sizeof word);
			flush_word(&p);
			continue;
		}
		if((ch = fgetc(ifd)) == EOF || ch == '\n')
			break;
		if(ch == '"') {
			in_quote = !in_quote;
			continue;
		}
		if(in_quote || !isspace(ch)) {
			if(isspace(ch) && p > word + 3) {
				flush_word(&p);
				if(no_fill) print_word(" ");
				continue;
			}
			*p++ = ch;
			if(ch == '\\') {
				if((ch = fgetc(ifd)) == EOF || ch == '\n') break;
				*p++ = ch;
			}
			continue;
		}

		if(p != word + 3) {
			if(early_exit) break;

			if(this_font == other_font) flush_word(&p);
			int i = this_font;
			this_font = other_font;
			other_font = i;
			insert_font(&p, this_font);
		}
	}
	ungetc(ch, ifd);

	if(p > word + 3) flush_word(&p);

	return 0;
}

static int do_noargs(int cmd_id) {
	if(cmd_id < 10)
		line_break();
	switch (cmd_id) {
		case 1:
			no_fill = 1;
			break;
		case 2:
			no_fill = 0;
			break;
		case 3:
			pending_nl = 1;
			break;
		case 4:
			break;
		case 5:
			page_break();
			break;
		case 6:
			left_indent = old_para_indent;
			pending_nl = 1;
			break;
		case 7:
			pending_nl = 1;
			left_indent += standard_tab;
			old_para_indent += standard_tab;
			break;
		case 8:
			pending_nl = 1;
			left_indent -= standard_tab;
			old_para_indent -= standard_tab;
			break;

		case 10:
			right_adjust = 1;
			break;
		case 11:
			right_adjust = 0;
			break;
		case 12:
			input_tab = atoi(word);
			if(input_tab <= 0)
				input_tab = 8;
			break;
	}
	return 0;
}

static int do_argvcmd(int cmd_id) {
	int ch;

	line_break();
	while((ch = fgetc(ifd)) != EOF && (ch == ' ' || ch == '\t')) ;
	ungetc(ch, ifd);

	switch (cmd_id + 10 * (ch == '\n')) {
		case 1:	/* Title and headers */
			page_break();
			left_indent = old_para_indent = standard_tab;
			build_headers();
			break;

		case 2:	/* Section */
			left_indent = 0;
			next_line_indent = old_para_indent = standard_tab;
			no_nl = 0;
			keep_nl = 1;
			pending_nl = 1;

			do_fontwords(2, 2, 0);
			return 0;
		case 3:	/* Subsection */
			left_indent = standard_tab / 2;
			next_line_indent = old_para_indent = standard_tab;
			no_nl = 0;
			keep_nl = 1;
			pending_nl = 1;

			do_fontwords(1, 1, 0);
			break;

		case 15:
		case 5:	/* New para, indent except line 1 */
			do_skipeol();
			next_line_indent = old_para_indent + standard_tab;
			left_indent = old_para_indent;
			pending_nl = 1;
			keep_nl = 1;
			optional_keep = 1;
			break;

		case 4:	/* New para, indent except argument 1 */
			next_line_indent = old_para_indent + standard_tab;
			left_indent = old_para_indent;
			pending_nl = 1;
			keep_nl = 1;
			optional_keep = 1;
			do_fontwords(1, 1, 1);
			do_skipeol();
			break;

		case 14:
			pending_nl = 1;
			left_indent = old_para_indent + standard_tab;
			break;
	}

	return 0;
}

static void build_headers(void) {
	char buffer[5][80];
	int strno = 0;
	unsigned stroff = 0;
	int last_ch = 0, ch, in_quote = 0;

	for(ch = 0; ch < 5; ch++)
		buffer[ch][0] = 0;

	for(;;) {
		if((ch = fgetc(ifd)) == EOF || ch == '\n')
			break;
		if(ch == '"') {
			if(last_ch == '\\') {
				assert(stroff > 0);
				stroff--;
				break;
			}
			in_quote = !in_quote;
			continue;
		}
		last_ch = ch;
		if(in_quote || !isspace(ch)) {
			/* Nb, this does nothing about backslashes, perhaps it should */
			if(stroff < sizeof(buffer[strno]) - 1)
				buffer[strno][stroff++] = ch;
			continue;
		}
		buffer[strno][stroff] = 0;

		if(buffer[strno][0]) {
			strno++;
			stroff = 0;
			if(strno == 5)
				break;
		}
	}
	if(strno < 5)
		buffer[strno][stroff] = 0;
	ungetc(ch, ifd);

	/* Ok we should have upto 5 arguments build the header and footer */

	size_t l0 = strlen(buffer[0]),
	       l1 = strlen(buffer[1]),
	       l2 = strlen(buffer[2]),
	       l3 = strlen(buffer[3]),
	       l4 = strlen(buffer[4]),
	       l01 = l0 + l1 + 2;
	snprintf(line_header, sizeof line_header, "%s(%s)%*s%*s(%s)", buffer[0],
	         buffer[1], (int) (right_margin/2-l01+l4/2+(l4&1)), buffer[4],
	         (int) (right_margin/2-l4/2-l01+l0-(l4&1)), buffer[0], buffer[1]);
	snprintf(doc_footer, sizeof doc_footer, "%s%*s%*s(%s)", buffer[3],
	         (int) (right_margin/2-l3+l2/2+(l2&1)), buffer[2],
	         (int) (right_margin/2-l2/2-l01+l0-(l2&1)), buffer[0], buffer[1]);

	do_skipeol();
}

static void print_word(char *pword) {
/* Eat   \&  \a .. \z and \A .. \Z
 * \fX   Switch to font X (R B I S etc)
 * \(XX  Special character XX
 * \X    Print as X
 */
#define checkw(X) assert(d+X<wword+(sizeof wword/sizeof wword[0]))
#define checkl(X) assert(line_ptr+X<line+(sizeof line/sizeof line[0]))
	char *s;
	int *d, ch = 0;
	int length = 0;
	int wword[256];
	int sp_font = cur_font;

	/* Eat and translate characters. */
	for(s = pword, d = wword; *s; s++) {
		ch = 0;
		if(*s == '\n')
			continue;
		if(*s != '\\') {
			checkw(1);
			*d++ = (ch = *s) + cur_font;
			length++;
		} else {
			if(s[1] == 0)
				break;
			s++;
			if(*s == 'f') {
				if(!is_tty) s++;
				else if(s[1]) {
					static char fnt[] = " RBI";
					char *p = strchr(fnt, *++s);
					if(p == 0)
						cur_font = 0x100;
					else
						cur_font = 0x100 * (p - fnt);
				}
				continue;
			} else if(*s == 's') {
				/* Font size adjusts - strip */
				while(s[1] && strchr("+-0123456789", s[1]))
					s++;
				continue;
			} else if(isalpha(*s) || strchr("!&^[]|~", *s))
				continue;
			else if(*s == '(' || *s == '*') {
			/* XXX Humm character xlate - http://mdocml.bsd.lv/man/mandoc_char.7.html */
				int out = '*';
				if(*s == '*') {
					if(s[1])
						++s;
				} else if(s[1] == 'm' && s[2] == 'i') {
					out = '-';
					s+=2;
					goto K;
				}
				if(s[1])
					++s;
				if(s[1])
					++s;
				K:
				checkw(1);
				*d++ = out + cur_font;
				length++;
				continue;
			}

			checkw(1);
			*d++ = *s + cur_font;
			length++;
		}
	}

	checkw(1);
	*d = 0;
#ifdef SPLATTER
	{
		int *x;
		fprintf(ofd, ">WORD:");
		for(x = wword; *x; x++)
			fputc(*x, ofd);
		fprintf(ofd, ":\n");
	}
#endif

	if(*wword == 0)
		return;

	if(line_ptr)
		if(line_ptr + ((line_ptr[-1] & 0xFF) == '.') - line + length >= right_margin - left_indent) {
			right_adjust = -right_adjust;
			line_break();
		}

	if(line_ptr == 0)
		line_ptr = line;
	else {
		assert(line_ptr > line);
		if(!no_fill && (line_ptr[-1] & 0xFF) > ' ') {
			if((line_ptr[-1] & 0xFF) == '.') {
				checkl(1);
				*line_ptr++ = cur_font + ' ';
			}
			checkl(1);
			*line_ptr++ = sp_font;
			gaps_on_line++;
		}
	}

	checkl(length);
	memcpy(line_ptr, wword, length * sizeof(int));
	line_ptr += length;
#undef checkw
#undef checkl
}

static void line_break(void) {
	int *d, ch;
	int spg = 1, rspg = 1, spgs = 0, gap = 0;

	if(line_ptr == 0)
		return;

	if(current_line == 0)
		print_header();

	if(current_line)
		current_line += 1 + pending_nl;
	for(; pending_nl > 0; pending_nl--)
		fprintf(ofd, "\n");

	if(right_adjust < 0) {
		int over = right_margin - left_indent - (line_ptr - line);
#ifdef SPLATTER
		fprintf(ofd, ">Gaps=%d, Over=%d, ", gaps_on_line, over);
#endif
		if(gaps_on_line && over) {
			spg = rspg = 1 + over / gaps_on_line;
			over = over % gaps_on_line;
			if(over) {
				if(current_line % 2) {
					spgs = over;
					spg++;
				} else {
					spgs = gaps_on_line - over;
					rspg++;
				}
			}
		}
#ifdef SPLATTER
		fprintf(ofd, " (%d,%d) sw=%d\n", spg, rspg, spgs);
#endif
		right_adjust = 1;
	}

	*line_ptr = 0;
	if(*line)
		for(ch = left_indent; ch > 0; ch--)
			fputc(' ', ofd);

	for(d = line; *d; d++) {
		ch = *d;
		if((ch & 0xFF) == 0) {
			int i;
			if(gap++ < spgs)
				i = spg;
			else
				i = rspg;
			for(; i > 0; i--)
				fputc(' ', ofd);
		} else
			switch (ch >> 8) {
				case 2:
					fputc(ch & 0xFF, ofd);
					fputc('\b', ofd);
					fputc(ch & 0xFF, ofd);
					break;
				case 3:
					fputc('_', ofd);
					fputc('\b', ofd);
					fputc(ch & 0xFF, ofd);
					break;
				default:
					fputc(ch & 0xFF, ofd);
					break;
			}
	}
	fputc('\n', ofd);

	line_ptr = 0;

	if(next_line_indent > 0)
		left_indent = next_line_indent;
	next_line_indent = -1;
	gaps_on_line = 0;
}

static void page_break(void) {
	line_break();
}

static void print_header(void) {
	pending_nl = 0;
	if(*line_header) {
		current_line = 1;
		fprintf(ofd, "%s\n\n", line_header);
	}
}

static void print_doc_footer(void) {
	line_break();
	int i;
	for(i = 0; i < 3; i++) fputc('\n', ofd);
	fprintf(ofd, "%s", doc_footer);
}


code:
#!/usr/bin/awk -f
function indent() {
	if(close_indent) {
		print ".RE"
		close_indent = 0
	} else {
		print ".RS"
		close_indent = 1
	}
}
function make_date(d) {
	gsub("[ \t,]+", "-", d)
	return d;
}

function trigger_header(hdate, hsect, htitle) {
	if(hdate) date = make_date(hdate)
	if(hsect) sect = hsect
	if(htitle) title = htitle
	if(sect && date && title)
		print ".TH", title, sect, date
}
# turns something like aa "b c" d "e f g"
# into a 0-indexed array with the members(aa, b c, d, e f g)
# returns length of array
function unquotewords(wordsstr, ao,    l,a,out,inpara,start,i) {
	l = split(wordsstr, a, "")
	start = 1
	out = 0
	inpara = 0
	for(i = 1; i<=l; i++) {
		if(a[i] == " ") {
			if(start == i) print "ERR"
			if(!inpara) {
				ao[out++] = substr(wordsstr, start, i-start);
				start = i + 1
			}
		} else if(a[i] == "\"") {
			if(inpara) {
				ao[out++] = substr(wordsstr, start, i-start);
				start = i + 2
				i++
			} else {
				if(start != i) print "err"
				start++;
			}
			inpara = !inpara;
		}
	}
	if(i > start) ao[out++] = substr(wordsstr, start, i-start);
	return out;
}

function arr2str(arr, start, len,    i,str) {
	for(i=start;i<=len;i++) if(i in arr) str=str arr[i] " ";
	return str
}

function cfunc(str,   i,l,a,out,restore) {
	l = unquotewords(str, a)
	# first array index, 0, contains macro name still so we skip it
	#print arr2str(a, 0, l)
	if(a[l-1] == ",") {
		restore = a[l-1];
		l--;
	}
	for(i = 0; i < l; i++) {
		out = out a[i]
		if(i == 0) out = out " "
		else if(i == 1) out = out "("
		if (i == l - 1) out = out ")"
		else if(i > 1) out = out ", "
	}
	if(restore) out = out restore
	return out;
}
function brify(str,appendnl,   temp) {
	str = ".BR \"" substr(str, index(str, " ")+1) "\""
	if(appendnl) str = str "\n"
	return str
}
function italify(str,appendnl,   temp) {
	str = ".I \"" substr(str, index(str, " ")+1) "\""
	if(appendnl) str = str "\n"
	return str
}
function fields(start, last,    buf,i,sp) {
	buf = ""
	for(i=start;i<=last;i++) {
		sp = i+1<=last ? " " : ""
		buf = buf $i sp
	}
	return buf
}
function update_var(var_name, complete_line) {
	if(!current_var) {
		current_var = var_name
		groff_vars[current_var] = substr(complete_line, 4+length(var_name)+2)
	} else {
		groff_vars[current_var] = groff_vars[current_var] complete_line
	}
	if(groff_vars[current_var] ~ /\\$/) {
		sub(/\\$/, "\n", groff_vars[current_var])
	} else {
		current_var = ""
	}
}

function replace_vars(line,   var, p) {
	# match(s,r) test whether s contains a substring matched by r
	# return index or 0, sets RSTART and RLENGTH
	while((p = match(line, /\\\*\(([A-Za-z0-9_]+)/))) {
		var = substr(line, RSTART+3, RLENGTH-3)
		if(!var in groff_vars) print "ERROR: $var not in groff_vars"
		if(groff_vars[var] ~ /\\\*\(([A-Za-z0-9_]+)/) {
			print "ERROR: groff variable substitution attempts infite loop"
			exit 1
		}
		line = substr(line, 0, RSTART-1) groff_vars[var] substr(line, RSTART+RLENGTH)
	}
	return line
}
BEGIN {
	current_var = ""
}

{
	if($1 ~ /^\./ && close_indent) {
		#indent()
	}

	if(!current_var)
		$0 = replace_vars($0)

	if(0) ;
	else if(current_var) {
		#process multiline groff string vars.
		update_var(current_var, $0)
		$0 = ""
# mdoc commands
# http://web.archive.org/web/20140327172811/http://mdocml.bsd.lv/mdoc.7.html
	} else if($1 == ".Bl") {
		$0 = ""
		$0 = ".sp\n.RS\n.nf\n"
		$0 = ".sp\n.RS\n"
		blockmode = 1
	} else if ($1 == ".El") {
		$0 = ""
		$0 = ".fi\n.RE"
		$0 = ".RE"
		blockmode = 0
		#indent()
	} else if($1 == ".Bd") {
		# code block - dump directly until we hit .Ed
		$0 = ".sp\n.RS\n.nf\n\\fB"
	} else if($1 == ".Ed") {
		$0 = "\\fP\n.fi\n.RE"
	} else if($1 == ".Ex") {
		locname = NF==3?$3:name
		$0 = "The \n.BR " locname "\nutility exits 0 on success, and >0 if an error occurs.\n"
	} else if($1 == ".Dd") {
		$0 = substr($0, 5)
		trigger_header($0, "", "")
		$0 = ""
	} else if($1 == ".Dt") {
		trigger_header("", $3, $2)
		$0 = ""
	} else if($1 == ".Dq") {
		if ($NF == "." || $NF == ",") {
			safe = $NF;
			$0 = substr($0, 0, length($0) - 2)
		} else safe = ""
		$0 = "“" substr($0, 5) "”" safe
	} else if($1 == ".Dv") {
		sub(/^\.Dv /, "")
	} else if($1 == ".Xr") {
		$0 = $2 "(" $3 ")"
	} else if($1 == ".An") {
		if($2 ~ "^-") $0 = ""
		else $0 = substr($0, 5)
	} else if($1 == ".In") {
		$0 = "\n.BR \"#include <" $2 ">\"\n"
	} else if($1 == ".Ft") {
		$1 = ".I"
	} else if($1 == ".Fn") {
		$0 = brify(cfunc($0), $NF != ",")
	} else if($1 == ".Fo") {
		fnblock = $0
		$0 = ""
	} else if($1 == ".Fa") {
		if(fnblock != "") {
			fnblock = fnblock " " substr($0, 5)
			$0 = ""
		} else {
			l = unquotewords(substr($0, 5), foo)
			$0 = ".XX "
			for(i=0;i<l;i++) {
				sp = i+1<l?", ":"";
				$0 = $0 foo[i] sp
			}
			$0 = italify($0, 0)
		}
	} else if($1 == ".Fc") {
		$0 = brify(cfunc(fnblock), 1)
		fnblock = ""
	} else if($1 == ".Cm") {
		out = ".Cm "
		for(i = 2; i <= NF; i+=2)
			out = out $i " "
		$0 = brify(out, 0)
	} else if($1 == ".Ic") {
		$0 = brify($0, 0)
	} else if($1 == ".Tn" || $1 == ".Va" || $1 == ".Fx") {
		$0 = substr($0, 5)
	} else if($1 == ".Po") {
		$1 = "("
	} else if($1 == ".Pc") {
		$1 = ")"
	} else if($1 == ".Pq") {
		out = ""
		for(i = 2; i <= NF; i++)
			if(!(length($i) == 2 && $i ~ /[A-Z][a-z]/))
				out = out $i " "
		if(substr(out, length(out)) == " ")
			out = substr(out, 0, length(out) -1)
		$0 = "(“" out "”)"
	} else if($1 == ".Pf") {
		$0 = $2 $4
	} else if($1 == ".Pp") {
		$0 = ".sp\n"
	} else if($1 == ".Sm") {
		spacing = $2=="on"?1:0 #unused
		$0 = ""
	} else if($1 == ".Oo" || $1 == ".Oc") {
		# denotes .Op block start/end - ignore
		$0 = ""
	} else if($1 == ".It" || $1 == ".Op") {
		if(blockmode && $1 == ".It" && $2 != "Pa") print "\n"
		#if(blockmode) indent_after=1
		out = $1 == ".Op" ? "[" : "";
		for(i = 2; i <= NF; i++) {
			if(i == 2 && $i == "Fn" && $1 == ".It") {
				print ".sp"
				out = ".Fn " substr($0, 8)
				out = brify(cfunc(out),1)
				indent_after = 1
				break;
			} else if (i == 2 && $i == "Pa" && $1 == ".It") {
				sub(/^\.It Pa/, ".I")
				out = $0 "\n.br"
				break
			} else if (i == 2 && $i == "Ev" && $1 == ".It") {
				# ignore
			} else if (i == 2 && $i == "Xo") {
				out = ""
				break
			} else if($i == "Fl" || $i == "Ar" || $i == "Cm") {
				if($i == "Fl") str = "BR -"
				else if($i == "Ar") str = "I "
				else str = "BR "
				i++;
				if(out == "") { nl = "" } else { nl = "\n" }
				out = out nl "." str $i;
				if($i == "Fl") while($(i+1) == "|") {
					out = out " | -" $(i+2)
					i += 2;
				}
			} else {
				sp = i+1<=NF?" ":""
				out = out $i sp;
			}
		}
		if($1 == ".Op") out = out "\n]"
		if(blockmode && $1 == ".It") out = out "\n"
		$0 = out;
	} else if($1 == ".Ar") {
		$1 = ".I"
		$(NF+1) = "\n.br"
	} else if($1 == ".Fl") {
		#if(blockmode) indent()
		$1 = ".BR"
		for(i = 2; i <= NF; i++) {
			$i = "-" $i
		}
	} else if($1 == ".Nd") {
		$1 = "-"
	} else if($1 == ".Nm") {
		if(name == "" && NF == 2) {
			name = $2
			$0 = ".Nm"
		}
		sep = NF > 1 ? "\n" : ""
		$0 = ".BR \"" name "\"" sep fields(2, NF)
	} else if($1 == ".At") {
		$0 = "AT&T UNIX"
	} else if($1 == ".Bx") {
		$0 = "BSD"
	} else if($1 == ".Nx") {
		$0 = "NetBSD"
	} else if($1 == ".Ux") {
		$0 = "UNIX"
	} else if($1 == ".St") {
		if(0) ;
		else if($2 == "-p1003.1-88")
			$0 = "IEEE Std 1003.1-1988 (“POSIX.1”)"
		else if($2 == "-p1003.1-90")
			$0 = "IEEE Std 1003.1-1990 (“POSIX.1”)"
		else if($2 == "-p1003.1-96")
			$0 = "ISO/IEC 9945-1:1996 (“POSIX.1”)"
		else if($2 == "-p1003.1-2001")
			$0 = "IEEE Std 1003.1-2001 (“POSIX.1”)"
		else if($2 == "-p1003.1-2004")
			$0 = "IEEE Std 1003.1-2004 (“POSIX.1”)"
		else if($2 == "-p1003.1-2008")
			$0 = "IEEE Std 1003.1-2008 (“POSIX.1”)"
		else if($2 == "-p1003.1")
			$0 = "IEEE Std 1003.1 (“POSIX.1”)"
		else if($2 == "-p1003.1b")
			$0 = "IEEE Std 1003.1b (“POSIX.1”)"
		else if($2 == "-p1003.1b-93")
			$0 = "IEEE Std 1003.1b-1993 (“POSIX.1”)"
		else if($2 == "-p1003.1c-95")
			$0 = "IEEE Std 1003.1c-1995 (“POSIX.1”)"
		else if($2 == "-p1003.1g-2000")
			$0 = "IEEE Std 1003.1g-2000 (“POSIX.1”)"
		else if($2 == "-p1003.1i-95")
			$0 = "IEEE Std 1003.1i-1995 (“POSIX.1”)"
		else if($2 == "-p1003.2-92")
			$0 = "IEEE Std 1003.2-1992 (“POSIX.2”)"
		else if($2 == "-p1003.2a-92")
			$0 = "IEEE Std 1003.2a-1992 (“POSIX.2”)"
		else if($2 == "-p1387.2-95")
			$0 = "IEEE Std 1387.2-1995 (“POSIX.7.2”)"
		else if($2 == "-p1003.2")
			$0 = "IEEE Std 1003.2 (“POSIX.2”)"
		else if($2 == "-p1387.2")
			$0 = "IEEE Std 1387.2 (“POSIX.7.2”)"
		else if($2 == "-isoC")
			$0 = "ISO/IEC 9899:1990 (“ISO C90”)"
		else if($2 == "-isoC-90")
			$0 = "ISO/IEC 9899:1990 (“ISO C90”)"
		else if($2 == "-isoC-amd1")
			$0 = "ISO/IEC 9899/AMD1:1995 (“ISO C90, Amendment 1”)"
		else if($2 == "-isoC-tcor1")
			$0 = "ISO/IEC 9899/TCOR1:1994 (“ISO C90, Technical Corrigendum 1”)"
		else if($2 == "-isoC-tcor2")
			$0 = "ISO/IEC 9899/TCOR2:1995 (“ISO C90, Technical Corrigendum 2”)"
		else if($2 == "-isoC-99")
			$0 = "ISO/IEC 9899:1999 (“ISO C99”)"
		else if($2 == "-isoC-2011")
			$0 = "ISO/IEC 9899:2011 (“ISO C11”)"
		else if($2 == "-iso9945-1-90")
			$0 = "ISO/IEC 9945-1:1990 (“POSIX.1”)"
		else if($2 == "-iso9945-1-96")
			$0 = "ISO/IEC 9945-1:1996 (“POSIX.1”)"
		else if($2 == "-iso9945-2-93")
			$0 = "ISO/IEC 9945-2:1993 (“POSIX.2”)"
		else if($2 == "-ansiC")
			$0 = "ANSI X3.159-1989 (“ANSI C89”)"
		else if($2 == "-ansiC-89")
			$0 = "ANSI X3.159-1989 (“ANSI C89”)"
		else if($2 == "-ansiC-99")
			$0 = "ANSI/ISO/IEC 9899-1999 (“ANSI C99”)"
		else if($2 == "-ieee754")
			$0 = "IEEE Std 754-1985"
		else if($2 == "-iso8802-3")
			$0 = "ISO 8802-3: 1989"
		else if($2 == "-iso8601")
			$0 = "ISO 8601"
		else if($2 == "-ieee1275-94")
			$0 = "IEEE Std 1275-1994 (“Open Firmware”)"
		else if($2 == "-xpg3")
			$0 = "X/Open Portability Guide Issue 3 (“XPG3”)"
		else if($2 == "-xpg4")
			$0 = "X/Open Portability Guide Issue 4 (“XPG4”)"
		else if($2 == "-xpg4.2")
			$0 = "X/Open Portability Guide Issue 4, Version 2 (“XPG4.2”)"
		else if($2 == "-xpg4.3")
			$0 = "X/Open Portability Guide Issue 4, Version 3 (“XPG4.3”)"
		else if($2 == "-xbd5")
			$0 = "X/Open Base Definitions Issue 5 (“XBD5”)"
		else if($2 == "-xcu5")
			$0 = "X/Open Commands and Utilities Issue 5 (“XCU5”)"
		else if($2 == "-xsh5")
			$0 = "X/Open System Interfaces and Headers Issue 5 (“XSH5”)"
		else if($2 == "-xns5")
			$0 = "X/Open Networking Services Issue 5 (“XNS5”)"
		else if($2 == "-xns5.2")
			$0 = "X/Open Networking Services Issue 5.2 (“XNS5.2”)"
		else if($2 == "-xns5.2d2.0")
			$0 = "X/Open Networking Services Issue 5.2 Draft 2.0 (“XNS5.2D2.0”)"
		else if($2 == "-xcurses4.2")
			$0 = "X/Open Curses Issue 4, Version 2 (“XCURSES4.2”)"
		else if($2 == "-susv2")
			$0 = "Version 2 of the Single UNIX Specification"
		else if($2 == "-susv3")
			$0 = "Version 3 of the Single UNIX Specification"
		else if($2 == "-svid4")
			$0 = "System V Interface Definition, Fourth Edition (“SVID4”)"
	} else if($1 == ".Pa" || $1 == ".Em") {
		$0 = italify($0, 0)
	} else if($1 == ".Bk" || $1 == ".Ek" || $1 == ".Xc" || $1 == ".Os") {
		# comments go here
		$0 = "\n"
	} else if($1 == ".D1" || $1 == ".Dl") {
		$1 = "\t"
	} else if($1 == ".Ev") {
		$0 = brify($0, 0)
	} else if($1 == ".Aq") {
		cut=4
		if(NF > 2 && length($2)==2) cut+=3
		$0 = substr($0, cut)
		$1 = "<" $1 ">"
	} else if($1 == ".Qq") {
		$0 = "\"" $2 "\"" fields(3, NF)
	} else if($1 == ".Sq") {
		$0 = "'" $2 "'" fields(3, NF)
	} else if($1 == ".Sx" || $1 == ".Sy") {
		$0 = brify($0, 0)
	} else if($1 == ".Sh") {
		$1 = ".SH"
	} else if($1 == ".Ss") {
		$1 = ".SS"
# xman stuff starts here
	} else if($1 == ".ZN") {
		$0 = italify($0, 0)
# groff stuff starts here
# http://web.cecs.pdx.edu/~trent/gnu/groff/groff.html
# lowercase stuff supported by man.c:
# nh hy nf fi sp br bp ad na ta
	} else if($1 == ".if") { #single if block
		$0 = ""
	} else if($1 == ".ie") { #if else branch starting
		$0 = ""
	} else if($1 == ".el") { #else block
		$0 = ""
	} else if($1 == ".ds") { #set a string variable.
		update_var($2, $0)
		$0 = ""
	} else if($1 == ".ds" ||
	          $1 == ".de" ||
	          $1 == ".ce" ||
	          $1 == ".ll" ||
	          $1 == ".in" ||
	          $1 == "." ||
	          $1 == ".." ||
	          $1 == "..." ||
	          $1 == ".\\\\$" ||
	          $1 == ".\\\"" ||
	          $1 == ".ft" ||
	          $1 == ".ps" ||
	          $1 == ".ny0" ||
	          $1 == ".nr" ||
	          $1 == ".ns" ||
	          $1 == ".ne" ||
	          0) { #other groff junk
		$0 = ""
	} else if($1 == ".KS" ||
	          $1 == ".DE" ||
	          $1 == ".TA" ||
	          $1 == ".TB" ||
	          $1 == ".KE" ||
	          $1 == ".D" ||
	          $1 == ".R" ||
	          $1 == ".Sp" ||
	          $1 == ".Ve" ||

		0) { #other unknown stuff
		$0 = ""
# perl stuff starts here
# http://www.opensource.apple.com/source/perl/perl-24.1/perl/lib/Pod/Man.pm
	} else if($1 == ".Vb") { #perl verbose section starts
		$0 = ".sp\n.RS\n.nf\n"
	} else if($1 == ".Ve") { #perl verbose section ends
		$0 = ".fi\n.RE\n"
	} else if($1 == ".tr" ||
	          $1 == ".el\\" ||
	          $1 == ".rm" ||
	          $1 == ".\\}" ||
		0) { #other perl junk
		$0 = 0
	}
	print;
	if(indent_after) {
		#indent()
		indent_after = 0
	}
}

path: KEEP/manpp


code:
--- mc-4.8.1.7.org/lib/tty/tty-ncurses.c	2016-02-23 22:12:17.815464286 +0000
+++ mc-4.8.1.7/lib/tty/tty-ncurses.c	2016-02-24 03:14:50.927519155 +0000
@@ -185,11 +185,13 @@
     ESCDELAY = 200;
 #endif /* HAVE_ESCDELAY */

+    struct termios mode;
+    tcgetattr (STDIN_FILENO, &mode);
     /* use Ctrl-g to generate SIGINT */
-    cur_term->Nttyb.c_cc[VINTR] = CTRL ('g');   /* ^g */
+    mode.c_cc[VINTR] = CTRL ('g');   /* ^g */
     /* disable SIGQUIT to allow use Ctrl-\ key */
-    cur_term->Nttyb.c_cc[VQUIT] = NULL_VALUE;
-    tcsetattr (cur_term->Filedes, TCSANOW, &cur_term->Nttyb);
+    mode.c_cc[VQUIT] = NULL_VALUE;
+    tcsetattr (STDIN_FILENO, TCSANOW, &mode);

     tty_start_interrupt_key ();


code:
--- mdadm-3.2.6.org/platform-intel.c	2013-02-01 20:41:53.717000003 +0000
+++ mdadm-3.2.6/platform-intel.c	2013-02-01 20:48:23.468000004 +0000
@@ -116,7 +116,7 @@

 		list->dev_id = (__u16) dev_id;
 		list->type = type;
-		list->path = canonicalize_file_name(path);
+		list->path = realpath(path, NULL);
 		list->next = NULL;
 		if ((list->pci_id = strrchr(list->path, '/')) != NULL)
 			list->pci_id++;
@@ -459,7 +459,7 @@
 	char device[46];

 	sprintf(device, "/sys/dev/block/%d:%d/device", major(dev), minor(dev));
-	return canonicalize_file_name(device);
+	return realpath(device, NULL);
 }

 char *diskfd_to_devpath(int fd)


code:
--- mdadm-3.2.6.org/mdadm.h	2013-02-01 20:41:53.711000003 +0000
+++ mdadm-3.2.6/mdadm.h	2013-02-01 20:42:40.706000003 +0000
@@ -25,13 +25,6 @@
 #define	_GNU_SOURCE
 #define _FILE_OFFSET_BITS 64
 #include	<unistd.h>
-#if !defined(__dietlibc__) && !defined(__KLIBC__)
-extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
-#else
-# if defined(__NO_STAT64) || __WORDSIZE != 32
-# define lseek64 lseek
-# endif
-#endif

 #include	<sys/types.h>
 #include	<sys/stat.h>


code:
--- ./include/c11/threads_posix.h.orig
+++ ./include/c11/threads_posix.h
@@ -178,7 +178,7 @@
         return thrd_error;
     pthread_mutexattr_init(&attr);
     if ((type & mtx_recursive) != 0) {
-#if defined(__linux__) || defined(__linux)
+#if defined(__GLIBC__)
         pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
 #else
         pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
--- ./src/gallium/winsys/svga/drm/vmw_screen.h.orig
+++ ./src/gallium/winsys/svga/drm/vmw_screen.h
@@ -34,7 +34,7 @@
 #ifndef VMW_SCREEN_H_
 #define VMW_SCREEN_H_

-
+#include <sys/stat.h>
 #include "pipe/p_compiler.h"
 #include "pipe/p_state.h"


code:
patch for https://bugs.freedesktop.org/show_bug.cgi?id=35268
affected: anything using openGL, most notably firefox and wine.
this needs to be used in combination with --disable-asm
(since the asm uses the same trickery).

--- Mesa-10.2.7.org/src/egl/main/eglcurrent.c
+++ Mesa-10.2.7/src/egl/main/eglcurrent.c
@@ -51,8 +51,8 @@
 static void (*_egl_FreeTSD)(_EGLThreadInfo *);

 #ifdef GLX_USE_TLS
-static __thread const _EGLThreadInfo *_egl_TLS
-   __attribute__ ((tls_model("initial-exec")));
+#include "tls-model.h"
+static __thread const _EGLThreadInfo *_egl_TLS TLS_MODEL;
 #endif

 static INLINE void _eglSetTSD(const _EGLThreadInfo *t)
--- Mesa-10.2.7.org/src/glx/glxclient.h
+++ Mesa-10.2.7/src/glx/glxclient.h
@@ -637,8 +637,9 @@

 # if defined( GLX_USE_TLS )

-extern __thread void *__glX_tls_Context
-   __attribute__ ((tls_model("initial-exec")));
+#include "tls-model.h"
+
+extern __thread void *__glX_tls_Context TLS_MODEL;

 #  define __glXGetCurrentContext() __glX_tls_Context

--- Mesa-10.2.7.org/src/glx/glxcurrent.c
+++ Mesa-10.2.7/src/glx/glxcurrent.c
@@ -79,6 +79,8 @@

 # if defined( GLX_USE_TLS )

+#include "tls-model.h"
+
 /**
  * Per-thread GLX context pointer.
  *
@@ -86,7 +88,7 @@
  * \b never be \c NULL.  This is important!  Because of this
  * \c __glXGetCurrentContext can be implemented as trivial macro.
  */
-__thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec")))
+__thread void *__glX_tls_Context TLS_MODEL
    = &dummyContext;

 _X_HIDDEN void
--- Mesa-10.2.7.org/src/mapi/glapi/glapi.h
+++ Mesa-10.2.7/src/mapi/glapi/glapi.h
@@ -85,11 +85,10 @@

 #if defined (GLX_USE_TLS)

-_GLAPI_EXPORT extern __thread struct _glapi_table * _glapi_tls_Dispatch
-    __attribute__((tls_model("initial-exec")));
+#include "tls-model.h"

-_GLAPI_EXPORT extern __thread void * _glapi_tls_Context
-    __attribute__((tls_model("initial-exec")));
+_GLAPI_EXPORT extern __thread struct _glapi_table * _glapi_tls_Dispatch TLS_MODEL;
+_GLAPI_EXPORT extern __thread void * _glapi_tls_Context TLS_MODEL;

 _GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch;
 _GLAPI_EXPORT extern const void *_glapi_Context;
--- Mesa-10.2.7.org/src/mapi/u_current.c
+++ Mesa-10.2.7/src/mapi/u_current.c
@@ -98,13 +98,11 @@
  */
 /*@{*/
 #if defined(GLX_USE_TLS)
-
-__thread struct mapi_table *u_current_table
-    __attribute__((tls_model("initial-exec")))
+#include "tls-model.h"
+__thread struct mapi_table *u_current_table TLS_MODEL
     = (struct mapi_table *) table_noop_array;

-__thread void *u_current_context
-    __attribute__((tls_model("initial-exec")));
+__thread void *u_current_context TLS_MODEL;

 #else

--- Mesa-10.2.7.org/src/mapi/u_current.h
+++ Mesa-10.2.7/src/mapi/u_current.h
@@ -30,11 +30,10 @@

 #ifdef GLX_USE_TLS

-extern __thread struct mapi_table *u_current_table
-    __attribute__((tls_model("initial-exec")));
+#include "tls-model.h"
+extern __thread struct mapi_table *u_current_table TLS_MODEL;

-extern __thread void *u_current_context
-    __attribute__((tls_model("initial-exec")));
+extern __thread void *u_current_context TLS_MODEL;

 #else /* GLX_USE_TLS */

--- Mesa-10.2.7.org/src/mesa/drivers/dri/common/dri_test.c
+++ Mesa-10.2.7/src/mesa/drivers/dri/common/dri_test.c
@@ -11,11 +11,10 @@

 #if defined(GLX_USE_TLS)

-PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch
-    __attribute__((tls_model("initial-exec")));
+#include "tls-model.h"

-PUBLIC __thread void * _glapi_tls_Context
-    __attribute__((tls_model("initial-exec")));
+PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch TLS_MODEL;
+PUBLIC __thread void * _glapi_tls_Context TLS_MODEL;

 PUBLIC const struct _glapi_table *_glapi_Dispatch;
 PUBLIC const void *_glapi_Context;
--- /dev/null
+++ Mesa-10.2.7/include/c11/tls-model.h
@@ -0,0 +1,11 @@
+#ifndef TLS_MODEL_H
+#define TLS_MODEL_H
+
+#ifdef __GLIBC__
+#define TLS_MODEL __attribute__ ((tls_model("initial-exec")))
+#else
+#define TLS_MODEL
+#endif
+
+#endif
+


code:
--- Mesa-9.1.6.org/src/mesa/main/querymatrix.c	2013-08-04 18:12:47.046000003 +0000
+++ Mesa-9.1.6/src/mesa/main/querymatrix.c	2013-08-04 18:23:35.360000003 +0000
@@ -71,7 +71,7 @@
     }
 }

-#elif defined(__APPLE__) || defined(__CYGWIN__) || defined(__FreeBSD__) || \
+#elif defined(fpclassify) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__FreeBSD__) || \
      defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
      (defined(__sun) && defined(__C99FEATURES__)) || defined(__MINGW32__) || \
      (defined(__sun) && defined(__GNUC__)) || defined(ANDROID) || defined(__HAIKU__)