Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "file_util.h"
 
#include <gtest/gtest.h>
#include <stdio.h>
 
#ifdef _WIN32
#include <io.h>
#include <Windows.h>
#include <fcntl.h>
#endif
 
namespace onnxruntime {
namespace test {
 
PathString GetSharedLibraryFileName(const PathString& base_library_name) {
#if defined(_WIN32)
  constexpr auto kPrefix{ORT_TSTR("")}, kSuffix{ORT_TSTR(".dll")};
#elif defined(__APPLE__)
  constexpr auto kPrefix{ORT_TSTR("lib")}, kSuffix{ORT_TSTR(".dylib")};
#else
  constexpr auto kPrefix{ORT_TSTR("lib")}, kSuffix{ORT_TSTR(".so")};
#endif
 
  return PathString{kPrefix} + base_library_name + kSuffix;
}
 
void DeleteFileFromDisk(const ORTCHAR_T* path) {
#ifdef _WIN32
  ASSERT_EQ(TRUE, DeleteFileW(path));
#else
  ASSERT_EQ(0, unlink(path));
#endif
}
void CreateTestFile(int& out, std::basic_string<ORTCHAR_T>& filename_template) {
  if (filename_template.empty())
    ORT_THROW_EX(std::runtime_error, "file name template can't be empty");
 
  ORTCHAR_T* filename = const_cast<ORTCHAR_T*>(filename_template.c_str());
#ifdef _WIN32
  ASSERT_EQ(0, _wmktemp_s(filename, filename_template.length() + 1));
  int fd;
  int err = _wsopen_s(&fd, filename, _O_CREAT | _O_EXCL | _O_SEQUENTIAL | _O_BINARY | _O_WRONLY, _SH_DENYRW, _S_IREAD | _S_IWRITE);
  if (err != 0)
    ORT_THROW_EX(std::runtime_error, "open temp file failed");
#else
  int fd = mkstemp(filename);
  if (fd < 0) {
    ORT_THROW_EX(std::runtime_error, "open temp file failed");
  }
#endif
  out = fd;
}
void CreateTestFile(FILE*& out, std::basic_string<ORTCHAR_T>& filename_template) {
  if (filename_template.empty())
    ORT_THROW_EX(std::runtime_error, "file name template can't be empty");
 
  ORTCHAR_T* filename = const_cast<ORTCHAR_T*>(filename_template.c_str());
#ifdef _WIN32
  ASSERT_EQ(0, _wmktemp_s(filename, filename_template.length() + 1));
  FILE* fp = nullptr;
  ASSERT_EQ(0, _wfopen_s(&fp, filename, ORT_TSTR("wb")));
#else
  int fd = mkstemp(filename);
  if (fd < 0) {
    ORT_THROW_EX(std::runtime_error, "open temp file failed");
  }
  FILE* fp = fdopen(fd, "w");
#endif
  out = fp;
}
}  // namespace test
}  // namespace onnxruntime