Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ if(CORTEXT_EMBED_OBJSTORE)
${CMAKE_CURRENT_SOURCE_DIR}/third_party/sqlite-objstore/src/backend_sqlite.c
)
endif()
if(WIN32)
list(APPEND CORTEXT_OBJSTORE_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/third_party/sqlite-objstore/src/win_dirent.c
)
endif()
if(CORTEXT_TARGET_AARCH64)
list(APPEND CORTEXT_OBJSTORE_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/third_party/sqlite-objstore/third_party/blake3/blake3_neon.c
Expand Down
4 changes: 4 additions & 0 deletions third_party/sqlite-objstore/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ if(OBJSTORE_BACKEND_VFS)
list(APPEND OBJSTORE_SOURCES backend_vfs.c)
endif()

if(WIN32)
list(APPEND OBJSTORE_SOURCES win_dirent.c)
endif()

function(_objstore_configure_library target)
target_include_directories(${target}
PUBLIC
Expand Down
4 changes: 4 additions & 0 deletions third_party/sqlite-objstore/src/backend_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

#include "backend_fs_common.h"

#if defined(_WIN32)
#include "win_dirent.h"
#else
#include <dirent.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
Expand Down
4 changes: 4 additions & 0 deletions third_party/sqlite-objstore/src/backend_fs_common.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "backend_fs_common.h"

#if defined(_WIN32)
#include "win_dirent.h"
#else
#include <dirent.h>
#endif
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
Expand Down
4 changes: 4 additions & 0 deletions third_party/sqlite-objstore/src/backend_portable.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "backend_portable.h"

#if defined(_WIN32)
#include "win_dirent.h"
#else
#include <dirent.h>
#endif
#include <errno.h>
#include <limits.h>
#include <stddef.h>
Expand Down
85 changes: 85 additions & 0 deletions third_party/sqlite-objstore/src/win_dirent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "win_dirent.h"

#include <errno.h>
#include <stdlib.h>
#include <string.h>

#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

DIR *
opendir (const char *path)
{
DIR *dir;
WIN32_FIND_DATAA find_data;
HANDLE handle;

if (path == NULL)
{
errno = ENOENT;
return NULL;
}

dir = (DIR *) malloc (sizeof (DIR));
if (dir == NULL)
{
errno = ENOMEM;
return NULL;
}

handle = FindFirstFileA (path, &find_data);
if (handle == INVALID_HANDLE_VALUE)
{
free (dir);
errno = ENOENT;
return NULL;
}

dir->handle = (void *) handle;
memcpy (dir->entry.d_name, find_data.cFileName,
sizeof (find_data.cFileName));
dir->entry_valid = 1;
Comment on lines +30 to +41
return dir;
}

struct dirent *
readdir (DIR *dir)
{
WIN32_FIND_DATAA find_data;

if (dir == NULL)
{
errno = EBADF;
return NULL;
}

if (dir->entry_valid)
{
dir->entry_valid = 0;
return &dir->entry;
}

if (!FindNextFileA ((HANDLE) dir->handle, &find_data))
{
return NULL;
}

memcpy (dir->entry.d_name, find_data.cFileName,
sizeof (find_data.cFileName));
dir->entry_valid = 1;
Comment on lines +67 to +69
return &dir->entry;
}

int
closedir (DIR *dir)
{
if (dir == NULL)
{
errno = EBADF;
return -1;
}

FindClose ((HANDLE) dir->handle);
free (dir);
return 0;
}
36 changes: 36 additions & 0 deletions third_party/sqlite-objstore/src/win_dirent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef OBJSTORE_WIN_DIRENT_H
#define OBJSTORE_WIN_DIRENT_H

/*
* Minimal POSIX dirent subset for Windows (MSVC and clang-cl).
*
* sqlite-objstore only needs opendir(), readdir(), closedir(), and
* d_name; the system <dirent.h> does not exist on Windows. On other
* platforms the real <dirent.h> is used instead.
*/

#ifdef __cplusplus
extern "C" {
#endif

struct dirent
{
char d_name[260];
};

typedef struct
{
void *handle;
int entry_valid;
struct dirent entry;
} DIR;

DIR *opendir (const char *path);
struct dirent *readdir (DIR *dir);
int closedir (DIR *dir);

#ifdef __cplusplus
}
#endif

#endif /* OBJSTORE_WIN_DIRENT_H */
Loading