VaneDB 0.1.0
Embeddable vector database for edge AI
Loading...
Searching...
No Matches
file_utils.h
Go to the documentation of this file.
1// VaneDB - Copyright (c) 2025 Anton Tsvetkov - MIT License
2#pragma once
3
4#include <string>
5
6#if defined(_WIN32) || defined(_WIN64)
7#ifndef NOMINMAX
8#define NOMINMAX
9#endif
10#include <windows.h>
11#elif defined(__unix__) || defined(__APPLE__)
12#include <fcntl.h>
13#include <unistd.h>
14#endif
15
16namespace vanedb {
17namespace detail {
18
24inline void fsync_file(const std::string& path) noexcept {
25#if defined(_WIN32) || defined(_WIN64)
26 HANDLE hFile = CreateFileA(path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL,
27 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
28 if (hFile != INVALID_HANDLE_VALUE) { FlushFileBuffers(hFile); CloseHandle(hFile); }
29#elif defined(__unix__) || defined(__APPLE__)
30 int fd = open(path.c_str(), O_WRONLY);
31 if (fd >= 0) { fsync(fd); close(fd); }
32#endif
33}
34
35} // namespace detail
36} // namespace vanedb
void fsync_file(const std::string &path) noexcept
Definition file_utils.h:24