MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / open_file

Function open_file

extra/innochecksum.cc:143–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141*/
142
143FILE*
144open_file(
145 const char* name)
146{
147 int fd; /* file descriptor. */
148 FILE* fil_in;
149#ifdef __WIN__
150 HANDLE hFile; /* handle to open file. */
151 DWORD access; /* define access control */
152 int flags; /* define the mode for file
153 descriptor */
154
155 access = GENERIC_READ;
156 flags = _O_RDONLY | _O_BINARY;
157 hFile = CreateFile(
158 (LPCTSTR) name, access, 0L, NULL,
159 OPEN_EXISTING, NULL, NULL);
160
161 if (hFile == INVALID_HANDLE_VALUE) {
162 /* print the error message. */
163 fprintf(stderr, "Filename::%s %s\n",
164 win32_error_message(GetLastError()));
165
166 return (NULL);
167 }
168
169 /* get the file descriptor. */
170 fd= _open_osfhandle((intptr_t)hFile, flags);
171#else /* __WIN__ */
172
173 int create_flag;
174 create_flag = O_RDONLY;
175
176 fd = open(name, create_flag);
177 if ( -1 == fd) {
178 perror("open");
179 return (NULL);
180 }
181
182#endif /* __WIN__ */
183
184 fil_in = fdopen(fd, "rb");
185
186 return (fil_in);
187}
188
189/* command line argument to do page checks (that's it) */
190/* another argument to specify page ranges... seek to right spot and go from there */

Callers 1

innochecksum.ccFile · 0.70

Calls 2

win32_error_messageFunction · 0.85
perrorFunction · 0.85

Tested by

no test coverage detected