MCPcopy Create free account
hub / github.com/NetHack/NetHack / unlock_file

Function unlock_file

src/files.c:2415–2456  ·  view source on GitHub ↗

unlock file, which must be currently locked by lock_file */

Source from the content-addressed store, hash-verified

2413
2414/* unlock file, which must be currently locked by lock_file */
2415void
2416unlock_file(const char *filename)
2417{
2418#ifndef USE_FCNTL
2419 char locknambuf[BUFSZ];
2420 const char *lockname;
2421#endif
2422
2423 if (gn.nesting == 1) {
2424#ifdef USE_FCNTL
2425 sflock.l_type = F_UNLCK;
2426 if (lockfd >= 0) {
2427 if (fcntl(lockfd, F_SETLK, &sflock) == -1)
2428 HUP raw_printf("Can't remove fcntl lock on %s.", filename);
2429 (void) close(lockfd), lockfd = -1;
2430 }
2431#else
2432 lockname = make_lockname(filename, locknambuf);
2433#ifndef NO_FILE_LINKS /* LOCKDIR should be subsumed by LOCKPREFIX */
2434 lockname = fqname(lockname, LOCKPREFIX, 2);
2435#endif
2436
2437#if defined(UNIX) || defined(VMS)
2438 if (unlink(lockname) < 0)
2439 HUP raw_printf("Can't unlink %s.", lockname);
2440#ifdef NO_FILE_LINKS
2441 (void) nhclose(lockfd), lockfd = -1;
2442#endif
2443
2444#endif /* UNIX || VMS */
2445
2446#if defined(AMIGA) || defined(WIN32) || defined(MSDOS)
2447 if (gl.lockptr)
2448 Close(gl.lockptr);
2449 DeleteFile(lockname);
2450 gl.lockptr = 0;
2451#endif /* AMIGA || WIN32 || MSDOS */
2452#endif /* USE_FCNTL */
2453 }
2454
2455 gn.nesting--;
2456}
2457
2458#undef UNUSED_conditional
2459

Callers 9

getlockFunction · 0.85
ask_about_panic_saveFunction · 0.85
getlockFunction · 0.85
getlockFunction · 0.85
getlockFunction · 0.85
pcunix.cFile · 0.85
toptenFunction · 0.85
livelog_addFunction · 0.85
getlockFunction · 0.85

Calls 6

closeFunction · 0.85
make_locknameFunction · 0.85
fqnameFunction · 0.85
unlinkFunction · 0.85
nhcloseFunction · 0.85
raw_printfFunction · 0.70

Tested by

no test coverage detected