small cleanups to avoid a few ifdef _WIN32
This commit is contained in:
parent
f0efed545d
commit
b118c93b4f
@ -161,7 +161,6 @@ string mimetype(const string &fn, const struct PathStat *stp,
|
||||
|
||||
string mtype;
|
||||
|
||||
#ifndef _WIN32
|
||||
// Extended attribute has priority on everything, as per:
|
||||
// http://freedesktop.org/wiki/CommonExtendedAttributes
|
||||
if (pxattr::get(fn, "mime_type", &mtype)) {
|
||||
@ -172,7 +171,6 @@ string mimetype(const string &fn, const struct PathStat *stp,
|
||||
return mtype;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cfg == 0) {
|
||||
LOGERR("Mimetype: null config ??\n");
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2004 J.F.Dockes
|
||||
/* Copyright (C) 2004-2022 J.F.Dockes
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
|
||||
@ -69,11 +69,9 @@ bool MimeHandlerText::set_document_file_impl(const string&, const string &fn)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
// Check for charset defined in extended attribute as per:
|
||||
// http://freedesktop.org/wiki/CommonExtendedAttributes
|
||||
pxattr::get(m_fn, "charset", &m_charsetfromxattr);
|
||||
#endif
|
||||
|
||||
getparams();
|
||||
if (m_maxmbs != -1 && m_totlen / (1024*1024) > m_maxmbs) {
|
||||
@ -88,8 +86,7 @@ bool MimeHandlerText::set_document_file_impl(const string&, const string &fn)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MimeHandlerText::set_document_string_impl(const string&,
|
||||
const string& otext)
|
||||
bool MimeHandlerText::set_document_string_impl(const string&, const string& otext)
|
||||
{
|
||||
m_fn.clear();
|
||||
m_totlen = otext.size();
|
||||
|
||||
@ -14,8 +14,9 @@
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "autoconfig.h"
|
||||
|
||||
#include "winschedtool.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -97,4 +98,3 @@ void WinSchedToolW::startWinScheduler()
|
||||
vector<string> lcmd{"c:/windows/system32/taskschd.msc"};
|
||||
m_cmd->startExec("rclstartw", lcmd, false, false);
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
94
src/testmains/trcopyfile.cpp
Normal file
94
src/testmains/trcopyfile.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/* Copyright (C) 2021 J.F.Dockes
|
||||
*
|
||||
* License: GPL 2.1
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "copyfile.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static int op_flags;
|
||||
#define OPT_MOINS 0x1
|
||||
#define OPT_m 0x2
|
||||
#define OPT_e 0x4
|
||||
|
||||
static const char *thisprog;
|
||||
static char usage [] =
|
||||
"trcopyfile [-m] src dst\n"
|
||||
" -m : move instead of copying\n"
|
||||
" -e : fail if dest exists (only for copy)\n"
|
||||
"\n"
|
||||
;
|
||||
static void
|
||||
Usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s: usage:\n%s", thisprog, usage);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
thisprog = argv[0];
|
||||
argc--; argv++;
|
||||
|
||||
while (argc > 0 && **argv == '-') {
|
||||
(*argv)++;
|
||||
if (!(**argv))
|
||||
/* Cas du "adb - core" */
|
||||
Usage();
|
||||
while (**argv)
|
||||
switch (*(*argv)++) {
|
||||
case 'm': op_flags |= OPT_m; break;
|
||||
case 'e': op_flags |= OPT_e; break;
|
||||
default: Usage(); break;
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
if (argc != 2)
|
||||
Usage();
|
||||
string src = *argv++;argc--;
|
||||
string dst = *argv++;argc--;
|
||||
bool ret;
|
||||
string reason;
|
||||
if (op_flags & OPT_m) {
|
||||
ret = renameormove(src.c_str(), dst.c_str(), reason);
|
||||
} else {
|
||||
int flags = 0;
|
||||
if (op_flags & OPT_e) {
|
||||
flags |= COPYFILE_EXCL;
|
||||
}
|
||||
ret = copyfile(src.c_str(), dst.c_str(), reason, flags);
|
||||
}
|
||||
if (!ret) {
|
||||
cerr << reason << endl;
|
||||
exit(1);
|
||||
} else {
|
||||
cout << "Succeeded" << endl;
|
||||
if (!reason.empty()) {
|
||||
cout << "Warnings: " << reason << endl;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
38
src/testmains/trcpuconf.cpp
Normal file
38
src/testmains/trcpuconf.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/* Copyright (C) 2021 J.F.Dockes
|
||||
*
|
||||
* License: GPL 2.1
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include "cpuconf.h"
|
||||
|
||||
// Test driver
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
CpuConf cpus;
|
||||
if (!getCpuConf(cpus)) {
|
||||
cerr << "getCpuConf failed" << endl;
|
||||
exit(1);
|
||||
}
|
||||
cout << "Cpus: " << cpus.ncpus << endl;
|
||||
exit(0);
|
||||
}
|
||||
@ -37,7 +37,6 @@
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/uio.h>
|
||||
#define O_BINARY 0
|
||||
#else
|
||||
struct iovec {
|
||||
void *iov_base;
|
||||
|
||||
@ -14,25 +14,26 @@
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
#ifndef TEST_COPYFILE
|
||||
|
||||
#include "autoconfig.h"
|
||||
|
||||
#include "copyfile.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "safefcntl.h"
|
||||
#include <sys/types.h>
|
||||
#include "safesysstat.h"
|
||||
#include "safeunistd.h"
|
||||
#include "pathut.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/time.h>
|
||||
#include <utime.h>
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "copyfile.h"
|
||||
#include "pathut.h"
|
||||
#include "log.h"
|
||||
|
||||
using namespace std;
|
||||
@ -189,85 +190,3 @@ bool renameormove(const char *src, const char *dst, string &reason)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "copyfile.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static int op_flags;
|
||||
#define OPT_MOINS 0x1
|
||||
#define OPT_m 0x2
|
||||
#define OPT_e 0x4
|
||||
|
||||
static const char *thisprog;
|
||||
static char usage [] =
|
||||
"trcopyfile [-m] src dst\n"
|
||||
" -m : move instead of copying\n"
|
||||
" -e : fail if dest exists (only for copy)\n"
|
||||
"\n"
|
||||
;
|
||||
static void
|
||||
Usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s: usage:\n%s", thisprog, usage);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
thisprog = argv[0];
|
||||
argc--; argv++;
|
||||
|
||||
while (argc > 0 && **argv == '-') {
|
||||
(*argv)++;
|
||||
if (!(**argv))
|
||||
/* Cas du "adb - core" */
|
||||
Usage();
|
||||
while (**argv)
|
||||
switch (*(*argv)++) {
|
||||
case 'm': op_flags |= OPT_m; break;
|
||||
case 'e': op_flags |= OPT_e; break;
|
||||
default: Usage(); break;
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
if (argc != 2)
|
||||
Usage();
|
||||
string src = *argv++;argc--;
|
||||
string dst = *argv++;argc--;
|
||||
bool ret;
|
||||
string reason;
|
||||
if (op_flags & OPT_m) {
|
||||
ret = renameormove(src.c_str(), dst.c_str(), reason);
|
||||
} else {
|
||||
int flags = 0;
|
||||
if (op_flags & OPT_e) {
|
||||
flags |= COPYFILE_EXCL;
|
||||
}
|
||||
ret = copyfile(src.c_str(), dst.c_str(), reason, flags);
|
||||
}
|
||||
if (!ret) {
|
||||
cerr << reason << endl;
|
||||
exit(1);
|
||||
} else {
|
||||
cout << "Succeeded" << endl;
|
||||
if (!reason.empty()) {
|
||||
cout << "Warnings: " << reason << endl;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 J.F.Dockes
|
||||
/* Copyright (C) 2013-2022 J.F.Dockes
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
@ -14,11 +14,8 @@
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
#ifndef TEST_CPUCONF
|
||||
|
||||
#include "autoconfig.h"
|
||||
|
||||
|
||||
#include "cpuconf.h"
|
||||
|
||||
#include <thread>
|
||||
@ -39,25 +36,3 @@ bool getCpuConf(CpuConf& cpus)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#else // TEST_CPUCONF
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include "cpuconf.h"
|
||||
|
||||
// Test driver
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
CpuConf cpus;
|
||||
if (!getCpuConf(cpus)) {
|
||||
cerr << "getCpuConf failed" << endl;
|
||||
exit(1);
|
||||
}
|
||||
cout << "Cpus: " << cpus.ncpus << endl;
|
||||
exit(0);
|
||||
}
|
||||
#endif // TEST_CPUCONF
|
||||
|
||||
@ -171,7 +171,6 @@
|
||||
#define DIRENT dirent
|
||||
#define DIRHDL DIR
|
||||
#define MKDIR(a,b) mkdir(a,b)
|
||||
#define O_BINARY 0
|
||||
#define OPEN ::open
|
||||
#define UNLINK ::unlink
|
||||
#define RMDIR ::rmdir
|
||||
|
||||
@ -81,6 +81,8 @@ bool path_exists(const std::string& path);
|
||||
bool path_readable(const std::string& path);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
// Constants for _waccess()
|
||||
# ifndef R_OK
|
||||
# define R_OK 4
|
||||
# endif
|
||||
@ -94,7 +96,30 @@ bool path_readable(const std::string& path);
|
||||
# ifndef F_OK
|
||||
# define F_OK 0
|
||||
# endif
|
||||
#endif /* _WIN32 */
|
||||
|
||||
// Conversion between utf-8 and wide char file names.
|
||||
|
||||
#include <memory>
|
||||
bool wchartoutf8(const wchar_t *in, std::string& out, size_t len = 0);
|
||||
std::string wchartoutf8(const wchar_t *in, size_t len = 0);
|
||||
bool utf8towchar(const std::string& in, wchar_t *out, size_t obytescap);
|
||||
std::unique_ptr<wchar_t[]> utf8towchar(const std::string& in);
|
||||
|
||||
// Convert between slash and backslash separators.
|
||||
void path_slashize(std::string& s);
|
||||
void path_backslashize(std::string& s);
|
||||
|
||||
extern std::string path_shortpath(const std::string& path);
|
||||
|
||||
#else // !_WIN32 ->
|
||||
|
||||
#include <unistd.h>
|
||||
#define path_shortpath(path) (path)
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#endif /* !_WIN32 */
|
||||
|
||||
/// access() or _waccess()
|
||||
bool path_access(const std::string& path, int mode);
|
||||
|
||||
@ -125,14 +150,6 @@ extern int path_fileprops(const std::string path, struct PathStat *stp,
|
||||
/// Return separator for PATH environment variable
|
||||
extern std::string path_PATHsep();
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <memory>
|
||||
bool wchartoutf8(const wchar_t *in, std::string& out, size_t len = 0);
|
||||
std::string wchartoutf8(const wchar_t *in, size_t len = 0);
|
||||
bool utf8towchar(const std::string& in, wchar_t *out, size_t obytescap);
|
||||
std::unique_ptr<wchar_t[]> utf8towchar(const std::string& in);
|
||||
#endif
|
||||
|
||||
/// Directory reading interface. UTF-8 on Windows.
|
||||
class PathDirContents {
|
||||
public:
|
||||
@ -219,15 +236,6 @@ public:
|
||||
std::string fragment;
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
/// Convert \ separators to /
|
||||
void path_slashize(std::string& s);
|
||||
void path_backslashize(std::string& s);
|
||||
extern std::string path_shortpath(const std::string& path);
|
||||
#else
|
||||
#define path_shortpath(path) (path)
|
||||
#endif
|
||||
|
||||
/// Lock/pid file class. This is quite close to the pidfile_xxx
|
||||
/// utilities in FreeBSD with a bit more encapsulation. I'd have used
|
||||
/// the freebsd code if it was available elsewhere
|
||||
|
||||
1002
src/utils/pxattr.cpp
1002
src/utils/pxattr.cpp
File diff suppressed because it is too large
Load Diff
@ -35,7 +35,7 @@
|
||||
#define OPEN _wopen
|
||||
|
||||
#else
|
||||
#define O_BINARY 0
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -24,12 +24,6 @@
|
||||
#include "log.h"
|
||||
#include "pathut.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include "safeunistd.h"
|
||||
#else // Not windows ->
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
int wipedir(const std::string& dir, bool selfalso, bool recurse)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user