1st mods to get a build under windows. Does not build yet, far from it

--HG--
branch : WINDOWSPORT
This commit is contained in:
Jean-Francois Dockes
2015-08-30 11:19:18 +02:00
parent d63b16de93
commit d4cd1dd91c
48 changed files with 1855 additions and 71 deletions
+2 -2
View File
@@ -184,7 +184,7 @@ public:
// Offset of last write (newest header)
off_t m_nheadoffs;
// Pad size for newest entry.
int m_npadsize;
off_t m_npadsize;
// Keep history or only last entry
bool m_uniquentries;
///////////////////// End header entries
@@ -1009,7 +1009,7 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
// Data compression ?
const char *datap = data.c_str();
unsigned int datalen = data.size();
size_t datalen = data.size();
unsigned short flags = 0;
TempBuf compbuf;
if (!(iflags & NoCompHint)) {
+1 -3
View File
@@ -14,9 +14,7 @@
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "autoconfig.h"
#ifndef TEST_CONFTREE
+7 -2
View File
@@ -15,14 +15,18 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef TEST_COPYFILE
#include "autoconfig.h"
#include <stdio.h>
#include <errno.h>
#include "safefcntl.h"
#include <sys/types.h>
#include "safesysstat.h"
#include "safeunistd.h"
#ifndef _WIN32
#include <sys/time.h>
#include <utime.h>
#endif
#include <cstring>
@@ -43,7 +47,7 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags)
LOGDEB(("copyfile: %s to %s\n", src, dst));
if ((sfd = ::open(src, O_RDONLY)) < 0) {
if ((sfd = ::open(src, O_RDONLY, 0)) < 0) {
reason += string("open ") + src + ": " + strerror(errno);
goto out;
}
@@ -149,6 +153,7 @@ bool renameormove(const char *src, const char *dst, string &reason)
return false;
}
#ifndef _WIN32
// Try to preserve modes, owner, times. This may fail for a number
// of reasons
if ((st1.st_mode & 0777) != (st.st_mode & 0777)) {
@@ -167,7 +172,7 @@ bool renameormove(const char *src, const char *dst, string &reason)
times[1].tv_sec = st.st_mtime;
times[1].tv_usec = 0;
utimes(dst, times);
#endif
// All ok, get rid of origin
if (unlink(src) < 0) {
reason += string("Can't unlink ") + src + "Error : " + strerror(errno);
+2 -2
View File
@@ -16,7 +16,7 @@
*/
#ifndef _EXECMD_H_INCLUDED_
#define _EXECMD_H_INCLUDED_
#ifndef _WIN32
#include <signal.h>
#include <string>
@@ -279,5 +279,5 @@ private:
std::string m_reason;
std::stack<void (*)(void)> m_atexitfuncs;
};
#endif /* !_WIN32 */
#endif /* _EXECMD_H_INCLUDED_ */
+1
View File
@@ -15,6 +15,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef TEST_FILEUDI
#include "autoconfig.h"
#include <stdio.h>
#include <cstdlib>
+2 -2
View File
@@ -14,9 +14,8 @@
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "autoconfig.h"
#endif
#ifndef TEST_FSTREEWALK
@@ -25,6 +24,7 @@
#include <sys/stat.h>
#include <errno.h>
#include <fnmatch.h>
#include "safesysstat.h"
#include <cstring>
#include <algorithm>
+4 -2
View File
@@ -15,6 +15,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef TEST_IDFILE
#include "autoconfig.h"
#include <stdlib.h>
#include <ctype.h>
#include <cstring>
@@ -82,11 +84,11 @@ static string idFileInternal(istream& input, const char *fn)
}
// gcount includes the \n
int ll = input.gcount() - 1;
std::streamsize ll = input.gcount() - 1;
if (ll > 0)
gotnonempty = true;
LOGDEB2(("idfile: lnum %d ll %d: [%s]\n", lnum, ll, cline));
LOGDEB2(("idfile: lnum %d ll %u: [%s]\n", lnum, (unsigned int)ll, cline));
// Check for a few things that can't be found in a mail file,
// (optimization to get a quick negative)
+33 -5
View File
@@ -19,17 +19,19 @@
#include "autoconfig.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include "safefcntl.h"
#include "safeunistd.h"
#include "dirent.h"
#ifndef _WIN32
#include <sys/param.h>
#include <pwd.h>
#include <sys/file.h>
#include <glob.h>
#endif
#include <math.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/file.h>
#include "safesysstat.h"
#include <glob.h>
// Let's include all files where statfs can be defined and hope for no
// conflict...
@@ -61,6 +63,9 @@ using namespace std;
bool fsocc(const string &path, int *pc, long long *blocks)
{
#ifdef _WIN32
return false;
#else
#ifdef sun
struct statvfs buf;
if (statvfs(path.c_str(), &buf) != 0) {
@@ -94,6 +99,7 @@ bool fsocc(const string &path, int *pc, long long *blocks)
}
}
return true;
#endif
}
const string& tmplocation()
@@ -112,6 +118,7 @@ const string& tmplocation()
bool maketmpdir(string& tdir, string& reason)
{
#ifndef _WIN32
tdir = path_cat(tmplocation(), "rcltmpXXXXXX");
char *cp = strdup(tdir.c_str());
@@ -146,11 +153,15 @@ bool maketmpdir(string& tdir, string& reason)
#endif
return true;
#else
return false;
#endif
}
TempFileInternal::TempFileInternal(const string& suffix)
: m_noremove(false)
{
#ifndef _WIN32
string filename = path_cat(tmplocation(), "rcltmpfXXXXXX");
char *cp = strdup(filename.c_str());
if (!cp) {
@@ -177,6 +188,7 @@ TempFileInternal::TempFileInternal(const string& suffix)
m_reason = string("Could not open/create") + m_filename;
m_filename.erase();
}
#endif
}
TempFileInternal::~TempFileInternal()
@@ -285,6 +297,9 @@ string path_suffix(const string& s)
string path_home()
{
#ifdef _WIN32
return "c:\\";
#else
uid_t uid = getuid();
struct passwd *entry = getpwuid(uid);
@@ -299,10 +314,14 @@ string path_home()
string homedir = entry->pw_dir;
path_catslash(homedir);
return homedir;
#endif
}
string path_tildexpand(const string &s)
{
#ifdef _WIN32
return s;
#else
if (s.empty() || s[0] != '~')
return s;
string o = s;
@@ -318,6 +337,7 @@ string path_tildexpand(const string &s)
o.replace(0, l+1, entry->pw_dir);
}
return o;
#endif
}
string path_absolute(const string &is)
@@ -402,6 +422,9 @@ bool makepath(const string& ipath)
vector<string> path_dirglob(const string &dir, const string pattern)
{
#ifdef _WIN32
return vector<string>();
#else
vector<string> res;
glob_t mglob;
string mypat=path_cat(dir, pattern);
@@ -413,6 +436,7 @@ vector<string> path_dirglob(const string &dir, const string pattern)
}
globfree(&mglob);
return res;
#endif
}
bool path_isdir(const string& path)
@@ -679,6 +703,9 @@ int Pidfile::flopen()
m_reason = "fcntl lock failed";
return -1;
}
#else
#ifdef _WIN32
return 0;
#else
int operation = LOCK_EX | LOCK_NB;
if (flock(m_fd, operation) == -1) {
@@ -688,6 +715,7 @@ int Pidfile::flopen()
m_reason = "flock failed";
return -1;
}
#endif // ! win32
#endif // ! sun
if (ftruncate(m_fd, 0) != 0) {
+80 -10
View File
@@ -708,10 +708,80 @@ typedef int clockid_t;
#undef USE_CLOCK_GETTIME
#endif
#ifdef WIN32
#include "safewindows.h"
// Note: struct timespec is defined by pthread.h (from pthreads-w32)
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
LARGE_INTEGER getFILETIMEoffset()
{
SYSTEMTIME s;
FILETIME f;
LARGE_INTEGER t;
s.wYear = 1970;
s.wMonth = 1;
s.wDay = 1;
s.wHour = 0;
s.wMinute = 0;
s.wSecond = 0;
s.wMilliseconds = 0;
SystemTimeToFileTime(&s, &f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
return (t);
}
int clock_gettime(int X, struct timespec *tv)
{
LARGE_INTEGER t;
FILETIME f;
double microseconds;
static LARGE_INTEGER offset;
static double frequencyToMicroseconds;
static int initialized = 0;
static BOOL usePerformanceCounter = 0;
if (!initialized) {
LARGE_INTEGER performanceFrequency;
initialized = 1;
usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
if (usePerformanceCounter) {
QueryPerformanceCounter(&offset);
frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.;
}
else {
offset = getFILETIMEoffset();
frequencyToMicroseconds = 10.;
}
}
if (usePerformanceCounter) QueryPerformanceCounter(&t);
else {
GetSystemTimeAsFileTime(&f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
}
t.QuadPart -= offset.QuadPart;
microseconds = (double)t.QuadPart / frequencyToMicroseconds;
t.QuadPart = (long long)microseconds;
tv->tv_sec = t.QuadPart / 1000000;
tv->tv_nsec = (t.QuadPart % 1000000) * 1000;
return (0);
}
#define USE_CLOCK_GETTIME
#else /* -> !_WIN32 */
#ifndef USE_CLOCK_GETTIME
#include <sys/time.h>
#endif
#endif
static void gettime(clockid_t clk_id, struct timespec *ts)
{
#ifndef USE_CLOCK_GETTIME
@@ -740,29 +810,29 @@ Chrono::Chrono()
}
// Reset and return value before rest in milliseconds
long Chrono::restart()
time_t Chrono::restart()
{
struct timespec tv;
gettime(CLOCK_REALTIME, &tv);
long ret = MILLIS(tv);
time_t ret = MILLIS(tv);
m_secs = tv.tv_sec;
m_nsecs = tv.tv_nsec;
return ret;
}
// Get current timer value, milliseconds
long Chrono::millis(int frozen)
time_t Chrono::millis(int frozen)
{
return nanos() / 1000000;
}
//
long Chrono::micros(int frozen)
time_t Chrono::micros(int frozen)
{
return nanos() / 1000;
}
long long Chrono::nanos(int frozen)
time_t Chrono::nanos(int frozen)
{
if (frozen) {
return NANOS(frozen_tv);
@@ -773,12 +843,12 @@ long long Chrono::nanos(int frozen)
}
}
float Chrono::secs(int frozen)
double Chrono::secs(int frozen)
{
struct timespec tv;
gettime(CLOCK_REALTIME, &tv);
float secs = (float)(frozen?frozen_tv.tv_sec:tv.tv_sec - m_secs);
float nsecs = (float)(frozen?frozen_tv.tv_nsec:tv.tv_nsec - m_nsecs);
double secs = (double)(frozen?frozen_tv.tv_sec:tv.tv_sec - m_secs);
double nsecs = (double)(frozen?frozen_tv.tv_nsec:tv.tv_nsec - m_nsecs);
return secs + nsecs * 1e-9;
}
@@ -818,7 +888,7 @@ static bool parsedate(vector<string>::const_iterator& it,
return false;
}
if (it == end || sscanf(it++->c_str(), "%d", &dip->d1) != 1) {
return -1;
return false;
}
return true;
@@ -1062,7 +1132,7 @@ void catstrerror(string *reason, const char *what, int _errno)
reason->append(" : ");
#ifdef sun
#if defined(sun) || defined(_WIN32)
// Note: sun strerror is noted mt-safe ??
reason->append(strerror(_errno));
#else
+8 -8
View File
@@ -153,7 +153,7 @@ class Chrono {
public:
Chrono();
/** Reset origin */
long restart();
time_t restart();
/** Snapshot current time */
static void refnow();
/** Get current elapsed since creation or restart
@@ -162,14 +162,14 @@ class Chrono {
* allow for using one actual system call to get values from many
* chrono objects, like when examining timeouts in a queue)
*/
long millis(int frozen = 0);
long ms() {return millis();}
long micros(int frozen = 0);
long long nanos(int frozen = 0);
float secs(int frozen = 0);
time_t millis(int frozen = 0);
time_t ms() {return millis();}
time_t micros(int frozen = 0);
time_t nanos(int frozen = 0);
double secs(int frozen = 0);
private:
long m_secs;
long m_nsecs;
time_t m_secs;
time_t m_nsecs;
};
/** Temp buffer with automatic deallocation */