/** Set a file's access and modify time to u.udeathday. */ static void adjust_file_timestamp(const char *fpath) { # ifdef HAVE_UTIME_H if (u.udeathday > 0) { struct utimbuf tv; tv.actime = u.udeathday; tv.modtime = u.udeathday; if (utime(fpath, &tv)) { paniclog("adjust_file_timestamp: utime failed: ", strerror(errno)); } } # endif }
/*VARARGS1*/ noreturn void panic_core(const char *file, int line, const char *str, ...) { va_list the_args; const char *buf; nonfatal_dump_core(); va_start(the_args, str); if (program_state.panicking++) terminate(GAME_DETACHED); /* avoid loops - this should never happen */ buf = msgvprintf(str, the_args, TRUE); paniclog("panic", buf); DEBUG_LOG_BACKTRACE("panic() called: %s\n", buf); log_recover_noreturn(get_log_start_of_turn_offset(), buf, file, line); }
/*VARARGS1*/ void impossible_core(const char *file, int line, const char *s, ...) { nonfatal_dump_core(); va_list args; const char *pbuf; va_start(args, s); if (program_state.in_impossible) panic("impossible called impossible"); program_state.in_impossible = 1; pbuf = msgvprintf(s, args, TRUE); paniclog("impossible", pbuf); DEBUG_LOG_BACKTRACE("impossible() called: %s\n", pbuf); va_end(args); program_state.in_impossible = 0; log_recover_core(get_log_start_of_turn_offset(), TRUE, pbuf, file, line); }
/* * Parameter validator for generic yes/no function to prevent * the core from sending too long a prompt string to the * window port causing a buffer overflow there. */ char yn_function(const char *query,const char *resp, char def) { char qbuf[QBUFSZ], key; unsigned truncspot, reduction = sizeof(" [N] ?") + 1; if (resp) reduction += strlen(resp) + sizeof(" () "); if (strlen(query) >= (QBUFSZ - reduction)) { paniclog("Query truncated: ", query); reduction += sizeof("..."); truncspot = QBUFSZ - reduction; strncpy(qbuf, query, (int)truncspot); qbuf[truncspot] = '\0'; strcat(qbuf,"..."); } else strcpy(qbuf, query); key = (*windowprocs.win_yn_function)(qbuf, resp, def); log_yn_function(key); return key; }