From 66bc94d1e87fac016034553147e7cccaaaa72ac8 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 2 Sep 2015 08:40:39 +0200 Subject: [PATCH] _WIN32 ifdefs cleanup --- src/common/conf_post.h | 1 + src/common/rclconfig.cpp | 4 ---- src/common/rclinit.cpp | 2 -- src/index/recollindex.cpp | 3 +-- src/utils/cpuconf.cpp | 1 - src/utils/debuglog.cpp | 5 +---- src/utils/pathut.cpp | 29 ++++++++++++++++++++--------- src/utils/pathut.h | 5 ----- src/utils/workqueue.cpp | 7 +------ src/xaposix/safefcntl.h | 4 +--- 10 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/common/conf_post.h b/src/common/conf_post.h index 4bcbb4e8..8ae5fd6f 100644 --- a/src/common/conf_post.h +++ b/src/common/conf_post.h @@ -47,6 +47,7 @@ typedef int ssize_t; #define strncasecmp _strnicmp #define strcasecmp _stricmp #define ftruncate _chsize_s +#define chdir _chdir #define PATH_MAX MAX_PATH #define MAXPATHLEN PATH_MAX #define R_OK 4 diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index 5513cd7d..62a66cb6 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -459,14 +459,10 @@ void RclConfig::initThrConf() if (vq.size() > 0 && vq[0] == 0) { LOGDEB(("RclConfig::initThrConf: autoconf requested\n")); CpuConf cpus; -#ifdef _WIN32 - cpus.ncpus = 1; -#else if (!getCpuConf(cpus) || cpus.ncpus < 1) { LOGERR(("RclConfig::initThrConf: could not retrieve cpu conf\n")); cpus.ncpus = 1; } -#endif // Arbitrarily set threads config based on number of CPUS. This also // depends on the IO setup actually, so we're bound to be wrong... if (cpus.ncpus == 1) { diff --git a/src/common/rclinit.cpp b/src/common/rclinit.cpp index 5d17c9b1..88a10fec 100644 --- a/src/common/rclinit.cpp +++ b/src/common/rclinit.cpp @@ -31,9 +31,7 @@ #include "pathut.h" #include "unac.h" #include "smallut.h" -#ifndef _WIN32 #include "execmd.h" -#endif #ifndef _WIN32 static const int catchedSigs[] = {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2}; diff --git a/src/index/recollindex.cpp b/src/index/recollindex.cpp index 24dcfdd6..7471979a 100644 --- a/src/index/recollindex.cpp +++ b/src/index/recollindex.cpp @@ -494,7 +494,7 @@ int main(int argc, char **argv) if ((op_flags & OPT_E)) { exit(0); } -#ifndef _WIN32 + string rundir; config->getConfParam("idxrundir", rundir); if (!rundir.compare("tmp")) { @@ -512,7 +512,6 @@ int main(int argc, char **argv) rundir.c_str(), errno)); } } -#endif bool rezero((op_flags & OPT_z) != 0); bool inPlaceReset((op_flags & OPT_Z) != 0); diff --git a/src/utils/cpuconf.cpp b/src/utils/cpuconf.cpp index 98899210..378d0c38 100644 --- a/src/utils/cpuconf.cpp +++ b/src/utils/cpuconf.cpp @@ -62,7 +62,6 @@ bool getCpuConf(CpuConf& cpus) } #endif - #else // TEST_CPUCONF #include diff --git a/src/utils/debuglog.cpp b/src/utils/debuglog.cpp index 2153e08e..f9ac92b5 100644 --- a/src/utils/debuglog.cpp +++ b/src/utils/debuglog.cpp @@ -22,10 +22,7 @@ #include #include #include -#ifndef _WIN32 -#include -#endif - +#include // in case O_APPEND is in there #ifdef INCLUDE_NEW_H #include #endif diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 2f54fa71..c506360f 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -250,6 +250,14 @@ bool maketmpdir(string& tdir, string& reason) return false; } + // There is a race condition between name computation and + // mkdir. try to make sure that we at least don't shoot ourselves + // in the foot +#if !defined(HAVE_MKDTEMP) || defined(_WIN32) + static PTMutexInit mlock; + PTMutexLocker lock(mlock); +#endif + if (! #ifdef HAVE_MKDTEMP mkdtemp(cp) @@ -265,8 +273,6 @@ bool maketmpdir(string& tdir, string& reason) } tdir = cp; free(cp); - // At this point the directory does not exist yet if mktemp was used - #else // _WIN32 // There is a race condition between name computation and // mkdir. try to make sure that we at least don't shoot ourselves @@ -276,6 +282,9 @@ bool maketmpdir(string& tdir, string& reason) tdir = path_wingettempfilename(TEXT("rcltmp")); #endif + // At this point the directory does not exist yet except if we used + // mkdtemp + #if !defined(HAVE_MKDTEMP) || defined(_WIN32) if (mkdir(tdir.c_str(), 0700) < 0) { reason = string("maketmpdir: mkdir ") + tdir + " failed"; @@ -290,6 +299,13 @@ bool maketmpdir(string& tdir, string& reason) TempFileInternal::TempFileInternal(const string& suffix) : m_noremove(false) { + // Because we need a specific suffix, can't use mkstemp + // well. There is a race condition between name computation and + // file creation. try to make sure that we at least don't shoot + // our own selves in the foot. maybe we'll use mkstemps one day. + static PTMutexInit mlock; + PTMutexLocker lock(mlock); + #ifndef _WIN32 string filename = path_cat(tmplocation(), "rcltmpfXXXXXX"); char *cp = strdup(filename.c_str()); @@ -298,8 +314,8 @@ TempFileInternal::TempFileInternal(const string& suffix) return; } - // Yes using mkstemp this way is awful (bot the suffix adding and - // using mkstemp() just to avoid the warnings) + // Using mkstemp this way is awful (bot the suffix adding and + // using mkstemp() instead of mktemp just to avoid the warnings) int fd; if ((fd = mkstemp(cp)) < 0) { free(cp); @@ -311,11 +327,6 @@ TempFileInternal::TempFileInternal(const string& suffix) filename = cp; free(cp); #else - // There is a race condition between name computation and - // mkdir. try to make sure that we at least don't shoot ourselves - // in the foot - static PTMutexInit mlock; - PTMutexLocker lock(mlock); string filename = path_wingettempfilename(TEXT("recoll")); #endif diff --git a/src/utils/pathut.h b/src/utils/pathut.h index 4fd6f1a6..bf7a6c1f 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -97,11 +97,6 @@ extern bool maketmpdir(std::string& tdir, std::string& reason); /// mkdir -p extern bool makepath(const std::string& path); -#ifdef _WIN32 -/// Convert \ separators to / -extern void path_slashize(std::string& s); -#endif - /// Sub-directory for default recoll config (e.g: .recoll) extern std::string path_defaultrecollconfsubdir(); /// Where we create the user data subdirs diff --git a/src/utils/workqueue.cpp b/src/utils/workqueue.cpp index 16f56b2e..1ba38188 100644 --- a/src/utils/workqueue.cpp +++ b/src/utils/workqueue.cpp @@ -21,12 +21,7 @@ #include #include -#ifdef _WIN32 -#include -static inline unsigned int sleep(unsigned int s) {Sleep(s * 1000); return 0;} -#else -#include -#endif +#include "safeunistd.h" #include "workqueue.h" diff --git a/src/xaposix/safefcntl.h b/src/xaposix/safefcntl.h index e8e591f8..6248351e 100644 --- a/src/xaposix/safefcntl.h +++ b/src/xaposix/safefcntl.h @@ -34,9 +34,7 @@ #ifdef _MSC_VER // MSVC #define-s open but also defines a function called open, so just undef // the macro. -// Jf/recoll: don't do this, open() seems to be finally deprecated in vs 2015, we need _open(). Hopefully recoll has -// no open() methods.. -//# undef open +# undef open #else inline int fcntl_open_(const char *filename, int flags, mode_t mode) {