unlock file, which must be currently locked by lock_file */
| 2413 | |
| 2414 | /* unlock file, which must be currently locked by lock_file */ |
| 2415 | void |
| 2416 | unlock_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 |
no test coverage detected