Skip to content

Commit

Permalink
Merge pull request #649 from jrade/main
Browse files Browse the repository at this point in the history
Fixed compilation error with Visual Studio
  • Loading branch information
erikbern committed Jun 2, 2023
2 parents 71c3951 + 62a6b24 commit 7595fb3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/annoylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,11 @@ template<typename S, typename T, typename Distance, typename Random, class Threa

bool on_disk_build(const char* file, char** error=NULL) {
_on_disk = true;
#ifndef _MSC_VER
_fd = open(file, O_RDWR | O_CREAT | O_TRUNC, (int) 0600);
#else
_fd = _open(file, _O_RDWR | _O_CREAT | _O_TRUNC, (int) 0600);
#endif
if (_fd == -1) {
set_error_from_errno(error, "Unable to open");
_fd = 0;
Expand Down Expand Up @@ -1013,7 +1017,11 @@ template<typename S, typename T, typename Distance, typename Random, class Threa
return true;
} else {
// Delete file if it already exists (See issue #335)
#ifndef _MSC_VER
unlink(filename);
#else
_unlink(filename);
#endif

FILE *f = fopen(filename, "wb");
if (f == NULL) {
Expand Down Expand Up @@ -1050,12 +1058,20 @@ template<typename S, typename T, typename Distance, typename Random, class Threa

void unload() {
if (_on_disk && _fd) {
#ifndef _MSC_VER
close(_fd);
#else
_close(_fd);
#endif
munmap(_nodes, _s * _nodes_size);
} else {
if (_fd) {
// we have mmapped data
#ifndef _MSC_VER
close(_fd);
#else
_close(_fd);
#endif
munmap(_nodes, _n_nodes * _s);
} else if (_nodes) {
// We have heap allocated data
Expand All @@ -1067,7 +1083,11 @@ template<typename S, typename T, typename Distance, typename Random, class Threa
}

bool load(const char* filename, bool prefault=false, char** error=NULL) {
#ifndef _MSC_VER
_fd = open(filename, O_RDONLY, (int)0400);
#else
_fd = _open(filename, _O_RDONLY, (int)0400);
#endif
if (_fd == -1) {
set_error_from_errno(error, "Unable to open");
_fd = 0;
Expand Down

0 comments on commit 7595fb3

Please sign in to comment.