MCPcopy Index your code
hub / github.com/NetHack/NetHack / open

Function open

outdated/sys/wince/celib.c:204–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202}
203
204int __cdecl open(const char *filename, int oflag, ...)
205{
206 TCHAR fname[MAX_PATH + 1];
207 TCHAR path[MAX_PATH + 1];
208 HANDLE f;
209 DWORD fileaccess;
210 DWORD filecreate;
211
212 /* O_TEXT is not supported */
213
214 /*
215 * decode the access flags
216 */
217 switch (oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
218 case _O_RDONLY: /* read access */
219 fileaccess = GENERIC_READ;
220 break;
221 case _O_WRONLY: /* write access */
222 fileaccess = GENERIC_READ | GENERIC_WRITE;
223 break;
224 case _O_RDWR: /* read and write access */
225 fileaccess = GENERIC_READ | GENERIC_WRITE;
226 break;
227 default: /* error, bad oflag */
228 return -1;
229 }
230
231 /*
232 * decode open/create method flags
233 */
234 switch (oflag & (_O_CREAT | _O_EXCL | _O_TRUNC)) {
235 case 0:
236 case _O_EXCL: // ignore EXCL w/o CREAT
237 filecreate = OPEN_EXISTING;
238 break;
239
240 case _O_CREAT:
241 filecreate = OPEN_ALWAYS;
242 break;
243
244 case _O_CREAT | _O_EXCL:
245 case _O_CREAT | _O_TRUNC | _O_EXCL:
246 filecreate = CREATE_NEW;
247 break;
248
249 case _O_TRUNC:
250 case _O_TRUNC | _O_EXCL: // ignore EXCL w/o CREAT
251 filecreate = TRUNCATE_EXISTING;
252 break;
253
254 case _O_CREAT | _O_TRUNC:
255 filecreate = CREATE_ALWAYS;
256 break;
257
258 default:
259 return -1;
260 }
261

Callers 15

tty_display_fileFunction · 0.85
getlockFunction · 0.85
getlockFunction · 0.85
vms_openFunction · 0.85
getlockFunction · 0.85
getlockFunction · 0.85
pcmainFunction · 0.85
crashreport_initFunction · 0.85
submit_web_reportFunction · 0.85
create_levelfileFunction · 0.85
open_levelfileFunction · 0.85
create_bonesfileFunction · 0.85

Calls 1

alloc_file_handleFunction · 0.85

Tested by

no test coverage detected