本文整理汇总了C++中sizeof函数的典型用法代码示例。如果您正苦于以下问题:C++ sizeof函数的具体用法?C++ sizeof怎么用?C++ sizeof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sizeof函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: avi_writer_emit_opendml_indexes
/* caller must ensure we're at the movi chunk level */
int avi_writer_emit_opendml_indexes(avi_writer *w) {
unsigned long long chunk_ofs=0,chunk_max;
riff_indx_AVISUPERINDEX_entry suie;
avi_writer_stream_index *si;
unsigned int chunk,chks,out_chunks;
riff_indx_AVISTDINDEX_entry *stdie;
unsigned long long superindex;
riff_indx_AVISTDINDEX stdh;
avi_writer_stream *s;
riff_chunk newchunk;
int stream,in1,in2;
long long offset;
if (w == NULL) return 0;
if (!w->enable_opendml_index) return 0;
if (avi_io_buffer_init(sizeof(*stdie)) == NULL) return 0;
for (stream=0;stream < w->avi_stream_max;stream++) {
s = w->avi_stream + stream;
if (s->indx_entryofs != 0) break;
if (s->sample_index == NULL) continue;
in1 = ((stream / 10) % 10) + '0';
in2 = (stream % 10) + '0';
for (chunk=0;chunk < s->sample_index_max;) {
/* scan up to 2000 samples, and determine a good base offset for them */
si = s->sample_index + chunk;
chunk_ofs = chunk_max = si->offset;
chks = chunk + 1; si++;
while (chks < (chunk + 2000) && chks < s->sample_index_max) {
if (chunk_max < si->offset) {
if (si->offset > (chunk_ofs + 0x7FFF0000ULL))
break;
chunk_max = si->offset;
}
else if (chunk_ofs > si->offset) {
if ((si->offset + 0x7FFF0000ULL) <= chunk_max)
break;
chunk_ofs = si->offset;
}
chks++;
si++;
}
/* make sure the above loop does it's job */
assert((chunk_ofs + 0x7FFF0000ULL) > chunk_max);
/* start an AVISUPERINDEX */
out_chunks = 0;
if ((superindex = avi_writer_stream_alloc_superindex(w,s)) == 0ULL) {
fprintf(stderr,"Cannot alloc superindex for %u\n",s->index);
break;
}
/* start an index chunk */
assert(riff_stack_begin_new_chunk_here(w->riff,&newchunk));
assert(riff_stack_set_chunk_data_type(&newchunk,riff_fourcc_const('i','x',in1,in2)));
assert(riff_stack_push(w->riff,&newchunk)); /* NTS: we can reuse chunk, the stack copies it here */
memset(&stdh,0,sizeof(stdh));
stdh.wLongsPerEntry = 2;
stdh.bIndexType = riff_indx_type_AVI_INDEX_OF_CHUNKS;
stdh.dwChunkId = s->chunk_fourcc;
stdh.qwBaseOffset = chunk_ofs;
assert(riff_stack_write(w->riff,riff_stack_top(w->riff),&stdh,sizeof(stdh)) == (int)sizeof(stdh));
avi_io_write = avi_io_buf;
while (chunk < s->sample_index_max) {
si = s->sample_index + chunk;
offset = (long long)si->offset - (long long)chunk_ofs;
if (offset < 0LL || offset >= 0x7FFF0000LL)
break;
if ((avi_io_write+sizeof(*stdie)) > avi_io_fence) {
size_t sz = (size_t)(avi_io_write - avi_io_buf);
/* flush to disk */
assert(riff_stack_write(w->riff,riff_stack_top(w->riff),avi_io_buf,sz) == (int)sz);
/* reset pointer */
avi_io_write = avi_io_buf;
}
stdie = (riff_indx_AVISTDINDEX_entry*)avi_io_write;
avi_io_write += sizeof(*stdie);
stdie->dwOffset = (uint32_t)offset;
stdie->dwSize = si->length;
if ((si->dwFlags & riff_idx1_AVIOLDINDEX_flags_KEYFRAME) == 0) stdie->dwSize |= (1UL << 31UL);
out_chunks++;
chunk++;
}
if (avi_io_write != avi_io_fence) {
size_t sz = (size_t)(avi_io_write - avi_io_buf);
/* flush to disk */
assert(riff_stack_write(w->riff,riff_stack_top(w->riff),avi_io_buf,sz) == (int)sz);
//.........这里部分代码省略.........
开发者ID:joncampbell123,项目名称:dosbox-x,代码行数:101,代码来源:avi_writer.cpp
示例2: CalcMeleeDamage
//.........这里部分代码省略.........
int iAtk = 0;
// level must be ignored when multiply by fAR, so subtract it before calculation.
iAtk = pkAttacker->GetPoint(POINT_ATT_GRADE) + iDam - (pkAttacker->GetLevel() * 2);
iAtk = (int) (iAtk * fAR);
iAtk += pkAttacker->GetLevel() * 2; // and add again
if (pWeapon)
{
iAtk += pWeapon->GetValue(5) * 2;
// 2004.11.12.myevan.TESTSERVER_SHOW_ATTACKINFO
DEBUG_iDamBonus = pWeapon->GetValue(5) * 2;
///////////////////////////////////////////////
}
iAtk += pkAttacker->GetPoint(POINT_PARTY_ATTACKER_BONUS); // party attacker role bonus
iAtk = (int) (iAtk * (100 + (pkAttacker->GetPoint(POINT_ATT_BONUS) + pkAttacker->GetPoint(POINT_MELEE_MAGIC_ATT_BONUS_PER))) / 100);
iAtk = CalcAttBonus(pkAttacker, pkVictim, iAtk);
int iDef = 0;
if (!bIgnoreDefense)
{
iDef = (pkVictim->GetPoint(POINT_DEF_GRADE) * (100 + pkVictim->GetPoint(POINT_DEF_BONUS)) / 100);
if (!pkAttacker->IsPC())
iDef += pkVictim->GetMarriageBonus(UNIQUE_ITEM_MARRIAGE_DEFENSE_BONUS);
}
if (pkAttacker->IsNPC())
iAtk = (int) (iAtk * pkAttacker->GetMobDamageMultiply());
iDam = MAX(0, iAtk - iDef);
if (test_server)
{
int DEBUG_iLV = pkAttacker->GetLevel()*2;
int DEBUG_iST = int((pkAttacker->GetPoint(POINT_ATT_GRADE) - DEBUG_iLV) * fAR);
int DEBUG_iPT = pkAttacker->GetPoint(POINT_PARTY_ATTACKER_BONUS);
int DEBUG_iWP = 0;
int DEBUG_iPureAtk = 0;
int DEBUG_iPureDam = 0;
char szRB[32] = "";
char szGradeAtkBonus[32] = "";
DEBUG_iWP = int(DEBUG_iDamCur * fAR);
DEBUG_iPureAtk = DEBUG_iLV + DEBUG_iST + DEBUG_iWP+DEBUG_iDamBonus;
DEBUG_iPureDam = iAtk - iDef;
if (pkAttacker->IsNPC())
{
snprintf(szGradeAtkBonus, sizeof(szGradeAtkBonus), "=%d*%.1f", DEBUG_iPureAtk, pkAttacker->GetMobDamageMultiply());
DEBUG_iPureAtk = int(DEBUG_iPureAtk * pkAttacker->GetMobDamageMultiply());
}
if (DEBUG_iDamBonus != 0)
snprintf(szRB, sizeof(szRB), "+RB(%d)", DEBUG_iDamBonus);
char szPT[32] = "";
if (DEBUG_iPT != 0)
snprintf(szPT, sizeof(szPT), ", PT=%d", DEBUG_iPT);
char szUnknownAtk[32] = "";
if (iAtk != DEBUG_iPureAtk)
snprintf(szUnknownAtk, sizeof(szUnknownAtk), "+?(%d)", iAtk-DEBUG_iPureAtk);
char szUnknownDam[32] = "";
if (iDam != DEBUG_iPureDam)
snprintf(szUnknownDam, sizeof(szUnknownDam), "+?(%d)", iDam-DEBUG_iPureDam);
char szMeleeAttack[128];
snprintf(szMeleeAttack, sizeof(szMeleeAttack),
"%s(%d)-%s(%d)=%d%s, ATK=LV(%d)+ST(%d)+WP(%d)%s%s%s, AR=%.3g%s",
pkAttacker->GetName(),
iAtk,
pkVictim->GetName(),
iDef,
iDam,
szUnknownDam,
DEBUG_iLV,
DEBUG_iST,
DEBUG_iWP,
szRB,
szUnknownAtk,
szGradeAtkBonus,
fAR,
szPT);
pkAttacker->ChatPacket(CHAT_TYPE_TALKING, "%s", szMeleeAttack);
pkVictim->ChatPacket(CHAT_TYPE_TALKING, "%s", szMeleeAttack);
}
return CalcBattleDamage(iDam, pkAttacker->GetLevel(), pkVictim->GetLevel());
}
开发者ID:Rarder44,项目名称:Server,代码行数:101,代码来源:battle.cpp
示例3: fread
cibar_t *cibar_open(FILE *f)
{
cibar_internal_file_entry_t *entries;
char *strings;
uint8_t *data;
cibar_internal_t cb;
cibar_t *out;
int i;
if (!f)
return NULL;
/* Read the header */
fread(&cb, sizeof(cibar_internal_t), 1, f);
if (cb.magic != 0x12344321)
{
printf("cibar: Wrong magic: 0x%08x\n", cb.magic);
goto error_1;
}
/* Allocate structures */
if ( !(entries = (cibar_internal_file_entry_t*)malloc(sizeof(cibar_internal_file_entry_t) * cb.n_file_entries)) )
goto error_1;
if ( !(strings = (char*)malloc( cb.strtab_length )) )
goto error_2;
if ( !(data = (uint8_t*)malloc( cb.data_length )) )
goto error_3;
if ( !(out = (cibar_t*)malloc( sizeof(cibar_t) + sizeof(cibar_file_entry_t) * cb.n_file_entries)) )
goto error_4;
/* Read the rest of the file */
if (fread(entries, 1, sizeof(cibar_internal_file_entry_t) * cb.n_file_entries, f) !=
sizeof(cibar_internal_file_entry_t) * cb.n_file_entries)
goto error_4;
if (fread(strings, 1, cb.strtab_length, f) != cb.strtab_length)
goto error_4;
if (fread(data, 1, cb.data_length, f) != cb.data_length)
goto error_4;
/* Fill in the out stucture */
out->n_files = cb.n_file_entries;
out->strings = strings;
out->data = data;
for (i = 0; i < cb.n_file_entries; i++)
{
cibar_file_entry_t *p = &out->files[i];
p->cibar = out;
p->data = data + entries[i].data_offset;
p->data_size = entries[i].data_size;
p->name = strings + entries[i].strtab_offset;
}
free(entries);
return out;
error_4:
free(data);
error_3:
free(strings);
error_2:
free(entries);
error_1:
return NULL;
}
开发者ID:NoamSheffer,项目名称:WazeWP7,代码行数:66,代码来源:cibar.c
示例4: ibmveth_start_xmit
static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
struct net_device *netdev)
{
struct ibmveth_adapter *adapter = netdev_priv(netdev);
unsigned int desc_flags;
union ibmveth_buf_desc descs[6];
int last, i;
int force_bounce = 0;
dma_addr_t dma_addr;
/*
* veth handles a maximum of 6 segments including the header, so
* we have to linearize the skb if there are more than this.
*/
if (skb_shinfo(skb)->nr_frags > 5 && __skb_linearize(skb)) {
netdev->stats.tx_dropped++;
goto out;
}
/* veth can't checksum offload UDP */
if (skb->ip_summed == CHECKSUM_PARTIAL &&
((skb->protocol == htons(ETH_P_IP) &&
ip_hdr(skb)->protocol != IPPROTO_TCP) ||
(skb->protocol == htons(ETH_P_IPV6) &&
ipv6_hdr(skb)->nexthdr != IPPROTO_TCP)) &&
skb_checksum_help(skb)) {
netdev_err(netdev, "tx: failed to checksum packet\n");
netdev->stats.tx_dropped++;
goto out;
}
desc_flags = IBMVETH_BUF_VALID;
if (skb->ip_summed == CHECKSUM_PARTIAL) {
unsigned char *buf = skb_transport_header(skb) +
skb->csum_offset;
desc_flags |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD);
/* Need to zero out the checksum */
buf[0] = 0;
buf[1] = 0;
}
retry_bounce:
memset(descs, 0, sizeof(descs));
/*
* If a linear packet is below the rx threshold then
* copy it into the static bounce buffer. This avoids the
* cost of a TCE insert and remove.
*/
if (force_bounce || (!skb_is_nonlinear(skb) &&
(skb->len < tx_copybreak))) {
skb_copy_from_linear_data(skb, adapter->bounce_buffer,
skb->len);
descs[0].fields.flags_len = desc_flags | skb->len;
descs[0].fields.address = adapter->bounce_buffer_dma;
if (ibmveth_send(adapter, descs)) {
adapter->tx_send_failed++;
netdev->stats.tx_dropped++;
} else {
netdev->stats.tx_packets++;
netdev->stats.tx_bytes += skb->len;
}
goto out;
}
/* Map the header */
dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
skb_headlen(skb), DMA_TO_DEVICE);
if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
goto map_failed;
descs[0].fields.flags_len = desc_flags | skb_headlen(skb);
descs[0].fields.address = dma_addr;
/* Map the frags */
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
dma_addr = skb_frag_dma_map(&adapter->vdev->dev, frag, 0,
skb_frag_size(frag), DMA_TO_DEVICE);
if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
goto map_failed_frags;
descs[i+1].fields.flags_len = desc_flags | skb_frag_size(frag);
descs[i+1].fields.address = dma_addr;
}
if (ibmveth_send(adapter, descs)) {
adapter->tx_send_failed++;
netdev->stats.tx_dropped++;
} else {
netdev->stats.tx_packets++;
//.........这里部分代码省略.........
开发者ID:marceleng,项目名称:linux,代码行数:101,代码来源:ibmveth.c
示例5: return
return (vm->heap.next + size + sizeof(size_t) < vm->heap.end);
}
void* allocate(VM* vm, size_t size, int outerlock) {
// return malloc(size);
int lock = vm->processes > 0 && !outerlock;
if (lock) { // not message passing
pthread_mutex_lock(&vm->alloc_lock);
}
if ((size & 7)!=0) {
size = 8 + ((size >> 3) << 3);
}
size_t chunk_size = size + sizeof(size_t);
if (vm->heap.next + chunk_size < vm->heap.end) {
STATS_ALLOC(vm->stats, chunk_size)
void* ptr = (void*)(vm->heap.next + sizeof(size_t));
*((size_t*)(vm->heap.next)) = chunk_size;
vm->heap.next += chunk_size;
assert(vm->heap.next <= vm->heap.end);
memset(ptr, 0, size);
if (lock) { // not message passing
pthread_mutex_unlock(&vm->alloc_lock);
}
return ptr;
开发者ID:DanielWaterworth,项目名称:Idris-dev,代码行数:31,代码来源:idris_rts.c
示例6: memcpy
void quadrotor::State::save(const std::list<State> & states, std::string path)
{
MATFile *result;
mxArray *R;
mxArray *xq;
mxArray *omega;
mxArray *vq;
void *p;
mwSize *dims=new mwSize[3];
result=matOpen(path.c_str(),"w");
std::list<State>::const_iterator it_state;
it_state=states.cbegin();
dims[0]=3;
dims[1]=3;
dims[2]=states.size();
R=mxCreateNumericArray(3,dims,mxDOUBLE_CLASS,mxREAL);
for(p=mxGetPr(R);it_state!=states.cend();it_state++)
{
Mat3 R=it_state->g.block(0,0,3,3);
memcpy(p,R.data(),sizeof(double)*dims[0]*dims[1]);
p+=sizeof(double)*dims[0]*dims[1];
}
matPutVariable(result,"R",R);
mxDestroyArray(R);
it_state=states.cbegin();
dims[0]=3;
dims[1]=1;
dims[2]=states.size();
xq=mxCreateNumericArray(3,dims,mxDOUBLE_CLASS,mxREAL);
for(p=mxGetPr(xq);it_state!=states.cend();it_state++)
{
memcpy(p,it_state->g.block(0,3,3,1).data(),sizeof(double)*dims[0]*dims[1]);
p+=sizeof(double)*dims[0]*dims[1];
}
matPutVariable(result,"xq",xq);
mxDestroyArray(xq);
it_state=states.cbegin();
dims[0]=3;
dims[1]=1;
dims[2]=states.size();
vq=mxCreateNumericArray(3,dims,mxDOUBLE_CLASS,mxREAL);
for(p=mxGetPr(vq);it_state!=states.cend();it_state++)
{
memcpy(p,it_state->v.tail(3).data(),sizeof(double)*dims[0]*dims[1]);
p+=sizeof(double)*dims[0]*dims[1];
}
matPutVariable(result,"vq",vq);
mxDestroyArray(vq);
it_state=states.cbegin();
dims[0]=3;
dims[1]=1;
dims[2]=states.size();
omega=mxCreateNumericArray(3,dims,mxDOUBLE_CLASS,mxREAL);
for(p=mxGetPr(omega);it_state!=states.cend();it_state++)
{
memcpy(p,it_state->v.head(3).data(),sizeof(double)*dims[0]*dims[1]);
p+=sizeof(double)*dims[0]*dims[1];
}
matPutVariable(result,"omega",omega);
mxDestroyArray(omega);
}
开发者ID:fantaosha,项目名称:sac,代码行数:86,代码来源:quadrotor.hpp
示例7: ibmveth_open
static int ibmveth_open(struct net_device *netdev)
{
struct ibmveth_adapter *adapter = netdev_priv(netdev);
u64 mac_address;
int rxq_entries = 1;
unsigned long lpar_rc;
int rc;
union ibmveth_buf_desc rxq_desc;
int i;
struct device *dev;
netdev_dbg(netdev, "open starting\n");
napi_enable(&adapter->napi);
for(i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
rxq_entries += adapter->rx_buff_pool[i].size;
adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
if (!adapter->buffer_list_addr || !adapter->filter_list_addr) {
netdev_err(netdev, "unable to allocate filter or buffer list "
"pages\n");
rc = -ENOMEM;
goto err_out;
}
dev = &adapter->vdev->dev;
adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) *
rxq_entries;
adapter->rx_queue.queue_addr =
dma_alloc_coherent(dev, adapter->rx_queue.queue_len,
&adapter->rx_queue.queue_dma, GFP_KERNEL);
if (!adapter->rx_queue.queue_addr) {
rc = -ENOMEM;
goto err_out;
}
adapter->buffer_list_dma = dma_map_single(dev,
adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
adapter->filter_list_dma = dma_map_single(dev,
adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
(dma_mapping_error(dev, adapter->filter_list_dma))) {
netdev_err(netdev, "unable to map filter or buffer list "
"pages\n");
rc = -ENOMEM;
goto err_out;
}
adapter->rx_queue.index = 0;
adapter->rx_queue.num_slots = rxq_entries;
adapter->rx_queue.toggle = 1;
mac_address = ibmveth_encode_mac_addr(netdev->dev_addr);
rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
adapter->rx_queue.queue_len;
rxq_desc.fields.address = adapter->rx_queue.queue_dma;
netdev_dbg(netdev, "buffer list @ 0x%p\n", adapter->buffer_list_addr);
netdev_dbg(netdev, "filter list @ 0x%p\n", adapter->filter_list_addr);
netdev_dbg(netdev, "receive q @ 0x%p\n", adapter->rx_queue.queue_addr);
h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address);
if (lpar_rc != H_SUCCESS) {
netdev_err(netdev, "h_register_logical_lan failed with %ld\n",
lpar_rc);
netdev_err(netdev, "buffer TCE:0x%llx filter TCE:0x%llx rxq "
"desc:0x%llx MAC:0x%llx\n",
adapter->buffer_list_dma,
adapter->filter_list_dma,
rxq_desc.desc,
mac_address);
rc = -ENONET;
goto err_out;
}
for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
if (!adapter->rx_buff_pool[i].active)
continue;
if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) {
netdev_err(netdev, "unable to alloc pool\n");
adapter->rx_buff_pool[i].active = 0;
rc = -ENOMEM;
goto err_out;
}
}
netdev_dbg(netdev, "registering irq 0x%x\n", netdev->irq);
rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name,
netdev);
if (rc != 0) {
netdev_err(netdev, "unable to request irq 0x%x, rc %d\n",
//.........这里部分代码省略.........
开发者ID:marceleng,项目名称:linux,代码行数:101,代码来源:ibmveth.c
示例8: main
int main(int argc, char *const *argv)
{
char *fname = NULL;
int rc, ch;
char data[1000];
char pat[500];
FILE *fd;
bool match_only = true;
int lineno;
bool no_linenos = false;
int ic = 0;
setlocale(LC_ALL, "");
bindtextdomain("bareos", LOCALEDIR);
textdomain("bareos");
while ((ch = getopt(argc, argv, "d:f:in?")) != -1) {
switch (ch) {
case 'd': /* set debug level */
debug_level = atoi(optarg);
if (debug_level <= 0) {
debug_level = 1;
}
break;
case 'f': /* data */
fname = optarg;
break;
case 'i': /* ignore case */
ic = FNM_CASEFOLD;
break;
case 'l':
no_linenos = true;
break;
case 'n':
match_only = false;
break;
case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;
if (!fname) {
printf("A data file must be specified.\n");
usage();
}
OSDependentInit();
for ( ;; ) {
printf("Enter a wild-card: ");
if (fgets(pat, sizeof(pat)-1, stdin) == NULL) {
break;
}
strip_trailing_newline(pat);
if (pat[0] == 0) {
exit(0);
}
fd = fopen(fname, "r");
if (!fd) {
printf(_("Could not open data file: %s\n"), fname);
exit(1);
}
lineno = 0;
while (fgets(data, sizeof(data)-1, fd)) {
strip_trailing_newline(data);
lineno++;
rc = fnmatch(pat, data, ic);
if ((match_only && rc == 0) || (!match_only && rc != 0)) {
if (no_linenos) {
printf("%s\n", data);
} else {
printf("%5d: %s\n", lineno, data);
}
}
}
fclose(fd);
}
exit(0);
}
开发者ID:viniciusingracio,项目名称:bareos,代码行数:89,代码来源:bwild.c
示例9: main
int main(int argc, char **argv)
{
burrow_st *burrow;
client_st client;
msg_st *msg;
int use_http = 0;
argc--;
argv++;
if (strcmp(argv[0], "http") == 0) {
use_http = 1;
argc--;
argv++;
}
if (argc < 4 || argc % 2 != 0)
return -1;
client.account = argv[0];
client.queue = argv[1];
argc -= 2;
argv += 2;
client.messages = NULL;
client.message_count = 0;
while (argc) {
msg = malloc(sizeof(msg_st));
if (!msg)
return -2;
msg->msg_id = argv[0];
msg->body = (uint8_t *)argv[1];
msg->body_size = strlen(argv[1]);
msg->next = client.messages;
client.messages = msg;
client.message_count++;
argc -= 2;
argv += 2;
}
client.return_code = 0;
client.current_message = client.messages;
if (use_http == 0) {
burrow = burrow_create(NULL, "dummy");
printf("burrow = %p\n", burrow);
} else {
burrow = burrow_create(NULL, "http");
printf("burrow = %p\n", burrow);
burrow_backend_set_option(burrow, "server", "localhost");
burrow_backend_set_option(burrow, "port", "8080");
}
burrow_set_context(burrow, &client);
burrow_set_complete_fn(burrow, &_complete);
burrow_set_log_fn(burrow, &_log);
/* Insert the first one here to kick the loop off. This only sets start state,
it doesn't run the loop. */
msg = client.current_message;
burrow_create_message(burrow, client.account, client.queue,
msg->msg_id, msg->body, msg->body_size, NULL);
/* This runs until there are no more tasks. */
burrow_process(burrow);
burrow_destroy(burrow);
return client.return_code;
}
开发者ID:emonty,项目名称:libburrow,代码行数:72,代码来源:complete_loop.c
示例10: atof
/*
============
Cvar_Validate
============
*/
static const char *Cvar_Validate( cvar_t *var,
const char *value, qboolean warn )
{
static char s[ MAX_CVAR_VALUE_STRING ];
float valuef;
qboolean changed = qfalse;
if( !var->validate )
return value;
if( !value )
return value;
if( Q_isanumber( value ) )
{
valuef = atof( value );
if( var->integral )
{
if( !Q_isintegral( valuef ) )
{
if( warn )
Com_Printf( "WARNING: cvar '%s' must be integral", var->name );
valuef = (int)valuef;
changed = qtrue;
}
}
}
else
{
if( warn )
Com_Printf( "WARNING: cvar '%s' must be numeric", var->name );
valuef = atof( var->resetString );
changed = qtrue;
}
if( valuef < var->min )
{
if( warn )
{
if( changed )
Com_Printf( " and is" );
else
Com_Printf( "WARNING: cvar '%s'", var->name );
if( Q_isintegral( var->min ) )
Com_Printf( " out of range (min %d)", (int)var->min );
else
Com_Printf( " out of range (min %f)", var->min );
}
valuef = var->min;
changed = qtrue;
}
else if( valuef > var->max )
{
if( warn )
{
if( changed )
Com_Printf( " and is" );
else
Com_Printf( "WARNING: cvar '%s'", var->name );
if( Q_isintegral( var->max ) )
Com_Printf( " out of range (max %d)", (int)var->max );
else
Com_Printf( " out of range (max %f)", var->max );
}
valuef = var->max;
changed = qtrue;
}
if( changed )
{
if( Q_isintegral( valuef ) )
{
Com_sprintf( s, sizeof( s ), "%d", (int)valuef );
if( warn )
Com_Printf( ", setting to %d\n", (int)valuef );
}
else
{
Com_sprintf( s, sizeof( s ), "%f", valuef );
if( warn )
Com_Printf( ", setting to %f\n", valuef );
}
return s;
}
else
//.........这里部分代码省略.........
开发者ID:AlienHoboken,项目名称:Tremulous-xserverx-tremded,代码行数:101,代码来源:cvar.c
示例11: DEF_GPUTEST_FOR_RENDERING_CONTEXTS
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrPipelineDynamicStateTest, reporter, ctxInfo) {
GrContext* const context = ctxInfo.grContext();
GrResourceProvider* rp = context->resourceProvider();
sk_sp<GrRenderTargetContext> rtc(
context->makeDeferredRenderTargetContext(SkBackingFit::kExact, kScreenSize, kScreenSize,
kRGBA_8888_GrPixelConfig, nullptr));
if (!rtc) {
ERRORF(reporter, "could not create render target context.");
return;
}
constexpr float d = (float) kScreenSize;
Vertex vdata[kNumMeshes * 4] = {
{0, 0, kMeshColors[0]},
{0, d, kMeshColors[0]},
{d, 0, kMeshColors[0]},
{d, d, kMeshColors[0]},
{0, 0, kMeshColors[1]},
{0, d, kMeshColors[1]},
{d, 0, kMeshColors[1]},
{d, d, kMeshColors[1]},
{0, 0, kMeshColors[2]},
{0, d, kMeshColors[2]},
{d, 0, kMeshColors[2]},
{d, d, kMeshColors[2]},
{0, 0, kMeshColors[3]},
{0, d, kMeshColors[3]},
{d, 0, kMeshColors[3]},
{d, d, kMeshColors[3]}
};
sk_sp<const GrBuffer> vbuff(rp->createBuffer(sizeof(vdata), kVertex_GrBufferType,
kDynamic_GrAccessPattern,
GrResourceProvider::kNoPendingIO_Flag |
GrResourceProvider::kRequireGpuMemory_Flag,
vdata));
if (!vbuff) {
ERRORF(reporter, "vbuff is null.");
return;
}
uint32_t resultPx[kScreenSize * kScreenSize];
for (ScissorState scissorState : {ScissorState::kEnabled, ScissorState::kDisabled}) {
rtc->clear(nullptr, 0xbaaaaaad, true);
rtc->priv().testingOnly_addDrawOp(
skstd::make_unique<GrPipelineDynamicStateTestOp>(scissorState, vbuff));
rtc->readPixels(SkImageInfo::Make(kScreenSize, kScreenSize,
kRGBA_8888_SkColorType, kPremul_SkAlphaType),
resultPx, 4 * kScreenSize, 0, 0, 0);
for (int y = 0; y < kScreenSize; ++y) {
for (int x = 0; x < kScreenSize; ++x) {
int expectedColorIdx;
if (ScissorState::kEnabled == scissorState) {
expectedColorIdx = (x < kScreenSplitX ? 0 : 2) + (y < kScreenSplitY ? 0 : 1);
} else {
expectedColorIdx = kNumMeshes - 1;
}
uint32_t expected = kMeshColors[expectedColorIdx];
uint32_t actual = resultPx[y * kScreenSize + x];
if (expected != actual) {
ERRORF(reporter, "[scissor=%s] pixel (%i,%i): got 0x%x expected 0x%x",
ScissorState::kEnabled == scissorState ? "enabled" : "disabled", x, y,
actual, expected);
return;
}
}
}
}
}
开发者ID:MIPS,项目名称:external-skia,代码行数:74,代码来源:GrPipelineDynamicStateTest.cpp
示例12: uthread_alloc
void *
uthread_alloc(task_t task, thread_t thread, int noinherit)
{
proc_t p;
uthread_t uth;
uthread_t uth_parent;
void *ut;
if (!uthread_zone_inited)
uthread_zone_init();
ut = (void *)zalloc(uthread_zone);
bzero(ut, sizeof(struct uthread));
p = (proc_t) get_bsdtask_info(task);
uth = (uthread_t)ut;
uth->uu_kwe.kwe_uth = uth;
/*
* Thread inherits credential from the creating thread, if both
* are in the same task.
*
* If the creating thread has no credential or is from another
* task we can leave the new thread credential NULL. If it needs
* one later, it will be lazily assigned from the task's process.
*/
uth_parent = (uthread_t)get_bsdthread_info(current_thread());
if ((noinherit == 0) && task == current_task() &&
uth_parent != NULL &&
IS_VALID_CRED(uth_parent->uu_ucred)) {
/*
* XXX The new thread is, in theory, being created in context
* XXX of parent thread, so a direct reference to the parent
* XXX is OK.
*/
kauth_cred_ref(uth_parent->uu_ucred);
uth->uu_ucred = uth_parent->uu_ucred;
/* the credential we just inherited is an assumed credential */
if (uth_parent->uu_flag & UT_SETUID)
uth->uu_flag |= UT_SETUID;
} else {
/* sometimes workqueue threads are created out task context */
if ((task != kernel_task) && (p != PROC_NULL))
uth->uu_ucred = kauth_cred_proc_ref(p);
else
uth->uu_ucred = NOCRED;
}
if ((task != kernel_task) && p) {
proc_lock(p);
if (noinherit != 0) {
/* workq threads will not inherit masks */
uth->uu_sigmask = ~workq_threadmask;
} else if (uth_parent) {
if (uth_parent->uu_flag & UT_SAS_OLDMASK)
uth->uu_sigmask = uth_parent->uu_oldmask;
else
uth->uu_sigmask = uth_parent->uu_sigmask;
}
uth->uu_context.vc_thread = thread;
TAILQ_INSERT_TAIL(&p->p_uthlist, uth, uu_list);
proc_unlock(p);
#if CONFIG_DTRACE
if (p->p_dtrace_ptss_pages != NULL) {
uth->t_dtrace_scratch = dtrace_ptss_claim_entry(p);
}
#endif
}
return (ut);
}
开发者ID:kongove,项目名称:xnu,代码行数:74,代码来源:kern_fork.c
示例13: forkproc
/*
* forkproc
*
* Description: Create a new process structure, given a parent process
* structure.
*
* Parameters: parent_proc The parent process
*
* Returns: !NULL The new process structure
* NULL Error (insufficient free memory)
*
* Note: When successful, the newly created process structure is
* partially initialized; if a caller needs to deconstruct the
* returned structure, they must call forkproc_free() to do so.
*/
proc_t
forkproc(proc_t parent_proc)
{
proc_t child_proc; /* Our new process */
static int nextpid = 0, pidwrap = 0, nextpidversion = 0;
static uint64_t nextuniqueid = 0;
int error = 0;
struct session *sessp;
uthread_t parent_uthread = (uthread_t)get_bsdthread_info(current_thread());
MALLOC_ZONE(child_proc, proc_t , sizeof *child_proc, M_PROC, M_WAITOK);
if (child_proc == NULL) {
printf("forkproc: M_PROC zone exhausted\n");
goto bad;
}
/* zero it out as we need to insert in hash */
bzero(child_proc, sizeof *child_proc);
MALLOC_ZONE(child_proc->p_stats, struct pstats *,
sizeof *child_proc->p_stats, M_PSTATS, M_WAITOK);
if (child_proc->p_stats == NULL) {
printf("forkproc: M_SUBPROC zone exhausted (p_stats)\n");
FREE_ZONE(child_proc, sizeof *child_proc, M_PROC);
child_proc = NULL;
goto bad;
}
MALLOC_ZONE(child_proc->p_sigacts, struct sigacts *,
sizeof *child_proc->p_sigacts, M_SIGACTS, M_WAITOK);
if (child_proc->p_sigacts == NULL) {
printf("forkproc: M_SUBPROC zone exhausted (p_sigacts)\n");
FREE_ZONE(child_proc->p_stats, sizeof *child_proc->p_stats, M_PSTATS);
FREE_ZONE(child_proc, sizeof *child_proc, M_PROC);
child_proc = NULL;
goto bad;
}
/* allocate a callout for use by interval timers */
child_proc->p_rcall = thread_call_allocate((thread_call_func_t)realitexpire, child_proc);
if (child_proc->p_rcall == NULL) {
FREE_ZONE(child_proc->p_sigacts, sizeof *child_proc->p_sigacts, M_SIGACTS);
FREE_ZONE(child_proc->p_stats, sizeof *child_proc->p_stats, M_PSTATS);
FREE_ZONE(child_proc, sizeof *child_proc, M_PROC);
child_proc = NULL;
goto bad;
}
/*
* Find an unused PID.
*/
proc_list_lock();
nextpid++;
retry:
/*
* If the process ID prototype has wrapped around,
* restart somewhat above 0, as the low-numbered procs
* tend to include daemons that don't exit.
*/
if (nextpid >= PID_MAX) {
nextpid = 100;
pidwrap = 1;
}
if (pidwrap != 0) {
/* if the pid stays in hash both for zombie and runniing state */
if (pfind_locked(nextpid) != PROC_NULL) {
nextpid++;
goto retry;
}
if (pgfind_internal(nextpid) != PGRP_NULL) {
nextpid++;
goto retry;
}
if (session_find_internal(nextpid) != SESSION_NULL) {
nextpid++;
goto retry;
}
}
nprocs++;
child_proc->p_pid = nextpid;
child_proc->p_idversion = nextpidversion++;
/* kernel process is handcrafted and not from fork, so start from 1 */
//.........这里部分代码省略.........
开发者ID:kongove,项目名称:xnu,代码行数:101,代码来源:kern_fork.c
示例14: sizeof
//=============================================================================
// Build Header
//-----------------------------------------------------------------------------
// RFC 2616 / 6 Response (Header)
//
// The first line of a Response message is the Status-Line, consisting
// of the protocol version followed by a numeric status code and its
// associated textual phrase, with each element separated by SP
// characters. No CR or LF is allowed except in the final CRLF sequence.
//
// Response =Status-Line ; generated by SendHeader
// *(( general-header
// | response-header
// | entity-header ) CRLF)
// CRLF ; generated by SendHeader
// [ message-body ] ; by HOOK Handling Loop or Sendfile
//
// Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF ; generated by SendHeader
//
// general-header = Cache-Control ; not implemented
// | Connection ; implemented
// | Date ; implemented
// | Pragma ; not implemented
// | Trailer ; not implemented
// | Transfer-Encoding ; not implemented
// | Upgrade ; not implemented
// | Via ; not implemented
// | Warning ; not implemented
//
// response-header = Accept-Ranges ; not implemented
// | Age ; not implemented
// | ETag ; not implemented
// | Location ; implemented (redirection / Object moved)
// | Proxy-Authenticate ; not implemented
// | Retry-After ; not implemented
// | Server ; implemented
// | Vary ; not implemented
// | WWW-Authenticate ; implemented (by mod_auth and SendHeader)
//
// entity-header = Allow ; not implemented
// | Content-Encoding ; not implemented
// | Content-Language ; not implemented
// | Content-Length ; implemented
// | Content-Location ; not implemented
// | Content-MD5 ; not implemented
// | Content-Range ; not implemented
// | Content-Type ; implemented
// | Expires ; not implemented
// | Last-Modified ; implemented for static files
// | extension-header
//
// extension-header = message-header
//=============================================================================
std::string CyhookHandler::BuildHeader(bool cache) {
std::string result = "";
const char *responseString = "";
const char *infoString = 0;
// get Info Index
for (unsigned int i = 0; i < (sizeof(httpResponseNames)
/ sizeof(httpResponseNames[0])); i++)
if (httpResponseNames[i].type == httpStatus) {
responseString = httpResponseNames[i].name;
infoString = httpResponseNames[i].info;
break;
}
// print Status-line
result = string_printf(HTTP_PROTOCOL " %d %s\r\nContent-Type: %s\r\n",httpStatus, responseString, ResponseMimeType.c_str());
log_level_printf(2, "Respose: HTTP/1.1 %d %s\r\nContent-Type: %s\r\n",
httpStatus, responseString, ResponseMimeType.c_str());
switch (httpStatus) {
case HTTP_UNAUTHORIZED:
result += "WWW-Authenticate: Basic realm=\"";
result += AUTH_NAME_MSG "\r\n";
break;
case HTTP_MOVED_TEMPORARILY:
case HTTP_MOVED_PERMANENTLY:
// Status HTTP_*_TEMPORARILY (redirection)
result += string_printf("Location: %s\r\n", NewURL.c_str());
// NO break HERE !!!
default:
time_t timer = time(0);
char timeStr[80];
// cache
if (!cache && (HookVarList["CacheCategory"]).empty())
result += "Cache-Control: no-cache\r\n";
else {
time_t x_time = time(NULL);
struct tm *ptm = gmtime(&x_time);
ptm->tm_mday += 1;
x_time = mktime(ptm);
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&x_time));
result += string_printf("Expires: %s\r\n", timeStr);
}
result += "Server: " WEBSERVERNAME "\r\n";
// actual date
//.........这里部分代码省略.........
开发者ID:FFTEAM,项目名称:evolux-spark-sh4,代码行数:101,代码来源:yhook.cpp
示例15: while
} while (bytestream2_get_bytes_left(&s->gb) > 0);
memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE);
*got_frame = 1;
if ((ret = av_frame_ref(data, s->frame)) < 0)
return ret;
return buf_size;
}
static av_cold int decode_end(AVCodecContext *avctx)
{
AnmContext *s = avctx->priv_data;
av_frame_free(&s->frame);
return 0;
}
AVCodec ff_anm_decoder = {
.name = "anm",
.long_name = NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_ANM,
.priv_data_size = sizeof(AnmContext),
.init = decode_init,
.close = decode_end,
.decode = decode_frame,
.capabilities = CODEC_CAP_DR1,
};
开发者ID:TaoheGit,项目名称:hmi_sdl_android,代码行数:30,代码来源:anm.c
示例16: HaiCrypt_Clone
int HaiCrypt_Clone(HaiCrypt_Handle hhcSrc, HaiCrypt_CryptoDir tx, HaiCrypt_Handle *phhc)
{
hcrypt_Session *cryptoSrc = (hcrypt_Session *)hhcSrc;
hcrypt_Session *cryptoClone;
unsigned char *mem_buf;
size_t mem_siz, inbuf_siz;
*phhc = NULL;
ASSERT(NULL != hhcSrc);
/*
* If cipher has no special input buffer alignment requirement,
* handle it in the crypto session.
*/
inbuf_siz = cryptoSrc->inbuf_siz ;
/* Allocate crypto session control struct */
mem_siz = sizeof(hcrypt_Session) // structure
+ inbuf_siz;
cryptoClone = malloc(mem_siz);
if (NULL == cryptoClone){
HCRYPT_LOG(LOG_ERR, "%s\n", "malloc failed");
return(-1);
}
mem_buf = (unsigned char *)cryptoClone;
mem_buf += sizeof(*cryptoClone);
memset(cryptoClone, 0, sizeof(*cryptoClone));
memcpy(cryptoClone, cryptoSrc, sizeof(*cryptoClone));
if (inbuf_siz) {
cryptoClone->inbuf = mem_buf;
mem_buf += inbuf_siz;
}
timerclear(&cryptoClone->km.tx_last);
/* Adjust pointers pointing into cryproSrc after copy
msg_info adn ciphers are extern statics so this is ok*/
cryptoClone->ctx_pair[0].alt = &cryptoClone->ctx_pair[1];
cryptoClone->ctx_pair[1].alt = &cryptoClone->ctx_pair[0];
/* create a new cipher (OpenSSL) context */
cryptoClone->cipher_data = cryptoClone->cipher->open(cryptoClone->cfg.data_max_len);
if (NULL == cryptoClone->cipher_data) {
//shred
free(cryptoClone);
return(-1);
}
if (tx) { /* Sender */
hcrypt_Ctx *ctx = cryptoClone->ctx = &cryptoClone->ctx_pair[0];
cryptoClone->ctx_pair[0].flags |= HCRYPT_CTX_F_ENCRYPT;
cryptoClone->ctx_pair[1].flags |= HCRYPT_CTX_F_ENCRYPT;
/* Set SEK in cipher */
if (cryptoClone->cipher->setkey(cryptoClone->cipher_data, ctx, ctx->sek, ctx->sek_len)) {
HCRYPT_LOG(LOG_ERR, "cipher setkey(sek[%zd]) failed\n", ctx->sek_len);
return(-1);
}
ctx->status = HCRYPT_CTX_S_ACTIVE;
} else { /* Receiver */
/* Configure contexts */
if (hcryptCtx_Rx_Init(cryptoClone, &cryptoClone->ctx_pair[0], NULL)
|| hcryptCtx_Rx_Init(cryptoClone, &cryptoClone->ctx_pair[1], NULL)) {
free(cryptoClone);
return(-1);
}
/* Clear salt to force later regeneration of KEK as AES decrypting key,
copyed one is encrypting key */
cryptoClone->ctx_pair[0].flags &= ~HCRYPT_CTX_F_ENCRYPT;
cryptoClone->ctx_pair[1].flags &= ~HCRYPT_CTX_F_ENCRYPT;
memset(cryptoClone->ctx_pair[0].salt, 0, sizeof(cryptoClone->ctx_pair[0].salt));
cryptoClone->ctx_pair[0].salt_len = 0;
}
*phhc = (void *)cryptoClone;
return(0);
}
开发者ID:liu58995,项目名称:srt,代码行数:81,代码来源:hcrypt.c
示例17: main
//.........这里部分代码省略.........
Hit_Map_ana->GetYaxis()->SetRangeUser(1,78);
Hit_Map_ana->SetTitle("Analysis of measured data");
Hit_Map_ana->Draw("COLZ");
Hit_Map_ana->SetStats(0);
char txt[256];
sprintf(txt,"RUN%i_HitMap.pdf",RUN);
c3->SaveAs(txt);
/*
*cluster size
*/
//simulated data
TCanvas * c4 = new TCanvas("c4","c4",1200,600);
c4->Divide(2,1);
c4->cd(1);
c4->SetLogy(1);
sprintf(histname,"MyCMSPixelClusteringProcessor/detector_%i/clustersize_d%i",ROC_DUT,ROC_
|
请发表评论