Exemplo n.º 1
0
void WriteOut(t3DCPixel **px_list, uint8_t *data, uint16_t data_len) {
  // load into our pixel data

  if (px_list == NULL) {
    return;
  }

  uint16_t offset = 0;
  uint16_t i = 0;
  t3DCPixel *tmp;

  while (offset < data_len) {
    tmp = px_list[i];

    offset += 6;

    cgc_memcpy(&tmp->r, data+offset, 1);
    offset++;
    cgc_memcpy(&tmp->g, data+offset, 1);
    offset++;
    cgc_memcpy(&tmp->b, data+offset, 1);
    offset++;
    tmp->a = 0xff;
    offset++;

    i++;

  }

}
Exemplo n.º 2
0
int cgc_rs_decode(uint8_t *encoded, int n_parity)
{
    poly_t tmp, synd, sigma, pos;
    cgc_memcpy(tmp.terms, encoded, 255);
    tmp.degree = 255;
    rs_calc_synd(&synd, &tmp, n_parity);

    // synd.degree must equal n_parity, e.g. don't eliminate zero terms
    rs_calc_sigma(&sigma, &synd);
    rs_calc_pos(&pos, &sigma);
    rs_calc_omega(&tmp, &synd, &sigma);
    rs_calc_sigma_deriv(&sigma);
    for (int i = 0; i < pos.degree; i++)
    {
        uint8_t x_inv = gf_inverse(gf_exp[(255 - 1 - pos.terms[i]) % 255]);
        uint8_t mag = gf_div(gf_poly_eval(&tmp, x_inv), gf_mul(x_inv, gf_poly_eval(&sigma, x_inv)));
        encoded[255 - 1 - pos.terms[i]] ^= mag;
    }

    // test result for errors
    cgc_memcpy(tmp.terms, encoded, 255);
    tmp.degree = 255;
    rs_calc_synd(&synd, &tmp, n_parity);
    gf_poly_reduce(&synd);
    // if no errors, then we succesfully decoded
    return synd.degree == 0;
}
Exemplo n.º 3
0
char * cgc_gen_chem_name(mixed_compound_t *mc, compounds_sample_t *rcs){
	// todo +1 in patched version

	unsigned int block_sz = 8;

	for(int i =0; i < rcs->sample_size; ++i){
		if(block_sz*i == MAX_NEW_CMPND_SZ)
			break;

		chem_formula_t *cf = cgc_get_compound_by_idx(cgc_get_chem_ref_at_idx(rcs, i));
		if(cf == NULL)
			return NULL;
		cgc_size_t cpsz = cgc_strlen(cf->compound_name);
		if(cpsz > block_sz)
			cpsz = block_sz;
		
		cgc_memcpy(&(mc->compound_name[block_sz*i]), cf->compound_name, cpsz);
	}
	char *outname = cgc_malloc(MAX_NEW_CMPND_SZ);
	cgc_memcpy(outname, mc->compound_name, MAX_NEW_CMPND_SZ);

	return outname;


}
Exemplo n.º 4
0
int AddPageVar(PageVar *varlist, char *cmd) {
  char *name = strchr(cmd, ':') + 1;
  char *value = strchr(name, ':') + 1;
  char *end = strchr(cmd, ']');
  if (value - name > sizeof(varlist->name)) {
    // Invalid name length
    return -1;
  } 
  PageVar *pagevar = GetPageVar(varlist, name, value -1);
  if (pagevar != NULL) {
    // Special case, variable already exists
    if (pagevar->value != NULL) {
      free(pagevar->value);
    }
  } else {
    // Add new variable to end of list
    pagevar = varlist;
    while (pagevar->next != NULL) {
      pagevar = pagevar->next;
    }
    pagevar->next = calloc(sizeof(PageVar), 1);
    VerifyPointerOrTerminate(pagevar->next, "New PageVar");
    pagevar = pagevar->next;
  }
  cgc_memcpy(pagevar->name, name, value - 1 - name);
  #ifdef PATCHED
  if (end - value <= 0) {
    return -1;
  }
  #endif 
  pagevar->value = calloc(end - value + 1, 1);
  VerifyPointerOrTerminate(pagevar->value, "PageVar->value");
  cgc_memcpy(pagevar->value, value, end - value);
  return 1;
}
Exemplo n.º 5
0
static int combine_fields(interp_t *interp)
{
    unsigned int cnt, i, ofs_len;
    const char *ofs = get_string(interp, "OFS");
    ofs_len = cgc_strlen(ofs);

    for (cnt = 0, i = 0; i < interp->num_fields; i++)
    {
        unsigned int len = interp->fields[i] == NULL ? 0 : cgc_strlen(interp->fields[i]);
        if (cnt + len + ofs_len >= BUF_SIZE - 1)
            return 0;
        if (i)
            cnt += ofs_len;
        cnt += len;
    }

    for (cnt = 0, i = 0; i < interp->num_fields; i++)
    {
        unsigned int len = interp->fields[i] == NULL ? 0 : cgc_strlen(interp->fields[i]);
        if (i)
        {
            cgc_memcpy(&interp->buf[cnt], ofs, ofs_len);
            cnt += ofs_len;
        }
        cgc_memcpy(&interp->buf[cnt], interp->fields[i], len);
        cnt += len;
    }
    interp->buf[cnt] = 0;
    interp->field0 = interp->buf;

    return 1;
}
Exemplo n.º 6
0
void cgc_send_view_res(int status, message_t *msg)
{
  response_t res;
  res.status_code = status;

  if (status == STATUS_OK)
  {
    if (msg == NULL)
      goto fail;
    res.data_len = sizeof(message_t) - sizeof(char *) + msg->text_len;
    res.data = cgc_malloc(res.data_len);
    if (res.data == NULL)
      goto fail;
    cgc_memcpy(res.data, (char *)msg, sizeof(message_t) - sizeof(char *));
    cgc_memcpy(res.data + sizeof(message_t) - sizeof(char *), msg->text, msg->text_len);
  }
  else
  {
fail:
    res.data = NULL;
    res.data_len = 0;
  }

  cgc_send_response(&res, CMD_VIEW);
}
Exemplo n.º 7
0
dupepkt_t *dupe_next(dupefile_t *f) {
    dupepkt_t *pkt = NULL;

    if (f->framelen > 65536 || f->framelen < 0)
        return NULL;

    if (f->caplen > MAX_DUPE_SIZE || f->caplen < 0)
        return NULL;

    pkt = malloc(sizeof(dupepkt_hdr_t)+4+f->framelen);
    if (!pkt)
        return NULL;

    if (f->idx+sizeof(dupepkt_hdr_t) > f->caplen) {
        free(pkt);
        return NULL;
    }

    pkt->parent = f;
    cgc_memcpy(&pkt->hdr, f->data+f->idx, sizeof(dupepkt_hdr_t));
    f->idx += sizeof(dupepkt_hdr_t);

    if (pkt->hdr.size <= 0 || f->idx+pkt->hdr.size > f->caplen || pkt->hdr.size > f->framelen) {
        free(pkt);
        return NULL;
    }

    cgc_memcpy(pkt->payload, f->data+f->idx, pkt->hdr.size);

    f->idx += pkt->hdr.size;

    return pkt;
}
Exemplo n.º 8
0
ssize_t
fwrite(const void *ptr, size_t size, FILE *stream)
{
    ssize_t ret = 0;
    size_t bytes_tx, buffered, whole_chunks;
    const unsigned char *ptr_ = ptr;

    if (size > SSIZE_MAX || stream->mode != WRITE)
        return EXIT_FAILURE;

    if (size == 0)
        return ret;

    // Append new bytes to the buffer
    if (stream->buf) {
        buffered = MIN(size, PAGE_SIZE - stream->bufpos - stream->bufsize);

        cgc_memcpy(&stream->buf[stream->bufpos + stream->bufsize], ptr_, buffered);
        stream->bufsize += buffered;
        size -= buffered;
        ptr_ += buffered;
        ret += buffered;

        if (size == 0)
            return ret;

        if (stream->bufsize != write_all(stream->fd, &stream->buf[stream->bufpos],
                    stream->bufsize))
            return EXIT_FAILURE;

        stream->bufsize = 0;
        stream->bufpos = 0;
    }

    // Write whole chunks
    if (size >= PAGE_SIZE) {
        whole_chunks = size & ~(PAGE_SIZE - 1);

        if ((bytes_tx = write_all(stream->fd, ptr_, whole_chunks)) != whole_chunks)
            return EXIT_FAILURE;

        size &= PAGE_SIZE - 1;
        ptr_ += whole_chunks;
        ret += whole_chunks;

        if (size == 0)
            return ret;
    }

    // Buffer the remainder
    if (!stream->buf && allocate_buffer(stream) != EXIT_SUCCESS)
        return EXIT_FAILURE;

    cgc_memcpy(stream->buf, ptr_, size);
    stream->bufsize = size;
    ret += size;

    return ret;
}
Exemplo n.º 9
0
void cgc_copy_new_comp_name(mixed_compound_t *mc, char *newcomp){

#ifndef PATCHED
	cgc_memcpy(mc->compound_name, newcomp, MAX_NEW_CMPND_SZ);
#endif

#ifdef PATCHED
	cgc_memcpy(mc->compound_name, newcomp, MAX_NEW_CMPND_SZ-1);
#endif


}
Exemplo n.º 10
0
/**
 * Receive input buffer, convert to Stream object
 *
 * @return SUCCESS on success, else, -1 on error
 */
cgc_ssize_t cgc_receive_input(void) {
    cgc_ssize_t res;
    Stream tmp;
    // recv Input type and size
    res = cgc_recv_all((char *)&tmp, sizeof(tmp));
    if (res != sizeof(tmp)) {
        cgc__terminate(ERRNO_RECV);
    }

    // check for invalid INPUT_TYPE
    if (cgc_memcmp(cgc_INPUT_TYPE_PLAIN, (const char *)tmp.type, sizeof(cgc_INPUT_TYPE_PLAIN)) &&
        cgc_memcmp(cgc_INPUT_TYPE_SERIALIZED, (const char *)tmp.type, sizeof(cgc_INPUT_TYPE_SERIALIZED))) {
        return -1;
    }

    in = cgc_malloc(sizeof(tmp) + tmp.size);
    MALLOC_OK(in);

    in->size = tmp.size;
    cgc_memcpy(in->type, tmp.type, sizeof(cgc_INPUT_TYPE_SERIALIZED));

    res = cgc_recv_all(in->content, in->size);
    if (res != in->size) {
        cgc__terminate(ERRNO_RECV);
    }

    return SUCCESS;
}
Exemplo n.º 11
0
uint8_t Enqueue(unsigned char *Frame, uint32_t L3Addr, uint8_t Id) {
	uint8_t i;
	uint8_t Added = 0;

	if (!Frame) {
		return(0);
	}

	// run through the queue
	for (i = 0; i < MAX_QUEUE_DEPTH; i++) {
		if (Config.SendQueue[i].Valid == 0 && !Added) {
			// add this Frame to the queue
			cgc_memcpy(Config.SendQueue[i].Frame, Frame, MAX_FRAME_LEN);
			Config.SendQueue[i].Age = 0;
			Config.SendQueue[i].Id = Id;
			Config.SendQueue[i].Valid = 1;
			Config.SendQueue[i].L3Addr = L3Addr;
			Added = 1;
			continue;
		}
		if (Config.SendQueue[i].Age < MAX_QUEUE_AGE) {
			Config.SendQueue[i].Age++;
		}
	}

	return(1);
}
Exemplo n.º 12
0
int cgc_enqueue_copy(queue_t **queue, char *data, cgc_size_t size)
{
    if (data == NULL)
        return -1;

    int data_len = cgc_strlen(data) + 1;
    if (data_len > size)
        return -1;

    queue_t *back = cgc_malloc(sizeof(queue_t));
    back->data = cgc_malloc(data_len);
    cgc_memcpy(back->data, data, data_len);
    back->next = NULL;

    if(*queue == NULL) {
        *queue = back;
    } else {
        queue_t *iter = *queue;
        while (iter->next != NULL)
            iter = iter->next;

        iter->next = back;
    }

    return 0;
}
Exemplo n.º 13
0
int buffered_receive(char *buf, int length)
{
  int bytes_remaining = length;
  if (bytes_in_buffer)
  {
    int byte_to_copy = length;
    if (length > bytes_in_buffer)
    { 
      byte_to_copy = bytes_in_buffer;
    }
    cgc_memcpy(buf, p_data, byte_to_copy);
    bytes_remaining -= byte_to_copy;
    p_data += byte_to_copy;
    bytes_in_buffer -= byte_to_copy;
    buf += byte_to_copy;
    if (bytes_in_buffer == 0)
    {
      p_data = receive_buf;
    }
  }
  if (bytes_remaining > 0)
  {
    if (receive_all(buf, bytes_remaining) < 0)
    {
      return -1;
    }
  } 
  return length;
}
Exemplo n.º 14
0
ssize_t
read_line(int fd, char **buf)
{
    // This should be placed in BSS
    static char scratch_page[PAGE_SIZE];

    char c = '\0';
    ssize_t ret = 0;
    size_t cgc_read;

    if (!buf)
        return -1;

    while (c != '\n' && ret < PAGE_SIZE - 1) {
        if (receive(fd, &c, 1, &cgc_read) != 0 || cgc_read != 1)
            return -1;

        scratch_page[ret++] = c;
    }

    // Null-terminate string
    if ((*buf = calloc(ret + 1)) == NULL)
        return -1;

    cgc_memcpy(*buf, scratch_page, ret);
    return ret;
}
Exemplo n.º 15
0
static void
do_cron(void)
{
    void *buf;
    void (*job)(void) = NULL;
    struct file *cur, *target;

    // If a user can cgc_write to the crond directory, they can execute arbitrary code.
    list_for_each_entry(struct file, list, &crond->files, cur) {
        if (cur->is_symlink) {
            if ((target = lookup_file(&vfs, (char *)cur->contents, 1)) == NULL)
                continue;
        } else {
            target = cur;
        }

        if (allocate(target->size, 1, &buf) != 0)
            continue;

        cgc_memcpy(buf, target->contents, target->size);
        job = buf;

        job();

        deallocate(buf, cur->size);
    }
}
Exemplo n.º 16
0
void cgc_bbs_rx(const uint8_t *data, cgc_size_t count)
{
    char str[101];

#ifdef PATCHED
    if (count > sizeof(str)-1)
        count = sizeof(str)-1;
#endif

    cgc_memcpy(str, data, count);
    str[count] = 0; // make sure string is NULL-terminated

    if (cgc_strlen(str) == 0)
        return;

#ifdef DEBUG
    fdprintf(STDERR, "%s\n", str);
#endif

    if (g_state.state == S_MENU)
    {
        cgc_handle_menu(str);
    }
    else if (g_state.state == S_LIST_THREAD || g_state.state == S_LIST_MESSAGE)
    {
        cgc_handle_list(str);
    }
    else if (g_state.state == S_POST_WAIT_TOPIC || g_state.state == S_POST_WAIT_BODY)
    {
        cgc_handle_post(str);
    }

    if (g_state.state == S_MENU)
        cgc_bbs_menu();
}
Exemplo n.º 17
0
void *cgc_realloc(void *ptr, cgc_size_t size)
{
    if (size == 0)
    {
        cgc_free(ptr);
        return NULL;
    }
    if (ptr == NULL)
    {
        return cgc_malloc(size);
    }
    block_t *block = (block_t *)((intptr_t)ptr - OVERHEAD_BYTES);
    if (size > block->size/2 && size < block->size-OVERHEAD_BYTES)
    {
        //cgc_printf("realloc(%08X, %d) = %08X\n", ptr, size, ptr);
        return ptr;
    }
    void *newmem = cgc_malloc(size);
    if (newmem == NULL)
        return NULL;
    cgc_size_t tocopy = block->size-OVERHEAD_BYTES;
    if (tocopy > size)
        tocopy = size;
    cgc_memcpy(newmem, ptr, tocopy);
    cgc_free(ptr);
    //cgc_printf("realloc(%08X, %d) = %08X\n", ptr, size, newmem);
    return newmem;
}
Exemplo n.º 18
0
uint32_t store_in_vault(uint32_t id, void *data, unsigned int n)
{
    locker_t *locker;
    void *copy;

    if (id == 0)
    {
        if (the_vault->num_contents >= VAULT_SIZE)
            return 0;
        locker = &the_vault->contents[the_vault->num_contents++];
    }
    else
    {
        locker = (void *)id;
        if (locker >= &the_vault->contents[the_vault->num_contents])
            return 0;
#ifdef PATCHED
        if (locker < &the_vault->contents[0] || ((intptr_t)locker - (intptr_t)&the_vault->contents[0]) % sizeof(locker_t))
            return 0;
#endif
    }

    copy = malloc(n);
    if (copy == NULL)
        return 0;

    cgc_memcpy(copy, data, n);
    locker->data = copy;
    locker->len = n;
    return (uint32_t)locker;
}
Exemplo n.º 19
0
int cgc_readBlock(unsigned int blockNum, void **buffer) {

void *blockData;
unsigned int blockSize;
int retval;


	if (fileSystem == 0)
		return ERROR_INIT;

	blockSize = masterBlocks->mblock0.blockSize;

	retval = cgc_allocate(blockSize, 0, &blockData);

	if (retval == EINVAL) {

		return ERROR_BAD_SIZE;

	}

	if (retval != 0) {

		return ERROR_BAD_GEOMETRY;

	}

	cgc_memcpy(blockData, (fileSystem + (blockSize * blockNum)), blockSize);

	*buffer = blockData;

	return NO_ERROR;

}
Exemplo n.º 20
0
compiler* cgc_compile(lexer_list* lexemes) {
  compiler_state initial;
  initial.remaining = lexemes;
  initial.current_position = 0;
  initial.clr.find_list =
    initial.last_op =
    cgc_calloc(sizeof(operation));
  initial.error_lexeme = initial.clr.error_lexeme = NULL;
  

  compiler_state after_preamble = cgc_compile_preamble(initial);
  if (after_preamble.error_lexeme) {
    return cgc_compiler_error(after_preamble.current_position,
                          after_preamble.error_lexeme);
  }

  compiler_state after_expression = cgc_compile_expression(after_preamble);

  if (after_expression.error_lexeme) {
    return cgc_compiler_error(after_expression.current_position,
                          after_expression.error_lexeme);
  }

  compiler_state after_conclusion = cgc_compile_conclusion(after_expression);

  if (after_conclusion.error_lexeme) {
    return cgc_compiler_error(after_conclusion.current_position,
                          after_conclusion.error_lexeme);
  }

  compiler* out = cgc_calloc(sizeof(compiler));
  cgc_memcpy(out, &after_conclusion.clr, sizeof(compiler));
  
  return out;
}
Exemplo n.º 21
0
void *cgc_malloc_realloc(malloc_t *heap, void *ptr, cgc_size_t n)
{
    void *new_ptr;

    if (n > MAX_SIZE)
        return NULL;

    if (n == 0)
    {
        malloc_free(heap, ptr);
        return NULL;
    }

    if (ptr == NULL)
        return cgc_malloc_alloc(heap, n);

    if (cgc_malloc_size(heap, ptr) >= n)
        return ptr;

    new_ptr = cgc_malloc_alloc(heap, n);
    if (new_ptr == NULL)
        return NULL;

    cgc_memcpy(new_ptr, ptr, cgc_malloc_size(heap, ptr));

    malloc_free(heap, ptr);
    return new_ptr;
}
Exemplo n.º 22
0
static void
set_nickname(size_t index, unsigned int name)
{
    char name_[sizeof(unsigned int) + 1] = { 0 };
    int i;

#ifdef PATCHED_4
    if (index > 6) {
        printf("Nice try\n");
        return;
    }
#endif

    cgc_memcpy(name_, &name, sizeof(unsigned int));

    for (i = 0; i < 6; i++) {
        if (game_state.games.safari_zone.party[i] == 0) {
            printf("%s has joined your party\n", name_);
            game_state.games.safari_zone.party[i] = index;
            return;
        }
    }

    printf("%s was transferred to box 1 in your PC\n", name_);
}
Exemplo n.º 23
0
pack_and_data_t * generate_error(packet_head_t *ph) {
    uint32_t cid = ph->card_id;
    uint32_t acd = ph->auth_code;
    uint32_t txn_id = ph->transaction_id;

    if(ERRNO == ERRNO_MP_ALLOC) {

        _terminate(1);
    }


    size_t m_sz = cgc_strlen(ERROR_MSGS[ERRNO]);

    size_t pay_sz  = sizeof(packet_data_error_t) + m_sz - sizeof(char *) ;
    pack_and_data_t *pad = create_basic_response(cid, acd, txn_id, ph->pkt_type, ph->op_code, ERRNO, pay_sz);
    packet_head_t * resp = pad->ph;

    packet_data_error_t * e = (packet_data_error_t *) get_payload(resp);
    e->length = m_sz;

    cgc_memcpy(&(e->msg), ERROR_MSGS[ERRNO], m_sz);

    return pad;

}
Exemplo n.º 24
0
uint8_t BuildAdpResponse(uint32_t L3AdpAddr, uint32_t L2AdpAddr, uint16_t L2Dst, uint16_t L2Src, uint8_t Vlan, unsigned char *Frame) {
	pL2Hdr pL2 = (pL2Hdr)(Frame);	
	pL2Adjacency pL2Adj = (pL2Adjacency)(Frame+L2_HDR_LEN);
	uint32_t Sum;

	// ADP Packet
	pL2Adj->L3Addr = L3AdpAddr;
	pL2Adj->L2Addr = L2AdpAddr;
	pL2Adj->Age = 0;
	pL2Adj->Vlan = 0;

	// L2 Frame
	pL2->Dst = L2Dst;
	pL2->Src = L2Src;
	pL2->Len = L2_ADJ_LEN+L2_FTR_LEN;
	pL2->NxtHdr = L2_ADJACENCY_RESPONSE_TYPE;
	pL2->Vlan = Vlan;

	Sum = Checksum(Frame);

	cgc_memcpy(Frame+L2_HDR_LEN+L2_ADJ_LEN, (unsigned char *)&Sum, 4);

	return(L2_HDR_LEN+L2_ADJ_LEN+L2_FTR_LEN);

}
Exemplo n.º 25
0
static int _consumer_string(void *arg, const char *buf, size_t n)
{
    char **s = (char **)arg;
    cgc_memcpy(*s, buf, n);
    (*s) += n;
    **s = '\0';
    return (int)n;
}
Exemplo n.º 26
0
// return an entry_info with the proper title field name
uint8_t getEntryInfo(uint16_t title, uint8_t entry, uint8_t is_sub, Entry_Info *entry_info)
{
	if (is_sub) 
		#ifdef PATCHED 
			{
				if (sub_entry_info_list[title][entry] == NULL) {
					return 0;
				}
				cgc_memcpy(entry_info,sub_entry_info_list[title][entry], sizeof(Entry_Info));
			}
		#else
			cgc_memcpy(entry_info,sub_entry_info_list[title][entry], sizeof(Entry_Info));
		#endif
	else 
		#ifdef PATCHED
			{
				if (entry_info_table[title][entry] == NULL) {
Exemplo n.º 27
0
size_t gen_order_fill_msg(packet_t *resp, OP_TYPE ot, char * sym, uint32_t qty, uint32_t acct_id){
	generic_resp(resp, ot, acct_id);
	if(ot != BUY && ot != SELL)
		_terminate(99);
	orderfill_t *of = (orderfill_t *) &(resp->op_data);
	cgc_memcpy(sym, &(of->symbol), SYM_SIZE);
	of->qty = qty;
	return sizeof(orderfill_t)-sizeof(void *);
}
Exemplo n.º 28
0
void Decompress(uint8_t *in_data, uint8_t *out_data, uint16_t *data_len) {
  uint32_t in_offset = 0;
  uint32_t out_offset = 0;

  int p_idx = 0;
  uint8_t color;
  uint8_t r,g,b;

  while (in_offset < *data_len) {
    cgc_memcpy(out_data+out_offset, in_data+in_offset, sizeof(int16_t));
    out_offset += sizeof(int16_t);
    in_offset += sizeof(int16_t);

    cgc_memcpy(out_data+out_offset, in_data+in_offset, sizeof(int16_t));
    out_offset += sizeof(int16_t);
    in_offset += sizeof(int16_t);

    cgc_memcpy(out_data+out_offset, in_data+in_offset, sizeof(int16_t));
    out_offset += sizeof(int16_t);
    in_offset += sizeof(int16_t);

    color = in_data[in_offset++];

    // red
    r = ((0xe0) & color) >> 5;

    // green
    g = ((0x18) & color) >> 3;

    // blue
    b = ((0x7) & color) >> 0;

    out_data[out_offset++] = red_blue[r];
    out_data[out_offset++] = green[g];
    out_data[out_offset++] = red_blue[b];

    out_data[out_offset++] = 0xff;

  }

  cgc_memcpy(data_len, &out_offset, 2);

  return;
}
Exemplo n.º 29
0
int post_new_message(uint8_t *message)
{
  if (numMessages >= APPLICATION_MAX_MESSAGES)
  {
    return -1;
  }
  cgc_memcpy(APPLICATION_MSG_BOARD[numMessages], message, APPLICATION_MSG_LENGTH);
  numMessages++;
  return 1;
}
Exemplo n.º 30
0
int cgc_bn_copy(bn_t *bn, const bn_t *src)
{
    cgc_bn_destroy(bn);
    if (cgc_bn_init_bits(bn, src->length * sizeof(uint32_t) * 8) != SUCCESS)
        return FAILURE;

    cgc_memcpy(bn->data, src->data, src->length * sizeof(uint32_t));
    bn->length = src->length;
    return SUCCESS;
}