MCPcopy Create free account
hub / github.com/alibaba/MNN / MNNOpenFile

Function MNNOpenFile

source/core/MNNFileUtils.cpp:88–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88file_t MNNOpenFile(const char * file_name, uint32_t flags)
89{
90 if (!MNNFileExist(file_name)) {
91 MNN_PRINT("File not exist: %s\n", file_name);
92 return INVALID_FILE;
93 }
94#if defined(WIN32) || defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)
95 DWORD mode = 0;
96 if (flags & MNN_FILE_READ) {
97 mode |= GENERIC_READ;
98 }
99 if (flags & MNN_FILE_WRITE) {
100 mode |= GENERIC_WRITE;
101 }
102 HANDLE hd = CreateFile(
103 file_name, // File Name
104 mode, // Opening Mode
105 0, // No Sharing
106 NULL, // No Security
107 OPEN_EXISTING, // Only Open Existing File
108 FILE_ATTRIBUTE_NORMAL, // Normal Attribute
109 NULL // No Template
110 );
111 if (hd == INVALID_HANDLE_VALUE) {
112 MNN_PRINT("Failed to open the file: %s\n", file_name);
113 return INVALID_FILE;
114 }
115 return hd;
116#else
117 int mode = 0;
118 if (flags & MNN_FILE_READ) {
119 mode = O_RDONLY;
120 }
121 if (flags & MNN_FILE_WRITE) {
122 mode = O_RDWR;
123 }
124 int fd = open(file_name, mode);
125 if (fd == -1) {
126 MNN_PRINT("Failed to open the file: %s\n", file_name);
127 return INVALID_FILE;
128 }
129 return fd;
130#endif
131}
132
133ErrorCode MNNCloseFile(file_t file)
134{

Callers 10

mainFunction · 0.85
mainFunction · 0.85
setPrefixCacheFileMethod · 0.85
onAllocMethod · 0.85
onCreateMethod · 0.85
onExecuteMethod · 0.85
onAllocMethod · 0.85
openMethod · 0.85
onAllocMethod · 0.85
runMethod · 0.85

Calls 2

MNNFileExistFunction · 0.85
openFunction · 0.85

Tested by 1

runMethod · 0.68