本文整理汇总了C++中reallocf函数的典型用法代码示例。如果您正苦于以下问题:C++ reallocf函数的具体用法?C++ reallocf怎么用?C++ reallocf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reallocf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mfi_config_read_opcode
int
mfi_config_read_opcode(int fd, uint32_t opcode, struct mfi_config_data **configp,
uint8_t *mbox, size_t mboxlen)
{
struct mfi_config_data *config;
uint32_t config_size;
int error;
/*
* Keep fetching the config in a loop until we have a large enough
* buffer to hold the entire configuration.
*/
config = NULL;
config_size = 1024;
fetch:
config = reallocf(config, config_size);
if (config == NULL)
return (-1);
if (mfi_dcmd_command(fd, opcode, config,
config_size, mbox, mboxlen, NULL) < 0) {
error = errno;
free(config);
errno = error;
return (-1);
}
if (config->size > config_size) {
config_size = config->size;
goto fetch;
}
*configp = config;
return (0);
}
示例2: merge_alias
static int
merge_alias(const char *name, build_hostent_t *h)
{
int i;
if (name == NULL) return 0;
if (h == NULL) return 0;
if ((h->host.h_name != NULL) && (string_equal(name, h->host.h_name))) return 0;
for (i = 0; i < h->alias_count; i++)
{
if (string_equal(name, h->host.h_aliases[i])) return 0;
}
if (h->alias_count == 0) h->host.h_aliases = (char **)calloc(2, sizeof(char *));
else h->host.h_aliases = (char **)reallocf(h->host.h_aliases, (h->alias_count + 2) * sizeof(char *));
if (h->host.h_aliases == NULL)
{
h->alias_count = 0;
return -1;
}
h->host.h_aliases[h->alias_count] = lower_case(name);
h->alias_count++;
h->host.h_aliases[h->alias_count] = NULL;
return 0;
}
示例3: mfi_pd_get_list
int
mfi_pd_get_list(int fd, struct mfi_pd_list **listp, uint8_t *statusp)
{
struct mfi_pd_list *list;
uint32_t list_size;
/*
* Keep fetching the list in a loop until we have a large enough
* buffer to hold the entire list.
*/
list = NULL;
list_size = 1024;
fetch:
list = reallocf(list, list_size);
if (list == NULL)
return (-1);
if (mfi_dcmd_command(fd, MFI_DCMD_PD_GET_LIST, list, list_size, NULL,
0, statusp) < 0) {
free(list);
return (-1);
}
if (list->size > list_size) {
list_size = list->size;
goto fetch;
}
*listp = list;
return (0);
}
示例4: __collate_substitute
u_char *
__collate_substitute(const u_char *s)
{
#if 0
int dest_len, len, nlen;
int delta = strlen(s);
u_char *dest_str = NULL;
if (s == NULL || *s == '\0')
return (__collate_strdup(""));
delta += delta / 8;
dest_str = malloc(dest_len = delta);
if (dest_str == NULL)
__collate_err(EX_OSERR, __func__);
len = 0;
while (*s) {
nlen = len + strlen(__collate_substitute_table[*s]);
if (dest_len <= nlen) {
dest_str = reallocf(dest_str, dest_len = nlen + delta);
if (dest_str == NULL)
__collate_err(EX_OSERR, __func__);
}
(void)strcpy(dest_str + len, __collate_substitute_table[*s++]);
len = nlen;
}
return (dest_str);
#endif
printf("Warning: __collate_substitute() stubbed out!\n");
return NULL;
}
示例5: brace_subst
/*
* brace_subst --
* Replace occurrences of {} in s1 with s2 and return the result string.
*/
void
brace_subst(char *orig, char **store, char *path, size_t len)
{
const char *pastorigend, *p, *q;
char *dst;
size_t newlen, plen;
plen = strlen(path);
newlen = strlen(orig) + 1;
pastorigend = orig + newlen;
for (p = orig; (q = strstr(p, "{}")) != NULL; p = q + 2) {
if (plen > 2 && newlen + plen - 2 < newlen)
errx(2, "brace_subst overflow");
newlen += plen - 2;
}
if (newlen > len) {
*store = reallocf(*store, newlen);
if (*store == NULL)
err(2, NULL);
}
dst = *store;
for (p = orig; (q = strstr(p, "{}")) != NULL; p = q + 2) {
memcpy(dst, p, q - p);
dst += q - p;
memcpy(dst, path, plen);
dst += plen;
}
memcpy(dst, p, pastorigend - p);
}
示例6: malloc
/* Decode a hexadecimal string, set *len to length, in[] to the bytes. This
decodes liberally, in that hex digits can be adjacent, in which case two in
a row writes a byte. Or they can delimited by any non-hex character, where
the delimiters are ignored except when a single hex digit is followed by a
delimiter in which case that single digit writes a byte. The returned
data is allocated and must eventually be freed. NULL is returned if out of
memory. If the length is not needed, then len can be NULL. */
static unsigned char *h2b(const char *hex, unsigned *len)
{
unsigned char *in;
unsigned next, val;
in = malloc((strlen(hex) + 1) >> 1);
if (in == NULL)
return NULL;
next = 0;
val = 1;
do {
if (*hex >= '0' && *hex <= '9')
val = (val << 4) + *hex - '0';
else if (*hex >= 'A' && *hex <= 'F')
val = (val << 4) + *hex - 'A' + 10;
else if (*hex >= 'a' && *hex <= 'f')
val = (val << 4) + *hex - 'a' + 10;
else if (val != 1 && val < 32) /* one digit followed by delimiter */
val += 240; /* make it look like two digits */
if (val > 255) { /* have two digits */
in[next++] = val & 0xff; /* save the decoded byte */
val = 1; /* start over */
}
} while (*hex++); /* go through the loop with the terminating null */
if (len != NULL)
*len = next;
in = reallocf(in, next);
return in;
}
示例7: read_file
static ssize_t
read_file(int fd, void **rv)
{
uint8_t *retval;
size_t len;
off_t off;
ssize_t red;
len = 4096;
off = 0;
retval = malloc(len);
do {
red = read(fd, retval + off, len - off);
off += red;
if (red < (ssize_t)(len - off))
break;
len *= 2;
retval = reallocf(retval, len);
if (retval == NULL)
return -1;
} while (1);
*rv = retval;
return off;
}
示例8: _internal_remove_controlled_name
static void
_internal_remove_controlled_name(notify_state_t *ns, name_info_t *n)
{
uint32_t i, j;
for (i = 0; i < ns->controlled_name_count; i++)
{
if (ns->controlled_name[i] == n)
{
for (j = i + 1; j < ns->controlled_name_count; j++)
{
ns->controlled_name[j-1] = ns->controlled_name[j];
}
ns->controlled_name_count--;
if (ns->controlled_name_count == 0)
{
free(ns->controlled_name);
ns->controlled_name = NULL;
}
else
{
ns->controlled_name = (name_info_t **)reallocf(ns->controlled_name, ns->controlled_name_count * sizeof(name_info_t *));
}
return;
}
}
}
示例9: nzb_fetch_add_server
int nzb_fetch_add_server(nzb_fetch *fetcher, char *address, int port,
char *username, char *password, int threads,
int ssl, int priority)
{
server_t *new_server, *server;
int required_queues;
int current_queues;
if (priority < 0)
{
fprintf(stderr, "Error: priority should be > 0\n");
return -1;
}
#if !HAVE_LIBSSL
if (ssl > 0)
{
fprintf(stderr, "Error: SSL Support is not compiled in\n");
return -1;
}
#endif
new_server = server_create(address, port, username, password,
threads, ssl, priority);
// Insert into server linked list
server = fetcher->servers;
if(server == NULL)
fetcher->servers = new_server;
else
{
// Append server at the end
while(server->next != NULL)
server = server->next;
server->next = new_server;
new_server->prev = server;
}
required_queues = server_calc_priorities(fetcher);
if (required_queues > 1)
{
current_queues = sizeof(fetcher->priority_queues) /
sizeof(queue_list_t *);
if (required_queues > current_queues)
{
fetcher->priority_queues = reallocf(fetcher->priority_queues,
sizeof(queue_list_t *) *
required_queues);
fetcher->priority_queues[new_server->priority] = queue_list_create();
fetcher->priority_queues[new_server->priority]->id = strdup("priority queue");
}
}
return 0;
}
示例10: CGPathWriter_snprintf
/** internal, re-allocating snprintf helper */
void CGPathWriter_snprintf(CGPathWriter_t *const t, char *fmt, ...)
{
assert(t != NULL);
for(;; ) {
if( t->buffer == NULL )
return;
assert(t->used >= 0);
assert(t->allocated >= t->used);
const size_t max = t->allocated - t->used;
// http://stackoverflow.com/questions/498705/create-a-my-printf-that-sends-data-to-both-a-sprintf-and-the-normal-printf
va_list ap;
va_start(ap, fmt);
const int len = vsnprintf(t->buffer + t->used, max, fmt, ap);
va_end(ap);
assert(len >= 0);
if( len >= max ) {
assert(t->increment >= 0);
const size_t inc = MAX(len - max + 1, t->increment);
assert(t->allocated < INT_MAX - inc);
// fprintf(stderr, "CGPathToCString::re-allocating %zu\n", inc);
t->buffer = reallocf(t->buffer, t->allocated += inc);
assert(t->allocated > t->used);
t->buffer[t->used] = '\0';
assert(t->buffer[t->used] == '\0');
} else {
t->used += len;
return;
}
}
}
示例11: raosnprintf
static int
raosnprintf(char **buf, size_t *size, ssize_t *offset, char *fmt, ...)
{
va_list ap;
int ret;
do
{
if (*offset < *size)
{
va_start(ap, fmt);
ret = vsnprintf(*buf + *offset, *size - *offset, fmt, ap);
va_end(ap);
if (ret < (*size - *offset))
{
*offset += ret;
return ret;
}
}
*buf = reallocf(*buf, (*size *= 2));
} while (*buf);
//warn("reallocf failure");
return 0;
}
示例12: aeron_reallocf
int aeron_reallocf(void **ptr, size_t size)
{
#if defined(__linux__) || defined(AERON_COMPILER_MSVC)
/* mimic reallocf */
if ((*ptr = realloc(*ptr, size)) == NULL)
{
if (0 == size)
{
*ptr = NULL;
}
else
{
free(*ptr);
errno = ENOMEM;
return -1;
}
}
#else
if ((*ptr = reallocf(*ptr, size)) == NULL)
{
errno = ENOMEM;
return -1;
}
#endif
return 0;
}
示例13: fts_sort
static FTSENT *
fts_sort(FTS *sp, FTSENT *head, size_t nitems)
{
FTSENT **ap, *p;
/*
* Construct an array of pointers to the structures and call qsort(3).
* Reassemble the array in the order returned by qsort. If unable to
* sort for memory reasons, return the directory entries in their
* current order. Allocate enough space for the current needs plus
* 40 so don't realloc one entry at a time.
*/
if (nitems > sp->fts_nitems) {
sp->fts_nitems = nitems + 40;
if ((sp->fts_array = reallocf(sp->fts_array,
sp->fts_nitems * sizeof(FTSENT *))) == NULL) {
sp->fts_nitems = 0;
return (head);
}
}
for (ap = sp->fts_array, p = head; p; p = p->fts_link)
*ap++ = p;
if (ISSET(FTS_COMPAR_B))
qsort_r(sp->fts_array, nitems, sizeof(FTSENT *),
sp->fts_compar_b, fts_compar_b);
else
qsort(sp->fts_array, nitems, sizeof(FTSENT *), fts_compar);
for (head = *(ap = sp->fts_array); --nitems; ++ap)
ap[0]->fts_link = ap[1];
ap[0]->fts_link = NULL;
return (head);
}
示例14: __collate_substitute
u_char *
__collate_substitute(const u_char *s)
{
int dest_len, len, nlen;
int delta = strlen(s);
u_char *dest_str = NULL;
if (s == NULL || *s == '\0')
return (__collate_strdup(""));
delta += delta / 8;
dest_str = malloc(dest_len = delta);
if (dest_str == NULL)
__collate_err(EX_OSERR, __func__);
len = 0;
while (*s) {
nlen = len + strlen(__collate_substitute_table[*s]);
if (dest_len <= nlen) {
dest_str = reallocf(dest_str, dest_len = nlen + delta);
if (dest_str == NULL)
__collate_err(EX_OSERR, __func__);
}
strcpy(dest_str + len, __collate_substitute_table[*s++]);
len = nlen;
}
return (dest_str);
}
示例15: fts_palloc
/*
* Allow essentially unlimited paths; find, rm, ls should all work on any tree.
* Most systems will allow creation of paths much longer than MAXPATHLEN, even
* though the kernel won't resolve them. Add the size (not just what's needed)
* plus 256 bytes so don't realloc the path 2 bytes at a time.
*/
static int
fts_palloc(FTS *sp, size_t more)
{
sp->fts_pathlen += more + 256;
sp->fts_path = reallocf(sp->fts_path, sp->fts_pathlen);
return (sp->fts_path == NULL);
}