File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 1717#include < fcntl.h>
1818#include < sys/stat.h>
1919#include < sys/types.h>
20- #include < unistd.h>
20+ #include < executorch/runtime/platform/ unistd.h>
2121
2222#include < executorch/runtime/core/error.h>
2323#include < executorch/runtime/core/result.h>
2626// Some platforms (e.g. Xtensa) do not support pread() that we use to read the
2727// file at different offsets simultaneously from multiple threads not affecting
2828// each other. We list them below and use a workaround for them.
29- #if defined(__xtensa__)
29+ #if defined(__xtensa__) || defined(_WIN64)
3030#define ET_HAVE_PREAD 0
31- #endif // defined(__xtensa__)
31+ #endif // defined(__xtensa__) || defined(_WIN64)
3232
3333#ifndef ET_HAVE_PREAD
3434#define ET_HAVE_PREAD 1
@@ -71,6 +71,9 @@ FileDataLoader::~FileDataLoader() {
7171 std::free (const_cast <char *>(file_name_));
7272 // fd_ can be -1 if this instance was moved from, but closing a negative fd is
7373 // safe (though it will return an error).
74+ if (fd_ == -1 ) {
75+ return ;
76+ }
7477 ::close (fd_);
7578}
7679
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3+ * All rights reserved.
4+ *
5+ * This source code is licensed under the BSD-style license found in the
6+ * LICENSE file in the root directory of this source tree.
7+ */
8+
9+ /**
10+ * @file
11+ * unistd.h related macros for POSIX/Windows compatibility.
12+ */
13+ #pragma once
14+
15+ #if defined(_WIN32 ) && !defined(_WIN64 )
16+ #error "You're trying to build ExecuTorch with a too old version of Windows. We need Windows 64-bit."
17+ #endif
18+
19+ #if !defined(_WIN64 )
20+ #include <unistd.h>
21+ #else
22+ #include <io.h>
23+ #define O_RDONLY _O_RDONLY
24+ #define open _open
25+ #define close _close
26+ #define read _read
27+ #define write _write
28+ #define stat _stat64
29+ #define fstat _fstat64
30+ #define off_t _off_t
31+ #define lseek _lseeki64
32+
33+ #endif // !defined(_WIN64)
You can’t perform that action at this time.
0 commit comments