… | |
… | |
27 | |
27 | |
28 | #include <global.h> |
28 | #include <global.h> |
29 | #include <funcpoint.h> |
29 | #include <funcpoint.h> |
30 | #include <material.h> |
30 | #include <material.h> |
31 | |
31 | |
|
|
32 | #include <sys/time.h> |
|
|
33 | #include <time.h> |
32 | #include <glib.h> |
34 | #include <glib.h> |
33 | |
35 | |
34 | /* |
36 | /* |
35 | * The random functions here take luck into account when rolling random |
37 | * The random functions here take luck into account when rolling random |
36 | * dice or numbers. This function has less of an impact the larger the |
38 | * dice or numbers. This function has less of an impact the larger the |
… | |
… | |
555 | assert (!rc_next); |
557 | assert (!rc_next); |
556 | assert (!refcnt); |
558 | assert (!refcnt); |
557 | } |
559 | } |
558 | #endif |
560 | #endif |
559 | |
561 | |
560 | void *alloc (int s) throw (std::bad_alloc) |
562 | void *salloc (int size) throw (std::bad_alloc) |
561 | { |
563 | { |
562 | void *p = g_slice_alloc (s); |
564 | void *ptr = g_slice_alloc (size); |
563 | |
565 | |
564 | if (!p) |
566 | if (!ptr) |
565 | throw std::bad_alloc (); |
567 | throw std::bad_alloc (); |
566 | |
568 | |
567 | return p; |
569 | return ptr; |
|
|
570 | } |
|
|
571 | |
|
|
572 | void *salloc (int size, void *src) throw (std::bad_alloc) |
|
|
573 | { |
|
|
574 | void *ptr = salloc (size); |
|
|
575 | |
|
|
576 | memcpy (ptr, src, size); |
|
|
577 | |
|
|
578 | return ptr; |
568 | } |
579 | } |
569 | |
580 | |
570 | void assign (char *dst, const char *src, int maxlen) |
581 | void assign (char *dst, const char *src, int maxlen) |
571 | { |
582 | { |
572 | if (!src) |
583 | if (!src) |
… | |
… | |
589 | } |
600 | } |
590 | else |
601 | else |
591 | memcpy (dst, src, len + 1); |
602 | memcpy (dst, src, len + 1); |
592 | } |
603 | } |
593 | |
604 | |
|
|
605 | tstamp now () |
|
|
606 | { |
|
|
607 | struct timeval tv; |
594 | |
608 | |
|
|
609 | gettimeofday (&tv, 0); |
|
|
610 | return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); |
|
|
611 | } |
|
|
612 | |