当前位置: 首页>>代码示例>>C++>>正文


C++ OPENSSL_realloc函数代码示例

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


在下文中一共展示了OPENSSL_realloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sk_insert

int sk_insert(_STACK *st, void *data, int loc)
{
    char **s;

    if (st == NULL)
        return 0;
    if (st->num_alloc <= st->num + 1) {
        s = OPENSSL_realloc((char *)st->data,
                            (unsigned int)sizeof(char *) * st->num_alloc * 2);
        if (s == NULL)
            return (0);
        st->data = s;
        st->num_alloc *= 2;
    }
    if ((loc >= (int)st->num) || (loc < 0))
        st->data[st->num] = data;
    else {
        int i;
        char **f, **t;

        f = st->data;
        t = &(st->data[1]);
        for (i = st->num; i >= loc; i--)
            t[i] = f[i];

#ifdef undef                    /* no memmove on sunos :-( */
        memmove(&(st->data[loc + 1]),
                &(st->data[loc]), sizeof(char *) * (st->num - loc));
#endif
        st->data[loc] = data;
    }
    st->num++;
    st->sorted = 0;
    return (st->num);
}
开发者ID:IIJ-NetBSD,项目名称:netbsd-src,代码行数:35,代码来源:stack.c

示例2: ERR_add_error_vdata

void ERR_add_error_vdata(int num, va_list args)
{
    int i, n, s;
    char *str, *p, *a;

    s = 80;
    str = OPENSSL_malloc(s + 1);
    if (str == NULL)
        return;
    str[0] = '\0';

    n = 0;
    for (i = 0; i < num; i++) {
        a = va_arg(args, char *);
        if (a == NULL)
            a = "<NULL>";
        n += strlen(a);
        if (n > s) {
            s = n + 20;
            p = OPENSSL_realloc(str, s + 1);
            if (p == NULL) {
                OPENSSL_free(str);
                return;
            }
            str = p;
        }
        OPENSSL_strlcat(str, a, (size_t)s + 1);
    }
    ERR_set_error_data(str, ERR_TXT_MALLOCED | ERR_TXT_STRING);
}
开发者ID:danielctull-forks,项目名称:openssl,代码行数:30,代码来源:err.c

示例3: mime_canon

/* Called by:  clear_sign, extract_certificate, extract_request, main, open_private_key, sign */
char*
mime_canon(const char* s)
{
  char* d;
  char* p;
  int len;
  len = strlen(s);
  p = d = (char*)OPENSSL_malloc(len + len);  /* Reserve spaces for CR's to be inserted. */
  if (!d) GOTO_ERR("no memory?");
  
  /* Scan and copy */

  for (; *s; s++) {
    if (s[0] != '\015' && s[0] != '\012')
      *(p++) = *s; /* pass thru */
    else {
      if (s[0] == '\015' && s[1] == '\012') s++;  /* already CRLF */
      *(p++) = '\015'; *(p++) = '\012';
    }
  }
  *(p++) = '\0';

  /* Shrink the buffer back to actual size (not very likely to fail) */

  return (char*)OPENSSL_realloc(d, (p-d));
err:
  return NULL;
}
开发者ID:gitpan,项目名称:zxid,代码行数:29,代码来源:smimemime.c

示例4: BUF_MEM_grow

int BUF_MEM_grow(BUF_MEM *str, size_t len)
{
    char *ret;
    size_t n;

    if (str->length >= len) {
        str->length = len;
        return (len);
    }
    if (str->max >= len) {
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
        return (len);
    }
    /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
    if (len > LIMIT_BEFORE_EXPANSION) {
        BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    n = (len + 3) / 3 * 4;
    if (str->data == NULL)
        ret = OPENSSL_malloc(n);
    else
        ret = OPENSSL_realloc(str->data, n);
    if (ret == NULL) {
        BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE);
        len = 0;
    } else {
        str->data = ret;
        str->max = n;
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
    }
    return (len);
}
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:35,代码来源:buffer.c

示例5: memcpy

_STACK *sk_dup(_STACK *sk)
{
    _STACK *ret;
    char **s;

    if ((ret = sk_new(sk->comp)) == NULL)
        goto err;
    s = (char **)OPENSSL_realloc((char *)ret->data,
                                 (unsigned int)sizeof(char *) *
                                 sk->num_alloc);
    if (s == NULL)
        goto err;
    ret->data = s;

    ret->num = sk->num;
    memcpy(ret->data, sk->data, sizeof(char *) * sk->num);
    ret->sorted = sk->sorted;
    ret->num_alloc = sk->num_alloc;
    ret->comp = sk->comp;
    return (ret);
 err:
    if (ret)
        sk_free(ret);
    return (NULL);
}
开发者ID:IIJ-NetBSD,项目名称:netbsd-src,代码行数:25,代码来源:stack.c

示例6: BUF_MEM_grow

int BUF_MEM_grow(BUF_MEM *str, size_t len)
	{
	char *ret;
	size_t n;

	if (str->length >= len)
		{
		str->length=len;
		return(len);
		}
	if (str->max >= len)
		{
		memset(&str->data[str->length],0,len-str->length);
		str->length=len;
		return(len);
		}
	n=(len+3)/3*4;
	if (str->data == NULL)
		ret=OPENSSL_malloc(n);
	else
		ret=OPENSSL_realloc(str->data,n);
	if (ret == NULL)
		{
		BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
		len=0;
		}
	else
		{
		str->data=ret;
		str->max=n;
		memset(&str->data[str->length],0,len-str->length);
		str->length=len;
		}
	return(len);
	}
开发者ID:CoryXie,项目名称:BarrelfishOS,代码行数:35,代码来源:buffer.c

示例7: append_buf

static int append_buf(char **buf, int *size, const char *s)
{
    if (*buf == NULL) {
        *size = 256;
        *buf = app_malloc(*size, "engine buffer");
        **buf = '\0';
    }

    if (strlen(*buf) + strlen(s) >= (unsigned int)*size) {
        char *tmp;
        *size += 256;
        tmp = OPENSSL_realloc(*buf, *size);
        if (tmp == NULL) {
            OPENSSL_free(*buf);
            *buf = NULL;
            return 0;
        }
        *buf = tmp;
    }

    if (**buf != '\0')
        OPENSSL_strlcat(*buf, ", ", *size);
    OPENSSL_strlcat(*buf, s, *size);

    return 1;
}
开发者ID:Barathrum-Liu,项目名称:openssl,代码行数:26,代码来源:engine.c

示例8: OPENSSL_PUT_ERROR

ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
{
    ASN1_ENUMERATED *ret;
    int len,j;

    if (ai == NULL)
        ret=M_ASN1_ENUMERATED_new();
    else
        ret=ai;
    if (ret == NULL)
    {
        OPENSSL_PUT_ERROR(ASN1, BN_to_ASN1_ENUMERATED, ASN1_R_NESTED_ASN1_ERROR);
        goto err;
    }
    if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED;
    else ret->type=V_ASN1_ENUMERATED;
    j=BN_num_bits(bn);
    len=((j == 0)?0:((j/8)+1));
    if (ret->length < len+4)
    {
        unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
        if (!new_data)
        {
            OPENSSL_PUT_ERROR(ASN1, BN_to_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
            goto err;
        }
        ret->data=new_data;
    }

    ret->length=BN_bn2bin(bn,ret->data);
    return(ret);
err:
    if (ret != ai) M_ASN1_ENUMERATED_free(ret);
    return(NULL);
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:35,代码来源:a_enum.c

示例9: ASN1_STRING_set

int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
	{
	unsigned char *c;
	const char *data=_data;
	if (len < 0)
		{
		if (data == NULL)
			return(0);
		else
			len=strlen(data);
		}
	if ((str->length < len) || (str->data == NULL))
		{
		c=str->data;
		if (c == NULL)
			str->data=OPENSSL_malloc(len+1);
		else
			str->data=OPENSSL_realloc(c,len+1);

		if (str->data == NULL)
			{
			ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE);
			str->data=c;
			return(0);
			}
		}
	str->length=len;
	if (data != NULL)
		{
		memcpy(str->data,data,len);
		/* an allowance for strings :-) */
		str->data[len]='\0';
		}
	return(1);
	}
开发者ID:Gucan,项目名称:h3_lichee,代码行数:35,代码来源:asn1_string.c

示例10: sk_insert

int sk_insert(STACK *st, char *data, int loc)
	{
	char **s;

	if(st == NULL) return 0;
	if (st->num_alloc <= st->num+1)
		{
		s=(char **)OPENSSL_realloc((char *)st->data,
			(unsigned int)sizeof(char *)*st->num_alloc*2);
		if (s == NULL)
			return(0);
		st->data=s;
		st->num_alloc*=2;
		}
	if ((loc >= (int)st->num) || (loc < 0))
		st->data[st->num]=data;
	else
		{
		int i;
		char **f,**t;

		f=(char **)st->data;
		t=(char **)&(st->data[1]);
		for (i=st->num; i>=loc; i--)
			t[i]=f[i];

		st->data[loc]=data;
		}
	st->num++;
	st->sorted=0;
	return(st->num);
	}
开发者ID:Gucan,项目名称:h3_lichee,代码行数:32,代码来源:stk.c

示例11: append_buf

static int append_buf(char **buf, const char *s, int *size, int step)
	{
	int l = strlen(s);

	if (*buf == NULL)
		{
		*size = step;
		*buf = OPENSSL_malloc(*size);
		if (*buf == NULL)
			return 0;
		**buf = '\0';
		}

	if (**buf != '\0')
		l += 2;		/* ", " */

	if (strlen(*buf) + strlen(s) >= (unsigned int)*size)
		{
		*size += step;
		*buf = OPENSSL_realloc(*buf, *size);
		}

	if (*buf == NULL)
		return 0;

	if (**buf != '\0')
		BUF_strlcat(*buf, ", ", *size);
	BUF_strlcat(*buf, s, *size);

	return 1;
	}
开发者ID:oss-forks,项目名称:openssl,代码行数:31,代码来源:engine.c

示例12: sk_insert

int sk_insert(_STACK *st, void *data, int loc)
{
    char **s;

    if (st == NULL)
        return 0;
    if (st->num_alloc <= st->num + 1) {
        s = OPENSSL_realloc((char *)st->data,
                            (unsigned int)sizeof(char *) * st->num_alloc * 2);
        if (s == NULL)
            return (0);
        st->data = s;
        st->num_alloc *= 2;
    }
    if ((loc >= (int)st->num) || (loc < 0))
        st->data[st->num] = data;
    else {
        memmove(&(st->data[loc + 1]),
                &(st->data[loc]), sizeof(char *) * (st->num - loc));
        st->data[loc] = data;
    }
    st->num++;
    st->sorted = 0;
    return (st->num);
}
开发者ID:nicholasmsanford,项目名称:openssl,代码行数:25,代码来源:stack.c

示例13: ERR_add_error_vdata

void ERR_add_error_vdata(int num, va_list args)
{
    int i, n, s;
    char *str, *p, *a;

    s = 80;
    str = OPENSSL_malloc(s + 1);
    if (str == NULL)
        return;
    str[0] = '\0';

    n = 0;
    for (i = 0; i < num; i++) {
        a = va_arg(args, char *);
        /* ignore NULLs, thanks to Bob Beck <[email protected]> */
        if (a != NULL) {
            n += strlen(a);
            if (n > s) {
                s = n + 20;
                p = OPENSSL_realloc(str, s + 1);
                if (p == NULL) {
                    OPENSSL_free(str);
                    return;
                }
                str = p;
            }
            OPENSSL_strlcat(str, a, (size_t)s + 1);
        }
    }
    ERR_set_error_data(str, ERR_TXT_MALLOCED | ERR_TXT_STRING);
}
开发者ID:ZuyingWo,项目名称:openssl,代码行数:31,代码来源:err.c

示例14: ERR_add_error_vdata

void ERR_add_error_vdata(int num, va_list args)
{
    int i, n, s;
    char *str, *p, *a;

    s = 80;
    if ((str = OPENSSL_malloc(s + 1)) == NULL) {
        /* ERRerr(ERR_F_ERR_ADD_ERROR_VDATA, ERR_R_MALLOC_FAILURE); */
        return;
    }
    str[0] = '\0';

    n = 0;
    for (i = 0; i < num; i++) {
        a = va_arg(args, char *);
        if (a == NULL)
            a = "<NULL>";
        n += strlen(a);
        if (n > s) {
            s = n + 20;
            p = OPENSSL_realloc(str, s + 1);
            if (p == NULL) {
                OPENSSL_free(str);
                return;
            }
            str = p;
        }
        OPENSSL_strlcat(str, a, (size_t)s + 1);
    }
    if (!err_set_error_data_int(str, ERR_TXT_MALLOCED | ERR_TXT_STRING))
        OPENSSL_free(str);
}
开发者ID:dgalaxy,项目名称:openssl,代码行数:32,代码来源:err.c

示例15: sk_new

_STACK *sk_dup(const _STACK *sk) {
  _STACK *ret;
  void **s;

  if (sk == NULL) {
    return NULL;
  }

  ret = sk_new(sk->comp);
  if (ret == NULL) {
    goto err;
  }

  s = (void **)OPENSSL_realloc(ret->data, sizeof(void *) * sk->num_alloc);
  if (s == NULL) {
    goto err;
  }
  ret->data = s;

  ret->num = sk->num;
  OPENSSL_memcpy(ret->data, sk->data, sizeof(void *) * sk->num);
  ret->sorted = sk->sorted;
  ret->num_alloc = sk->num_alloc;
  ret->comp = sk->comp;
  return ret;

err:
  sk_free(ret);
  return NULL;
}
开发者ID:AadityaDev,项目名称:AadityaDev.github.io,代码行数:30,代码来源:stack.c


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