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


C++ safe_calloc函数代码示例

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


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

示例1: safe_calloc

struct poolworker_state *poolworker_create(int numThreads) {
    struct poolworker_state *pw;
    int i;

    pw = safe_calloc(1, sizeof *pw);
    pw->p = safe_calloc(numThreads, sizeof *pw->p);
    pw->jobs_req = NULL;
    pw->jobs_active = NULL;

    pthread_mutex_init(&pw->lock, NULL);
    pthread_cond_init(&pw->cond_req, NULL);
    pthread_cond_init(&pw->cond_cmp, NULL);

    atomic_write(&pw->numRunning, 0);
    atomic_write(&pw->exit, 0);

    Log(LGPFX " creating %u threads\n", numThreads);

    for (i = 0; i < numThreads; i++) {
        pthread_create(&pw->p[i].tid, NULL, poolworker_main, pw);

        while (atomic_read(&pw->numRunning) != i + 1) {
            sched_yield();
        }
    }
    return pw;
}
开发者ID:jma127,项目名称:bitc-rpc,代码行数:27,代码来源:poolworker.c

示例2: while

int *get_adrcmd_from_key(int cxt, struct key_entry *key, int create) {
    flrn_assoc_key_cmd *pc;
    unsigned char hash;
    int i;
    if (key==NULL) return NULL;
    if (key->entry==ENTRY_ERROR_KEY) return NULL;
    hash=get_hash_key(key);
    pc=Flcmd_rev[hash];
    if (pc==NULL) {
        if (create) 
	    pc=Flcmd_rev[hash]=safe_calloc(1,sizeof(flrn_assoc_key_cmd));
	else return NULL;
    } else { 
	while (pc->next) {
            if (key_are_equal(&(pc->key),key)) break;
	    pc=pc->next;
	}
	if (key_are_equal(&(pc->key),key)) return &(pc->cmd[cxt]);
	if (create==0) return NULL;
	pc->next=safe_calloc(1,sizeof(flrn_assoc_key_cmd));
	pc=pc->next;
    }
    /* create = 1 */
    for (i=0;i<NUMBER_OF_CONTEXTS;i++) pc->cmd[i]=FLCMD_UNDEF;
    memcpy(&(pc->key),key,sizeof(struct key_entry));
    if (key->entry==ENTRY_ALLOCATED_STRING) 
	pc->key.value.allocstr=safe_flstrdup(key->value.allocstr);
    return &(pc->cmd[cxt]);
}
开发者ID:Cigaes,项目名称:flrn,代码行数:29,代码来源:flrn_command.c

示例3: init_map

/*  
 * -- init_map
 *
 * initializes global shared map.
 *
 */
void
init_map(struct _como * m)
{
    int i; 

    memset(m, 0, sizeof(struct _como));
    m->whoami = SUPERVISOR;
    m->running = NORMAL; 
    m->logflags = DEFAULT_LOGFLAGS;
    m->mem_size = DEFAULT_MEMORY;
    m->maxfilesize = DEFAULT_FILESIZE;
    m->module_max = DEFAULT_MODULE_MAX;
    m->module_last = -1; 
    m->modules = safe_calloc(m->module_max, sizeof(module_t));
    for (i = 0; i < m->module_max; i++) 
	m->modules[i].status = MDL_UNUSED; 
    m->workdir = mkdtemp(strdup("/tmp/comoXXXXXX"));
    m->basedir = strdup(DEFAULT_BASEDIR);
    m->libdir = strdup(DEFAULT_LIBDIR);
    m->node = safe_calloc(1, sizeof(node_t)); 
    m->node->id = 0;
    m->node->name = strdup("CoMo Node");
    m->node->location = strdup("Unknown");
    m->node->type = strdup("Unknown");
    m->node->query_port = DEFAULT_QUERY_PORT;
    m->node_count = 1;
}
开发者ID:JackieXie168,项目名称:como,代码行数:33,代码来源:config.c

示例4: term_init

/*
 * Initialize a term, using a window of the given size.
 * Also prepare the "input queue" for "k" keypresses
 * By default, the cursor starts out "invisible"
 * By default, we "erase" using "black spaces"
 */
errr term_init(term *t, int w, int h, int k)
{
	int y;

	/* Wipe it */
	memset(t, 0, sizeof(term));


	/* Prepare the input queue */
	t->key_head = t->key_tail = 0;

	/* Determine the input queue size */
	t->key_size = k;

	/* Allocate the input queue */
	t->key_queue = safe_calloc(t->key_size, sizeof(char));


	/* Save the size */
	t->wid = w;
	t->hgt = h;

	/* Allocate change arrays */
	t->x1 = safe_calloc(h, sizeof(byte));
	t->x2 = safe_calloc(h, sizeof(byte));


	/* Allocate "displayed" */
	t->old = safe_calloc(1, sizeof(struct term_win));

	/* Initialize "displayed" */
	term_win_init(t->old, w, h);


	/* Allocate "requested" */
	t->scr = safe_calloc(1, sizeof(struct term_win));

	/* Initialize "requested" */
	term_win_init(t->scr, w, h);


	/* Assume change */
	for (y = 0; y < h; y++)
	{
		/* Assume change */
		t->x1[y] = 0;
		t->x2[y] = w - 1;
	}

	/* Assume change */
	t->y1 = 0;
	t->y2 = h - 1;

	/* Force "total erase" */
	t->total_erase = TRUE;


	/* Success */
	return (0);
}
开发者ID:Alkalinear,项目名称:tome2,代码行数:66,代码来源:z-term.c

示例5: calculate_client_keys

/**
 * For a given client, calculate the master key and do key expansion
 * to determine the symmetric cypher key and IV salt, and hash key
 */
void calculate_client_keys(struct pr_group_list_t *group, int hostidx)
{
    unsigned char *seed, *prf_buf;
    int explen, len, seedlen;
    struct pr_destinfo_t *dest;

    dest = &group->destinfo[hostidx];

    explen = group->keylen + group->ivlen +
             group->hmaclen;
    seedlen = sizeof(group->rand1) * 2;
    seed = safe_calloc(seedlen, 1);
    prf_buf = safe_calloc(MASTER_LEN + explen + group->hmaclen, 1);

    memcpy(seed, group->rand1, sizeof(group->rand1));
    memcpy(seed + sizeof(group->rand1), dest->rand2,
            sizeof(dest->rand2));
    PRF(group->hashtype, MASTER_LEN, dest->premaster, dest->premaster_len,
            "master secret", seed, seedlen, prf_buf, &len);
    memcpy(dest->master,prf_buf, sizeof(dest->master));

    PRF(group->hashtype, explen, dest->master, sizeof(dest->master),
            "key expansion", seed, seedlen, prf_buf, &len);
    memcpy(dest->hmackey, prf_buf, group->hmaclen);
    memcpy(dest->key, prf_buf + group->hmaclen, group->keylen);
    memcpy(dest->salt, prf_buf + group->hmaclen + group->keylen, group->ivlen);

    free(seed);
    free(prf_buf);
}
开发者ID:PumpkinSpace,项目名称:uftp,代码行数:34,代码来源:proxy_downstream.c

示例6: init_map

/*  
 * -- init_map
 *
 * initializes global shared map.
 *
 */
void
init_map(struct _como * m)
{
    int i; 

    memset(m, 0, sizeof(struct _como));
    m->whoami = SUPERVISOR;
    m->runmode = RUNMODE_NORMAL; 
    m->logflags = DEFAULT_LOGFLAGS;
    m->mem_size = DEFAULT_MEMORY;
    m->maxfilesize = DEFAULT_FILESIZE;
    m->module_max = DEFAULT_MODULE_MAX;
    m->module_last = -1; 
    m->modules = safe_calloc(m->module_max, sizeof(module_t));
    for (i = 0; i < m->module_max; i++) 
	m->modules[i].status = MDL_UNUSED; 
    m->workdir = mkdtemp(strdup("/tmp/comoXXXXXX"));
    m->dbdir = strdup(DEFAULT_DBDIR);
    m->libdir = strdup(DEFAULT_LIBDIR);
    m->node = safe_calloc(1, sizeof(node_t)); 
    m->node[0].name = strdup("CoMo Node");
    m->node[0].location = strdup("Unknown");
    m->node[0].type = strdup("Unknown");
    m->node[0].query_port = DEFAULT_QUERY_PORT;
    m->node_count = 1;
    m->debug_sleep = 20;
    m->asnfile = NULL;
    m->live_thresh = TIME2TS(0, 10000); /* default 10 ms */
}
开发者ID:JackieXie168,项目名称:como,代码行数:35,代码来源:config.c

示例7: send_keyinfo_ack

/**
 * Sends a KEYINFO_ACK in response to a KEYINFO
 */
void send_keyinfo_ack(struct group_list_t *group)
{
    unsigned char *buf, *encrypted;
    struct uftp_h *header;
    struct keyinfoack_h *keyinfo_ack;
    unsigned char *verifydata, *verify_hash, *verify_val;
    unsigned int payloadlen, hashlen;
    int verifylen, enclen, len;

    buf = safe_calloc(MAXMTU, 1);

    header = (struct uftp_h *)buf;
    keyinfo_ack = (struct keyinfoack_h *)(buf + sizeof(struct uftp_h));

    set_uftp_header(header, KEYINFO_ACK, group);
    keyinfo_ack->func = KEYINFO_ACK;
    keyinfo_ack->hlen = sizeof(struct keyinfoack_h) / 4;

    verifydata = build_verify_data(group, &verifylen);
    if (!verifydata) {
        glog0(group, "Error getting verify data");
        send_abort(group, "Error getting verify data");
        free(buf);
        return;
    }

    verify_hash = safe_calloc(group->hmaclen, 1);
    verify_val = safe_calloc(VERIFY_LEN + group->hmaclen, 1);
    hash(group->hashtype, verifydata, verifylen, verify_hash, &hashlen);
    PRF(group->hashtype, VERIFY_LEN, group->groupmaster,
            sizeof(group->groupmaster), "client finished",
            verify_hash, hashlen, verify_val, &len);
    memcpy(keyinfo_ack->verify_data, verify_val, VERIFY_LEN);
    free(verifydata);
    free(verify_hash);
    free(verify_val);

    payloadlen = sizeof(struct keyinfoack_h);
    encrypted = NULL;
    if (!encrypt_and_sign(buf, &encrypted, payloadlen, &enclen, group->keytype,
            group->groupkey, group->groupsalt, &group->ivctr, group->ivlen,
            group->hashtype, group->grouphmackey, group->hmaclen,group->sigtype,
            group->keyextype, group->client_privkey,group->client_privkeylen)) {
        glog0(group, "Error encrypting KEYINFO_ACK");
        free(buf);
        return;
    }
    payloadlen = enclen + sizeof(struct uftp_h);

    if (nb_sendto(listener, encrypted, payloadlen, 0,
               (struct sockaddr *)&(group->replyaddr),
               family_len(group->replyaddr)) == SOCKET_ERROR) {
        gsockerror(group, "Error sending KEYINFO_ACK");
    } else {
        glog2(group, "KEYINFO_ACK sent");
    }
    free(encrypted);
    free(buf);
}
开发者ID:PumpkinSpace,项目名称:uftp,代码行数:62,代码来源:client_announce.c

示例8: Create_Stack

// crate a stack of <no_element> size
nodes_stack * Create_Stack(int no_elements) {
  nodes_stack * s = (nodes_stack *)safe_calloc(1, sizeof(nodes_stack));
  assert(no_elements);
  s->top = 0;
  s->max_size = no_elements;
  s->nodes = (int *)safe_calloc(no_elements, sizeof(int));
  return s;
}
开发者ID:cdunn2001,项目名称:DConvert,代码行数:9,代码来源:UtilsREZ.C

示例9: mutt_expand_file_fmt

static QUERY *run_query (char *s, int quiet)
{
        FILE *fp;
        QUERY *first = NULL;
        QUERY *cur = NULL;
        char cmd[_POSIX_PATH_MAX];
        char *buf = NULL;
        size_t buflen;
        int dummy = 0;
        char msg[STRING];
        char *p;
        pid_t thepid;

        mutt_expand_file_fmt (cmd, sizeof(cmd), QueryCmd, s);

        if ((thepid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) {
                dprint (1, (debugfile, "unable to fork command: %s", cmd));
                return 0;
        }
        if (!quiet)
                mutt_message _("Waiting for response...");
        fgets (msg, sizeof (msg), fp);
        if ((p = strrchr (msg, '\n')))
                *p = '\0';
        while ((buf = mutt_read_line (buf, &buflen, fp, &dummy, 0)) != NULL) {
                if ((p = strtok(buf, "\t\n"))) {
                        if (first == NULL) {
                                first = (QUERY *) safe_calloc (1, sizeof (QUERY));
                                cur = first;
                        }
                        else {
                                cur->next = (QUERY *) safe_calloc (1, sizeof (QUERY));
                                cur = cur->next;
                        }

                        cur->addr = rfc822_parse_adrlist (cur->addr, p);
                        p = strtok(NULL, "\t\n");
                        if (p) {
                                cur->name = safe_strdup (p);
                                p = strtok(NULL, "\t\n");
                                if (p)
                                        cur->other = safe_strdup (p);
                        }
                }
        }
        FREE (&buf);
        safe_fclose (&fp);
        if (mutt_wait_filter (thepid)) {
                dprint (1, (debugfile, "Error: %s\n", msg));
                if (!quiet)  mutt_error ("%s", msg);
        }
        else {
                if (!quiet)
                        mutt_message ("%s", msg);
        }

        return first;
}
开发者ID:tejux,项目名称:mutt-hacks,代码行数:58,代码来源:query.c

示例10: handle_keyinfo_ack

/**
 * Handles an incoming KEYINFO_ACK message from a client
 */
void handle_keyinfo_ack(struct pr_group_list_t *group, int hostidx,
                        const unsigned char *message, unsigned meslen)
{
    const struct keyinfoack_h *keyinfoack;
    unsigned char *verifydata, *verify_hash, *verify_test;
    int verifylen, len, dupmsg;
    unsigned int hashlen;
    struct pr_destinfo_t *dest;

    keyinfoack = (const struct keyinfoack_h *)message;
    dest = &group->destinfo[hostidx];

    if ((meslen < (keyinfoack->hlen * 4U)) ||
            ((keyinfoack->hlen * 4U) < sizeof(struct keyinfoack_h))) {
        glog1(group, "Rejecting KEYINFO_ACK from %s: invalid message size",
                     dest->name);
        send_downstream_abort(group, dest->id, "Invalid message size", 0);
        return;
    }

    if (!(verifydata = build_verify_data(group, hostidx, &verifylen,1))) {
        glog1(group, "Rejecting KEYINFO_ACK from %s: "
                     "error exporting client public key", dest->name);
        return;
    }
    verify_hash = safe_calloc(group->hmaclen, 1);
    verify_test = safe_calloc(VERIFY_LEN + group->hmaclen, 1);
    hash(group->hashtype, verifydata, verifylen, verify_hash, &hashlen);
    PRF(group->hashtype, VERIFY_LEN, group->groupmaster,
            sizeof(group->groupmaster), "client finished",
            verify_hash, hashlen, verify_test, &len);
    if (memcmp(keyinfoack->verify_data, verify_test, VERIFY_LEN)) {
        glog1(group, "Rejecting KEYINFO_ACK from %s: verify data mismatch",
                     dest->name);
        free(verifydata);
        free(verify_hash);
        free(verify_test);
        return;
    }

    free(verifydata);
    free(verify_hash);
    free(verify_test);

    dupmsg = (dest->state == PR_CLIENT_READY);
    glog2(group, "Received KEYINFO_ACK%s from %s", dupmsg ? "+" : "",
                 dest->name);
    dest->state = PR_CLIENT_READY;
    if (!check_unfinished_clients(group, 0)) {
        group->phase = PR_PHASE_RECEIVING;
    }
}
开发者ID:PumpkinSpace,项目名称:uftp,代码行数:55,代码来源:proxy_downstream.c

示例11: make_bitfield

struct bitfield *
make_bitfield(const UChar *word, const UChar *alphabet)
{
    int alphabetlength = u_strlen(alphabet);
    int *freqs = safe_calloc(alphabetlength, sizeof(int));
    struct bitfield *bf;
    int maxfreq = 0;
    int index;

    if (freqs == NULL)
        return NULL;

    while (*word) {
        const UChar *p = alphabet;
        for (index = 0; *p && (*p != *word); p++, index++) {
        }
        if (*p) {
            freqs[index]++;
            if (freqs[index] > maxfreq) {
                maxfreq = freqs[index];
            }
        } else {
            /* character not in alphabet */
            free(freqs);
            return NULL;
        }
        word++;
    }

    bf = safe_calloc(1, sizeof(struct bitfield));
    if (bf != NULL) {
        bitpattern thisbit;

        bf->depth = maxfreq;
        bf->bits = safe_calloc(sizeof(bitpattern), maxfreq);
        thisbit = 1;

        for (index = 0; index <alphabetlength; index++) {
            bitpattern *bits = bf->bits;
            while (freqs[index] > 0) {
                *bits |= thisbit;
                bits++;
                freqs[index]--;
            }
            thisbit <<= 1;        
        }
    }
    free(freqs);
    return bf;
}
开发者ID:LeandroLovisolo,项目名称:an,代码行数:50,代码来源:bitfield.c

示例12: ssl_socket_open

static int ssl_socket_open (CONNECTION * conn)
{
  sslsockdata *data;
  int maxbits;

  if (raw_socket_open (conn) < 0)
    return -1;

  data = (sslsockdata *) safe_calloc (1, sizeof (sslsockdata));
  conn->sockdata = data;

  data->ctx = SSL_CTX_new (SSLv23_client_method ());

  /* disable SSL protocols as needed */
  if (!option(OPTTLSV1))
  {
    SSL_CTX_set_options(data->ctx, SSL_OP_NO_TLSv1);
  }
  /* TLSv1.1/1.2 support was added in OpenSSL 1.0.1, but some OS distros such
   * as Fedora 17 are on OpenSSL 1.0.0.
   */
#ifdef SSL_OP_NO_TLSv1_1
  if (!option(OPTTLSV1_1))
  {
    SSL_CTX_set_options(data->ctx, SSL_OP_NO_TLSv1_1);
  }
#endif
#ifdef SSL_OP_NO_TLSv1_2
  if (!option(OPTTLSV1_2))
  {
    SSL_CTX_set_options(data->ctx, SSL_OP_NO_TLSv1_2);
  }
#endif
  if (!option(OPTSSLV2))
  {
    SSL_CTX_set_options(data->ctx, SSL_OP_NO_SSLv2);
  }
  if (!option(OPTSSLV3))
  {
    SSL_CTX_set_options(data->ctx, SSL_OP_NO_SSLv3);
  }

  ssl_get_client_cert(data, conn);

  data->ssl = SSL_new (data->ctx);
  SSL_set_fd (data->ssl, conn->fd);

  if (ssl_negotiate(conn, data))
  {
    mutt_socket_close (conn);
    return -1;
  }

  data->isopen = 1;

  conn->ssf = SSL_CIPHER_get_bits (SSL_get_current_cipher (data->ssl),
    &maxbits);

  return 0;
}
开发者ID:Ishpeck,项目名称:mutt-kz,代码行数:60,代码来源:mutt_ssl.c

示例13: RSA_encrypt

/**
 * Encrypts a small block of data with an RSA public key.
 * Output buffer must be at least the key size.
 */
int RSA_encrypt(RSA_key_t rsa, const unsigned char *from, unsigned int fromlen,
                unsigned char *to, unsigned int *tolen)
{
    DWORD _tolen;
    int flags;
    unsigned int i;
    unsigned char *outbuf;

    if (RSA_keylen(rsa) * 8 < 768) {
        flags = 0;
    } else {
        flags = CRYPT_OAEP;
    }

    outbuf = safe_calloc(RSA_keylen(rsa), 1);
    memcpy(outbuf, from, fromlen);
    _tolen = fromlen;
    if (!CryptEncrypt(rsa, 0, 1, flags, outbuf, &_tolen, RSA_keylen(rsa))) {
        mserror("CryptEncrypt failed");
        free(outbuf);
        return 0;
    }
    *tolen = _tolen;

    // CryptoAPI returns ciphertext in little endian, so reverse the bytes
    for (i = 0; i < _tolen; i++) {
        to[i] = outbuf[_tolen - i - 1];
    }

    free(outbuf);
    return 1;
}
开发者ID:PumpkinSpace,项目名称:uftp,代码行数:36,代码来源:encrypt_cryptoapi.c

示例14: sniffer_init

/*
 * -- sniffer_init
 * 
 */
static sniffer_t *
sniffer_init(const char * device, const char * args)
{
    struct bpf_me *me;
    
    me = safe_calloc(1, sizeof(struct bpf_me));

    me->sniff.max_pkts = 8192;
    me->sniff.flags = SNIFF_SELECT | SNIFF_SHBUF;
    me->device = device;
    
    /* create the capture buffer */
    if (capbuf_init(&me->capbuf, args, NULL, BPF_MIN_BUFSIZE,
		    BPF_MAX_BUFSIZE) < 0)
	goto error;

    /* create the pkt_t buffer */
    if (capbuf_init(&me->pktbuf, args, "pktbuf=", BPF_MIN_PKTBUFSIZE,
		    BPF_MAX_PKTBUFSIZE) < 0)
	goto error;

    me->read_size = me->capbuf.size / 2;
    me->min_proc_size = BPF_DEFAULT_MIN_PROC_SIZE;
    
    return (sniffer_t *) me;
error:
    free(me);
    return NULL; 
}
开发者ID:JackieXie168,项目名称:como,代码行数:33,代码来源:sniffer-bpf.c

示例15: Term_load

/*
 * Restore the "requested" contents (see above).
 *
 * Every "Term_save()" should match exactly one "Term_load()"
 */
errr Term_load(void)
{
	int y;

	int w = Term->wid;
	int h = Term->hgt;

	/* Create */
	if (!Term->mem)
	{
		/* Allocate window */
		Term->mem = safe_calloc(1, sizeof(struct term_win));

		/* Initialize window */
		term_win_init(Term->mem, w, h);
	}

	/* Load */
	term_win_copy(Term->scr, Term->mem, w, h);

	/* Assume change */
	for (y = 0; y < h; y++)
	{
		/* Assume change */
		Term->x1[y] = 0;
		Term->x2[y] = w - 1;
	}

	/* Assume change */
	Term->y1 = 0;
	Term->y2 = h - 1;

	/* Success */
	return (0);
}
开发者ID:Alkalinear,项目名称:tome2,代码行数:40,代码来源:z-term.c


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