1 |
/* This file is part of GNU RADIUS. |
/* This file is part of GNU Radius. |
2 |
Copyright (C) 2000,2001 Sergey Poznyakoff |
Copyright (C) 2000,2001,2002,2003 Sergey Poznyakoff |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Radius is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
7 |
(at your option) any later version. |
(at your option) any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Radius is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
GNU General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software Foundation, |
along with GNU Radius; if not, write to the Free Software Foundation, |
16 |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
|
#ifndef lint |
|
|
static char rcsid[] = |
|
|
"$Id$"; |
|
|
#endif |
|
|
|
|
18 |
#define RADIUS_MODULE_MEM_C |
#define RADIUS_MODULE_MEM_C |
19 |
|
|
20 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
78 |
sizeof(Align_t)*((size + sizeof(Align_t) - 1) / sizeof(Align_t)) |
sizeof(Align_t)*((size + sizeof(Align_t) - 1) / sizeof(Align_t)) |
79 |
|
|
80 |
size_t |
size_t |
81 |
mem_effective_size(size) |
mem_effective_size(size_t size) |
|
size_t size; |
|
82 |
{ |
{ |
83 |
if (size < ENTRY_SIZE) |
if (size < ENTRY_SIZE) |
84 |
size = ENTRY_SIZE; |
size = ENTRY_SIZE; |
119 |
#define free_class mem_free |
#define free_class mem_free |
120 |
|
|
121 |
Bucketclass |
Bucketclass |
122 |
alloc_class(size) |
alloc_class(size_t size) |
|
size_t size; |
|
123 |
{ |
{ |
124 |
Bucketclass bcp; |
Bucketclass bcp; |
125 |
count_t count; |
count_t count; |
153 |
|
|
154 |
|
|
155 |
Bucket |
Bucket |
156 |
alloc_bucket(class) |
alloc_bucket(Bucketclass class) |
|
Bucketclass class; |
|
157 |
{ |
{ |
158 |
Bucket bp; |
Bucket bp; |
159 |
union { |
union { |
202 |
*/ |
*/ |
203 |
|
|
204 |
void * |
void * |
205 |
mem_alloc_nl(size) |
mem_alloc_nl(size_t size) |
|
size_t size; |
|
206 |
{ |
{ |
207 |
Bucketclass class_ptr; |
Bucketclass class_ptr; |
208 |
Entry ptr; |
Entry ptr; |
236 |
} |
} |
237 |
|
|
238 |
void * |
void * |
239 |
mem_alloc(size) |
mem_alloc(size_t size) |
|
size_t size; |
|
240 |
{ |
{ |
241 |
void *p; |
void *p; |
242 |
mem_lock(); |
mem_lock(); |
246 |
} |
} |
247 |
|
|
248 |
void |
void |
249 |
put_back(class, ptr) |
put_back(Bucketclass class, void *ptr) |
|
Bucketclass class; |
|
|
void *ptr; |
|
250 |
{ |
{ |
251 |
Entry eptr = (Entry)ptr; |
Entry eptr = (Entry)ptr; |
252 |
|
|
261 |
} |
} |
262 |
|
|
263 |
void |
void |
264 |
mem_free(ptr) |
mem_free(void *ptr) |
|
void *ptr; |
|
265 |
{ |
{ |
266 |
Bucketclass class; |
Bucketclass class; |
267 |
Bucket bucket; |
Bucket bucket; |
289 |
/* Allocate COUNT contiguous objects of size SIZE |
/* Allocate COUNT contiguous objects of size SIZE |
290 |
*/ |
*/ |
291 |
void * |
void * |
292 |
mem_calloc(count, size) |
mem_calloc(count_t count, size_t size) |
|
count_t count; |
|
|
size_t size; |
|
293 |
{ |
{ |
294 |
Bucketclass class_ptr; |
Bucketclass class_ptr; |
295 |
Entry first, last; |
Entry first, last; |
389 |
* allocated using mem_calloc(). |
* allocated using mem_calloc(). |
390 |
*/ |
*/ |
391 |
void |
void |
392 |
mem_cfree(ptr, count) |
mem_cfree(void *ptr, count_t count) |
|
void *ptr; |
|
|
count_t count; |
|
393 |
{ |
{ |
394 |
Bucketclass class; |
Bucketclass class; |
395 |
Bucket bucket; |
Bucket bucket; |
408 |
} |
} |
409 |
|
|
410 |
void |
void |
411 |
put_back_cont(class, ptr, count) |
put_back_cont(Bucketclass class, void *ptr, count_t count) |
|
Bucketclass class; |
|
|
void *ptr; |
|
|
count_t count; |
|
412 |
{ |
{ |
413 |
int i; |
int i; |
414 |
Entry sptr = (Entry)ptr; |
Entry sptr = (Entry)ptr; |
472 |
/* string_alloc(): Allocate a string of given length |
/* string_alloc(): Allocate a string of given length |
473 |
*/ |
*/ |
474 |
char * |
char * |
475 |
string_alloc(length) |
string_alloc(size_t length) |
|
size_t length; |
|
476 |
{ |
{ |
477 |
count_t count; |
count_t count; |
478 |
STRHDR *p; |
STRHDR *p; |
492 |
* STRVAL and store the latter into it. |
* STRVAL and store the latter into it. |
493 |
*/ |
*/ |
494 |
char * |
char * |
495 |
string_create(strval) |
string_create(char *strval) |
|
char *strval; |
|
496 |
{ |
{ |
497 |
char *p; |
char *p; |
498 |
if (!strval) |
if (!strval) |
504 |
/* string_dup(): create a copy of existing string object |
/* string_dup(): create a copy of existing string object |
505 |
*/ |
*/ |
506 |
char * |
char * |
507 |
string_dup(str) |
string_dup(char *str) |
|
char *str; |
|
508 |
{ |
{ |
509 |
STRHDR *hp; |
STRHDR *hp; |
510 |
|
|
524 |
* with the new string value. |
* with the new string value. |
525 |
*/ |
*/ |
526 |
char * |
char * |
527 |
string_replace(str, string_value) |
string_replace(char **str, char *string_value) |
|
char **str; |
|
|
char *string_value; |
|
528 |
{ |
{ |
529 |
int length = strlen(string_value); |
int length = strlen(string_value); |
530 |
STRHDR *hp; |
STRHDR *hp; |
549 |
* and deallocate the object when the counter becomes zero |
* and deallocate the object when the counter becomes zero |
550 |
*/ |
*/ |
551 |
void |
void |
552 |
string_free(str) |
string_free(char *str) |
|
char *str; |
|
553 |
{ |
{ |
554 |
STRHDR *hp; |
STRHDR *hp; |
555 |
|
|
568 |
*/ |
*/ |
569 |
|
|
570 |
void |
void |
571 |
mem_get_stat(stat) |
mem_get_stat(MEM_STAT *stat) |
|
MEM_STAT *stat; |
|
572 |
{ |
{ |
573 |
Bucketclass class; |
Bucketclass class; |
574 |
|
|
592 |
} |
} |
593 |
|
|
594 |
int |
int |
595 |
mem_stat_enumerate(fun, closure) |
mem_stat_enumerate(int (*fun)(), void *closure) |
|
int (*fun)(); |
|
|
void *closure; |
|
596 |
{ |
{ |
597 |
CLASS_STAT stat; |
CLASS_STAT stat; |
598 |
Bucketclass class; |
Bucketclass class; |
612 |
|
|
613 |
#ifdef MAINTAINER_MODE |
#ifdef MAINTAINER_MODE |
614 |
int |
int |
615 |
check_cont(class) |
check_cont(Bucketclass class) |
|
Bucketclass class; |
|
616 |
{ |
{ |
617 |
Entry ep, prev; |
Entry ep, prev; |
618 |
|
|