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.50 by root, Sat Apr 21 23:03:54 2007 UTC vs.
Revision 1.51 by root, Mon Apr 23 18:09:57 2007 UTC

607 memcpy (dst + maxlen - 4, "...", 4); 607 memcpy (dst + maxlen - 4, "...", 4);
608 } 608 }
609 } 609 }
610 else 610 else
611 memcpy (dst, src, len + 1); 611 memcpy (dst, src, len + 1);
612}
613
614const std::string
615format (const char *format, ...)
616{
617 int len;
618
619 {
620 char buf[128];
621
622 va_list ap;
623 va_start (ap, format);
624 len = vsnprintf (buf, sizeof (buf), format, ap);
625 va_end (ap);
626
627 assert (len >= 0); // shield againstz broken vsnprintf's
628
629 // was our static buffer short enough?
630 if (len < sizeof (buf))
631 return std::string (buf, len);
632 }
633
634 {
635 // longer, try harder
636 char *buf = salloc<char> (len + 1);
637
638 va_list ap;
639 va_start (ap, format);
640 vsnprintf (buf, len + 1, format, ap);
641 va_end (ap);
642
643 const std::string s (buf, len);
644 sfree<char> (buf, len + 1);
645
646 return buf;
647 }
612} 648}
613 649
614tstamp now () 650tstamp now ()
615{ 651{
616 struct timeval tv; 652 struct timeval tv;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines