feat(windows): add full Windows/MSVC support#11
Merged
Conversation
- Add bfc_win32_compat.h with POSIX shims (ssize_t, usleep, clock_gettime, S_IS* macros, fseeko/ftello, mkdir, fileno) - Add cli_win32_compat.h for CLI-layer POSIX shims (getopt, fnmatch, dirent, symlink stubs) - Fix MSVC warnings-as-errors: C4206 (empty TU), C4244 (narrowing), C4267 (size_t conversions), C4456 (variable shadowing), C4100 (unused params), C4702 (unreachable code after ZSTD guard) - Update CMakeLists.txt with MSVC /W4 /WX flags and _CRT_SECURE_NO_WARNINGS - Add GitHub Actions CI matrix for windows-latest with vcpkg (zstd, libsodium) - Add Windows release workflow with ZIP packaging and install.bat - Fix test_reader.c pre-existing assertion bug (wrong expected string in partial-read test) - Guard ZSTD-only test functions with #ifdef BFC_WITH_ZSTD body wrapping - Update README with Windows build instructions - Guard POSIX-only includes in benchmarks and examples with #ifndef _WIN32
- Add <sys/stat.h> to cli.h for Linux/macOS (S_ISSOCK, S_ISVTX missing) - Suppress unused verify_entry_callback warning (pragma+attribute, all platforms) - Guard <unistd.h> in encrypt_example.c with #ifndef _WIN32 - Map getpid to _getpid in bfc_win32_compat.h for Windows test_encrypt.c
- Set up MSVC vcvarsall + cmake + ninja for Windows via aminya/setup-cpp@v1 - Use unified shell: bash for configure, test, and Windows CLI steps - Fix Windows env var references to bash-style ($VCPKG_INSTALLATION_ROOT) - Convert Windows CLI test from PowerShell to bash (find bfc.exe)
…ions - Remove global -D_GNU_SOURCE from CMakeLists (source files already define it); add guarded #define _GNU_SOURCE in cli.h before sys/stat.h for Linux S_ISSOCK - Fix TOCTOU in create_parent_directories: use mkdir+EEXIST instead of stat+mkdir - Fix TOCTOU in extract_file: remove upfront stat, use O_EXCL/O_NOFOLLOW atomically - Fix TOCTOU in extract_directory: replace path-based chmod/utimensat with fd-based fchmod/futimens after opening directory with O_RDONLY|O_DIRECTORY
…rgets - Linux/CLI: move _GNU_SOURCE to target_compile_definitions in CLI CMakeLists so it precedes all system headers (fixes S_ISSOCK/S_ISVTX undeclared) - macOS: add _DARWIN_C_SOURCE in bfc_os.c to expose fdatasync under clang - Windows/encrypt_example: include bfc_win32_compat.h for S_ISREG/open/close/mkdir; add src/lib to encrypt_example include path - GCC: increase subdir_path/file_path buffer sizes in benchmark_writer.c to silence -Werror=format-truncation
- Remove #define _GNU_SOURCE from cmd_create.c and cmd_extract.c; CMake target_compile_definitions provides it for Linux without conflict - Add #include <process.h> to bfc_win32_compat.h to declare _getpid - Use fsync() fallback for bfc_os_sync() on macOS instead of fdatasync() (fdatasync availability under strict C17 is unreliable on macOS clang)
…hang - Add O_BINARY flag to open() in test_end_to_end_encryption for the second extraction (line 386 was missing it, unlike line 364 which had it); without O_BINARY on Windows text-mode open converts LF->CRLF causing size mismatch assertion - Suppress Windows assert() dialog box in test_main.c using _CrtSetReportMode so assertion failures print to stderr and exit instead of hanging on CI
On POSIX, replace the stat(path)+open(path) sequence with a single open(O_RDONLY|O_DIRECTORY|O_NOFOLLOW) probe. Branch on errno instead: - fd >= 0 → directory exists, update metadata via fd (fchmod/futimens) - ENOENT → create parent dirs then mkdir - ENOTDIR/ELOOP → non-dir or symlink at path; unlink if -f, then mkdir - other → hard error Windows path retains stat-based logic (O_DIRECTORY/O_NOFOLLOW unavailable). Resolves GitHub Advanced Security CodeQL TOCTOU alert at cmd_extract.c:288.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #9 — full Windows/MSVC build support for bfc, built on top of the existing
feature/windows-supportpartial work.bfc_win32_compat.h(lib) andcli_win32_compat.h(CLI) — full POSIX shims replacing inline definitions#if defined(_MSC_VER) || defined(_WIN32)covering both MSVC and MinGW/W4 /WX /wd4996,_CRT_SECURE_NO_WARNINGS)$env:VCPKG_INSTALLATION_ROOT(not hardcoded path), PowerShell syntax, unified test stepbfc-<version>-windows-x86_64.zipwithbfc.exe,bfc.lib, headers,install.battest_reader.c; ZSTD-guard pattern fixed for MSVC C4702Test plan
ctest -C Debug→100% tests passed/W4 /WXwarningswindows-latest