From 3bedf8846f4d7a5cb38276b274662d62a36dcd52 Mon Sep 17 00:00:00 2001 From: Martin Ebourne Date: Mon, 12 Dec 2005 20:50:00 +0000 Subject: Marged chris/win32/merge/07-win32-fixes at r210 to trunk --- lib/win32/emu.h | 426 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 426 insertions(+) create mode 100644 lib/win32/emu.h (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h new file mode 100644 index 00000000..5b506206 --- /dev/null +++ b/lib/win32/emu.h @@ -0,0 +1,426 @@ +// emulates unix syscalls to win32 functions + +#if ! defined EMU_INCLUDE && defined WIN32 +#define EMU_INCLUDE + +#define _STAT_DEFINED +#define _INO_T_DEFINED + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include + +#include + +#define gmtime_r( _clock, _result ) \ + ( *(_result) = *gmtime( (_clock) ), \ + (_result) ) + + +//signal in unix SIGVTALRM does not exist in win32 - but looking at the +#define SIGVTALRM 254 +#define SIGALRM SIGVTALRM +#define ITIMER_VIRTUAL 0 + +int setitimer(int type , struct itimerval *timeout, int); +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; + time_t pw_change; + char *pw_class; + char *pw_gecos; + char *pw_dir; + char *pw_shell; + time_t pw_expire; +}; + +extern passwd gTempPasswd; +inline struct passwd * getpwnam(const char * name) +{ + //for the mo pretend to be root + gTempPasswd.pw_uid = 0; + gTempPasswd.pw_gid = 0; + + return &gTempPasswd; +} + +#define S_IRWXG 1 +#define S_IRWXO 2 +#define S_ISUID 4 +#define S_ISGID 8 +#define S_ISVTX 16 + +#ifndef __MINGW32__ + //not sure if these are correct + //S_IWRITE - writing permitted + //_S_IREAD - reading permitted + //_S_IREAD | _S_IWRITE - + #define S_IRUSR S_IWRITE + #define S_IWUSR S_IREAD + #define S_IRWXU (S_IREAD|S_IWRITE|S_IEXEC) + + #define S_ISREG(x) (S_IFREG & x) + #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 + //If a large restore is required then + //it needs to restore files AND permissions + //reference AdjustTokenPrivileges + //GetAccountSid + //InitializeSecurityDescriptor + //SetSecurityDescriptorOwner + //The next function looks like the guy to use... + //SetFileSecurity + + //indicate success + return 0; +} + +inline int chmod(const char * Filename, int uid) +{ + //indicate sucsess + return 0; +} + +//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 +inline int setegid(int) +{ + return true; +} +inline int seteuid(int) +{ + return true; +} +inline int setgid(int) +{ + return true; +} +inline int setuid(int) +{ + return true; +} +inline int getgid(void) +{ + return 0; +} +inline int getuid(void) +{ + return 0; +} + +#ifndef PATH_MAX +#define PATH_MAX MAX_PATH +#endif + +// MinGW provides a getopt implementation +#ifndef __MINGW32__ + +//this will need to be implimented 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, 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 = str.find('-'); + + if ( index == -1 ) return -1; + + opt = str[1]; + + optind ++; + str = args[optind]; + } + while ( ( opttolookfor = interestin.find(opt)) == -1 ); + + if ( interestin[opttolookfor+1] == ':' ) + { + + //strcpy(optarg, str.c_str()); + optarg = args[optind]; + optind ++; + } + + //indicate we have finished + return opt[0]; +} +#endif // !__MINGW32__ + +#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 + +#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 +#define S_IWOTH S_IREAD | S_IREAD + +//again need to verify these +#define S_IFLNK 1 + +#define S_ISLNK(x) ( false ) + +// nasty implementation to get working - TODO get the win32 equiv +#ifdef _DEBUG +#define getpid() 1 +#endif + +#define vsnprintf _vsnprintf + +#ifndef __MINGW32__ +typedef unsigned int mode_t; +#endif + +inline int mkdir(const char *pathname, mode_t mode) +{ + return mkdir(pathname); +} + +#ifdef __MINGW32__ + #include +#else + inline int strcasecmp(const char *s1, const char *s2) + { + return _stricmp(s1,s2); + } + + struct dirent + { + char *d_name; + }; + + struct DIR + { + intptr_t fd; // filedescriptor + // struct _finddata_t info; + struct _wfinddata_t info; + // struct _finddata_t info; + struct dirent result; // d_name (first time null) + wchar_t *name; // null-terminated byte string + }; + + DIR *opendir(const char *name); + struct dirent *readdir(DIR *dp); + int closedir(DIR *dp); +#endif + +HANDLE openfile(const char *filename, int flags, int mode); + +#define LOG_INFO 6 +#define LOG_WARNING 4 +#define LOG_ERR 3 +#define LOG_PID 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, ...); + +#ifndef __MINGW32__ +#define strtoll _strtoi64 +#endif + +inline unsigned int sleep(unsigned int secs) +{ + Sleep(secs*1000); + return(ERROR_SUCCESS); +} + +#define INFTIM -1 +#define POLLIN 0x1 +#define POLLERR 0x8 +#define POLLOUT 0x4 + +#define SHUT_RDWR SD_BOTH +#define SHUT_RD SD_RECEIVE +#define SHUT_WR SD_SEND + +struct pollfd +{ + SOCKET fd; + short int events; + short int revents; +}; + +inline int ioctl(SOCKET sock, int flag, int * something) +{ + //indicate success + return 0; +} + +inline int waitpid(pid_t pid, int *status, int) +{ + return 0; +} + +//this shouldn't be needed. +struct statfs +{ + TCHAR f_mntonname[MAX_PATH]; +}; + +// 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; + DWORD st_mode; + short st_nlink; + short st_uid; + short st_gid; + //_dev_t st_rdev; + u_int64_t st_size; + time_t st_atime; + time_t st_mtime; + time_t st_ctime; +}; + +#ifndef __MINGW32__ +typedef u_int64_t _ino_t; +#endif + +int ourstat(const char * name, struct stat * st); +int ourfstat(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); + + 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); + return retVal; +} + +#define stat(x,y) ourstat(x,y) +#define fstat(x,y) ourfstat(x,y) +#define lstat(x,y) ourstat(x,y) + +int poll (struct pollfd *ufds, unsigned long nfds, int timeout); +bool EnableBackupRights( void ); + +// +// MessageId: MSG_ERR_EXIST +// MessageText: +// Box Backup. +// +#define MSG_ERR_EXIST ((DWORD)0xC0000004L) + +#endif // !EMU_INCLUDE && WIN32 -- cgit v1.2.3 From 830aa82e44381c85d8486e46de7ae0e26830457e Mon Sep 17 00:00:00 2001 From: Ben Summers Date: Mon, 13 Feb 2006 13:30:21 +0000 Subject: Merge chris/win32/vc2005-compile-fixes @ r455, add infrastructure/msvc to distribution --- lib/win32/emu.h | 196 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 126 insertions(+), 70 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 5b506206..ce0c884f 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -3,7 +3,6 @@ #if ! defined EMU_INCLUDE && defined WIN32 #define EMU_INCLUDE -#define _STAT_DEFINED #define _INO_T_DEFINED #include @@ -17,9 +16,6 @@ #include #include #include -//#include -//#include -//#include #include @@ -27,13 +23,21 @@ ( *(_result) = *gmtime( (_clock) ), \ (_result) ) - -//signal in unix SIGVTALRM does not exist in win32 - but looking at the -#define SIGVTALRM 254 -#define SIGALRM SIGVTALRM #define ITIMER_VIRTUAL 0 -int setitimer(int type , struct itimerval *timeout, int); +#ifdef _MSC_VER +// Microsoft decided to deprecate the standard POSIX functions. Great! +#define open(file,flags,mode) _open(file,flags,mode) +#define close(fd) _close(fd) +#define dup(fd) _dup(fd) +#define read(fd,buf,count) _read(fd,buf,count) +#define write(fd,buf,count) _write(fd,buf,count) +#define lseek(fd,off,whence) _lseek(fd,off,whence) +#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); @@ -109,11 +113,43 @@ inline int chown(const char * Filename, u_int32_t uid, u_int32_t gid) return 0; } -inline int chmod(const char * Filename, int uid) -{ - //indicate sucsess - 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 @@ -149,55 +185,56 @@ inline int getuid(void) // MinGW provides a getopt implementation #ifndef __MINGW32__ -//this will need to be implimented if we see fit that command line -//options are going to be used! (probably then:) -//where the calling function looks for the parsed parameter +// 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 + +// 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, char * tolookfor) +inline int getopt(int count, char * const * args, const char * tolookfor) { - if ( optind >= count ) return -1; + 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; + // just initialize the string - just in case it is used. + // optarg[0] = 0; std::string opt; - if ( count == 0 ) return -1; + if (count == 0) return -1; do { - if ( index != -1 ) + if (index != -1) { str = str.substr(index+1, str.size()); } - index = str.find('-'); + index = (int)str.find('-'); - if ( index == -1 ) return -1; + if (index == -1) return -1; opt = str[1]; optind ++; str = args[optind]; } - while ( ( opttolookfor = interestin.find(opt)) == -1 ); + while ((opttolookfor = (int)interestin.find(opt)) == -1); - if ( interestin[opttolookfor+1] == ':' ) + if (interestin[opttolookfor+1] == ':') { - //strcpy(optarg, str.c_str()); + // strcpy(optarg, str.c_str()); optarg = args[optind]; optind ++; } - //indicate we have finished + // indicate we have finished return opt[0]; } #endif // !__MINGW32__ @@ -244,49 +281,44 @@ struct itimerval #define S_ISLNK(x) ( false ) -// nasty implementation to get working - TODO get the win32 equiv -#ifdef _DEBUG -#define getpid() 1 -#endif - #define vsnprintf _vsnprintf #ifndef __MINGW32__ typedef unsigned int mode_t; #endif -inline int mkdir(const char *pathname, mode_t mode) +int emu_mkdir(const char* pPathName); + +inline int mkdir(const char *pPathName, mode_t mode) { - return mkdir(pathname); + return emu_mkdir(pPathName); } -#ifdef __MINGW32__ - #include -#else - inline int strcasecmp(const char *s1, const char *s2) - { - return _stricmp(s1,s2); - } +#ifndef __MINGW32__ +inline int strcasecmp(const char *s1, const char *s2) +{ + return _stricmp(s1,s2); +} +#endif - struct dirent - { - char *d_name; - }; +struct dirent +{ + char *d_name; +}; - struct DIR - { - intptr_t fd; // filedescriptor - // struct _finddata_t info; - struct _wfinddata_t info; - // struct _finddata_t info; - struct dirent result; // d_name (first time null) - wchar_t *name; // null-terminated byte string - }; - - DIR *opendir(const char *name); - struct dirent *readdir(DIR *dp); - int closedir(DIR *dp); -#endif +struct DIR +{ + intptr_t fd; // filedescriptor + // struct _finddata_t info; + struct _wfinddata_t info; + // struct _finddata_t info; + struct dirent result; // d_name (first time null) + wchar_t *name; // null-terminated byte string +}; + +DIR *opendir(const char *name); +struct dirent *readdir(DIR *dp); +int closedir(DIR *dp); HANDLE openfile(const char *filename, int flags, int mode); @@ -358,6 +390,7 @@ 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 @@ -381,9 +414,10 @@ struct stat { #ifndef __MINGW32__ typedef u_int64_t _ino_t; #endif +#endif -int ourstat(const char * name, struct stat * st); -int ourfstat(HANDLE file, struct stat * st); +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 @@ -395,7 +429,8 @@ inline time_t ConvertFileTimeToTime_t(FILETIME *fileTime) // 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; @@ -405,17 +440,35 @@ inline time_t ConvertFileTimeToTime_t(FILETIME *fileTime) // timeinfo.tm_yday = ...; timeinfo.tm_year = stUTC.wYear - 1900; - time_t retVal = mktime(&timeinfo); + time_t retVal = mktime(&timeinfo) - _timezone; return retVal; } -#define stat(x,y) ourstat(x,y) -#define fstat(x,y) ourfstat(x,y) -#define lstat(x,y) ourstat(x,y) +#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 -int poll (struct pollfd *ufds, unsigned long nfds, int timeout); +int poll(struct pollfd *ufds, unsigned long nfds, int timeout); bool EnableBackupRights( void ); +bool ConvertUtf8ToConsole(const char* pString, std::string& rDest); +bool ConvertConsoleToUtf8(const char* pString, std::string& rDest); + // // MessageId: MSG_ERR_EXIST // MessageText: @@ -423,4 +476,7 @@ bool EnableBackupRights( void ); // #define MSG_ERR_EXIST ((DWORD)0xC0000004L) +// replacement for _cgetws which requires a relatively recent C runtime lib +int console_read(char* pBuffer, size_t BufferSize); + #endif // !EMU_INCLUDE && WIN32 -- cgit v1.2.3 From 364ec72789db5a33c5ff35f0774a29348304d868 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 2 Sep 2006 11:32:38 +0000 Subject: (refs #3) Reorganise typedefs for clarity --- lib/win32/emu.h | 68 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 22 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index ce0c884f..5d67264a 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -3,7 +3,48 @@ #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 + typedef uint32_t u_int32_t; +#else // MSVC + typedef __int64 int64_t; + typedef __int32 int32_t; + typedef __int16 int16_t; + typedef __int8 int8_t; + + typedef unsigned __int64 u_int64_t; + typedef unsigned __int32 u_int32_t; + + typedef unsigned __int64 uint64_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int8 uint8_t; +#endif + +// emulated types, present on MinGW but not MSVC or vice versa + +#ifdef _MSC_VER + typedef unsigned int mode_t; + typedef unsigned int pid_t; + + // must define _INO_T_DEFINED before including + // 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 #include @@ -19,6 +60,8 @@ #include +// emulated functions + #define gmtime_r( _clock, _result ) \ ( *(_result) = *gmtime( (_clock) ), \ (_result) ) @@ -50,8 +93,8 @@ inline int geteuid(void) 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; @@ -252,17 +295,6 @@ 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 @@ -283,10 +315,6 @@ 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) @@ -410,10 +438,6 @@ struct stat { time_t st_mtime; time_t st_ctime; }; - -#ifndef __MINGW32__ -typedef u_int64_t _ino_t; -#endif #endif int emu_stat(const char * name, struct stat * st); -- cgit v1.2.3 From b8f9eeceb44b72bbab18ebd0644e1b6cabe624da Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 4 Sep 2006 00:02:12 +0000 Subject: (refs #3) Fixed looking up message source in syslog() Flush stdout after writing to it Allow syslog() to log to console even when openlog() has not been called --- lib/win32/emu.h | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 5d67264a..2c4e1550 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -354,26 +354,12 @@ HANDLE openfile(const char *filename, int flags, int mode); #define LOG_WARNING 4 #define LOG_ERR 3 #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 @@ -493,13 +479,6 @@ bool EnableBackupRights( void ); 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) - // replacement for _cgetws which requires a relatively recent C runtime lib int console_read(char* pBuffer, size_t BufferSize); -- cgit v1.2.3 From 98009bbda2550b7e6aa28fd53f3daaa14d6cd577 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 4 Sep 2006 00:05:08 +0000 Subject: (refs #3) Emulate readdir's d_type field --- lib/win32/emu.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 2c4e1550..69daaa67 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -329,9 +329,14 @@ inline int strcasecmp(const char *s1, const char *s2) } #endif +#ifdef _DIRENT_H_ +#error You must not include MinGW's dirent.h! +#endif + struct dirent { char *d_name; + unsigned long d_type; }; struct DIR -- cgit v1.2.3 From cfbb24dbc08bcb0e506922d826808549fd107181 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 4 Sep 2006 00:06:56 +0000 Subject: (refs #3) Remove more vestiges of old getopt --- lib/win32/emu.h | 54 +----------------------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 69daaa67..a861d3b9 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -227,59 +227,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 -- cgit v1.2.3 From 502fa3141e5330a0e2e91ff4d7258f3f3c0fcaa6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 4 Sep 2006 00:08:36 +0000 Subject: (refs #3) Added prototypes for new emulated functions emu_utimes, readv and writev --- lib/win32/emu.h | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index a861d3b9..2e9f8cd0 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -132,14 +132,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 @@ -159,23 +151,20 @@ inline int chown(const char * Filename, u_int32_t uid, u_int32_t gid) int emu_chdir (const char* pDirName); int emu_unlink(const char* pFileName); char* emu_getcwd(char* pBuffer, int BufSize); +int emu_utimes(const char* pName, const struct timeval[]); +int emu_chmod (const char* pName, mode_t mode); -#ifdef _MSC_VER - inline int emu_chmod(const char * Filename, int mode) - { - // indicate success - return 0; - } +#define utimes(buffer, times) emu_utimes(buffer, times) - #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) +#ifdef _MSC_VER + #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) + inline int chmod(const char * pName, mode_t mode) { - // indicate success - return 0; + return emu_chmod(pName, mode); } inline int chdir(const char* pDirName) @@ -435,4 +424,12 @@ bool ConvertConsoleToUtf8(const char* pString, std::string& rDest); // replacement for _cgetws which requires a relatively recent C runtime lib int console_read(char* pBuffer, size_t BufferSize); +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); + #endif // !EMU_INCLUDE && WIN32 -- cgit v1.2.3 From 012c1b4c977bc94d4f8859c04890223f48881463 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 4 Sep 2006 00:09:26 +0000 Subject: (refs #3) Remove inline ConvertFileTimeToTime_t, add prototypes for new versions in emu.cpp --- lib/win32/emu.h | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 2e9f8cd0..54280769 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -372,29 +372,9 @@ 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; -} +// need this for conversions +time_t ConvertFileTimeToTime_t(FILETIME *fileTime); +bool ConvertTime_tToFileTime(const time_t from, FILETIME *pTo); #ifdef _MSC_VER #define stat(filename, struct) emu_stat (filename, struct) -- cgit v1.2.3 From 9a1c50ad833480750f82168a0bea138c461ec8b6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 15 Oct 2006 19:20:49 +0000 Subject: Compile fix (refs #3) --- lib/win32/emu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 54280769..d898968a 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -267,7 +267,7 @@ inline int strcasecmp(const char *s1, const char *s2) #endif #ifdef _DIRENT_H_ -#error You must not include MinGW's dirent.h! +#error You must not include the MinGW dirent.h! #endif struct dirent -- cgit v1.2.3 From dd1026364150b2b80194015aa5ffafdd86b50fdb Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 17:20:40 +0000 Subject: Expanded character set conversion API to allow arbitrary conversions (needed to handle command lines with international encodings) (refs #3, merges [1038]) --- lib/win32/emu.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index d898968a..5b3e2280 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -254,7 +254,7 @@ struct itimerval int emu_mkdir(const char* pPathName); -inline int mkdir(const char *pPathName, mode_t mode) +inline int mkdir(const char *pPathName, mode_t mode = 0) { return emu_mkdir(pPathName); } @@ -398,6 +398,12 @@ bool ConvertTime_tToFileTime(const time_t from, FILETIME *pTo); 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); -- cgit v1.2.3 From a67d2d4364280ffa21f8054afde91af027f4214b Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 17:32:44 +0000 Subject: Fix handling of O_EXCL to behave just like Unix, not abused to lock files. Add a new constant which specifies that files are to be locked open. (refs #3, merges [1288]) --- lib/win32/emu.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 5b3e2280..0612e441 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -290,6 +290,9 @@ 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_INFO 6 -- cgit v1.2.3 From 28195d8d1da7a34fbff4c9d217f6333c5472ed7c Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 17:50:33 +0000 Subject: First attempt to achieve a more logical order in this chaos: reordered all typedefs to be clearer and more readable (refs #3, merges [766]) --- lib/win32/emu.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 0612e441..206e1f70 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -6,27 +6,24 @@ // basic types, may be required by other headers since we // don't include sys/types.h -#ifdef __MINGW32__ - #include - typedef uint32_t u_int32_t; -#else // MSVC - typedef __int64 int64_t; - typedef __int32 int32_t; - typedef __int16 int16_t; - typedef __int8 int8_t; - +#ifndef __MINGW32__ typedef unsigned __int64 u_int64_t; - typedef unsigned __int32 u_int32_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 _MSC_VER +#ifdef __MINGW32__ + typedef uint32_t u_int32_t; +#else typedef unsigned int mode_t; typedef unsigned int pid_t; -- cgit v1.2.3 From cb0dae3a34f9409780905c075e82b46ed18576c0 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 18:01:07 +0000 Subject: Added d_type member to struct dirent, initialise with S_IFDIR or S_IFREG MinGW compile fix (refs #3, merges [775]) --- lib/win32/emu.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 206e1f70..25bff02c 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -6,7 +6,9 @@ // basic types, may be required by other headers since we // don't include sys/types.h -#ifndef __MINGW32__ +#ifdef __MINGW32__ + #include +#else // MSVC typedef unsigned __int64 u_int64_t; typedef unsigned __int64 uint64_t; typedef __int64 int64_t; -- cgit v1.2.3 From 1013fe643a8a3ada3049b011ba8363ab73caeeab Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 18:52:15 +0000 Subject: Compile fix for [1397] (refs #3) --- lib/win32/emu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 25bff02c..ca461c95 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -65,7 +65,7 @@ ( *(_result) = *gmtime( (_clock) ), \ (_result) ) -#define ITIMER_VIRTUAL 0 +#define ITIMER_REAL 0 #ifdef _MSC_VER // Microsoft decided to deprecate the standard POSIX functions. Great! -- cgit v1.2.3 From 13d90d5a6f528952c7574e8e2529732fcc6ab044 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 18:57:00 +0000 Subject: Use #defines to replace POSIX functions with emulated ones on MinGW, like we do on MSVC. This allows us to #undef them when we really need to use the original platform function (if available). Disable emulated fstat() in raidfile (and use the platform one) by undefining fstat, since it doesn't use the other emulated file handling functions, or need Unicode support, and it can't take a filehandle returned by open() (only openfile()). (refs #3, merges [1045]) --- lib/win32/emu.h | 84 ++++++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 64 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index ca461c95..7ce4b831 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -147,41 +147,6 @@ 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); -int emu_utimes(const char* pName, const struct timeval[]); -int emu_chmod (const char* pName, mode_t mode); - -#define utimes(buffer, times) emu_utimes(buffer, times) - -#ifdef _MSC_VER - #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 * pName, mode_t mode) - { - return emu_chmod(pName, mode); - } - - 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 inline int setegid(int) @@ -251,13 +216,6 @@ struct itimerval #define vsnprintf _vsnprintf -int emu_mkdir(const char* pPathName); - -inline int mkdir(const char *pPathName, mode_t mode = 0) -{ - return emu_mkdir(pPathName); -} - #ifndef __MINGW32__ inline int strcasecmp(const char *s1, const char *s2) { @@ -370,32 +328,30 @@ struct stat { }; #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 conversions time_t ConvertFileTimeToTime_t(FILETIME *fileTime); bool ConvertTime_tToFileTime(const time_t from, FILETIME *pTo); -#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 +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); + +#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) + +int statfs(const char * name, struct statfs * s); int poll(struct pollfd *ufds, unsigned long nfds, int timeout); bool EnableBackupRights( void ); -- cgit v1.2.3 From 8ef165b887dfb88514e4d00a07fa4e3d0c53fbc1 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 19:01:11 +0000 Subject: Remove #define BOX_VERSION since we now get it from BoxVersion.h via BoxPlatform.h when building with MSVC, and from the Makefiles when building with MinGW. (refs #3, merges part of [634]) --- lib/win32/emu.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 7ce4b831..c8e15f3c 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -199,11 +199,6 @@ struct itimerval 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 -- cgit v1.2.3 From 40d737e975070ba43d15866b1b24e6e2d0922984 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 19:05:52 +0000 Subject: Reorder for clarity Expose GetErrorMessage() Improve comments (refs #3, merges [1365]) --- lib/win32/emu.h | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index c8e15f3c..f8bccb02 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -321,7 +321,7 @@ struct stat { time_t st_mtime; time_t st_ctime; }; -#endif +#endif // 0 // need this for conversions time_t ConvertFileTimeToTime_t(FILETIME *fileTime); @@ -349,6 +349,19 @@ char* emu_getcwd (char* pBuffer, int BufSize); int statfs(const char * name, struct statfs * s); int poll(struct pollfd *ufds, unsigned long nfds, int timeout); + +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. + bool EnableBackupRights( void ); bool ConvertEncoding (const std::string& rSource, int sourceCodePage, @@ -360,15 +373,12 @@ bool ConvertFromUtf8 (const std::string& rSource, std::string& rDest, bool ConvertUtf8ToConsole(const char* pString, std::string& rDest); bool ConvertConsoleToUtf8(const char* pString, std::string& rDest); -// replacement for _cgetws which requires a relatively recent C runtime lib -int console_read(char* pBuffer, size_t BufferSize); - -struct iovec { - void *iov_base; /* Starting address */ - size_t iov_len; /* Number of bytes */ -}; +// GetErrorMessage() returns a system error message, like strerror() +// but for Windows error codes. +std::string GetErrorMessage(DWORD errorCode); -int readv (int filedes, const struct iovec *vector, size_t count); -int writev(int filedes, const struct iovec *vector, size_t count); +// console_read() is a replacement for _cgetws which requires a +// relatively recent C runtime lib +int console_read(char* pBuffer, size_t BufferSize); #endif // !EMU_INCLUDE && WIN32 -- cgit v1.2.3 From 0beaa1cd614b55d27a409cd7727a793b0757cfdf Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 19:09:09 +0000 Subject: Add new syslog level emulations (refs #3, merges remainder of [1299]) --- lib/win32/emu.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index f8bccb02..fc88737d 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -247,9 +247,12 @@ int closedir(DIR *dp); 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 -- cgit v1.2.3 From 50f4c4a76a07ce1d34c4e50094d570a5087084cb Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 10 Mar 2007 19:12:57 +0000 Subject: Group remaining set*id() and get*id() functions. Improve comments about why they are being retained. (refs #3, related to [634]) --- lib/win32/emu.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index fc88737d..a4af6e64 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -83,12 +83,6 @@ 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; @@ -147,8 +141,9 @@ inline int chown(const char * Filename, u_int32_t uid, u_int32_t gid) return 0; } -//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; @@ -173,6 +168,10 @@ inline int getuid(void) { return 0; } +inline int geteuid(void) +{ + return 0; +} #ifndef PATH_MAX #define PATH_MAX MAX_PATH -- cgit v1.2.3 From 198d823a23f6fbece6a4792c6d7f7f787555ae1e Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 24 Mar 2007 22:53:45 +0000 Subject: Add emulated rename() with path conversion. (refs #3, merges [1436] and [1438]) --- lib/win32/emu.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index a4af6e64..ec6c0918 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -337,6 +337,7 @@ 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) @@ -347,6 +348,7 @@ char* emu_getcwd (char* pBuffer, int BufSize); #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) int statfs(const char * name, struct statfs * s); -- cgit v1.2.3 From 4a3627d5b883c0f66c9f2b770a427c18df51203f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 26 Jul 2007 22:04:53 +0000 Subject: Disable some warnings under MSVC to reduce build noise, thanks Gary! (refs #3, merges [1676]) --- lib/win32/emu.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index ec6c0918..1f078c14 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -385,4 +385,16 @@ std::string GetErrorMessage(DWORD errorCode); // 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 -- cgit v1.2.3 From 498e58eb188d98c6ec78e57cdc5f0c211f1f4dcf Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 26 Jul 2007 22:11:03 +0000 Subject: Make Configuration take a std::string filename instead of a char array, in C++ style. Add a function to get default config file paths at runtime, dependent on the location of the executable being run. Pass the config file name directly to Daemon::Main, instead of faking argv. No default raid file path at compile time on Windows, depends on executable location when run. Determine RaidFile path at runtime if not supplied in config file on Windows. Don't define default locations for config files at compile time on Windows, provide macros to determine them at runtime instead. Make FileHandleGuard take a std::string instead of a char array, C++ style. Determine config file location at runtime instead of hard-coding on Windows. Thanks to Paul MacKenzie, Per Thomsen, Pete Jalajas, Stuart Sanders, Dave Bamford and Gary for pushing me to do this. (fixes #12) Determine config file path at runtime. Call Daemon::Main with config file name instead of building fake argv. (refs #3, merges [1684] [1685] [1686] [1687] [1688] [1689] [1690] [1691] [1692]) --- lib/win32/emu.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 1f078c14..8ab74130 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -377,6 +377,10 @@ bool ConvertFromUtf8 (const std::string& rSource, std::string& rDest, bool ConvertUtf8ToConsole(const char* pString, std::string& rDest); bool ConvertConsoleToUtf8(const char* pString, std::string& rDest); +// 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); -- cgit v1.2.3 From 430bbb36f6e1040333a22b79938938754dd49aac Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 3 Aug 2008 06:54:40 +0000 Subject: Add getpid() emulation. --- lib/win32/emu.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 8ab74130..a19a86ff 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -205,6 +205,7 @@ struct itimerval //again need to verify these #define S_IFLNK 1 +#define S_IFSOCK 0 #define S_ISLNK(x) ( false ) @@ -292,6 +293,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; -- cgit v1.2.3 From a2d7aadb6a42dc45cdf3d5547025dd55c0bd9b17 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 30 Nov 2008 21:54:55 +0000 Subject: openfile() stores its Windows error code (from GetLastError() or synthetic) in winerrno, to enable better error handling outside. --- lib/win32/emu.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index a19a86ff..e8d87f19 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -245,6 +245,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 -- cgit v1.2.3 From 53ebf1afe9f796d56af20040bde0893e46ad1b73 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 1 Dec 2008 01:31:51 +0000 Subject: Fix the use of an unreasonably short type as the temporary storage for inode numbers on Windows, resulting in all inode numbers being coerced into 2^16 space and many duplicates on systems with large numbers of files being backed up, possibly resulting in store corruption due to unwanted file rename operations. --- lib/win32/emu.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index e8d87f19..1d3fd150 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -25,6 +25,9 @@ #ifdef __MINGW32__ typedef uint32_t u_int32_t; + typedef uint64_t _ino_t; + typedef _ino_t ino_t; + #define _INO_T_ #else typedef unsigned int mode_t; typedef unsigned int pid_t; -- cgit v1.2.3 From c13f1bfdc3673ba1d1b79284d834e9248c20e8ef Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 30 Dec 2008 18:30:12 +0000 Subject: Change ConvertTo/FromUtf8 to take a std::string instead of a const char *, for convenience and C++ style. --- lib/win32/emu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 1d3fd150..67921264 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -384,8 +384,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. -- cgit v1.2.3 From 4d33206efeeacf0a20d6daabb0f5bcfa6da78a39 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 21 Mar 2009 18:48:19 +0000 Subject: Fix tests (hopefully) on Win32 for struct stat ino_t change from 16 to 64 bits. --- lib/win32/emu.h | 66 +++++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 37 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 67921264..b29c901c 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 @@ -25,17 +37,9 @@ #ifdef __MINGW32__ typedef uint32_t u_int32_t; - typedef uint64_t _ino_t; - typedef _ino_t ino_t; - #define _INO_T_ #else typedef unsigned int mode_t; typedef unsigned int pid_t; - - // must define _INO_T_DEFINED before including - // 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 @@ -81,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; @@ -187,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 @@ -313,27 +305,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); @@ -342,8 +326,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); @@ -352,14 +336,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); -- cgit v1.2.3 From 280180a59acf2b59482033a70518e18de34f859a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 2 Apr 2009 00:06:07 +0000 Subject: Fix missing LOG_* defines on Windows. --- lib/win32/emu.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index b29c901c..811e6495 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -257,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 -- cgit v1.2.3 From afcac9017d4a46f4c69bdd0b4151daf2f6d4e68f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 26 Apr 2009 14:40:17 +0000 Subject: Provide a function to close a file handle on Windows, analogous to openfile(). --- lib/win32/emu.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 811e6495..f3389590 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -117,7 +117,7 @@ inline struct passwd * getpwnam(const char * name) #ifndef __MINGW32__ //not sure if these are correct //S_IWRITE - writing permitted - //_S_IREAD - reading permitted + //_S_IREAD - reading permitted //_S_IREAD | _S_IWRITE - #define S_IRUSR S_IWRITE #define S_IWUSR S_IREAD @@ -242,6 +242,15 @@ int closedir(DIR *dp); extern DWORD winerrno; /* used to report errors from openfile() */ HANDLE openfile(const char *filename, int flags, int mode); +inline int closefile(HANDLE handle) +{ + if (CloseHandle(handle) != TRUE) + { + errno = EINVAL; + return -1; + } + return 0; +} #define LOG_DEBUG LOG_INFO #define LOG_INFO 6 -- cgit v1.2.3 From 3991c90bb2d60a5811be90ea88f05e72e5d0d559 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 26 Mar 2011 23:21:03 +0000 Subject: Define WINVER and _WIN32_WINNT to Windows 2000 to avoid importing WSAPoll from winsock2.h, which conflicts with our definition of struct pollfd, on Windows Vista and above. --- lib/win32/emu.h | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index f3389590..1b071f7e 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -50,6 +50,23 @@ #define __MSVCRT_VERSION__ 0x0601 #endif +// WIN32_WINNT versions 0x0600 (Vista) and higher enable WSAPoll() in +// winsock2.h, whose struct pollfd conflicts with ours below, so for +// now we just set it lower than that, to Windows 2000. +#ifdef WINVER + #if WINVER != 0x0500 + #error Must include emu.h before setting WINVER + #endif +#endif +#define WINVER 0x0500 + +#ifdef _WIN32_WINNT + #if _WIN32_WINNT != 0x0500 + #error Must include emu.h before setting _WIN32_WINNT + #endif +#endif +#define _WIN32_WINNT 0x0500 + // Windows headers #include @@ -286,9 +303,18 @@ inline unsigned int sleep(unsigned int secs) } #define INFTIM -1 -#define POLLIN 0x1 -#define POLLERR 0x8 -#define POLLOUT 0x4 + +#ifndef POLLIN +# define POLLIN 0x1 +#endif + +#ifndef POLLERR +# define POLLERR 0x8 +#endif + +#ifndef POLLOUT +# define POLLOUT 0x4 +#endif #define SHUT_RDWR SD_BOTH #define SHUT_RD SD_RECEIVE -- cgit v1.2.3 From 2261a3f11a0f3951e774e339d0b532436445abc6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 27 Mar 2011 15:50:54 +0000 Subject: Add inline definition of ftruncate to fix MSVC compile. --- lib/win32/emu.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 1b071f7e..d5ac7e1e 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -435,6 +435,16 @@ std::string GetErrorMessage(DWORD errorCode); // relatively recent C runtime lib int console_read(char* pBuffer, size_t BufferSize); +// Defined thus by MinGW, but missing from MSVC +// [http://curl.haxx.se/mail/lib-2004-11/0260.html] +#ifndef HAVE_FTRUNCATE + int ftruncate(int, off_t); + inline int ftruncate(int __fd, off_t __length) + { + return _chsize(__fd, __length); + } +#endif + #ifdef _MSC_VER /* disable certain compiler warnings to be able to actually see the show-stopper ones */ #pragma warning(disable:4101) // unreferenced local variable -- cgit v1.2.3 From f6ca48ce8b9fb8488997c2b44d4e20c6a159a189 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 28 Mar 2011 23:40:58 +0000 Subject: Make ConvertFromWideString available to other modules. --- lib/win32/emu.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index d5ac7e1e..e398d5f6 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -422,6 +422,7 @@ bool ConvertFromUtf8 (const std::string& rSource, std::string& rDest, int destCodePage); bool ConvertUtf8ToConsole(const std::string& rSource, std::string& rDest); bool ConvertConsoleToUtf8(const std::string& rSource, std::string& rDest); +char* ConvertFromWideString(const WCHAR* pString, unsigned int codepage); // Utility function which returns a default config file name, // based on the path of the current executable. -- cgit v1.2.3 From d22fc3f49b5c1d1e1ccf0d250d7123b1a281dc18 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 6 Apr 2011 20:53:52 +0000 Subject: Add VSS: prefix to VSS log messages. Start a snapshot set and add backup locations as volumes. Modularise IVssAsync waiting code. --- lib/win32/emu.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index e398d5f6..b7aa5d47 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -423,6 +423,9 @@ bool ConvertFromUtf8 (const std::string& rSource, std::string& rDest, bool ConvertUtf8ToConsole(const std::string& rSource, std::string& rDest); bool ConvertConsoleToUtf8(const std::string& rSource, std::string& rDest); char* ConvertFromWideString(const WCHAR* pString, unsigned int codepage); +bool ConvertFromWideString(const std::wstring& rInput, + std::string* pOutput, unsigned int codepage); +std::string ConvertPathToAbsoluteUnicode(const char *pFileName); // Utility function which returns a default config file name, // based on the path of the current executable. -- cgit v1.2.3 From 46d65d06b31b88af89d45a837d0af4a92aebc78f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 20 Apr 2011 13:17:33 +0000 Subject: Remove getpid() emulation now that it's included in the SDK, which causes a conflict. --- lib/win32/emu.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index b7aa5d47..1ebd45c2 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -333,11 +333,6 @@ 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; @@ -377,12 +372,12 @@ 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 utimes(buffer, times) emu_utimes (buffer, times) -#define chmod(file, mode) emu_chmod (file, mode) -#define getcwd(buffer, size) emu_getcwd (buffer, size) +#define chdir(directory) emu_chdir (directory) +#define mkdir(path, mode) emu_mkdir (path) +#define unlink(file) emu_unlink (file) +#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 @@ -441,6 +436,8 @@ int console_read(char* pBuffer, size_t BufferSize); // Defined thus by MinGW, but missing from MSVC // [http://curl.haxx.se/mail/lib-2004-11/0260.html] +// note: chsize() doesn't work over 2GB: +// [https://stat.ethz.ch/pipermail/r-devel/2005-May/033339.html] #ifndef HAVE_FTRUNCATE int ftruncate(int, off_t); inline int ftruncate(int __fd, off_t __length) -- cgit v1.2.3 From 87abf9d2de4c75539b9ba7cb400f4baae35936ba Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 28 Aug 2011 19:07:17 +0000 Subject: Use "more standard" Windows API functions FindFirstFileW and FindNextFileW for directory enumeration instead of _wfindfirst and _wfindnext. Ignore reparse points when enumerating directories to avoid infinite loops. Convert VSS paths back to real paths when notifying users about backup progress. --- lib/win32/emu.h | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 1ebd45c2..151fa2cb 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -50,22 +50,30 @@ #define __MSVCRT_VERSION__ 0x0601 #endif +// We need WINVER at least 0x0500 to use GetFileSizeEx on Cygwin/MinGW, +// and 0x0501 for FindFirstFile(W) for opendir/readdir. +// // WIN32_WINNT versions 0x0600 (Vista) and higher enable WSAPoll() in // winsock2.h, whose struct pollfd conflicts with ours below, so for -// now we just set it lower than that, to Windows 2000. +// now we just set it lower than that, to Windows XP (0x0501). + #ifdef WINVER - #if WINVER != 0x0500 - #error Must include emu.h before setting WINVER - #endif +# if WINVER != 0x0501 +// provoke a redefinition warning to track down the offender +# define WINVER 0x0501 +# error Must include emu.h before setting WINVER +# endif #endif -#define WINVER 0x0500 +#define WINVER 0x0501 #ifdef _WIN32_WINNT - #if _WIN32_WINNT != 0x0500 - #error Must include emu.h before setting _WIN32_WINNT - #endif +# if _WIN32_WINNT != 0x0501 +// provoke a redefinition warning to track down the offender +# define _WIN32_WINNT 0x0501 +# error Must include emu.h before setting _WIN32_WINNT +# endif #endif -#define _WIN32_WINNT 0x0500 +#define _WIN32_WINNT 0x0501 // Windows headers @@ -237,17 +245,15 @@ inline int strcasecmp(const char *s1, const char *s2) struct dirent { char *d_name; - unsigned long d_type; + DWORD d_type; // file attributes }; struct DIR { - intptr_t fd; // filedescriptor - // struct _finddata_t info; - struct _wfinddata_t info; - // struct _finddata_t info; - struct dirent result; // d_name (first time null) - wchar_t *name; // null-terminated byte string + HANDLE fd; // the HANDLE returned by FindFirstFile + WIN32_FIND_DATAW info; + struct dirent result; // d_name (first time null) + wchar_t* name; // null-terminated byte string }; DIR *opendir(const char *name); -- cgit v1.2.3 From 79ea9acc7ab54b22ec4f453b75b372fc96152562 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 8 Oct 2011 12:06:34 +0000 Subject: Silence warnings from new MinGW headers that expect __MINGW_FEATURES__ to be defined. Check for fcntl.h and include it if we have it, not just on MSVC, now that MinGW also defines O_BINARY in newer versions. --- lib/win32/emu.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 151fa2cb..81370a1b 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -15,6 +15,11 @@ #if ! defined EMU_INCLUDE && defined WIN32 #define EMU_INCLUDE +// Shut up stupid new warnings. Thanks MinGW! Ever heard of "compatibility"? +#ifdef __MINGW32__ +# define __MINGW_FEATURES__ 0 +#endif + // basic types, may be required by other headers since we // don't include sys/types.h -- cgit v1.2.3 From 22bf0f91ab5a99881556af2085e6027c9766fc8c Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 8 Oct 2011 12:41:28 +0000 Subject: Recent Cygwin versions of MinGW now define O_BINARY as well, also in fcntl.h, so include it if we can find it, and only define O_BINARY if it turns out to be missing. --- lib/win32/emu.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 81370a1b..9582b138 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -15,6 +15,9 @@ #if ! defined EMU_INCLUDE && defined WIN32 #define EMU_INCLUDE +// Need feature detection macros below +#include "../common/BoxConfig.h" + // Shut up stupid new warnings. Thanks MinGW! Ever heard of "compatibility"? #ifdef __MINGW32__ # define __MINGW_FEATURES__ 0 @@ -450,7 +453,7 @@ int console_read(char* pBuffer, size_t BufferSize); // note: chsize() doesn't work over 2GB: // [https://stat.ethz.ch/pipermail/r-devel/2005-May/033339.html] #ifndef HAVE_FTRUNCATE - int ftruncate(int, off_t); + extern "C" int ftruncate(int, off_t); inline int ftruncate(int __fd, off_t __length) { return _chsize(__fd, __length); -- cgit v1.2.3 From 29a41bf9a00f560b4234a391b4ce3fe9028357fd Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 9 Oct 2011 11:24:45 +0000 Subject: Split Win32 defines out of emu.h to enable Boxi to include them before wx/wx.h (to set UNICODE properly) without also #including winnt.h before UNICODE is set properly. --- lib/win32/emu.h | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) (limited to 'lib/win32/emu.h') diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 9582b138..bf408050 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -1,5 +1,7 @@ // emulates unix syscalls to win32 functions +#include "emu_winver.h" + #ifdef WIN32 #define EMU_STRUCT_STAT struct emu_stat #define EMU_STAT emu_stat @@ -50,39 +52,6 @@ typedef unsigned int pid_t; #endif -// set up to include the necessary parts of Windows headers - -#define WIN32_LEAN_AND_MEAN - -#ifndef __MSVCRT_VERSION__ -#define __MSVCRT_VERSION__ 0x0601 -#endif - -// We need WINVER at least 0x0500 to use GetFileSizeEx on Cygwin/MinGW, -// and 0x0501 for FindFirstFile(W) for opendir/readdir. -// -// WIN32_WINNT versions 0x0600 (Vista) and higher enable WSAPoll() in -// winsock2.h, whose struct pollfd conflicts with ours below, so for -// now we just set it lower than that, to Windows XP (0x0501). - -#ifdef WINVER -# if WINVER != 0x0501 -// provoke a redefinition warning to track down the offender -# define WINVER 0x0501 -# error Must include emu.h before setting WINVER -# endif -#endif -#define WINVER 0x0501 - -#ifdef _WIN32_WINNT -# if _WIN32_WINNT != 0x0501 -// provoke a redefinition warning to track down the offender -# define _WIN32_WINNT 0x0501 -# error Must include emu.h before setting _WIN32_WINNT -# endif -#endif -#define _WIN32_WINNT 0x0501 - // Windows headers #include -- cgit v1.2.3