1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*
* ProFTPD - FTP server daemon
* Copyright (c) 1997, 1998 Public Flood Software
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
/* Memory allocation/anti-leak system. Yes, this *IS* stolen from Apache
* also. What can I say? It makes sense, and it's safe (more overhead
* though)
* $Id: pool.h,v 1.3 1999/08/31 01:31:59 flood Exp $
*/
#ifndef __POOL_H
#define __POOL_H
typedef struct pool pool;
extern pool *permanent_pool;
void init_alloc();
pool *make_sub_pool(pool*); /* All pools are sub-pools of perm */
pool *make_named_sub_pool(pool*,const char*);
/* Low-level memory allocation */
void *xmalloc(size_t);
void *xcalloc(size_t,size_t);
void *xrealloc(void*,size_t);
void pool_release_free_block_list(void);
/* Clears out _everything_ in a pool, destroying any sub-pools */
void destroy_pool(struct pool*);
void cleanup_for_exec();
/* allocate memory from a pool */
void *palloc(struct pool*, int nbytes);
void *pcalloc(struct pool*, int nbytes);
extern char *pstrdup(struct pool*, const char *s);
extern char *pstrndup(struct pool*, const char *s, int n);
char *pstrcat(struct pool*,...); /* Must be char* */
char *pdircat(struct pool*,...); /* Must be char* */
/* MM debugging */
void debug_walk_pools();
/* Array management */
typedef struct {
pool *pool;
int elt_size;
int nelts;
int nalloc;
void *elts;
} array_header;
array_header *make_array(pool *p, int nelts, int elt_size);
void *push_array(array_header*);
void array_cat(array_header *dst, const array_header *src);
array_header *append_arrays(pool *, const array_header *,
const array_header *);
array_header *copy_array(pool *p, const array_header *src);
array_header *copy_array_hdr(pool *p, const array_header *src);
/* Alarm signals can easily interfere with the pooled memory operations,
thus block_alarms() and unblock_alarms() provide for re-entrant
security. */
extern void block_alarms();
extern void unblock_alarms();
FILE *pfopen(struct pool *, const char *name, const char *fmode);
FILE *pfdopen(struct pool *, int fd, const char *fmode);
int popenf(struct pool *, const char *name, int flg, int mode);
int pfclose(struct pool *, FILE *);
int pclosef(struct pool *, int fd);
/* Functions for cleanup handlers */
void register_cleanup(pool*,void*,void (*plain_cleanup)(void*),
void (*child_cleanup)(void*));
void kill_cleanup(pool*,void*,void (*cleanup)(void*));
void cleanup_for_exec();
/* minimum free bytes in a new block pool */
#define BLOCK_MINFREE TUNABLE_NEW_POOL_SIZE
/* accounting */
long bytes_in_pool(pool *p);
long bytes_in_free_blocks();
#endif /* __POOL_H */
|