39 #endif
40
41 return (p);
42 }
43
44 void
45 xfree(sysdem_ops_t *ops, void *p, size_t len)
46 {
47 if (p == NULL || len == 0)
48 return;
49
50 ops->free(p, len);
51 }
52
53 void *
54 xrealloc(sysdem_ops_t *ops, void *p, size_t oldsz, size_t newsz)
55 {
56 if (newsz == oldsz)
57 return (p);
58
59 ASSERT3U(newsz, >, oldsz);
60
61 void *temp = zalloc(ops, newsz);
62
63 if (temp == NULL)
64 return (NULL);
65
66 if (oldsz > 0) {
67 (void) memcpy(temp, p, oldsz);
68 xfree(ops, p, oldsz);
69 }
70
71 return (temp);
72 }
73
74 /*ARGSUSED*/
75 static void
76 def_free(void *p, size_t len)
77 {
78 free(p);
79 }
80
81 /* BEGIN CSTYLED */
82 sysdem_ops_t *sysdem_ops_default = &(sysdem_ops_t){
83 .alloc = malloc,
84 .free = def_free
85 };
86 /* END CSTYLED */
|
39 #endif
40
41 return (p);
42 }
43
44 void
45 xfree(sysdem_ops_t *ops, void *p, size_t len)
46 {
47 if (p == NULL || len == 0)
48 return;
49
50 ops->free(p, len);
51 }
52
53 void *
54 xrealloc(sysdem_ops_t *ops, void *p, size_t oldsz, size_t newsz)
55 {
56 if (newsz == oldsz)
57 return (p);
58
59 VERIFY3U(newsz, >, oldsz);
60
61 void *temp = zalloc(ops, newsz);
62
63 if (temp == NULL)
64 return (NULL);
65
66 if (oldsz > 0) {
67 (void) memcpy(temp, p, oldsz);
68 xfree(ops, p, oldsz);
69 }
70
71 return (temp);
72 }
73
74 /*ARGSUSED*/
75 static void
76 def_free(void *p, size_t len)
77 {
78 free(p);
79 }
80
81 static sysdem_ops_t i_sysdem_ops_default = {
82 .alloc = malloc,
83 .free = def_free
84 };
85 sysdem_ops_t *sysdem_ops_default = &i_sysdem_ops_default;
|