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.10 by root, Mon Sep 11 01:16:20 2006 UTC vs.
Revision 1.12 by root, Tue Sep 12 20:55:40 2006 UTC

1 1
2/* 2/*
3 * static char *rcsid_utils_c = 3 * static char *rcsid_utils_c =
4 * "$Id: utils.C,v 1.10 2006/09/11 01:16:20 root Exp $"; 4 * "$Id: utils.C,v 1.12 2006/09/12 20:55:40 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
531 531
532 strncpy (tmp, input, MAX_BUF - 5); 532 strncpy (tmp, input, MAX_BUF - 5);
533 /*trim all trailing commas, spaces etc. */ 533 /*trim all trailing commas, spaces etc. */
534 for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--) 534 for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--)
535 tmp[i] = '\0'; 535 tmp[i] = '\0';
536
536 strcat (tmp, "."); 537 strcat (tmp, ".");
537 538
538 p = strrchr (tmp, ','); 539 p = strrchr (tmp, ',');
539 if (p) 540 if (p)
540 { 541 {
544 strcat (input, " and"); 545 strcat (input, " and");
545 strcat (input, p); 546 strcat (input, p);
546 } 547 }
547 else 548 else
548 strcpy (input, tmp); 549 strcpy (input, tmp);
550
549 return; 551 return;
550} 552}
551 553
552void * 554void *alloc (int s) throw (std::bad_alloc)
553zero_initialised::operator new (size_t s, void *p)
554{ 555{
555 memset (p, 0, s); 556 if (s)
556 return p;
557}
558
559void *
560zero_initialised::operator new (size_t s)
561{
562 //return calloc (1, s);
563 return g_slice_alloc0 (s); 557 return g_slice_alloc (s);
558 else
559 return 0;
564} 560}
565 561
566void * 562void dealloc (void *p, int s) throw ()
567 zero_initialised::operator new[] (size_t s)
568{ 563{
569 //return calloc (1, s); 564 if (s)
570 return g_slice_alloc0 (s);
571}
572
573void
574zero_initialised::operator delete (void *p, size_t s)
575{
576 //free (p); return;
577 g_slice_free1 (s, p); 565 g_slice_free1 (s, p);
578} 566}
579 567
580void 568void assign (char *dst, const char *src, int maxlen)
581zero_initialised::operator delete[] (void *p, size_t s)
582{ 569{
583 //free (p); return; 570 if (!src)
584 g_slice_free1 (s, p); 571 src = "";
572
573 int len = strlen (src);
574
575 if (len >= maxlen - 1)
576 {
577 if (maxlen <= 4)
578 {
579 memset (dst, '.', maxlen - 1);
580 dst [maxlen - 1] = 0;
581 }
582 else
583 {
584 memcpy (dst, src, maxlen - 4);
585 memcpy (dst + maxlen - 4, "...", 4);
586 }
587 }
588 else
589 memcpy (dst, src, len + 1);
585} 590}
591

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines