Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix filesystem #48

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
42 changes: 29 additions & 13 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DFileWatch_Build_Tests=ON -DFileWatch_Build_Tests_FileSystem=ON

- name: Build
working-directory: ${{runner.workspace}}/build
Expand All @@ -66,37 +66,44 @@ jobs:
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
cc: "gcc-10", cxx: "g++-10"
cc: "gcc-10", cxx: "g++-10",
build-file-system: 'ON'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
cc: "gcc-9", cxx: "g++-9"
cc: "gcc-9", cxx: "g++-9",
build-file-system: 'ON'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
cc: "gcc-8", cxx: "g++-8"
cc: "gcc-8", cxx: "g++-8",
build-file-system: 'ON'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
cc: "gcc-7", cxx: "g++-7"
cc: "gcc-7", cxx: "g++-7",
build-file-system: 'OFF'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
cc: "gcc-6", cxx: "g++-6"
cc: "gcc-6", cxx: "g++-6",
build-file-system: 'OFF'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
cc: "gcc-5", cxx: "g++-5"
cc: "gcc-5", cxx: "g++-5",
build-file-system: 'OFF'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
cc: "gcc-4.8", cxx: "g++-4.8"
cc: "gcc-4.8", cxx: "g++-4.8",
build-file-system: 'OFF'
}
steps:
- uses: actions/checkout@v2
Expand All @@ -120,7 +127,7 @@ jobs:
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DFileWatch_Build_Tests=ON -DFileWatch_Build_Tests_FileSystem=${{matrix.config.build-file-system}}
env:
CC: ${{matrix.config.cc}}
CXX: ${{matrix.config.cxx}}
Expand Down Expand Up @@ -149,36 +156,43 @@ jobs:
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
clang-version: "4.0",
build-file-system: 'OFF'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
clang-version: "5.0",
build-file-system: 'OFF'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
clang-version: "6.0",
build-file-system: 'OFF'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
clang-version: "7",
build-file-system: 'OFF'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
clang-version: "8",
build-file-system: 'ON'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
clang-version: "9",
build-file-system: 'ON'
}
- {
name: "Ubuntu 18.04", artifact: "Linux.7z",
os: ubuntu-18.04,
clang-version: "10",
build-file-system: 'ON'
}
steps:
- uses: actions/checkout@v2
Expand All @@ -204,7 +218,7 @@ jobs:
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DFileWatch_Build_Tests=ON -DFileWatch_Build_Tests_FileSystem=${{matrix.config.build-file-system}}
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
Expand All @@ -228,12 +242,14 @@ jobs:
- {
name: "MacOS 11", artifact: "macos.7z",
os: macos-11,
cc: "clang", cxx: "clang++"
cc: "clang", cxx: "clang++",
build-file-system: 'ON'
}
- {
name: MacOS 12", artifact: "macos.7z",
os: macos-12,
cc: "clang", cxx: "clang++"
cc: "clang", cxx: "clang++",
build-file-system: 'ON'
}
steps:
- uses: actions/checkout@v2
Expand All @@ -251,7 +267,7 @@ jobs:
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DFileWatch_Build_Tests=ON -DFileWatch_Build_Tests_FileSystem=${{matrix.config.build-file-system}}
env:
CC: ${{matrix.config.cc}}
CXX: ${{matrix.config.cxx}}
Expand Down
85 changes: 85 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"cmake.configureOnOpen": true,
"cmake.configureSettings": {
"FileWatch_Build_Example": "ON",
"FileWatch_Build_Tests": "ON",
"FileWatch_Build_Tests_FileSystem": "ON"
},
"files.associations": {
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"filesystem": "cpp",
"format": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ cmake_minimum_required(VERSION 3.1)
# Project name
project( FileWatch VERSION 0.0.1 LANGUAGES C CXX)

option(BuildTests "Build the unit tests" ON)
option(FileWatch_Build_Example "Build the example")
option(FileWatch_Build_Tests "Build the unit tests")
option(FileWatch_Build_Tests_FileSystem "Build the unit c++17 > filesystem tests")
enable_testing()

# Enable c++11
Expand All @@ -18,8 +20,8 @@ else()
endif()

if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework CoreServices")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework CoreServices")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()

# dial up the warnings
Expand All @@ -36,9 +38,11 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
endif()


# create and configure the unit test target
if(BuildTests)
add_subdirectory(tests)
endif()
add_subdirectory(tests)

# add_subdirectory(example)

if(FileWatch_Build_Example)
add_subdirectory(example)
endif()
44 changes: 31 additions & 13 deletions FileWatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
#include <cstdlib>
#include <iostream>

#ifdef __cpp_lib_filesystem
#include <filesystem>
#endif

#ifdef FILEWATCH_PLATFORM_MAC
extern "C" int __getdirentries64(int, char *, int, long *);
#endif // FILEWATCH_PLATFORM_MAC
Expand Down Expand Up @@ -659,6 +663,22 @@ namespace filewatch {
}
#endif // __unix__

template<typename StringType>
struct absolute_path_of_helper {
static StringType get(const char* buf) {
return StringType{buf};
}
};

#ifdef __cpp_lib_filesystem
template<>
struct absolute_path_of_helper<std::filesystem::path> {
static std::filesystem::path get(const char* buf) {
return std::filesystem::u8path(buf);
}
};
#endif

#if FILEWATCH_PLATFORM_MAC
static StringType absolute_path_of(const StringType& path) {
char buf[PATH_MAX];
Expand All @@ -684,12 +704,11 @@ namespace filewatch {
close(fd);

if (IsWChar<C>::value) {
size_t needed = mbsrtowcs(nullptr, &str, 0, &state) + 1;
StringType s;

s.reserve(needed);
mbsrtowcs((wchar_t*)&s[0], &str, s.size(), &state);
return s;
std::mbstate_t state = std::mbstate_t();
size_t needed = std::mbsrtowcs(nullptr, &str, 0, &state) + 1;
std::wstring s(needed, L'\0');
std::mbsrtowcs(&s[0], &str, s.size(), &state);
return StringType {s};
}
return StringType {buf};
}
Expand All @@ -715,12 +734,11 @@ namespace filewatch {
}

if (IsWChar<C>::value) {
size_t needed = mbsrtowcs(nullptr, &str, 0, &state) + 1;
StringType s;

s.reserve(needed);
mbsrtowcs((wchar_t*)&s[0], &str, s.size(), &state);
return s;
std::mbstate_t state = std::mbstate_t();
size_t needed = std::mbsrtowcs(nullptr, &str, 0, &state) + 1;
std::wstring s(needed, L'\0');
std::mbsrtowcs(&s[0], &str, s.size(), &state);
return StringType {s};
}
return StringType {buf};
}
Expand All @@ -738,7 +756,7 @@ namespace filewatch {
size / sizeof(TCHAR),
buf,
nullptr);
return StringType{(C*)buf, length};
return StringType{std::basic_string<StringType::value_type>((C*)buf, length)};
}
#endif

Expand Down
Loading
Loading