static void avi_writer_write_stream_format(AviWriter *self) { avi_writer_push_chunk(self, "strf"); /* This is a BITMAPINFO structure for video streams */ /* BITMAPINFOHEADER size */ write_int32(self->file, 0x28); /* width and height */ write_int32(self->file, self->width); write_int32(self->file, self->height); /* Number of planes, "must be set to 1" */ write_int16(self->file, 1); /* bits per pixel */ write_int16(self->file, 24); /* compression */ write_int32(self->file, 0); /* size, in bytes, of the image */ write_int32(self->file, self->width * self->height * 3); /* horizontal/vertical pixels per meter (75 dpi) */ write_int32(self->file, 2952); write_int32(self->file, 2952); /* Color table size and number of important colors */ write_int32(self->file, 0); write_int32(self->file, 0); avi_writer_pop_chunk(self); }
struct data_buffer* gen_stat_packet(char* cmd,uint8_t* type,MEM_POOL* mem_pool) { char* table_name = NULL; char* token = NULL; uint32_t tblen; if((table_name = strtok(NULL," ")) == NULL) return NULL; tblen = strlen(table_name); if((token = strtok(NULL," ")) == NULL) return NULL; *type = atoi(token); struct data_buffer *dbuf = init_data_buffer(); size_t data_len = tblen + 5 * sizeof(uint8_t) + MESSAGE_HEAD_LEN + 2*sizeof(uint32_t); databuf_resize(dbuf, data_len); //写入数据长度 write_int32(data_len,dbuf); write_int8(1, dbuf); write_int8(1, dbuf); write_int16(MT_CD_STAT, dbuf); write_int32(0, dbuf); //timeout write_int32(0, dbuf); //拼接协议包 write_int32(tblen,dbuf); write_bytes((uint8_t*)table_name,tblen,dbuf); write_int8(*type,dbuf); return dbuf; }
struct data_buffer* gen_set_load_threshold_packet(char* cmd,MEM_POOL* mem_pool) { struct data_buffer *dbuf = init_data_buffer(); size_t data_len = MESSAGE_HEAD_LEN + 2*sizeof(uint32_t) + sizeof(double); databuf_resize(dbuf, data_len); //写入数据长度 write_int32(data_len,dbuf); write_int8(1, dbuf); write_int8(1, dbuf); write_int16(MT_CD_EXE_SET_LOAD_THRESHOLD, dbuf); write_int32(0, dbuf); //timeout write_int32(0, dbuf); char *value_str = strtok(NULL, " "); if (!value_str) return NULL; double value = atof(value_str); write_bytes((uint8_t *)&value, sizeof(value), dbuf); return dbuf; }
int32_t process_test_message(struct mile_message_header* msg_head, struct data_buffer* rbuf, struct data_buffer* sbuf) { int32_t result_code = MILE_RETURN_SUCCESS; MEM_POOL_PTR mem_pool; switch (msg_head->message_type) { case MT_TEST_REQ_ECHO: // echo message for testing. { mem_pool = mem_pool_init(MB_SIZE); const char *str = read_cstring(rbuf, mem_pool); log_debug("get echo message [%s]", str); write_int32(0, sbuf); write_int8(msg_head->version_major, sbuf); write_int8(msg_head->version_minor, sbuf); write_int16(MT_TEST_RES_ECHO, sbuf); write_int32(msg_head->message_id, sbuf); write_int32(strlen(str), sbuf); write_bytes((uint8_t *) str, strlen(str), sbuf); fill_int32(sbuf->data_len, sbuf, 0); result_code = MILE_RETURN_SUCCESS; mem_pool_destroy(mem_pool); } break; default: result_code = -1; break; } return result_code; }
struct data_buffer* gen_load_packet(char* cmd,MEM_POOL* mem_pool) { char* table_name = NULL; char* segment_dir = NULL; char* token = NULL; uint32_t tblen; uint32_t dirlen; uint16_t sid; if((table_name = strtok(NULL," ")) == NULL) return NULL; tblen = strlen(table_name); if((token = strtok(NULL," ")) == NULL) return NULL; sid = atoi(token); if((segment_dir = strtok(NULL," ")) == NULL) return NULL; dirlen = strlen(segment_dir); struct data_buffer *dbuf = init_data_buffer(); size_t data_len = tblen + dirlen + 10 * sizeof(uint8_t) + MESSAGE_HEAD_LEN + 2*sizeof(uint32_t); databuf_resize(dbuf, data_len); //写入数据长度 write_int32(data_len,dbuf); write_int8(1, dbuf); write_int8(1, dbuf); write_int16(MT_CD_EXE_LOAD, dbuf); write_int32(0, dbuf); //timeout write_int32(0, dbuf); //拼接协议包 write_int32(tblen,dbuf); write_bytes((uint8_t*)table_name,tblen,dbuf); write_int16(sid,dbuf); write_int32(dirlen,dbuf); write_bytes((uint8_t*)segment_dir,dirlen,dbuf); return dbuf; }
static bool write_MOD_chunk(IOStream *ios, size_t chunk_size) { int init_func = -1; const void *init_idx; if (ST_find(&st_functions, "initialize", &init_idx)) init_func = (long)init_idx; return chunk_begin(ios, "MOD ", chunk_size) && write_int16(ios, 0x0100) && /* file version: 1.0 */ write_int16(ios, 0) && /* reserved */ write_int32(ios, AR_size(&ar_vars)) && write_int32(ios, num_entities) && write_int32(ios, AR_size(&ar_properties)) && write_int32(ios, init_func) && chunk_end(ios, chunk_size); }
void *spice_marshaller_add_int16(SpiceMarshaller *m, int16_t v) { uint8_t *ptr; ptr = spice_marshaller_reserve_space(m, sizeof(int16_t)); write_int16(ptr, v); return (void *)ptr; }
struct data_buffer* gen_ensure_index_packet(char* cmd,MEM_POOL* mem_pool) { char* table_name = NULL; char* field_name = NULL; uint32_t tblen; uint32_t fdlen; char* token; enum index_key_alg index_type; enum field_types data_type; if((table_name = strtok(NULL," ")) == NULL) return NULL; if((field_name = strtok(NULL," ")) == NULL) return NULL; if((token = strtok(NULL," ")) == NULL) return NULL; index_type = (index_key_alg)atoi(token); if(index_type > 0xff) return NULL; if((token = strtok(NULL," ")) == NULL) return NULL; data_type = (enum field_types)atoi(token); if(data_type > 0xff) return NULL; tblen = strlen(table_name); fdlen = strlen(field_name); struct data_buffer *dbuf = init_data_buffer(); size_t data_len = tblen + fdlen + 10 * sizeof(uint8_t) + MESSAGE_HEAD_LEN + 2*sizeof(uint32_t); databuf_resize(dbuf, data_len); //写入数据长度 write_int32(data_len,dbuf); write_int8(1, dbuf); write_int8(1, dbuf); write_int16(MT_CD_EXE_INDEX, dbuf); write_int32(0, dbuf); //timeout write_int32(0, dbuf); //拼接协议包 write_int32(tblen,dbuf); write_bytes((uint8_t*)table_name,tblen,dbuf); write_int32(fdlen,dbuf); write_bytes((uint8_t*)field_name,fdlen,dbuf); write_int8(index_type,dbuf); write_int8(data_type,dbuf); return dbuf; }
void save_exceptions() { dbFILE *f; int i; static time_t lastwarn = 0; if (! (f = open_db(s_OperServ, ExceptionDBName, "w", EXCEPTION_VERSION))) return; SAFE(write_int16(nexceptions, f)); for (i = 0; i < nexceptions; i++) { SAFE(write_string(exceptions[i].mask, f)); SAFE(write_int16(exceptions[i].limit, f)); SAFE(write_buffer(exceptions[i].who, f)); SAFE(write_string(exceptions[i].reason, f)); SAFE(write_int32(exceptions[i].time, f)); SAFE(write_int32(exceptions[i].expires, f)); } close_db(f); }
static int writer_int16(lua_State* L) { writer_t* writer = lua_touserdata(L, 1); lua_Integer integer = luaL_checkinteger(L, 2); if(integer < INT16_MIN || integer > INT16_MAX) luaL_error(L, "integer overflow"); write_int16(writer, (int16_t)integer); return 0; }
int key_value_write_lines(FILE *f, struct key_value_specification *kvs, void *base_address[]) { struct key_value_specification *k; int rc; int errs = 0; for (k = kvs; k->key; k++) { switch (k->type) { case KVS_STRING: rc = write_string(f, k, base_address); break; case KVS_INT64: rc = write_int64(f, k, base_address); break; case KVS_INT32: rc = write_int32(f, k, base_address); break; case KVS_INT16: rc = write_int16(f, k, base_address); break; case KVS_INT8: rc = write_int8(f, k, base_address); break; case KVS_UINT64: rc = write_uint64(f, k, base_address); break; case KVS_UINT32: rc = write_uint32(f, k, base_address); break; case KVS_UINT16: rc = write_uint16(f, k, base_address); break; case KVS_UINT8: rc = write_uint8(f, k, base_address); break; case KVS_DOUBLE: rc = write_double(f, k, base_address); break; case KVS_FLOAT: rc = write_float(f, k, base_address); break; default: fprintf(stderr, "%s:%d: unknown key type '%c' for key '%s'\n", __func__, __LINE__, k->type, k->key); rc = -1; break; } if (rc) errs++; } return errs; }
void Linker::read_atom(FILE* f, FILE* pFtarg) { aBYTE buf[2]; aINT16 temp, gatom; if (0 == fread(buf, 2, 1, f)) aborteof(aS("read atom")); temp = getint16(buf); gatom = map_atom(temp); //fwrite(&gatom, 2, 1, pFtarg); write_int16(gatom, pFtarg); }
struct data_buffer* gen_checkpoint_packet(char* cmd,MEM_POOL* mem_pool) { struct data_buffer *dbuf = init_data_buffer(); size_t data_len = MESSAGE_HEAD_LEN + 2*sizeof(uint32_t); databuf_resize(dbuf, data_len); //写入数据长度 write_int32(data_len,dbuf); write_int8(1, dbuf); write_int8(1, dbuf); write_int16(MT_CD_EXE_CP, dbuf); write_int32(0, dbuf); //timeout write_int32(0, dbuf); return dbuf; }
struct data_buffer* gen_get_load_threshold_packet(char* cmd,MEM_POOL* mem_pool) { struct data_buffer *dbuf = init_data_buffer(); size_t data_len = MESSAGE_HEAD_LEN + 2*sizeof(uint32_t); databuf_resize(dbuf, data_len); //写入数据长度 write_int32(data_len,dbuf); write_int8(1, dbuf); write_int8(1, dbuf); write_int16(MT_CD_EXE_GET_LOAD_THRESHOLD, dbuf); write_int32(0, dbuf); //timeout write_int32(0, dbuf); return dbuf; }
static void avi_writer_write_stream_header(AviWriter *self) { avi_writer_push_chunk(self, "strh"); /* data type: video stream */ write_fourcc(self->file, "vids"); /* data handler (video codec) */ write_fourcc(self->file, "DIB "); /* flags */ write_int32(self->file, 0); /* priority */ write_int16(self->file, 1); /* language */ write_int16(self->file, 0); /* initial frames */ write_int32(self->file, 0); /* scale followed by rate. For video streams, (rate/scale) is the frame rate. */ write_int32(self->file, RATE_SCALE); write_int32(self->file, self->frame_rate * RATE_SCALE); /* start */ write_int32(self->file, 0); /* length (we fill this in later) */ self->length_offset = ftell(self->file); write_int32(self->file, 0); /* suggested buffer size */ write_int32(self->file, self->width * self->height * 3 + 1024); /* quality */ write_int32(self->file, 10000); /* sample size */ write_int32(self->file, 0); /* frame position and size (left, top, right, bottom) */ write_int16(self->file, 0); write_int16(self->file, 0); write_int16(self->file, self->width - 1); write_int16(self->file, self->height - 1); avi_writer_pop_chunk(self); }
TEST(DATA_BUFFER_TEST, READ_AND_WRITE){ MEM_POOL_PTR pMemPool = mem_pool_init(MB_SIZE); struct data_buffer* buffer = init_data_buffer(); buffer->data_len = 256; buffer->data = (uint8*) mem_pool_malloc(pMemPool, 256); uint8 tmp8; uint16 tmp16; uint32 tmp32; uint64 tmp64; char* str = (char*) mem_pool_malloc(pMemPool, 100); char* result = (char*) mem_pool_malloc(pMemPool, 100); strcpy(str, "hello world!"); write_int8(122, buffer); write_int16(1111, buffer); write_int32(324, buffer); write_int64(2321, buffer); write_bytes((uint8*)str, strlen(str)+1, buffer); tmp8 = read_int8(buffer); ASSERT_EQ(tmp8, 122); tmp16 = read_int16(buffer); ASSERT_EQ(tmp16, 1111); tmp32 = read_int32(buffer); ASSERT_EQ(tmp32, 324); tmp64 = read_int64(buffer); ASSERT_EQ(tmp64, 2321); read_bytes(buffer, (uint8*)result, strlen(str)+1); ASSERT_EQ(0, strcmp(str, result)); destroy_data_buffer(buffer); mem_pool_destroy(pMemPool); }
static bool write_FUN_chunk(IOStream *ios, size_t chunk_size) { if (!chunk_begin(ios, "FUN ", chunk_size)) return false; Function *functions = (Function*)AR_data(&ar_functions); size_t nfunction = AR_size(&ar_functions), n, i; if (!write_int32(ios, (int)nfunction)) return false; /* Write function headers */ for (n = 0; n < nfunction; ++n) { if (!write_int16(ios, 0) || !write_int8(ios, functions[n].nret) || !write_int8(ios, functions[n].nparam)) { return false; } } /* Write function instructions */ for (n = 0; n < nfunction; ++n) { Instruction *ins = functions[n].instrs; for (i = 0; (int)i < functions[n].ninstr; ++i) { assert(ins[i].opcode == (ins[i].opcode&255)); assert(ins[i].argument >= -0x00800000 && ins[i].argument <= 0x007fffff); if (!write_int8(ios, ins[i].opcode) || !write_int24(ios, ins[i].argument)) return false; } if (!write_int32(ios, 0)) return false; } return chunk_end(ios, chunk_size); }
struct data_buffer *gen_ldb_control_packet(char *cmd, MEM_POOL *mem_pool) { // make cmd to full command while (strtok(NULL, " ")); struct data_buffer *dbuf = init_data_buffer(); // header write_int32(0, dbuf); write_int8(1, dbuf); write_int8(1, dbuf); write_int16(MT_CD_EXE_LDB_CONTROL, dbuf); write_int32(0, dbuf); //timeout write_int32(0, dbuf); write_int32(strlen(cmd), dbuf); write_bytes((uint8_t *)cmd, strlen(cmd), dbuf); fill_int32(dbuf->data_len, dbuf, 0); return dbuf; }
void save_os_dbase(void) { int i; dbFILE *f; static time_t lastwarn = 0; Akill *ak; SXLine *sx; if (!(f = open_db(s_OperServ, OperDBName, "w", OPER_VERSION))) return; SAFE(write_int32(maxusercnt, f)); SAFE(write_int32(maxusertime, f)); SAFE(write_int16(akills.count, f)); for (i = 0; i < akills.count; i++) { ak = akills.list[i]; SAFE(write_string(ak->user, f)); SAFE(write_string(ak->host, f)); SAFE(write_string(ak->by, f)); SAFE(write_string(ak->reason, f)); SAFE(write_int32(ak->seton, f)); SAFE(write_int32(ak->expires, f)); } SAFE(write_int16(sglines.count, f)); for (i = 0; i < sglines.count; i++) { sx = sglines.list[i]; SAFE(write_string(sx->mask, f)); SAFE(write_string(sx->by, f)); SAFE(write_string(sx->reason, f)); SAFE(write_int32(sx->seton, f)); SAFE(write_int32(sx->expires, f)); } SAFE(write_int16(sqlines.count, f)); for (i = 0; i < sqlines.count; i++) { sx = sqlines.list[i]; SAFE(write_string(sx->mask, f)); SAFE(write_string(sx->by, f)); SAFE(write_string(sx->reason, f)); SAFE(write_int32(sx->seton, f)); SAFE(write_int32(sx->expires, f)); } SAFE(write_int16(szlines.count, f)); for (i = 0; i < szlines.count; i++) { sx = szlines.list[i]; SAFE(write_string(sx->mask, f)); SAFE(write_string(sx->by, f)); SAFE(write_string(sx->reason, f)); SAFE(write_int32(sx->seton, f)); SAFE(write_int32(sx->expires, f)); } close_db(f); }
/* Writes instructions within a basic block boundary. */ void write_instructions(MVMThreadContext *tc, MVMSpeshGraph *g, SpeshWriterState *ws, MVMSpeshBB *bb) { MVMSpeshIns *ins = bb->first_ins; while (ins) { MVMint32 i; /* Process any annotations. */ MVMSpeshAnn *ann = ins->annotations; MVMSpeshAnn *deopt_one_ann = NULL; MVMSpeshAnn *deopt_all_ann = NULL; MVMSpeshAnn *deopt_inline_ann = NULL; while (ann) { switch (ann->type) { case MVM_SPESH_ANN_FH_START: ws->handlers[ann->data.frame_handler_index].start_offset = ws->bytecode_pos; break; case MVM_SPESH_ANN_FH_END: ws->handlers[ann->data.frame_handler_index].end_offset = ws->bytecode_pos; break; case MVM_SPESH_ANN_FH_GOTO: ws->handlers[ann->data.frame_handler_index].goto_offset = ws->bytecode_pos; break; case MVM_SPESH_ANN_DEOPT_ONE_INS: deopt_one_ann = ann; break; case MVM_SPESH_ANN_DEOPT_ALL_INS: deopt_all_ann = ann; break; case MVM_SPESH_ANN_INLINE_START: g->inlines[ann->data.inline_idx].start = ws->bytecode_pos; break; case MVM_SPESH_ANN_INLINE_END: g->inlines[ann->data.inline_idx].end = ws->bytecode_pos; break; case MVM_SPESH_ANN_DEOPT_INLINE: deopt_inline_ann = ann; break; case MVM_SPESH_ANN_DEOPT_OSR: g->deopt_addrs[2 * ann->data.deopt_idx + 1] = ws->bytecode_pos; break; } ann = ann->next; } if (ins->info->opcode != MVM_SSA_PHI) { /* Real instruction, not a phi. Emit opcode. */ if (ins->info->opcode == (MVMuint16)-1) { /* Ext op; resolve. */ MVMExtOpRecord *extops = g->sf->body.cu->body.extops; MVMuint16 num_extops = g->sf->body.cu->body.num_extops; MVMint32 found = 0; for (i = 0; i < num_extops; i++) { if (extops[i].info == ins->info) { write_int16(ws, MVM_OP_EXT_BASE + i); found = 1; break; } } if (!found) MVM_exception_throw_adhoc(tc, "Spesh: failed to resolve extop in code-gen"); } else { /* Core op. */ write_int16(ws, ins->info->opcode); } /* Write out operands. */ for (i = 0; i < ins->info->num_operands; i++) { MVMuint8 flags = ins->info->operands[i]; MVMuint8 rw = flags & MVM_operand_rw_mask; switch (rw) { case MVM_operand_read_reg: case MVM_operand_write_reg: write_int16(ws, ins->operands[i].reg.orig); break; case MVM_operand_read_lex: case MVM_operand_write_lex: write_int16(ws, ins->operands[i].lex.idx); write_int16(ws, ins->operands[i].lex.outers); break; case MVM_operand_literal: { MVMuint8 type = flags & MVM_operand_type_mask; switch (type) { case MVM_operand_int8: write_int8(ws, ins->operands[i].lit_i8); break; case MVM_operand_int16: write_int16(ws, ins->operands[i].lit_i16); break; case MVM_operand_int32: write_int32(ws, ins->operands[i].lit_i32); break; case MVM_operand_int64: write_int64(ws, ins->operands[i].lit_i64); break; case MVM_operand_num32: write_num32(ws, ins->operands[i].lit_n32); break; case MVM_operand_num64: write_num64(ws, ins->operands[i].lit_n64); break; case MVM_operand_callsite: write_int16(ws, ins->operands[i].callsite_idx); break; case MVM_operand_coderef: write_int16(ws, ins->operands[i].coderef_idx); break; case MVM_operand_str: write_int32(ws, ins->operands[i].lit_str_idx); break; case MVM_operand_ins: { MVMint32 offset = ws->bb_offsets[ins->operands[i].ins_bb->idx]; if (offset >= 0) { /* Already know where it is, so just write it. */ write_int32(ws, offset); } else { /* Need to fix it up. */ if (ws->num_fixups == ws->alloc_fixups) { ws->alloc_fixups *= 2; ws->fixup_locations = MVM_realloc(ws->fixup_locations, ws->alloc_fixups * sizeof(MVMint32)); ws->fixup_bbs = MVM_realloc(ws->fixup_bbs, ws->alloc_fixups * sizeof(MVMSpeshBB *)); } ws->fixup_locations[ws->num_fixups] = ws->bytecode_pos; ws->fixup_bbs[ws->num_fixups] = ins->operands[i].ins_bb; write_int32(ws, 0); ws->num_fixups++; } break; } case MVM_operand_spesh_slot: write_int16(ws, ins->operands[i].lit_i16); break; default: MVM_exception_throw_adhoc(tc, "Spesh: unknown operand type %d in codegen (op %s)", (int)type, ins->info->name); } } break; default: MVM_exception_throw_adhoc(tc, "Spesh: unknown operand type in codegen"); } } } /* If there was a deopt point annotation, update table. */ if (deopt_one_ann) g->deopt_addrs[2 * deopt_one_ann->data.deopt_idx + 1] = ws->bytecode_pos; if (deopt_all_ann) g->deopt_addrs[2 * deopt_all_ann->data.deopt_idx + 1] = ws->bytecode_pos; if (deopt_inline_ann) g->deopt_addrs[2 * deopt_inline_ann->data.deopt_idx + 1] = ws->bytecode_pos; ins = ins->next; } }
void write_bmp(int *picture, int width, int height) { FILE *out; int bmp_width; int bmp_size; int padding; int offset; int color; int x,y; out = fopen("out.bmp", "wb"); if (out == NULL) { printf("Can't open file for writing."); return; } bmp_width = width * 3; bmp_width = (bmp_width + 3) & (~0x3); bmp_size = (bmp_width * height) + 14 + 40; padding = bmp_width - (width * 3); //printf("width=%d (%d)\n", width, width*3); //printf("bmp_width=%d\n", bmp_width); //printf("bmp_size=%d\n", bmp_size); /* size: 14 bytes */ putc('B', out); putc('M', out); write_int32(out, bmp_size); write_int16(out, 0); write_int16(out, 0); write_int32(out, 54); /* head1: 14 head2: 40 */ write_int32(out, 40); /* biSize */ write_int32(out, width); write_int32(out, height); write_int16(out, 1); write_int16(out, 24); write_int32(out, 0); /* compression */ write_int32(out, bmp_width*height); write_int32(out, 0); /* biXPelsperMetre */ write_int32(out, 0); /* biYPelsperMetre */ write_int32(out, 0); write_int32(out, 0); for (y = 0; y < height; y++) { offset = y * width; for (x = 0; x < width; x++) { color = picture[offset++]; putc(color & 0xff, out); putc((color >> 8) & 0xff, out); putc((color >> 16) & 0xff, out); } for (x = 0; x < padding; x++) { putc(0, out); } } fclose(out); }
void Linker::read_const(FILE *f, FILE *pFtarg, long *pi) { /* a constant is a tag followed by constant data tag = 1 -> constant is short atom tag = 2 -> constant is short int tag = 3 -> constant is arb string terminated by EOS tag = 4 -> constant is 4 byte float tag = 5 -> constant is 4 byte long tag = 6 -> constant is 4 byte long wide char tag = 7 -> constant is 8 byte double tag = 8 -> constant is real */ aBYTE buf[8]; int ccount; aBYTE ibyte; aINT16 temp, length; aINT32 temp32; aCHAR ichar; if (0 == fread(buf, 1, 1, f)) aborteof(aS("read const")); ucFWRITE(buf, 1, 1, pFtarg); (*pi) += 1; switch(*buf) { case 1: read_atom(f, pFtarg); (*pi) += 2; break; case 2: if (0 == fread(buf, 2, 1, f)) aborteof(aS("read const 2")); ucFWRITE(buf, 2, 1, pFtarg); (*pi) += 2; break; case 3: // single byte string ccount = 1; if (0 == fread(&ibyte, 1, 1, f)) aborteof(aS("read const 3")); ichar = (aCHAR)ibyte; while(ichar) { ++ccount; ucFWRITE(&ichar, 1, 1, pFtarg); if (0 == fread(&ibyte, 1, 1, f)) aborteof(aS("read const 3b")); ichar = (aCHAR)ibyte; } ucFWRITE(&ichar, 1, 1, pFtarg); (*pi) += ccount*sizeof(char); break; case 4: // float if (0 == fread(buf, 4, 1, f)) aborteof(aS("read const 4")); ucFWRITE(buf, 4, 1, pFtarg); (*pi) += 4; break; case 5: // long if (0 == fread(buf, 4, 1, f)) aborteof(aS("read const 5")); ucFWRITE(buf, 4, 1, pFtarg); (*pi) += 4; break; case 6: // wide character string ccount = 1; // if (0 == fread(&ichar, sizeof(aCHAR), 1, f)) if (!read_int16(&temp, f)) aborteof(aS("read const 3")); while(temp) { ++ccount; // ucFWRITE(&ichar, sizeof(aCHAR), 1, pFtarg); write_int16(temp, pFtarg); // if (0 == fread(&ichar, sizeof(aCHAR), 1, f)) if (!read_int16(&temp, f)) aborteof(aS("read const 3b")); } // fwrite(&ichar, sizeof(aCHAR), 1, pFtarg); write_int16(temp, pFtarg); (*pi) += ccount*2; break; case 9: // fixed case 7: // C double if (0 == fread(buf, 8, 1, f)) aborteof(aS("read const 7")); ucFWRITE(buf, 8, 1, pFtarg); (*pi) += 8; break; case 8: for(ccount = 0; ccount < 6; ccount += 2) { // copy the real descr if (!read_int16(&temp, f)) aborteof(aS("read const 3")); if(ccount == 0) length = temp; // length write_int16(temp, pFtarg); } while(length) { // copy the gigits if (!read_int32(&temp32, f)) aborteof(aS("read const 3b")); write_int32(temp32, pFtarg); ccount+= 4; length--; } (*pi) += ccount; } // end switch }
void save_ns_dbase(void) { dbFILE *f; int i; NickInfo *ni; char **access; static time_t lastwarn = 0; if (!(f = open_db(s_NickServ, NickDBName, "w"))) return; for (ni = firstnick(); ni; ni = nextnick()) { SAFE(write_int8(1, f)); SAFE(write_buffer(ni->nick, f)); SAFE(write_buffer(ni->pass, f)); SAFE(write_string(ni->url, f)); SAFE(write_string(ni->email, f)); SAFE(write_string(ni->last_usermask, f)); SAFE(write_string(ni->last_realname, f)); SAFE(write_string(ni->last_quit, f)); SAFE(write_int32(ni->time_registered, f)); SAFE(write_int32(ni->last_seen, f)); SAFE(write_int16(ni->status, f)); if (ni->link) { SAFE(write_string(ni->link->nick, f)); SAFE(write_int16(ni->linkcount, f)); SAFE(write_int16(ni->channelcount, f)); } else { SAFE(write_string(NULL, f)); SAFE(write_int16(ni->linkcount, f)); SAFE(write_int32(ni->flags, f)); SAFE(write_ptr(ni->suspendinfo, f)); if (ni->suspendinfo) { SAFE(write_buffer(ni->suspendinfo->who, f)); SAFE(write_string(ni->suspendinfo->reason, f)); SAFE(write_int32(ni->suspendinfo->suspended, f)); SAFE(write_int32(ni->suspendinfo->expires, f)); } SAFE(write_int16(ni->accesscount, f)); for (i=0, access=ni->access; i<ni->accesscount; i++, access++) SAFE(write_string(*access, f)); SAFE(write_int16(ni->channelcount, f)); SAFE(write_int16(ni->channelmax, f)); SAFE(write_int16(ni->language, f)); } } /* for (ni) */ { /* This is an UGLY HACK but it simplifies loading. It will go away * in the next file version */ static char buf[256]; SAFE(write_buffer(buf, f)); } close_db(f); return; fail: restore_db(f); log_perror("Write error on %s", NickDBName); if (time(NULL) - lastwarn > WarningTimeout) { wallops(NULL, "Write error on %s: %s", NickDBName, strerror(errno)); lastwarn = time(NULL); } }