#ifdef TSRM_WIN32
#include "readdir.h"
-
+#include <sys/utime.h>
/* mode_t isn't defined on Windows */
typedef int mode_t;
(IS_SLASH(path[0]))
#endif
-#if HAVE_UTIME
-# ifdef TSRM_WIN32
-# include <sys/utime.h>
-# endif
-#endif
-
#ifdef TSRM_EXPORTS
#define CWD_EXPORTS
#endif
# define CWDLS_FETCH()
#endif
+/* The actual macros to be used in programs using TSRM
+ * If the program defines VIRTUAL_DIR it will use the
+ * virtual_* functions
+ */
+
+#ifdef VIRTUAL_DIR
+
+#define V_GETCWD(buff, size) virtual_getcwd(buff,size)
+#define V_FOPEN(path, mode) virtual_fopen(path, mode)
+/* The V_OPEN macro will need to be used as V_OPEN((path, flags, ...)) */
+#define V_OPEN(open_args) virtual_open open_args
+#define V_CREAT(path, mode) virtual_creat(path, mode)
+#define V_CHDIR(path) virtual_chdir(path)
+#define V_CHDIR_FILE(path) virtual_chdir_file(path, virtual_chdir)
+#define V_GETWD(buf)
+#define V_REALPATH(path,real_path) virtual_realpath(path,real_path)
+#define V_STAT(path, buff) virtual_stat(path, buff)
+#ifdef TSRM_WIN32
+#define V_LSTAT(path, buff) virtual_stat(path, buff)
+#else
+#define V_LSTAT(path, buff) virtual_lstat(path, buff)
+#endif
+#define V_UNLINK(path) virtual_unlink(path)
+#define V_MKDIR(pathname, mode) virtual_mkdir(pathname, mode)
+#define V_RMDIR(pathname) virtual_rmdir(pathname)
+#define V_OPENDIR(pathname) virtual_opendir(pathname)
+#define V_POPEN(command, type) virtual_popen(command, type)
+#if HAVE_UTIME
+#define V_UTIME(path,time) virtual_utime(path,time)
+#endif
+#define V_CHMOD(path,mode) virtual_chmod(path,mode)
+#ifndef TSRM_WIN32
+#define V_CHOWN(path,owner,group) virtual_chown(path,owner,group)
+#endif
+
+#else
+
+#define V_GETCWD(buff, size) getcwd(buff,size)
+#define V_FOPEN(path, mode) fopen(path, mode)
+#define V_OPEN(open_args) open open_args
+#define V_CREAT(path, mode) creat(path, mode)
+#define V_CHDIR(path) chdir(path)
+#define V_CHDIR_FILE(path) virtual_chdir_file(path, chdir)
+#define V_GETWD(buf) getwd(buf)
+#define V_STAT(path, buff) stat(path, buff)
+#define V_LSTAT(path, buff) lstat(path, buff)
+#define V_UNLINK(path) unlink(path)
+#define V_MKDIR(pathname, mode) mkdir(pathname, mode)
+#define V_RMDIR(pathname) rmdir(pathname)
+#define V_OPENDIR(pathname) opendir(pathname)
+#define V_POPEN(command, type) popen(command, type)
+#define V_REALPATH(path,real_path) realpath(path,real_path)
+#if HAVE_UTIME
+#define V_UTIME(path,time) utime(path,time)
+#endif
+#define V_CHMOD(path,mode) chmod(path,mode)
+#ifndef TSRM_WIN32
+#define V_CHOWN(path,owner,group) chown(path,owner,group)
+#endif
+
+#endif
+
#endif /* VIRTUAL_CWD_H */