ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/utils.C
(Generate patch)

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.64 by root, Fri Aug 10 11:02:44 2007 UTC vs.
Revision 1.67 by root, Tue Oct 16 05:34:24 2007 UTC

37#include <material.h> 37#include <material.h>
38 38
39#include <glib.h> 39#include <glib.h>
40 40
41refcnt_base::refcnt_t refcnt_dummy; 41refcnt_base::refcnt_t refcnt_dummy;
42 42size_t slice_alloc;
43rand_gen rndm; 43rand_gen rndm;
44 44
45void 45void
46tausworthe_random_generator::seed (uint32_t seed) 46tausworthe_random_generator::seed (uint32_t seed)
47{ 47{
472void *salloc_ (int n) throw (std::bad_alloc) 472void *salloc_ (int n) throw (std::bad_alloc)
473{ 473{
474#ifdef PREFER_MALLOC 474#ifdef PREFER_MALLOC
475 void *ptr = malloc (n); 475 void *ptr = malloc (n);
476#else 476#else
477 slice_alloc += n;
477 void *ptr = g_slice_alloc (n); 478 void *ptr = g_slice_alloc (n);
478#endif 479#endif
479 480
480 if (!ptr) 481 if (!ptr)
481 throw std::bad_alloc (); 482 throw std::bad_alloc ();
517 } 518 }
518 else 519 else
519 memcpy (dst, src, len + 1); 520 memcpy (dst, src, len + 1);
520} 521}
521 522
522const std::string 523const char *
523format (const char *format, ...) 524format (const char *format, ...)
524{ 525{
525 int len; 526 static dynbuf_text buf;
526 527
527 { 528 buf.clear ();
528 char buf[128];
529 529
530 va_list ap; 530 va_list ap;
531 va_start (ap, format); 531 va_start (ap, format);
532 len = vsnprintf (buf, sizeof (buf), format, ap); 532 buf.vprintf (format, ap);
533 va_end (ap); 533 va_end (ap);
534 534
535 assert (len >= 0); // shield againstz broken vsnprintf's
536
537 // was our static buffer short enough?
538 if (len < sizeof (buf))
539 return std::string (buf, len);
540 }
541
542 {
543 // longer, try harder
544 char *buf = salloc<char> (len + 1);
545
546 va_list ap;
547 va_start (ap, format);
548 vsnprintf (buf, len + 1, format, ap);
549 va_end (ap);
550
551 const std::string s (buf, len);
552 sfree<char> (buf, len + 1);
553
554 return buf; 535 return buf;
555 }
556} 536}
557 537
558tstamp now () 538tstamp now ()
559{ 539{
560 struct timeval tv; 540 struct timeval tv;
628 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, 608 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
629 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, 609 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
630 0x2d02ef8dL 610 0x2d02ef8dL
631}; 611};
632 612
633#if 0
634void xyzzy (object_ptr &a, object_ptr &o)
635{
636 asm volatile ("int3");
637 a = o;
638 asm volatile ("int3");
639}
640#endif
641

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines