Index: src/libcfa/libhdr/libdebug.c
===================================================================
--- src/libcfa/libhdr/libdebug.c	(revision 7a026ff9fb6fae7e12afeb2fe490474e97daed41)
+++ src/libcfa/libhdr/libdebug.c	(revision 7a026ff9fb6fae7e12afeb2fe490474e97daed41)
@@ -0,0 +1,88 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// libdebug.c --
+//
+// Author           : Thierry Delisle
+// Created On       : Thu Mar 30 12:30:01 2017
+// Last Modified By : 
+// Last Modified On : 
+// Update Count     : 0
+//
+
+extern "C" {
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <unistd.h>
+}
+
+enum { buffer_size = 512 };
+static char buffer[ buffer_size ];
+
+extern "C" {
+
+	void __lib_debug_write( int fd, const char *in_buffer, int len ) {
+		// ensure all data is written
+		for ( int count = 0, retcode; count < len; count += retcode ) { 
+			in_buffer += count;
+
+			for ( ;; ) {
+				retcode = write( fd, in_buffer, len - count );
+
+				// not a timer interrupt ?
+				if ( retcode != -1 || errno != EINTR ) break; 
+			}
+
+			if ( retcode == -1 ) _exit( EXIT_FAILURE );
+		}
+	}
+
+	void __lib_debug_acquire() __attribute__((__weak__)) {}
+	void __lib_debug_release() __attribute__((__weak__)) {}
+
+	void __lib_debug_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) )) {
+		va_list args;
+
+		va_start( args, fmt );
+		__lib_debug_acquire();
+		
+		int len = vsnprintf( buffer, buffer_size, fmt, args );
+		__lib_debug_write( STDERR_FILENO, buffer, len );
+
+		__lib_debug_release();
+		va_end( args );
+	}
+
+	void __lib_debug_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) )) {
+		va_list args;
+
+		va_start( args, fmt );
+		
+		int len = vsnprintf( buffer, buffer_size, fmt, args );
+		__lib_debug_write( STDERR_FILENO, buffer, len );
+
+		va_end( args );
+	}
+
+	void __lib_debug_print_vararg( const char fmt[], va_list args ) {
+		int len = vsnprintf( buffer, buffer_size, fmt, args );
+		__lib_debug_write( STDERR_FILENO, buffer, len );
+	}
+
+	void __lib_debug_print_buffer( char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) )) {
+		va_list args;
+
+		va_start( args, fmt );
+		
+		int len = vsnprintf( in_buffer, in_buffer_size, fmt, args );
+		__lib_debug_write( STDERR_FILENO, in_buffer, len );
+
+		va_end( args );
+	}
+}
Index: src/libcfa/libhdr/libdebug.h
===================================================================
--- src/libcfa/libhdr/libdebug.h	(revision d9c44c33df429b559731c041d43b7bee1cfcef97)
+++ src/libcfa/libhdr/libdebug.h	(revision 7a026ff9fb6fae7e12afeb2fe490474e97daed41)
@@ -25,10 +25,34 @@
 #endif
 
+#ifdef __cforall
+extern "C" {
+#endif
+      #include <stdarg.h>
+
+      extern void __lib_debug_write( int fd, const char *buffer, int len );
+      extern void __lib_debug_acquire();
+      extern void __lib_debug_release();
+      extern void __lib_debug_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
+      extern void __lib_debug_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
+      extern void __lib_debug_print_vararg( const char fmt[], va_list arg );
+      extern void __lib_debug_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) ));
+#ifdef __cforall
+}
+#endif
+
 #ifdef __CFA_DEBUG_PRINT__
-      #define LIB_DEBUG_PRINTF(...)   printf (__VA_ARGS__)
-      #define LIB_DEBUG_FPRINTF(...) fprintf (stderr, __VA_ARGS__)
+      #define LIB_DEBUG_WRITE( fd, buffer, len )  __lib_debug_write( fd, buffer, len )
+      #define LIB_DEBUG_ACQUIRE()                 __lib_debug_acquire()
+      #define LIB_DEBUG_RELEASE()                 __lib_debug_release()
+      #define LIB_DEBUG_PRINT_SAFE(...)           __lib_debug_print_safe   (__VA_ARGS__)
+      #define LIB_DEBUG_PRINT_NOLOCK(...)         __lib_debug_print_nolock (__VA_ARGS__)
+      #define LIB_DEBUG_PRINT_BUFFER(...)         __lib_debug_print_buffer (__VA_ARGS__)
 #else
-      #define LIB_DEBUG_PRINTF(...)  ((void)0)
-      #define LIB_DEBUG_FPRINTF(...) ((void)0)
+      #define LIB_DEBUG_WRITE(...)          ((void)0)
+      #define LIB_DEBUG_ACQUIRE()           ((void)0)
+      #define LIB_DEBUG_RELEASE()           ((void)0)
+      #define LIB_DEBUG_PRINT_SAFE(...)     ((void)0)
+      #define LIB_DEBUG_PRINT_NOLOCK(...)   ((void)0)
+      #define LIB_DEBUG_PRINT_BUFFER(...)   ((void)0)
 #endif
 
