Skip to content

Commit

Permalink
Define UNICODE and use Create* on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bugdea1er committed Jan 1, 2025
1 parent 6271156 commit 6b26c57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <utility>

#ifdef _WIN32
#define UNICODE
#include <Windows.h>
#else
#include <cerrno>
Expand Down Expand Up @@ -37,7 +38,7 @@ create_directory(std::string_view label) {
}

#ifdef _WIN32
if (!CreateDirectoryW(path.c_str(), nullptr)) {
if (!CreateDirectory(path.c_str(), nullptr)) {
ec = std::error_code(GetLastError(), std::system_category());
}
#else
Expand All @@ -52,9 +53,9 @@ create_directory(std::string_view label) {

#ifdef _WIN32
HANDLE handle =
CreateFileW(path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
CreateFile(path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
#else
int handle = open(path.data(), O_DIRECTORY);
#endif
Expand Down
7 changes: 4 additions & 3 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <utility>

#ifdef _WIN32
#define UNICODE
#include <Windows.h>
#else
#include <cerrno>
Expand Down Expand Up @@ -41,9 +42,9 @@ create_file(std::string_view label, std::string_view extension) {

#ifdef _WIN32
HANDLE handle =
CreateFileW(path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
CreateFile(path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);

if (handle == INVALID_HANDLE_VALUE) {
ec = std::error_code(GetLastError(), std::system_category());
Expand Down

0 comments on commit 6b26c57

Please sign in to comment.