--- deliantra/server/common/utils.C 2007/04/21 22:57:15 1.49 +++ deliantra/server/common/utils.C 2007/04/27 19:53:57 1.53 @@ -65,16 +65,16 @@ } uint32_t -tausworthe_random_generator::get_range (uint32_t r_max) +tausworthe_random_generator::get_range (uint32_t num) { - return (next () * (uint64_t)r_max) >> 32U; + return (next () * (uint64_t)num) >> 32U; } // return a number within (min .. max) int tausworthe_random_generator::get_range (int r_min, int r_max) { - return r_min + get_range (max (r_max - r_min + 1, 1)); + return r_min + get_range (max (r_max - r_min + 1, 0)); } /* @@ -99,7 +99,7 @@ if (r_max < 1 || r_max < r_min) { - LOG (llevError, "Calling random_roll with min=%d max=%d\n", r_min, r_max); + LOG (llevError | log_Backtrace, "Calling random_roll with min=%d max=%d\n", r_min, r_max); return r_min; } @@ -132,7 +132,7 @@ if (max < 1 || diff < 1) { - LOG (llevError, "Calling random_roll with min=%" PRId64 " max=%" PRId64 "\n", min, max); + LOG (llevError | log_Backtrace, "Calling random_roll64 with min=%" PRId64 " max=%" PRId64 "\n", min, max); return (min); /* avoids a float exception */ } @@ -555,6 +555,9 @@ if (!fork ()) { signal (SIGABRT, SIG_DFL); + // try to put corefiles into a subdirectory, if existing, to allow + // an administrator to reduce the I/O load. + chdir ("cores"); abort (); } @@ -611,6 +614,42 @@ memcpy (dst, src, len + 1); } +const std::string +format (const char *format, ...) +{ + int len; + + { + char buf[128]; + + va_list ap; + va_start (ap, format); + len = vsnprintf (buf, sizeof (buf), format, ap); + va_end (ap); + + assert (len >= 0); // shield againstz broken vsnprintf's + + // was our static buffer short enough? + if (len < sizeof (buf)) + return std::string (buf, len); + } + + { + // longer, try harder + char *buf = salloc (len + 1); + + va_list ap; + va_start (ap, format); + vsnprintf (buf, len + 1, format, ap); + va_end (ap); + + const std::string s (buf, len); + sfree (buf, len + 1); + + return buf; + } +} + tstamp now () { struct timeval tv;