diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h
index 0e2a63589787949b41f5aac92da5045924cc79df..9509271dda507dd2577ec22c774875483447bcbd 100644
--- a/src/xpdev/dirwrap.h
+++ b/src/xpdev/dirwrap.h
@@ -61,7 +61,12 @@ extern "C" {
 	#include <glob.h>		/* POSIX.2 directory pattern matching function */
 	#define MKDIR(dir)		mkdir(dir,0777)
 
-	#define FULLPATH(a,r,l)	realpath(r,a)
+	#if defined(__OpenBSD__) && defined(_THREADWRAP_H)
+		/* realpath() not threadsafe on OpenBSD */
+	    #define FULLPATH(a,r,l) realpath_r(r,a)	/* defined in threadwrap.c */
+	#else
+		#define FULLPATH(a,r,l)	realpath(r,a)
+	#endif
 
 #else