/** * Appends along the last dimensions. */ static hid_t make_dataset(ndio_hdf5_t self,nd_type_id_t type_id,unsigned ndim,size_t *shape, hid_t* filespace) { hsize_t *sh=0,*ori=0,*ext=0; TRY(self->isw); STACK_ALLOC(hsize_t,sh ,ndim); STACK_ALLOC(hsize_t,ori,ndim); STACK_ALLOC(hsize_t,ext,ndim); if(self->dataset>=0) // data set already exists...needs extending, append on slowest dim { HTRY(H5Sget_simple_extent_dims(space(self),sh,NULL)); ZERO(hsize_t,ori,ndim); ori[0]=sh[0]; sh[0]+=shape[ndim-1]; reverse_hsz_sz(ndim,ext,shape); HTRY(H5Dextend(self->dataset,sh)); HTRY(*filespace=H5Dget_space(self->dataset)); HTRY(H5Sselect_hyperslab(*filespace,H5S_SELECT_SET,ori,NULL,ext,NULL)); } else { HTRY(self->dataset=H5Dcreate( self->file,name(self), nd_to_hdf5_type(type_id), make_space(self,ndim,shape), H5P_DEFAULT,/*(rare) link creation props*/ dataset_creation_properties( /*set_deflate*/( set_chunk(self,ndim,shape))), H5P_DEFAULT /*(rare) dataset access props*/ )); reverse_hsz_sz(ndim,sh,shape); *filespace=H5S_ALL; } HTRY(H5Dset_extent(self->dataset,sh)); return self->dataset; Error: return -1; }
void ase_string_buffer::append(const value_type *str, size_type len) { value_type *const p = make_space(len); ::memcpy(p, str, len * sizeof(value_type)); append_done(len); }
// 确保可写字节 void NetMessage::ensure_writable_bytes(size_t size) { if (writeable() < size) { make_space(size); } assert(writeable() >= size); }
Stringc::Stringc(const char ch) { chunk_size = STRINGC_CHUNK_SIZE; num_chars = 1; make_space(); (*this)[0] = ch; (*this)[num_chars] = '\0'; }
Stringc::Stringc() { chunk_size = STRINGC_CHUNK_SIZE; total_size = 0; num_chars = 0; make_space(); char_array[num_chars] = '\0'; }
Stringc::Stringc(const Stringc& str) { num_chars = str.num_chars; chunk_size = str.chunk_size; make_space(); for (int i=0; i< num_chars; i++) (*this)[i] = str[i]; (*this)[num_chars] = '\0'; }
Stringc::Stringc(int ichar) { chunk_size = STRINGC_CHUNK_SIZE; num_chars = ichar; make_space(); for (int i=0; i<num_chars; i++) char_array[i] = ' '; char_array[num_chars] = '\0'; }
void board1(void) { //prints("helloworld", 0, 0, 1,1.5); make_space(); init_player(2, 2000); player1_position = 0; player2_position = 0; //DEBUG TEST do { if (player[1] > 0) { player1_turn(); #ifdef __APPLE__ sleep(1); #else Sleep(1000); #endif } else printf("Player[1] is bankrupted, skip\n\n"); if (player[2] > 0) { player2_turn(); #ifdef __APPLE__ sleep(1); #else Sleep(1000); #endif } else printf("Player[2] is bankrupted, skip\n\n"); } while (player[1] > 0 || player[2] > 0); //analysis printf("\n\n"); for (int i=0; i<40; i++) { if (space[i].occupy_condition == -1 || space[i].occupy_condition == 0) { printf("[%d]%s is owned by the Mother Nature\n",i, space[i].space_name); } else printf("[%d]%s is owned by Player[%d]\n",i, space[i].space_name, space[i].occupy_condition); } //dice_ui(-1, 1); }
Stringc::Stringc(const char *ch_array) { chunk_size = STRINGC_CHUNK_SIZE; if (ch_array) num_chars = strlen(ch_array); else num_chars = 0; make_space(); for (int i=0;i<num_chars;i++) (*this)[i] = ch_array[i]; (*this)[num_chars] = '\0'; }
int get_file_descriptor(int bytes) { // Open a new file descriptor, creating the file if it does not exist // 0666 = read + write access for user, group and world int file_descriptor = open("/tmp/mmap", O_RDWR | O_CREAT, 0666); if (file_descriptor < 0) { throw("Error opening file!\n"); } // Ensure that the file will hold enough space make_space(file_descriptor, bytes); return file_descriptor; }
void Stringc::append(char ch) { num_chars++; if ( (num_chars+1) >= total_size ) { char* old_char_array = char_array; make_space(); if ( old_char_array ) { memcpy(char_array, old_char_array, num_chars*sizeof(char)); delete [] old_char_array; } } char_array[num_chars-1] = ch; char_array[num_chars] = '\0'; }
/** * Appends on last dimension. */ static unsigned hdf5_write(ndio_t file, nd_t src) { ndio_hdf5_t self=(ndio_hdf5_t)ndioContext(file); hid_t filespace=-1,dset; dset=make_dataset(self,ndtype(src),ndndim(src),ndshape(src),&filespace); HTRY(H5Dwrite(dset, nd_to_hdf5_type(ndtype(src)), make_space(self,ndndim(src),ndshape(src)), /*mem-space selector*/ filespace, /*file-space selector ... set up by make_dataset()*/ H5P_DEFAULT,/*xfer props*/ nddata(src) )); if(filespace>0) HTRY(H5Sclose(filespace)); return 1; Error: return 0; }
void Stringc::rdelete(int istart, int iend) { int i=0; if ((istart > -1)&&(istart < num_chars)&&(iend > -1)&&(iend < num_chars) &&(istart <= iend)) { int new_num = num_chars - (iend-istart+1); int new_size = ((new_num+1)/chunk_size)*chunk_size; if (new_size == total_size) { for( i=istart; i<new_num; i++) char_array[i] = char_array[i+(iend-istart+1)]; num_chars = new_num; char_array[num_chars] = '\0'; } else { int new_length = num_chars - (iend-istart+1); char *new_char = new char[new_length+1]; for (i=0; i<istart; i++) new_char[i] = char_array[i]; int j=istart; for (i=iend+1; i<num_chars; i++) { new_char[j] = char_array[i]; j++; } clear_space(); num_chars = new_length; make_space(); for ( i=0; i<num_chars; i++) char_array[i] = new_char[i]; char_array[num_chars] = '\0'; delete [] new_char; } } else { cout << "num_chars = " << num_chars << "\n"; cout << "Error in Stringc::delete routine.\n"; cout << " Bad range " << istart << " to " << iend; cout << "... Nothing will be deleted.\n"; } }
void Stringc::prepend(char ch) { num_chars++; if ( (num_chars+1) >= total_size ) { char* old_char_array = char_array; make_space(); if ( old_char_array ) { memcpy(char_array+1, old_char_array, num_chars*sizeof(char)); delete [] old_char_array; } } else { // shift chars for (int i = num_chars-1; i > 0; i--) char_array[i] = char_array[i-1]; } char_array[0] = ch; char_array[num_chars] = '\0'; }
static void dump_acpi_namespace(acpi_ns_device_info *device, char *root, int indenting) { char result[255]; char output[320]; char tabs[255] = ""; char hid[16] = ""; int i; size_t written = 0; for (i = 0; i < indenting; i++) strlcat(tabs, "| ", sizeof(tabs)); strlcat(tabs, "|--- ", sizeof(tabs)); int depth = sizeof(char) * 5 * indenting + sizeof(char); // index into result where the device name will be. void *counter = NULL; while (device->acpi->get_next_entry(ACPI_TYPE_ANY, root, result, 255, &counter) == B_OK) { uint32 type = device->acpi->get_object_type(result); snprintf(output, sizeof(output), "%s%s", tabs, result + depth); switch(type) { case ACPI_TYPE_INTEGER: snprintf(output, sizeof(output), "%s INTEGER", output); break; case ACPI_TYPE_STRING: snprintf(output, sizeof(output), "%s STRING", output); break; case ACPI_TYPE_BUFFER: snprintf(output, sizeof(output), "%s BUFFER", output); break; case ACPI_TYPE_PACKAGE: snprintf(output, sizeof(output), "%s PACKAGE", output); break; case ACPI_TYPE_FIELD_UNIT: snprintf(output, sizeof(output), "%s FIELD UNIT", output); break; case ACPI_TYPE_DEVICE: hid[0] = 0; /* zero-terminate string; get_device_hid can (and will) fail! */ device->acpi->get_device_hid(result, hid, sizeof(hid)); snprintf(output, sizeof(output), "%s DEVICE (%s)", output, hid); break; case ACPI_TYPE_EVENT: snprintf(output, sizeof(output), "%s EVENT", output); break; case ACPI_TYPE_METHOD: snprintf(output, sizeof(output), "%s METHOD", output); break; case ACPI_TYPE_MUTEX: snprintf(output, sizeof(output), "%s MUTEX", output); break; case ACPI_TYPE_REGION: snprintf(output, sizeof(output), "%s REGION", output); break; case ACPI_TYPE_POWER: snprintf(output, sizeof(output), "%s POWER", output); break; case ACPI_TYPE_PROCESSOR: snprintf(output, sizeof(output), "%s PROCESSOR", output); break; case ACPI_TYPE_THERMAL: snprintf(output, sizeof(output), "%s THERMAL", output); break; case ACPI_TYPE_BUFFER_FIELD: snprintf(output, sizeof(output), "%s BUFFER_FIELD", output); break; case ACPI_TYPE_ANY: default: break; } written = 0; RingBuffer &ringBuffer = *device->buffer; size_t toWrite = strlen(output); if (toWrite <= 0) break; strlcat(output, "\n", sizeof(output)); toWrite++; if (!ringBuffer.Lock()) break; if (ringBuffer.WritableAmount() < toWrite && !make_space(device, toWrite)) break; written = ringBuffer.Write(output, toWrite); ringBuffer.Unlock(); dump_acpi_namespace(device, result, indenting + 1); } }
static error_t parse_opt(int key, char *arg, struct argp_state *state) { struct args *args = state->input; switch (key) { case 's': args->stack = arg; if (strcmp(arg, "ip") && strcmp(arg, "xia")) argp_error(state, "Stack must be either 'ip', or 'xia'"); break; case 'r': args->add_rules = 1; assert(!arg); break; case 'e': args->ebtables = arg; break; case 't': args->sleep = arg_to_long(state, arg); if (args->sleep < 1) argp_error(state, "Sleep period must be >= 1"); break; case 'p': args->parents = 1; assert(!arg); break; case 'd': args->daemon = 1; assert(!arg); break; case 'f': args->file = arg; break; case ARGP_KEY_INIT: break; case ARGP_KEY_ARG: if (!if_nametoindex(arg)) argp_error(state, "Invalid interface `%s'", arg); make_space(args); args->ifs[args->count++] = arg; break; case ARGP_KEY_END: if (args->add_rules && args->count < 1) argp_error(state, "There must be at least one " "inteface to add"); break; default: return ARGP_ERR_UNKNOWN; } return 0; }