本文整理汇总了C++中write_bytes函数的典型用法代码示例。如果您正苦于以下问题:C++ write_bytes函数的具体用法?C++ write_bytes怎么用?C++ write_bytes使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_fan_id
int
parse_fan_id(char *line)
{
unsigned int input_val, offset, i;
offset = fan_id_num * FAN_BLOCK_SIZE;
fan_id_num++;
if (scan_line(line, &input_val) == ERROR)
return (ERROR);
for (i = 0; i < fan_id_num-1; i++) {
if (!memcmp(&input_val, &id_header.fan_block[i*FAN_BLOCK_SIZE],
FAN_ID_SIZE)) {
printf("ERROR: Two fans with id = %x\n", input_val);
return (ERROR);
}
}
write_bytes(input_val, FAN_ID_SIZE, offset, id_header.fan_block);
offset += FAN_ID_SIZE;
write_bytes(running_offset, FAN_OFF_SIZE, offset, id_header.fan_block);
return (NO_ERROR);
}
示例2: store32
/* Store a 32-bit integer into the cache file according to the file format. */
static krb5_error_code
store32(krb5_context context, krb5_ccache id, uint32_t i)
{
unsigned char buf[4];
k5_cc_mutex_assert_locked(context, &((fcc_data *)id->data)->lock);
if (version(id) < 3)
store_32_n(i, buf);
else
store_32_be(i, buf);
return write_bytes(context, id, buf, 4);
}
示例3: llvm_gcda_emit_arcs
void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) {
uint32_t i;
uint64_t *old_ctrs = NULL;
uint32_t val = 0;
uint64_t save_cur_pos = cur_pos;
if (!output_file) return;
val = read_32bit_value();
if (val != (uint32_t)-1) {
/* There are counters present in the file. Merge them. */
if (val != 0x01a10000) {
fprintf(stderr, "profiling: %s: cannot merge previous GCDA file: "
"corrupt arc tag (0x%08x)\n",
filename, val);
return;
}
val = read_32bit_value();
if (val == (uint32_t)-1 || val / 2 != num_counters) {
fprintf(stderr, "profiling: %s: cannot merge previous GCDA file: "
"mismatched number of counters (%d)\n",
filename, val);
return;
}
old_ctrs = malloc(sizeof(uint64_t) * num_counters);
for (i = 0; i < num_counters; ++i)
old_ctrs[i] = read_64bit_value();
}
cur_pos = save_cur_pos;
/* Counter #1 (arcs) tag */
write_bytes("\0\0\xa1\1", 4);
write_32bit_value(num_counters * 2);
for (i = 0; i < num_counters; ++i) {
counters[i] += (old_ctrs ? old_ctrs[i] : 0);
write_64bit_value(counters[i]);
}
free(old_ctrs);
#ifdef DEBUG_GCDAPROFILING
fprintf(stderr, "llvmgcda: %u arcs\n", num_counters);
for (i = 0; i < num_counters; ++i)
fprintf(stderr, "llvmgcda: %llu\n", (unsigned long long)counters[i]);
#endif
}
示例4: parse_id
int
parse_id(char *line)
{
unsigned int input_val, offset, i;
offset = id_num * SENSOR_BLOCK_SIZE;
id_num++;
if (scan_line(line, &input_val) == ERROR)
return (ERROR);
for (i = 0; i < id_num-1; i++) {
if (!memcmp(&input_val, &id_header.id_block[i*SENSOR_BLOCK_SIZE],
ID_SIZE)) {
printf("ERROR: Two sensors with id = %x\n", input_val);
return (ERROR);
}
}
write_bytes(input_val, ID_SIZE, offset, id_header.id_block);
offset += ID_SIZE;
write_bytes(running_offset, OFFSET_SIZE, offset, id_header.id_block);
return (NO_ERROR);
}
示例5: va_start
int tu_file::printf(const char* fmt, ...)
// Use printf-like semantics to send output to this stream.
{
// Workspace for vsnprintf formatting.
static const int BUFFER_SIZE = 1000;
char buffer[BUFFER_SIZE];
va_list ap;
va_start(ap, fmt);
vsnprintf(buffer, BUFFER_SIZE, fmt, ap);
va_end(ap);
return write_bytes(buffer, (int) strlen(buffer));
}
示例6: write_708_cc
static int write_708_cc( obe_user_data_t *user_data, uint8_t *start, int cc_count )
{
bs_t s;
uint8_t temp[1000];
const char *user_identifier = "GA94";
const int data_type_code = 0x03;
/* TODO: when MPEG-2 is added make this do the right thing */
/* FIXME: enable echostar captions and add more types */
bs_init( &s, temp, 1000 );
/* N.B MPEG-4 only */
write_itu_t_codes( &s );
for( int i = 0; i < 4; i++ )
bs_write( &s, 8, user_identifier[i] ); // user_identifier
bs_write( &s, 8, data_type_code ); // user_data_type_code
// user_data_type_structure (echostar)
// cc_data
bs_write1( &s, 1 ); // reserved
bs_write1( &s, 1 ); // process_cc_data_flag
bs_write1( &s, 0 ); // zero_bit / additional_data_flag
bs_write( &s, 5, cc_count ); // cc_count
bs_write( &s, 8, 0xff ); // reserved
write_bytes( &s, start, cc_count*3 );
bs_write( &s, 8, 0xff ); // marker_bits
bs_flush( &s );
user_data->type = USER_DATA_AVC_REGISTERED_ITU_T35;
user_data->len = bs_pos( &s ) >> 3;
free( user_data->data );
user_data->data = malloc( user_data->len );
if( !user_data->data )
{
syslog( LOG_ERR, "Malloc failed\n" );
return -1;
}
memcpy( user_data->data, temp, user_data->len );
return 0;
}
示例7: store_principal
static krb5_error_code
store_principal(krb5_context context, krb5_ccache id, krb5_principal princ)
{
krb5_error_code ret;
unsigned char *bytes;
size_t len;
k5_cc_mutex_assert_locked(context, &((fcc_data *)id->data)->lock);
ret = k5_marshal_princ(princ, version(id), &bytes, &len);
if (ret)
return ret;
ret = write_bytes(context, id, bytes, len);
free(bytes);
return ret;
}
示例8: lwrite_binary_string
lref_t lwrite_binary_string(lref_t string, lref_t port)
{
if (!STRINGP(string))
vmerror_wrong_type_n(1, string);
if (!BINARY_PORTP(port))
vmerror_wrong_type_n(2, port);
size_t sz = (string->as.string.dim * sizeof(_TCHAR));
size_t written = write_bytes(port, string->as.string.data, sz);
if (written != sz)
vmerror_io_error(_T("error writing to port."), port);
return port;
}
示例9: do_page_fault
void do_page_fault(void *addr, size_t len, int fault_mode)
{
switch (fault_mode) {
case PG_FAULT_READ:
read_bytes(len, addr);
break;
case PG_FAULT_WRITE:
write_bytes(len, addr);
break;
case PG_FAULT_RWLOOP:
fault_rwloop(len, addr);
break;
case PG_FAULT_NONE:
default:
break;
}
}
示例10: lbinary_write_flonum
lref_t lbinary_write_flonum(lref_t v, lref_t port)
{
if (!NUMBERP(v))
vmerror_wrong_type_n(1, v);
if (!BINARY_PORTP(port))
vmerror_wrong_type_n(2, port);
uint8_t bytes[sizeof(flonum_t)];
io_encode_flonum(bytes, get_c_flonum(v));
if (write_bytes(port, bytes, sizeof(flonum_t)) != sizeof(flonum_t))
vmerror_io_error(_T("error writing to port."), port);
return port;
}
示例11: do_data_transfer
static int do_data_transfer(struct mmc *dev,
struct mmc_cmd *cmd,
struct mmc_data *data)
{
int error = -ETIMEDOUT;
struct pl180_mmc_host *host = dev->priv;
u32 blksz = 0;
u32 data_ctrl = 0;
u32 data_len = (u32) (data->blocks * data->blocksize);
if (!host->version2) {
blksz = (ffs(data->blocksize) - 1);
data_ctrl |= ((blksz << 4) & SDI_DCTRL_DBLKSIZE_MASK);
} else {
blksz = data->blocksize;
data_ctrl |= (blksz << SDI_DCTRL_DBLOCKSIZE_V2_SHIFT);
}
data_ctrl |= SDI_DCTRL_DTEN | SDI_DCTRL_BUSYMODE;
writel(SDI_DTIMER_DEFAULT, &host->base->datatimer);
writel(data_len, &host->base->datalength);
udelay(DATA_REG_DELAY);
if (data->flags & MMC_DATA_READ) {
data_ctrl |= SDI_DCTRL_DTDIR_IN;
writel(data_ctrl, &host->base->datactrl);
error = do_command(dev, cmd);
if (error)
return error;
error = read_bytes(dev, (u32 *)data->dest, (u32)data->blocks,
(u32)data->blocksize);
} else if (data->flags & MMC_DATA_WRITE) {
error = do_command(dev, cmd);
if (error)
return error;
writel(data_ctrl, &host->base->datactrl);
error = write_bytes(dev, (u32 *)data->src, (u32)data->blocks,
(u32)data->blocksize);
}
return error;
}
示例12: write_index
/**
* Goes back and writes out the subroutine list
*/
void write_index() {
fseek(dest_file, 3, SEEK_SET);
int bytesRemaining = indexSize - 3;
for (int i = 0; i < subroutinesCount; ++i) {
int entrySize = strlen(subroutinesTable[i].name) + 5;
// Ensure there is enough remaining space
if ((bytesRemaining - entrySize) < 0) {
printf("Index has exceeded allowable size.\n");
token = ERROR;
}
// Write out the name and the file offset
write_bytes((byte *)&subroutinesTable[i].name, strlen(subroutinesTable[i].name) + 1);
write_long(subroutinesTable[i].fileOffset);
}
}
示例13: dynamic_inflate
void dynamic_inflate(reader_t *reader)
{
size_t hlit = read_HLIT(reader) + 257;
size_t hdist = read_HDIST(reader) + 1;
size_t hclen = read_HCLEN(reader) + 4;
/*printf("hclen = %d, hlit = %d, hdist = %d\n", hclen, hlit, hdist);*/
huffman_code litlen_codes[hlit];
huffman_code offset_codes[hdist];
read_alphabets(reader,
litlen_codes, hlit,
offset_codes, hdist,
hclen);
io *io_s;
init_io(&io_s);
byte bytes[LEN_MAX];
size_t litlen;
bool is_end_of_block = false;
size_t block_size = 0;
while (!is_end_of_block) {
litlen = read_next_huffman_code(reader, litlen_codes, hlit);
block_size++;
if (litlen < END_OF_BLOCK)
write_byte(io_s, litlen);
else if (litlen == END_OF_BLOCK)
is_end_of_block = true;
else {
two_bytes length = decode_length(reader, litlen);
two_bytes offcode = read_next_huffman_code(reader,
offset_codes,
hdist);
two_bytes distance = decode_distance(reader, offcode);
get_cyclic_queue(io_s->output, bytes, length, distance);
write_bytes(io_s, bytes, length);
block_size = block_size - 1 + length;
}
}
/*printf("block_size = %d\n", block_size);*/
write_to_output(io_s, reader->output);
delete_io(&io_s);
}
示例14: msg_send
void msg_send(uint8_t chan, mavlink_message_t *p_msg)
{
uint8_t buf[1024];
uint16_t len;
uint16_t write_len;
len = mavlink_msg_to_send_buffer(buf, p_msg);
switch(chan)
{
case 0:
write_len = write_bytes((char *)buf, (uint32_t)len);
if( write_len != len ) printf("wlen %d : len %d\r\n", write_len, len);
break;
case 1:
break;
}
}
示例15: update_fan_table
int
update_fan_table(char *parameter, char *line)
{
int i = 0, offset = 0;
unsigned int input_val;
int size;
unsigned char *data_ptr;
while (strcmp(fan_parameters[i].name, parameter)) {
offset += fan_parameters[i++].size;
if (fan_parameters[i].name == NULL) {
fprintf(stderr,
"%s is not a valid fan parameter\n", parameter);
return (ERROR);
}
}
size = fan_parameters[i].size;
data_ptr = cur_fan_table->fan_data;
if (strcmp(parameter, "fan-min-range") == 0) {
offset = FAN_MIN_RANGE_SZ * current_fan_pair;
current_fan_pair++;
data_ptr = cur_fan_table->fan_ctl_data;
if ((fan_min_range_scan(line, &input_val) == ERROR))
return (ERROR);
} else if ((scan_line(line, &input_val) == ERROR))
return (ERROR);
if (strcmp(parameter, "num-ctl-pairs") == 0) {
num_fan_ctl_pairs = input_val;
cur_fan_table->fan_ctl_data =
(unsigned char *) malloc(FAN_MIN_RANGE_SZ *
num_fan_ctl_pairs);
cur_fan_table->fan_pair_size = num_fan_ctl_pairs *
FAN_MIN_RANGE_SZ;
}
write_bytes(input_val, size, offset, data_ptr);
return (NO_ERROR);
}