summaryrefslogtreecommitdiff
path: root/lib/win32/emu.h
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2008-01-19 15:08:54 +0100
committerReinhard Tartler <siretart@tauware.de>2008-01-19 15:08:54 +0100
commit2733267954e91e394fbb512ea3abb4c497c0752f (patch)
treed6cdebd8776bceba06a2fb5e4ed06a4744bc1b57 /lib/win32/emu.h
parent1d56581c644c53f1b9a182c6574bc2fc5243d4d1 (diff)
import version 0.11rc1
This commit has been made by 'bzr import'. I used the upstream tarball of Version 0.11rc1 for creating it. It has the md5sum: 75608d8bb72dff9a556850ccd0ae8cb9
Diffstat (limited to 'lib/win32/emu.h')
-rw-r--r--lib/win32/emu.h348
1 files changed, 135 insertions, 213 deletions
diff --git a/lib/win32/emu.h b/lib/win32/emu.h
index 7e7700f4..e67eeae9 100644
--- a/lib/win32/emu.h
+++ b/lib/win32/emu.h
@@ -1,4 +1,4 @@
-// distribution boxbackup-0.10 (svn version: 494)
+// distribution boxbackup-0.11rc1 (svn version: 2023_2024)
//
// Copyright (c) 2003 - 2006
// Ben Summers and contributors. All rights reserved.
@@ -41,7 +41,47 @@
#if ! defined EMU_INCLUDE && defined WIN32
#define EMU_INCLUDE
-#define _INO_T_DEFINED
+// basic types, may be required by other headers since we
+// don't include sys/types.h
+
+#ifdef __MINGW32__
+ #include <stdint.h>
+#else // MSVC
+ typedef unsigned __int64 u_int64_t;
+ typedef unsigned __int64 uint64_t;
+ typedef __int64 int64_t;
+ typedef unsigned __int32 uint32_t;
+ typedef unsigned __int32 u_int32_t;
+ typedef __int32 int32_t;
+ typedef unsigned __int16 uint16_t;
+ typedef __int16 int16_t;
+ typedef unsigned __int8 uint8_t;
+ typedef __int8 int8_t;
+#endif
+
+// emulated types, present on MinGW but not MSVC or vice versa
+
+#ifdef __MINGW32__
+ typedef uint32_t u_int32_t;
+#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
+
+#define WIN32_LEAN_AND_MEAN
+
+#ifndef __MSVCRT_VERSION__
+#define __MSVCRT_VERSION__ 0x0601
+#endif
+
+// Windows headers
#include <winsock2.h>
#include <fcntl.h>
@@ -57,11 +97,13 @@
#include <string>
+// emulated functions
+
#define gmtime_r( _clock, _result ) \
( *(_result) = *gmtime( (_clock) ), \
(_result) )
-#define ITIMER_VIRTUAL 0
+#define ITIMER_REAL 0
#ifdef _MSC_VER
// Microsoft decided to deprecate the standard POSIX functions. Great!
@@ -79,17 +121,11 @@ int setitimer(int type, struct itimerval *timeout, void *arg);
void InitTimer(void);
void FiniTimer(void);
-inline int geteuid(void)
-{
- //lets pretend to be root!
- return 0;
-}
-
struct passwd {
char *pw_name;
char *pw_passwd;
- uid_t pw_uid;
- gid_t pw_gid;
+ int pw_uid;
+ int pw_gid;
time_t pw_change;
char *pw_class;
char *pw_gecos;
@@ -127,14 +163,6 @@ inline struct passwd * getpwnam(const char * name)
#define S_ISDIR(x) (S_IFDIR & x)
#endif
-inline int utimes(const char * Filename, timeval[])
-{
- //again I am guessing this is quite important to
- //be functioning, as large restores would be a problem
-
- //indicate success
- return 0;
-}
inline int chown(const char * Filename, u_int32_t uid, u_int32_t gid)
{
//important - this needs implementing
@@ -151,46 +179,9 @@ inline int chown(const char * Filename, u_int32_t uid, u_int32_t gid)
return 0;
}
-int emu_chdir (const char* pDirName);
-int emu_unlink(const char* pFileName);
-char* emu_getcwd(char* pBuffer, int BufSize);
-
-#ifdef _MSC_VER
- inline int emu_chmod(const char * Filename, int mode)
- {
- // indicate success
- return 0;
- }
-
- #define chmod(file, mode) emu_chmod(file, mode)
- #define chdir(directory) emu_chdir(directory)
- #define unlink(file) emu_unlink(file)
- #define getcwd(buffer, size) emu_getcwd(buffer, size)
-#else
- inline int chmod(const char * Filename, int mode)
- {
- // indicate success
- return 0;
- }
-
- inline int chdir(const char* pDirName)
- {
- return emu_chdir(pDirName);
- }
-
- inline char* getcwd(char* pBuffer, int BufSize)
- {
- return emu_getcwd(pBuffer, BufSize);
- }
-
- inline int unlink(const char* pFileName)
- {
- return emu_unlink(pFileName);
- }
-#endif
-
-//I do not perceive a need to change the user or group on a backup client
-//at any rate the owner of a service can be set in the service settings
+// Windows and Unix owners and groups are pretty fundamentally different.
+// Ben prefers that we kludge here rather than litter the code with #ifdefs.
+// Pretend to be root, and pretend that set...() operations succeed.
inline int setegid(int)
{
return true;
@@ -215,6 +206,10 @@ inline int getuid(void)
{
return 0;
}
+inline int geteuid(void)
+{
+ return 0;
+}
#ifndef PATH_MAX
#define PATH_MAX MAX_PATH
@@ -222,59 +217,7 @@ inline int getuid(void)
// MinGW provides a getopt implementation
#ifndef __MINGW32__
-
-// this will need to be implemented if we see fit that command line
-// options are going to be used! (probably then:)
-// where the calling function looks for the parsed parameter
-extern char *optarg;
-
-// optind looks like an index into the string - how far we have moved along
-extern int optind;
-extern char nextchar;
-
-inline int getopt(int count, char * const * args, const char * tolookfor)
-{
- if (optind >= count) return -1;
-
- std::string str((const char *)args[optind]);
- std::string interestin(tolookfor);
- int opttolookfor = 0;
- int index = -1;
- // just initialize the string - just in case it is used.
- // optarg[0] = 0;
- std::string opt;
-
- if (count == 0) return -1;
-
- do
- {
- if (index != -1)
- {
- str = str.substr(index+1, str.size());
- }
-
- index = (int)str.find('-');
-
- if (index == -1) return -1;
-
- opt = str[1];
-
- optind ++;
- str = args[optind];
- }
- while ((opttolookfor = (int)interestin.find(opt)) == -1);
-
- if (interestin[opttolookfor+1] == ':')
- {
-
- // strcpy(optarg, str.c_str());
- optarg = args[optind];
- optind ++;
- }
-
- // indicate we have finished
- return opt[0];
-}
+#include "getopt.h"
#endif // !__MINGW32__
#define timespec timeval
@@ -290,25 +233,9 @@ struct itimerval
#define tv_nsec tv_usec
#ifndef __MINGW32__
- typedef unsigned __int64 u_int64_t;
- typedef unsigned __int64 uint64_t;
- typedef __int64 int64_t;
- typedef unsigned __int32 uint32_t;
- typedef unsigned __int32 u_int32_t;
- typedef __int32 int32_t;
- typedef unsigned __int16 uint16_t;
- typedef __int16 int16_t;
- typedef unsigned __int8 uint8_t;
- typedef __int8 int8_t;
-
typedef int socklen_t;
#endif
-// I (re-)defined here for the moment; has to be removed later !!!
-#ifndef BOX_VERSION
-#define BOX_VERSION "0.09hWin32"
-#endif
-
#define S_IRGRP S_IWRITE
#define S_IWGRP S_IREAD
#define S_IROTH S_IWRITE | S_IREAD
@@ -322,26 +249,20 @@ struct itimerval
#define vsnprintf _vsnprintf
#ifndef __MINGW32__
-typedef unsigned int mode_t;
-#endif
-
-int emu_mkdir(const char* pPathName);
-
-inline int mkdir(const char *pPathName, mode_t mode)
-{
- return emu_mkdir(pPathName);
-}
-
-#ifndef __MINGW32__
inline int strcasecmp(const char *s1, const char *s2)
{
return _stricmp(s1,s2);
}
#endif
+#ifdef _DIRENT_H_
+#error You must not include the MinGW dirent.h!
+#endif
+
struct dirent
{
char *d_name;
+ unsigned long d_type;
};
struct DIR
@@ -358,32 +279,24 @@ DIR *opendir(const char *name);
struct dirent *readdir(DIR *dp);
int closedir(DIR *dp);
+// local constant to open file exclusively without shared access
+#define O_LOCK 0x10000
+
HANDLE openfile(const char *filename, int flags, int mode);
+#define LOG_DEBUG LOG_INFO
#define LOG_INFO 6
+#define LOG_NOTICE LOG_INFO
#define LOG_WARNING 4
#define LOG_ERR 3
+#define LOG_CRIT LOG_ERR
#define LOG_PID 0
+#define LOG_LOCAL5 0
#define LOG_LOCAL6 0
-extern HANDLE gSyslogH;
-void MyReportEvent(LPCTSTR *szMsg, DWORD errinfo);
-inline void openlog(const char * daemonName, int, int)
-{
- gSyslogH = RegisterEventSource(
- NULL, // uses local computer
- daemonName); // source name
- if (gSyslogH == NULL)
- {
- }
-}
-
-inline void closelog(void)
-{
- DeregisterEventSource(gSyslogH);
-}
-
-void syslog(int loglevel, const char *fmt, ...);
+void openlog (const char * daemonName, int, int);
+void closelog(void);
+void syslog (int loglevel, const char *fmt, ...);
#ifndef __MINGW32__
#define strtoll _strtoi64
@@ -448,73 +361,82 @@ struct stat {
time_t st_mtime;
time_t st_ctime;
};
+#endif // 0
+
+// need this for conversions
+time_t ConvertFileTimeToTime_t(FILETIME *fileTime);
+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_utimes (const char* pName, const struct timeval[]);
+int emu_chmod (const char* pName, mode_t mode);
+char* emu_getcwd (char* pBuffer, int BufSize);
+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)
-#ifndef __MINGW32__
-typedef u_int64_t _ino_t;
-#endif
-#endif
-
-int emu_stat(const char * name, struct stat * st);
-int emu_fstat(HANDLE file, struct stat * st);
int statfs(const char * name, struct statfs * s);
-//need this for converstions
-inline time_t ConvertFileTimeToTime_t(FILETIME *fileTime)
-{
- SYSTEMTIME stUTC;
- struct tm timeinfo;
-
- // Convert the last-write time to local time.
- FileTimeToSystemTime(fileTime, &stUTC);
- // SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
-
- memset(&timeinfo, 0, sizeof(timeinfo));
- timeinfo.tm_sec = stUTC.wSecond;
- timeinfo.tm_min = stUTC.wMinute;
- timeinfo.tm_hour = stUTC.wHour;
- timeinfo.tm_mday = stUTC.wDay;
- timeinfo.tm_wday = stUTC.wDayOfWeek;
- timeinfo.tm_mon = stUTC.wMonth - 1;
- // timeinfo.tm_yday = ...;
- timeinfo.tm_year = stUTC.wYear - 1900;
-
- time_t retVal = mktime(&timeinfo) - _timezone;
- return retVal;
-}
+int poll(struct pollfd *ufds, unsigned long nfds, int timeout);
-#ifdef _MSC_VER
- #define stat(filename, struct) emu_stat (filename, struct)
- #define lstat(filename, struct) emu_stat (filename, struct)
- #define fstat(handle, struct) emu_fstat(handle, struct)
-#else
- inline int stat(const char* filename, struct stat* stat)
- {
- return emu_stat(filename, stat);
- }
- inline int lstat(const char* filename, struct stat* stat)
- {
- return emu_stat(filename, stat);
- }
- inline int fstat(HANDLE handle, struct stat* stat)
- {
- return emu_fstat(handle, stat);
- }
-#endif
+struct iovec {
+ void *iov_base; /* Starting address */
+ size_t iov_len; /* Number of bytes */
+};
+
+int readv (int filedes, const struct iovec *vector, size_t count);
+int writev(int filedes, const struct iovec *vector, size_t count);
+
+// The following functions are not emulations, but utilities for other
+// parts of the code where Windows API is used or windows-specific stuff
+// is needed, like codepage conversion.
-int poll(struct pollfd *ufds, unsigned long nfds, int timeout);
bool EnableBackupRights( void );
+bool ConvertEncoding (const std::string& rSource, int sourceCodePage,
+ std::string& rDest, int destCodePage);
+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);
-//
-// MessageId: MSG_ERR_EXIST
-// MessageText:
-// Box Backup.
-//
-#define MSG_ERR_EXIST ((DWORD)0xC0000004L)
+// Utility function which returns a default config file name,
+// based on the path of the current executable.
+std::string GetDefaultConfigFilePath(const std::string& rName);
+
+// GetErrorMessage() returns a system error message, like strerror()
+// but for Windows error codes.
+std::string GetErrorMessage(DWORD errorCode);
-// replacement for _cgetws which requires a relatively recent C runtime lib
+// console_read() is a replacement for _cgetws which requires a
+// relatively recent C runtime lib
int console_read(char* pBuffer, size_t BufferSize);
+#ifdef _MSC_VER
+ /* disable certain compiler warnings to be able to actually see the show-stopper ones */
+ #pragma warning(disable:4101) // unreferenced local variable
+ #pragma warning(disable:4244) // conversion, possible loss of data
+ #pragma warning(disable:4267) // conversion, possible loss of data
+ #pragma warning(disable:4311) // pointer truncation
+ #pragma warning(disable:4700) // uninitialized local variable used (hmmmmm...)
+ #pragma warning(disable:4805) // unsafe mix of type and type 'bool' in operation
+ #pragma warning(disable:4800) // forcing value to bool 'true' or 'false' (performance warning)
+ #pragma warning(disable:4996) // POSIX name for this item is deprecated
+#endif // _MSC_VER
+
#endif // !EMU_INCLUDE && WIN32