| 1011 | } |
| 1012 | |
| 1013 | DISABLE_WARNING_UNREACHABLE_CODE |
| 1014 | |
| 1015 | int |
| 1016 | getlock(void) |
| 1017 | { |
| 1018 | int fd, ern = 0, prompt_result = 1; |
| 1019 | int fcmask = FCMASK; |
| 1020 | #ifndef SELF_RECOVER |
| 1021 | char tbuf[BUFSZ]; |
| 1022 | #endif |
| 1023 | const char *fq_lock; |
| 1024 | #define OOPS_BUFSZ 512 |
| 1025 | char oops[OOPS_BUFSZ]; |
| 1026 | #ifdef WIN32CON |
| 1027 | boolean istty = WINDOWPORT(tty); |
| 1028 | #endif |
| 1029 | |
| 1030 | /* we ignore QUIT and INT at this point */ |
| 1031 | if (!lock_file(HLOCK, LOCKPREFIX, 10)) { |
| 1032 | wait_synch(); |
| 1033 | #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) |
| 1034 | chdirx(orgdir, 0); |
| 1035 | #endif |
| 1036 | error("Quitting."); |
| 1037 | } |
| 1038 | |
| 1039 | /* regularize(lock); */ /* already done in pcmain */ |
| 1040 | /*Sprintf(tbuf, "%s", fqname(gl.lock, LEVELPREFIX, 0)); */ |
| 1041 | set_levelfile_name(gl.lock, 0); |
| 1042 | fq_lock = fqname(gl.lock, LEVELPREFIX, 1); |
| 1043 | if ((fd = open(fq_lock, 0)) == -1) { |
| 1044 | if (errno == ENOENT) |
| 1045 | goto gotlock; /* no such file */ |
| 1046 | #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) |
| 1047 | chdirx(orgdir, 0); |
| 1048 | #endif |
| 1049 | error("Bad directory or name: %s\n%s\n", fq_lock, |
| 1050 | strerror(errno)); |
| 1051 | unlock_file(HLOCK); |
| 1052 | Sprintf(oops, "Cannot open %s", fq_lock); |
| 1053 | raw_print(oops); |
| 1054 | nethack_exit(EXIT_FAILURE); |
| 1055 | } |
| 1056 | |
| 1057 | (void) nhclose(fd); |
| 1058 | |
| 1059 | #ifdef WIN32CON |
| 1060 | if (WINDOWPORT(tty)) |
| 1061 | prompt_result = tty_self_recover_prompt(); |
| 1062 | else |
| 1063 | #endif |
| 1064 | prompt_result = other_self_recover_prompt(); |
| 1065 | /* |
| 1066 | * prompt_result == 1 means recover old game. |
| 1067 | * prompt_result == -1 means willfully destroy the old game. |
| 1068 | * prompt_result == 0 should just exit. |
| 1069 | */ |
| 1070 | Sprintf(oops, "You chose to %s.", |
no test coverage detected