diff --git a/src/xpdev/filewrap.h b/src/xpdev/filewrap.h
index c187e65904c57d20cd42e503e58dc63c5320cbf4..0ff267bc673134c94bd3d3019bbbe753a97c5c9c 100644
--- a/src/xpdev/filewrap.h
+++ b/src/xpdev/filewrap.h
@@ -150,7 +150,8 @@
 #define O_DENYNONE		SH_DENYNO
 #endif
 
-#define CLOSE_OPEN_FILE(x)	while((x) >= 0) { close(x); (x)=-1; break; }
+#define CLOSE_OPEN_FILE(x)	do { if((x) >= 0)    { close(x);  (x) = -1;   } } while(0)
+#define FCLOSE_OPEN_FILE(x)	do { if((x) != NULL) { fclose(x); (x) = NULL; } } while(0)
 
 /**************/
 /* Prototypes */