Blame libmisc/high_water_alloc.c
|
rpm-build |
0a0c83 |
/*
|
|
rpm-build |
0a0c83 |
File: high_water_alloc.c
|
|
rpm-build |
0a0c83 |
|
|
rpm-build |
0a0c83 |
Copyright (C) 2001-2002 Silicon Graphics, Inc. All Rights Reserved.
|
|
rpm-build |
0a0c83 |
|
|
rpm-build |
0a0c83 |
This program is free software; you can redistribute it and/or modify it under
|
|
rpm-build |
0a0c83 |
the terms of the GNU Lesser General Public License as published by the
|
|
rpm-build |
0a0c83 |
Free Software Foundation; either version 2.1 of the License, or (at
|
|
rpm-build |
0a0c83 |
your option) any later version.
|
|
rpm-build |
0a0c83 |
|
|
rpm-build |
0a0c83 |
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
rpm-build |
0a0c83 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
rpm-build |
0a0c83 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
rpm-build |
0a0c83 |
License for more details.
|
|
rpm-build |
0a0c83 |
|
|
rpm-build |
0a0c83 |
You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0a0c83 |
License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
rpm-build |
0a0c83 |
*/
|
|
rpm-build |
0a0c83 |
|
|
rpm-build |
0a0c83 |
#include "config.h"
|
|
rpm-build |
0a0c83 |
#include <stdio.h>
|
|
rpm-build |
0a0c83 |
#include <stdlib.h>
|
|
rpm-build |
0a0c83 |
#include "misc.h"
|
|
rpm-build |
0a0c83 |
|
|
rpm-build |
0a0c83 |
int __acl_high_water_alloc(void **buf, size_t *bufsize, size_t newsize)
|
|
rpm-build |
0a0c83 |
{
|
|
rpm-build |
0a0c83 |
#define CHUNK_SIZE 256
|
|
rpm-build |
0a0c83 |
/*
|
|
rpm-build |
0a0c83 |
* Goal here is to avoid unnecessary memory allocations by
|
|
rpm-build |
0a0c83 |
* using static buffers which only grow when necessary.
|
|
rpm-build |
0a0c83 |
* Size is increased in fixed size chunks (CHUNK_SIZE).
|
|
rpm-build |
0a0c83 |
*/
|
|
rpm-build |
0a0c83 |
if (*bufsize < newsize) {
|
|
rpm-build |
0a0c83 |
void *newbuf;
|
|
rpm-build |
0a0c83 |
|
|
rpm-build |
0a0c83 |
newsize = (newsize + CHUNK_SIZE-1) & ~(CHUNK_SIZE-1);
|
|
rpm-build |
0a0c83 |
newbuf = realloc(*buf, newsize);
|
|
rpm-build |
0a0c83 |
if (!newbuf)
|
|
rpm-build |
0a0c83 |
return 1;
|
|
rpm-build |
0a0c83 |
|
|
rpm-build |
0a0c83 |
*buf = newbuf;
|
|
rpm-build |
0a0c83 |
*bufsize = newsize;
|
|
rpm-build |
0a0c83 |
}
|
|
rpm-build |
0a0c83 |
return 0;
|
|
rpm-build |
0a0c83 |
}
|