*: check defined(_WIN32) instead of defined(WIN32)

Only _WIN32 is defined by the compiler, and WIN32 is not standardized
and may be missing.

Closes #169
This commit is contained in:
Max Kellermann
2017-12-12 10:22:20 +01:00
parent d9552d8a6d
commit dfaf08743c
91 changed files with 226 additions and 225 deletions

View File

@@ -31,7 +31,7 @@ AllocatedPath::~AllocatedPath() {}
AllocatedPath
AllocatedPath::FromUTF8(const char *path_utf8) noexcept
{
#if defined(HAVE_FS_CHARSET) || defined(WIN32)
#if defined(HAVE_FS_CHARSET) || defined(_WIN32)
try {
return AllocatedPath(::PathFromUTF8(path_utf8));
} catch (const std::runtime_error &) {
@@ -45,7 +45,7 @@ AllocatedPath::FromUTF8(const char *path_utf8) noexcept
AllocatedPath
AllocatedPath::FromUTF8Throw(const char *path_utf8)
{
#if defined(HAVE_FS_CHARSET) || defined(WIN32)
#if defined(HAVE_FS_CHARSET) || defined(_WIN32)
return AllocatedPath(::PathFromUTF8(path_utf8));
#else
return FromFS(path_utf8);

View File

@@ -24,7 +24,7 @@
#include "lib/icu/Converter.hxx"
#include "util/AllocatedString.hxx"
#ifdef WIN32
#ifdef _WIN32
#include "lib/icu/Win32.hxx"
#include <windows.h>
#endif
@@ -70,7 +70,7 @@ GetFSCharset() noexcept
{
#ifdef HAVE_FS_CHARSET
return fs_charset.empty() ? "UTF-8" : fs_charset.c_str();
#elif defined(WIN32)
#elif defined(_WIN32)
return "ACP";
#else
return "UTF-8";
@@ -100,7 +100,7 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
assert(path_fs != nullptr);
#endif
#ifdef WIN32
#ifdef _WIN32
const auto buffer = WideCharToMultiByte(CP_UTF8, path_fs);
return FixSeparators(PathTraitsUTF8::string(buffer.c_str()));
#else
@@ -116,7 +116,7 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
#endif
}
#if defined(HAVE_FS_CHARSET) || defined(WIN32)
#if defined(HAVE_FS_CHARSET) || defined(_WIN32)
PathTraitsFS::string
PathFromUTF8(PathTraitsUTF8::const_pointer_type path_utf8)
@@ -126,7 +126,7 @@ PathFromUTF8(PathTraitsUTF8::const_pointer_type path_utf8)
assert(path_utf8 != nullptr);
#endif
#ifdef WIN32
#ifdef _WIN32
const auto buffer = MultiByteToWideChar(CP_UTF8, path_utf8);
return PathTraitsFS::string(buffer.c_str());
#else

View File

@@ -24,7 +24,7 @@
#include "Compiler.h"
#include "Traits.hxx"
#if (defined(HAVE_ICU) || defined(HAVE_ICONV)) && !defined(WIN32)
#if (defined(HAVE_ICU) || defined(HAVE_ICONV)) && !defined(_WIN32)
#define HAVE_FS_CHARSET
#endif

View File

@@ -41,7 +41,7 @@ try {
return;
}
#ifndef WIN32
#ifndef _WIN32
try {
const auto x = AllocatedPath::Build(path_fs,
PathTraitsFS::CURRENT_DIRECTORY);

View File

@@ -21,7 +21,7 @@
#include "DirectoryReader.hxx"
#include "system/Error.hxx"
#ifdef WIN32
#ifdef _WIN32
DirectoryReader::DirectoryReader(Path dir)
:handle(FindFirstFile(MakeWildcardPath(dir.c_str()), &data))

View File

@@ -23,7 +23,7 @@
#include "check.h"
#include "Path.hxx"
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#include <tchar.h>

View File

@@ -26,13 +26,13 @@
#include <stdint.h>
#ifdef WIN32
#ifdef _WIN32
#include <fileapi.h>
#else
#include <sys/stat.h>
#endif
#ifdef WIN32
#ifdef _WIN32
static inline constexpr uint64_t
ConstructUint64(DWORD lo, DWORD hi)
@@ -54,7 +54,7 @@ class FileInfo {
bool follow_symlinks);
friend class FileReader;
#ifdef WIN32
#ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA data;
#else
struct stat st;
@@ -65,7 +65,7 @@ public:
FileInfo(Path path, bool follow_symlinks=true) {
if (!GetFileInfo(path, *this, follow_symlinks)) {
#ifdef WIN32
#ifdef _WIN32
throw FormatLastError("Failed to access %s",
path.ToUTF8().c_str());
#else
@@ -76,7 +76,7 @@ public:
}
bool IsRegular() const {
#ifdef WIN32
#ifdef _WIN32
return (data.dwFileAttributes &
(FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE)) == 0;
#else
@@ -85,7 +85,7 @@ public:
}
bool IsDirectory() const {
#ifdef WIN32
#ifdef _WIN32
return data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
#else
return S_ISDIR(st.st_mode);
@@ -93,7 +93,7 @@ public:
}
uint64_t GetSize() const {
#ifdef WIN32
#ifdef _WIN32
return ConstructUint64(data.nFileSizeLow, data.nFileSizeHigh);
#else
return st.st_size;
@@ -101,14 +101,14 @@ public:
}
time_t GetModificationTime() const {
#ifdef WIN32
#ifdef _WIN32
return FileTimeToTimeT(data.ftLastWriteTime);
#else
return st.st_mtime;
#endif
}
#ifndef WIN32
#ifndef _WIN32
uid_t GetUid() const {
return st.st_uid;
}
@@ -130,7 +130,7 @@ public:
inline bool
GetFileInfo(Path path, FileInfo &info, bool follow_symlinks=true)
{
#ifdef WIN32
#ifdef _WIN32
(void)follow_symlinks;
return GetFileAttributesEx(path.c_str(), GetFileExInfoStandard,
&info.data);

View File

@@ -29,7 +29,7 @@
void
RenameFile(Path oldpath, Path newpath)
{
#ifdef WIN32
#ifdef _WIN32
if (!MoveFileEx(oldpath.c_str(), newpath.c_str(),
MOVEFILE_REPLACE_EXISTING))
throw MakeLastError("Failed to rename file");
@@ -42,7 +42,7 @@ RenameFile(Path oldpath, Path newpath)
AllocatedPath
ReadLink(Path path)
{
#ifdef WIN32
#ifdef _WIN32
(void)path;
errno = EINVAL;
return AllocatedPath::Null();
@@ -63,7 +63,7 @@ ReadLink(Path path)
void
TruncateFile(Path path)
{
#ifdef WIN32
#ifdef _WIN32
HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, nullptr,
TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr);
@@ -83,7 +83,7 @@ TruncateFile(Path path)
void
RemoveFile(Path path)
{
#ifdef WIN32
#ifdef _WIN32
if (!DeleteFile(path.c_str()))
throw FormatLastError("Failed to delete %s", path.c_str());
#else

View File

@@ -26,7 +26,7 @@
#include "Path.hxx"
#ifdef WIN32
#ifdef _WIN32
#include <fileapi.h>
#endif
@@ -43,7 +43,7 @@ class AllocatedPath;
static inline FILE *
FOpen(Path file, PathTraitsFS::const_pointer_type mode)
{
#ifdef WIN32
#ifdef _WIN32
return _tfopen(file.c_str(), mode);
#else
return fopen(file.c_str(), mode);
@@ -56,7 +56,7 @@ FOpen(Path file, PathTraitsFS::const_pointer_type mode)
static inline int
OpenFile(Path file, int flags, int mode)
{
#ifdef WIN32
#ifdef _WIN32
return _topen(file.c_str(), flags, mode);
#else
return open_cloexec(file.c_str(), flags, mode);
@@ -71,7 +71,7 @@ OpenFile(Path file, int flags, int mode)
void
RenameFile(Path oldpath, Path newpath);
#ifndef WIN32
#ifndef _WIN32
/**
* Wrapper for stat() that uses #Path names.
@@ -107,7 +107,7 @@ RemoveFile(Path path);
AllocatedPath
ReadLink(Path path);
#ifndef WIN32
#ifndef _WIN32
static inline bool
MakeFifo(Path path, mode_t mode)
@@ -132,7 +132,7 @@ CheckAccess(Path path, int mode)
static inline bool
FileExists(Path path, bool follow_symlinks = true)
{
#ifdef WIN32
#ifdef _WIN32
(void)follow_symlinks;
const auto a = GetFileAttributes(path.c_str());
@@ -150,7 +150,7 @@ FileExists(Path path, bool follow_symlinks = true)
static inline bool
DirectoryExists(Path path, bool follow_symlinks = true)
{
#ifdef WIN32
#ifdef _WIN32
(void)follow_symlinks;
const auto a = GetFileAttributes(path.c_str());
@@ -167,7 +167,7 @@ DirectoryExists(Path path, bool follow_symlinks = true)
static inline bool
PathExists(Path path)
{
#ifdef WIN32
#ifdef _WIN32
return GetFileAttributes(path.c_str()) != INVALID_FILE_ATTRIBUTES;
#else
return CheckAccess(path, F_OK);

View File

@@ -26,7 +26,7 @@
#define HAVE_CLASS_GLOB
#include <string>
#include <fnmatch.h>
#elif defined(WIN32)
#elif defined(_WIN32)
#define HAVE_CLASS_GLOB
#include <string>
#include <shlwapi.h>
@@ -40,12 +40,12 @@
* (asterisk and question mark).
*/
class Glob {
#if defined(HAVE_FNMATCH) || defined(WIN32)
#if defined(HAVE_FNMATCH) || defined(_WIN32)
std::string pattern;
#endif
public:
#if defined(HAVE_FNMATCH) || defined(WIN32)
#if defined(HAVE_FNMATCH) || defined(_WIN32)
explicit Glob(const char *_pattern)
:pattern(_pattern) {}
@@ -57,7 +57,7 @@ public:
bool Check(const char *name_fs) const noexcept {
#ifdef HAVE_FNMATCH
return fnmatch(pattern.c_str(), name_fs, 0) == 0;
#elif defined(WIN32)
#elif defined(_WIN32)
return PathMatchSpecA(name_fs, pattern.c_str());
#endif
}

View File

@@ -25,7 +25,7 @@
#include <stddef.h>
#include <limits.h>
#if defined(WIN32)
#if defined(_WIN32)
static constexpr size_t MPD_PATH_MAX = 260;
#elif defined(MAXPATHLEN)
static constexpr size_t MPD_PATH_MAX = MAXPATHLEN;

View File

@@ -20,7 +20,7 @@
#include "config.h"
// Use X Desktop guidelines where applicable
#if !defined(__APPLE__) && !defined(WIN32) && !defined(ANDROID)
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(ANDROID)
#define USE_XDG
#endif
@@ -29,7 +29,7 @@
#include <array>
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#include <shlobj.h>
#else
@@ -53,7 +53,7 @@
#include "Main.hxx"
#endif
#if !defined(WIN32) && !defined(ANDROID)
#if !defined(_WIN32) && !defined(ANDROID)
class PasswdEntry
{
#if defined(HAVE_GETPWNAM_R) || defined(HAVE_GETPWUID_R)
@@ -113,7 +113,7 @@ SafePathFromFS(PathTraitsFS::const_pointer_type dir)
}
#endif
#ifdef WIN32
#ifdef _WIN32
static AllocatedPath GetStandardDir(int folder_id)
{
std::array<PathTraitsFS::value_type, MAX_PATH> dir;
@@ -226,7 +226,7 @@ try {
AllocatedPath
GetUserConfigDir() noexcept
{
#if defined(WIN32)
#if defined(_WIN32)
return GetStandardDir(CSIDL_LOCAL_APPDATA);
#elif defined(USE_XDG)
// Check for $XDG_CONFIG_HOME
@@ -251,7 +251,7 @@ GetUserConfigDir() noexcept
AllocatedPath
GetUserMusicDir() noexcept
{
#if defined(WIN32)
#if defined(_WIN32)
return GetStandardDir(CSIDL_MYMUSIC);
#elif defined(USE_XDG)
return GetUserDir("XDG_MUSIC_DIR");
@@ -287,7 +287,7 @@ GetUserCacheDir() noexcept
#endif
}
#ifdef WIN32
#ifdef _WIN32
AllocatedPath
GetSystemConfigDir() noexcept

View File

@@ -42,7 +42,7 @@ gcc_pure
AllocatedPath
GetUserCacheDir() noexcept;
#ifdef WIN32
#ifdef _WIN32
/**
* Obtains system configuration directory.

View File

@@ -78,7 +78,7 @@ GetParentPathImpl(typename Traits::const_pointer_type p)
return typename Traits::string(Traits::CURRENT_DIRECTORY);
if (sep == p)
return typename Traits::string(p, p + 1);
#ifdef WIN32
#ifdef _WIN32
if (Traits::IsDrive(p) && sep == p + 2)
return typename Traits::string(p, p + 3);
#endif

View File

@@ -25,7 +25,7 @@
#include "util/StringPointer.hxx"
#include "util/StringAPI.hxx"
#ifdef WIN32
#ifdef _WIN32
#include "util/CharUtil.hxx"
#include <tchar.h>
#endif
@@ -34,7 +34,7 @@
#include <assert.h>
#ifdef WIN32
#ifdef _WIN32
#define PATH_LITERAL(s) _T(s)
#else
#define PATH_LITERAL(s) (s)
@@ -44,7 +44,7 @@
* This class describes the nature of a native filesystem path.
*/
struct PathTraitsFS {
#ifdef WIN32
#ifdef _WIN32
typedef std::wstring string;
#else
typedef std::string string;
@@ -55,7 +55,7 @@ struct PathTraitsFS {
typedef Pointer::pointer_type pointer_type;
typedef Pointer::const_pointer_type const_pointer_type;
#ifdef WIN32
#ifdef _WIN32
static constexpr value_type SEPARATOR = '\\';
#else
static constexpr value_type SEPARATOR = '/';
@@ -65,7 +65,7 @@ struct PathTraitsFS {
static constexpr bool IsSeparator(value_type ch) noexcept {
return
#ifdef WIN32
#ifdef _WIN32
ch == '/' ||
#endif
ch == SEPARATOR;
@@ -78,7 +78,7 @@ struct PathTraitsFS {
assert(p != nullptr);
#endif
#ifdef WIN32
#ifdef _WIN32
const_pointer_type pos = p + GetLength(p);
while (p != pos && !IsSeparator(*pos))
--pos;
@@ -88,7 +88,7 @@ struct PathTraitsFS {
#endif
}
#ifdef WIN32
#ifdef _WIN32
gcc_pure gcc_nonnull_all
static constexpr bool IsDrive(const_pointer_type p) noexcept {
return IsAlphaASCII(p[0]) && p[1] == ':';
@@ -102,7 +102,7 @@ struct PathTraitsFS {
assert(p != nullptr);
#endif
#ifdef WIN32
#ifdef _WIN32
if (IsDrive(p) && IsSeparator(p[2]))
return true;
#endif
@@ -188,7 +188,7 @@ struct PathTraitsUTF8 {
return strrchr(p, SEPARATOR);
}
#ifdef WIN32
#ifdef _WIN32
gcc_pure gcc_nonnull_all
static constexpr bool IsDrive(const_pointer_type p) noexcept {
return IsAlphaASCII(p[0]) && p[1] == ':';
@@ -202,7 +202,7 @@ struct PathTraitsUTF8 {
assert(p != nullptr);
#endif
#ifdef WIN32
#ifdef _WIN32
if (IsDrive(p) && IsSeparator(p[2]))
return true;
#endif

View File

@@ -43,7 +43,7 @@ FileOutputStream::FileOutputStream(Path _path, Mode _mode)
}
}
#ifdef WIN32
#ifdef _WIN32
inline void
FileOutputStream::OpenCreate(gcc_unused bool visible)
@@ -223,7 +223,7 @@ FileOutputStream::Commit()
#endif
if (!Close()) {
#ifdef WIN32
#ifdef _WIN32
throw FormatLastError("Failed to commit %s",
path.ToUTF8().c_str());
#else

View File

@@ -25,14 +25,14 @@
#include "fs/AllocatedPath.hxx"
#include "Compiler.h"
#ifndef WIN32
#ifndef _WIN32
#include "system/FileDescriptor.hxx"
#endif
#include <assert.h>
#include <stdint.h>
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#endif
@@ -41,7 +41,7 @@ class Path;
class FileOutputStream final : public OutputStream {
const AllocatedPath path;
#ifdef WIN32
#ifdef _WIN32
HANDLE handle = INVALID_HANDLE_VALUE;
#else
FileDescriptor fd = FileDescriptor::Undefined();
@@ -116,7 +116,7 @@ private:
bool Close() {
assert(IsDefined());
#ifdef WIN32
#ifdef _WIN32
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
return true;
@@ -125,7 +125,7 @@ private:
#endif
}
#ifdef WIN32
#ifdef _WIN32
bool SeekEOF() {
return SetFilePointer(handle, 0, nullptr,
FILE_END) != 0xffffffff;
@@ -133,7 +133,7 @@ private:
#endif
bool IsDefined() const {
#ifdef WIN32
#ifdef _WIN32
return handle != INVALID_HANDLE_VALUE;
#else
return fd.IsDefined();

View File

@@ -24,7 +24,7 @@
#include <assert.h>
#ifdef WIN32
#ifdef _WIN32
FileReader::FileReader(Path _path)
:path(_path),

View File

@@ -25,11 +25,11 @@
#include "fs/AllocatedPath.hxx"
#include "Compiler.h"
#ifndef WIN32
#ifndef _WIN32
#include "system/FileDescriptor.hxx"
#endif
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#endif
@@ -39,7 +39,7 @@ class FileInfo;
class FileReader final : public Reader {
AllocatedPath path;
#ifdef WIN32
#ifdef _WIN32
HANDLE handle;
#else
FileDescriptor fd;
@@ -48,7 +48,7 @@ class FileReader final : public Reader {
public:
explicit FileReader(Path _path);
#ifdef WIN32
#ifdef _WIN32
FileReader(FileReader &&other)
:path(std::move(other.path)),
handle(other.handle) {
@@ -70,7 +70,7 @@ public:
protected:
bool IsDefined() const {
#ifdef WIN32
#ifdef _WIN32
return handle != INVALID_HANDLE_VALUE;
#else
return fd.IsDefined();
@@ -78,7 +78,7 @@ protected:
}
public:
#ifndef WIN32
#ifndef _WIN32
FileDescriptor GetFD() const {
return fd;
}
@@ -90,7 +90,7 @@ public:
gcc_pure
uint64_t GetSize() const noexcept {
#ifdef WIN32
#ifdef _WIN32
LARGE_INTEGER size;
return GetFileSizeEx(handle, &size)
? size.QuadPart
@@ -102,7 +102,7 @@ public:
gcc_pure
uint64_t GetPosition() const noexcept {
#ifdef WIN32
#ifdef _WIN32
LARGE_INTEGER zero;
zero.QuadPart = 0;
LARGE_INTEGER position;