summaryrefslogtreecommitdiff
path: root/lib/win32/emu.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/win32/emu.h')
-rw-r--r--lib/win32/emu.h83
1 files changed, 47 insertions, 36 deletions
diff --git a/lib/win32/emu.h b/lib/win32/emu.h
index 8ab74130..811e6495 100644
--- a/lib/win32/emu.h
+++ b/lib/win32/emu.h
@@ -1,5 +1,17 @@
// emulates unix syscalls to win32 functions
+#ifdef WIN32
+ #define EMU_STRUCT_STAT struct emu_stat
+ #define EMU_STAT emu_stat
+ #define EMU_FSTAT emu_fstat
+ #define EMU_LSTAT emu_stat
+#else
+ #define EMU_STRUCT_STAT struct stat
+ #define EMU_STAT ::stat
+ #define EMU_FSTAT ::fstat
+ #define EMU_LSTAT ::lstat
+#endif
+
#if ! defined EMU_INCLUDE && defined WIN32
#define EMU_INCLUDE
@@ -28,11 +40,6 @@
#else
typedef unsigned int mode_t;
typedef unsigned int pid_t;
-
- // must define _INO_T_DEFINED before including <sys/types.h>
- // to replace it with our own.
- typedef u_int64_t _ino_t;
- #define _INO_T_DEFINED
#endif
// set up to include the necessary parts of Windows headers
@@ -78,11 +85,6 @@
#define fileno(struct_file) _fileno(struct_file)
#endif
-int SetTimerHandler(void (__cdecl *func ) (int));
-int setitimer(int type, struct itimerval *timeout, void *arg);
-void InitTimer(void);
-void FiniTimer(void);
-
struct passwd {
char *pw_name;
char *pw_passwd;
@@ -184,13 +186,6 @@ inline int geteuid(void)
#define timespec timeval
-//not available in win32
-struct itimerval
-{
- timeval it_interval;
- timeval it_value;
-};
-
//win32 deals in usec not nsec - so need to ensure this follows through
#define tv_nsec tv_usec
@@ -205,6 +200,7 @@ struct itimerval
//again need to verify these
#define S_IFLNK 1
+#define S_IFSOCK 0
#define S_ISLNK(x) ( false )
@@ -244,6 +240,7 @@ int closedir(DIR *dp);
// local constant to open file exclusively without shared access
#define O_LOCK 0x10000
+extern DWORD winerrno; /* used to report errors from openfile() */
HANDLE openfile(const char *filename, int flags, int mode);
#define LOG_DEBUG LOG_INFO
@@ -260,6 +257,15 @@ void openlog (const char * daemonName, int, int);
void closelog(void);
void syslog (int loglevel, const char *fmt, ...);
+#define LOG_LOCAL0 0
+#define LOG_LOCAL1 0
+#define LOG_LOCAL2 0
+#define LOG_LOCAL3 0
+#define LOG_LOCAL4 0
+#define LOG_LOCAL5 0
+#define LOG_LOCAL6 0
+#define LOG_DAEMON 0
+
#ifndef __MINGW32__
#define strtoll _strtoi64
#endif
@@ -292,6 +298,11 @@ inline int ioctl(SOCKET sock, int flag, int * something)
return 0;
}
+extern "C" inline int getpid()
+{
+ return (int)GetCurrentProcessId();
+}
+
inline int waitpid(pid_t pid, int *status, int)
{
return 0;
@@ -303,27 +314,19 @@ struct statfs
TCHAR f_mntonname[MAX_PATH];
};
-#if 0
-// I think this should get us going
-// Although there is a warning about
-// mount points in win32 can now exists - which means inode number can be
-// duplicated, so potential of a problem - perhaps this needs to be
-// implemented with a little more thought... TODO
-
-struct stat {
- //_dev_t st_dev;
- u_int64_t st_ino;
+struct emu_stat {
+ int st_dev;
+ uint64_t st_ino;
DWORD st_mode;
short st_nlink;
short st_uid;
short st_gid;
//_dev_t st_rdev;
- u_int64_t st_size;
+ uint64_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
};
-#endif // 0
// need this for conversions
time_t ConvertFileTimeToTime_t(FILETIME *fileTime);
@@ -332,8 +335,8 @@ bool ConvertTime_tToFileTime(const time_t from, FILETIME *pTo);
int emu_chdir (const char* pDirName);
int emu_mkdir (const char* pPathName);
int emu_unlink (const char* pFileName);
-int emu_fstat (HANDLE file, struct stat* st);
-int emu_stat (const char* pName, struct stat* st);
+int emu_fstat (HANDLE file, struct emu_stat* st);
+int emu_stat (const char* pName, struct emu_stat* st);
int emu_utimes (const char* pName, const struct timeval[]);
int emu_chmod (const char* pName, mode_t mode);
char* emu_getcwd (char* pBuffer, int BufSize);
@@ -342,14 +345,22 @@ int emu_rename (const char* pOldName, const char* pNewName);
#define chdir(directory) emu_chdir (directory)
#define mkdir(path, mode) emu_mkdir (path)
#define unlink(file) emu_unlink (file)
-#define stat(filename, struct) emu_stat (filename, struct)
-#define lstat(filename, struct) emu_stat (filename, struct)
-#define fstat(handle, struct) emu_fstat (handle, struct)
#define utimes(buffer, times) emu_utimes (buffer, times)
#define chmod(file, mode) emu_chmod (file, mode)
#define getcwd(buffer, size) emu_getcwd (buffer, size)
#define rename(oldname, newname) emu_rename (oldname, newname)
+// Not safe to replace stat/fstat/lstat on mingw at least, as struct stat
+// has a 16-bit st_ino and we need a 64-bit one.
+//
+// #define stat(filename, struct) emu_stat (filename, struct)
+// #define lstat(filename, struct) emu_stat (filename, struct)
+// #define fstat(handle, struct) emu_fstat (handle, struct)
+//
+// But lstat doesn't exist on Windows, so we have to provide something:
+
+#define lstat(filename, struct) stat(filename, struct)
+
int statfs(const char * name, struct statfs * s);
int poll(struct pollfd *ufds, unsigned long nfds, int timeout);
@@ -374,8 +385,8 @@ bool ConvertToUtf8 (const std::string& rSource, std::string& rDest,
int sourceCodePage);
bool ConvertFromUtf8 (const std::string& rSource, std::string& rDest,
int destCodePage);
-bool ConvertUtf8ToConsole(const char* pString, std::string& rDest);
-bool ConvertConsoleToUtf8(const char* pString, std::string& rDest);
+bool ConvertUtf8ToConsole(const std::string& rSource, std::string& rDest);
+bool ConvertConsoleToUtf8(const std::string& rSource, std::string& rDest);
// Utility function which returns a default config file name,
// based on the path of the current executable.