• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ reallocf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中reallocf函数的典型用法代码示例。如果您正苦于以下问题:C++ reallocf函数的具体用法?C++ reallocf怎么用?C++ reallocf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reallocf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:2asoft,项目名称:freebsd,代码行数:34,代码来源:mfi_config.c


示例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;
}
开发者ID:apportable,项目名称:lookup,代码行数:30,代码来源:si_getaddrinfo.c


示例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);
}
开发者ID:hurricup,项目名称:freebsd_mfi,代码行数:30,代码来源:mfi_drive.c


示例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;
}
开发者ID:CoryXie,项目名称:BarrelfishOS,代码行数:30,代码来源:collate.c


示例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);
}
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:33,代码来源:misc.c


示例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;
}
开发者ID:eevans,项目名称:squash-deb,代码行数:36,代码来源:infcover.c


示例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;
}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:25,代码来源:efidp.c


示例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;
		}
	}
}
开发者ID:BelyyVedmak,项目名称:Libnotify,代码行数:29,代码来源:libnotify.c


示例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;
}
开发者ID:plague85,项目名称:nzblib,代码行数:60,代码来源:libnzb_fetch.c


示例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;
		}
	}
}
开发者ID:fvpolpeta,项目名称:MROGeometry,代码行数:33,代码来源:CGPathWriter.c


示例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;
}
开发者ID:Leon555,项目名称:Mac-src-essentials,代码行数:25,代码来源:acl_translate.c


示例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;
}
开发者ID:loveyoupeng,项目名称:Aeron,代码行数:27,代码来源:aeron_alloc.c


示例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);
}
开发者ID:outbackdingo,项目名称:uBSD,代码行数:32,代码来源:fts.c


示例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);
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:26,代码来源:collate.c


示例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);
}
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:14,代码来源:fts.c


示例16: reallocfRadar6337483_4

void reallocfRadar6337483_4() {
    char *buf = malloc(100);
    char *buf2 = (char*)reallocf(buf, 0x1000000);
    if (!buf2) {
      return;  // no warning - reallocf frees even on failure
    } else {
      free(buf2);
    }
}
开发者ID:ashwinma,项目名称:clang_trunk,代码行数:9,代码来源:malloc.c


示例17: add_arg

static void
add_arg(struct captured_main_args *args, char *arg)
{

	args->argc++;
	args->argv = reallocf(args->argv, (args->argc + 1) * sizeof(char *));
	if (args->argv == NULL)
		err(1, "Out of memory building argument list");
	args->argv[args->argc] = arg;
}
开发者ID:fatman2021,项目名称:DPorts,代码行数:10,代码来源:kgdb-main.c


示例18: _kvm_realloc

void *
_kvm_realloc(kvm_t *kd, void *p, size_t n)
{
	void *np;

	np = reallocf(p, n);
	if (np == NULL)
		_kvm_err(kd, kd->program, "out of memory");
	return (np);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:10,代码来源:kvm_proc.c


示例19: uhso_alloc_tty

/*
 * Expands allocated memory to fit an additional TTY.
 * Two arrays are kept with matching indexes, one for ucom and one
 * for our private data.
 */
static int
uhso_alloc_tty(struct uhso_softc *sc)
{

	sc->sc_ttys++;
	sc->sc_tty = reallocf(sc->sc_tty, sizeof(struct uhso_tty) * sc->sc_ttys,
	    M_USBDEV, M_WAITOK | M_ZERO);
	if (sc->sc_tty == NULL)
		return (-1);

	sc->sc_ucom = reallocf(sc->sc_ucom,
	    sizeof(struct ucom_softc) * sc->sc_ttys, M_USBDEV, M_WAITOK | M_ZERO);
	if (sc->sc_ucom == NULL)
		return (-1);

	sc->sc_tty[sc->sc_ttys - 1].ht_sc = sc;

	UHSO_DPRINTF(1, "Allocated TTY %d\n", sc->sc_ttys - 1);	
	return (sc->sc_ttys - 1);
}
开发者ID:vkhromov,项目名称:freebsd,代码行数:25,代码来源:uhso.c


示例20: reallocfRadar6337483_3

void reallocfRadar6337483_3() {
    char * buf = malloc(100);
    char * tmp;
    tmp = (char*)reallocf(buf, 0x1000000);
    if (!tmp) {
        free(buf); // expected-warning {{Attempt to free released memory}}
        return;
    }
    buf = tmp;
    free(buf);
}
开发者ID:ashwinma,项目名称:clang_trunk,代码行数:11,代码来源:malloc.c



注:本文中的reallocf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ reallymarkobject函数代码示例发布时间:2022-05-30
下一篇:
C++ reallocate函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap