static void move_layer_block( char *src_char, char *src_color, int src_width, int src_offset, char *dest_char, char *dest_color, int dest_width, int dest_offset, int block_width, int block_height, int clear_width, int clear_height) { // Similar to copy_layer_to_layer_buffered, but deletes the source // after copying to the buffer. char *buffer_char = cmalloc(block_width * block_height); char *buffer_color = cmalloc(block_width * block_height); // Copy source to buffer copy_layer_buffer_to_buffer( src_char, src_color, src_width, src_offset, buffer_char, buffer_color, block_width, 0, block_width, block_height); // Clear the source clear_layer_block( src_char, src_color, src_width, src_offset, clear_width, clear_height); // Copy buffer to destination copy_layer_buffer_to_buffer( buffer_char, buffer_color, block_width, 0, dest_char, dest_color, dest_width, dest_offset, block_width, block_height); free(buffer_char); free(buffer_color); }
void comm_pseudo(PSEUDO *pseudo,MPI_Comm world,int myid) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" if(myid!=0){ pseudo->vxc_typ = (char *)cmalloc(MAXWORD*sizeof(char)); pseudo->ggax_typ = (char *)cmalloc(MAXWORD*sizeof(char)); pseudo->ggac_typ = (char *)cmalloc(MAXWORD*sizeof(char)); }/*endif*/ Barrier(world); Bcast(&(pseudo->vxc_typ[0]),MAXWORD,MPI_CHAR,0,world); /* must be from 0*/ Bcast(&(pseudo->ggax_typ[0]),MAXWORD,MPI_CHAR,0,world); Bcast(&(pseudo->ggac_typ[0]),MAXWORD,MPI_CHAR,0,world); Bcast(&(pseudo->gga_cut),1,MPI_DOUBLE,0,world); Bcast(&(pseudo->b3_cut),1,MPI_DOUBLE,0,world); Bcast(&(pseudo->b3_alp),1,MPI_DOUBLE,0,world); Bcast(&(pseudo->alpha_conv_dual),1,MPI_DOUBLE,0,world); Bcast(&(pseudo->n_interp_pme_dual),1,MPI_INT,0,world); Bcast(&(pseudo->nsplin_g),1,MPI_INT,0,world); Bcast(&(pseudo->nl_cut_on),1,MPI_INT,0,world); Bcast(&(pseudo->nlvps_skin),1,MPI_DOUBLE,0,world); Barrier(world); /*------------------------------------------------------------------------*/ } /*end routine*/
void newgroup(FILE *output, char *group_name, char **description, int words) { group *g; char *dstring; int i, len = 0; if (group_name && words > 0) { g = get_group(group_name); if (g != NULL && ! prohibited_group_p(g)) { fprintf(output, "Group %s already exists\n.\n", group_name); return; } for (i = 0; i < words; i++) len += strlen(description[i]) + 1; dstring = cmalloc(len); for (i = 0; i < words; i++) { if (i > 0) strcat(dstring, " "); strcat(dstring, description[i]); } g->group_description = enter_string_storage(dstring); alphabetize_groups(); free(dstring); fprintf(output, "Created group %s\n.\n", group_name); } else { fprintf(output, "Not creating group %s\n.\n", group_name); } }
static void font_box_put_item ( char **item, /* Pointer to the pointer to the */ /* item to insert (C is great) */ /* RETURNED */ int *number, /* Pointer to the number of items */ /* RETURNED */ char ***menu_list) /* Pointer to the pointer to the */ /* array of items (C is $%*!@#) */ { int i, j; /* Do nothing if the item is undefined */ if (NULL == *item) return; /* Search an item equal to the one to insert in the list */ for (i = 0; (i < *number) && (strcmp ((*menu_list) [i], *item)); i++); /* If found, modify the pointer to the item */ if (i < *number) { eif_rt_xfree (*item); *item = (*menu_list) [i]; return; } /* If not insert it into the list */ if ((*number)++) *menu_list = (char **) crealloc (*menu_list, (*number)*sizeof (char *)); else *menu_list = (char **) cmalloc (sizeof (char *)); (*menu_list) [i] = *item; }
int load_mzm(struct world *mzx_world, char *name, int start_x, int start_y, int mode, int savegame) { FILE *input_file; size_t file_size; void *buffer; int success; input_file = fopen_unsafe(name, "rb"); if(input_file) { fseek(input_file, 0, SEEK_END); file_size = ftell(input_file); buffer = cmalloc(file_size); fseek(input_file, 0, SEEK_SET); fread(buffer, file_size, 1, input_file); fclose(input_file); success = load_mzm_common(mzx_world, buffer, (int)file_size, start_x, start_y, mode, savegame, name); free(buffer); return success; } else { error_message(E_MZM_DOES_NOT_EXIST, 0, name); return -1; } }
static bool swivel_current_dir(bool have_video) { bool ret = false; char *base_path; int g_ret; // Store the user's current directory, so we can get back to it getcwd(previous_dir, MAX_PATH); base_path = cmalloc(MAX_PATH); // Find and change into the base path for this MZX binary g_ret = get_path(process_argv[0], base_path, MAX_PATH); if(g_ret <= 0) goto err_free_base_path; if(chdir(base_path)) { if(have_video) error("Failed to change into install directory.", 1, 8, 0); else warn("Failed to change into install directory.\n"); goto err_free_base_path; } ret = true; err_free_base_path: free(base_path); return ret; }
void init_node_table(void) { node_table = (int*)cmalloc(node_table_length * sizeof(int)); #ifdef USAGE printf("Allocating %dM for node hash table\n", meg(node_table_length * sizeof(int))); #endif }
void help_open(struct world *mzx_world, const char *file_name) { mzx_world->help_file = fopen_unsafe(file_name, "rb"); if(!mzx_world->help_file) return; help = cmalloc(1024 * 64); }
void ·_Cfunc_CString(String s, int8 *p) { p = runtime·cmalloc(s.len+1); runtime·memmove((byte*)p, s.str, s.len); p[s.len] = 0; FLUSH(&p); }
int add_rule(char *s, char *t, char *c, char *p, policydb_t *policy) { type_datum_t *src, *tgt; class_datum_t *cls; perm_datum_t *perm; avtab_datum_t *av; avtab_key_t key; src = hashtab_search(policy->p_types.table, s); if (src == NULL) { fprintf(stderr, "source type %s does not exist\n", s); return 2; } tgt = hashtab_search(policy->p_types.table, t); if (tgt == NULL) { fprintf(stderr, "target type %s does not exist\n", t); return 2; } cls = hashtab_search(policy->p_classes.table, c); if (cls == NULL) { fprintf(stderr, "class %s does not exist\n", c); return 2; } perm = hashtab_search(cls->permissions.table, p); if (perm == NULL) { if (cls->comdatum == NULL) { fprintf(stderr, "perm %s does not exist in class %s\n", p, c); return 2; } perm = hashtab_search(cls->comdatum->permissions.table, p); if (perm == NULL) { fprintf(stderr, "perm %s does not exist in class %s\n", p, c); return 2; } } // See if there is already a rule key.source_type = src->s.value; key.target_type = tgt->s.value; key.target_class = cls->s.value; key.specified = AVTAB_ALLOWED; av = avtab_search(&policy->te_avtab, &key); if (av == NULL) { int ret; av = cmalloc(sizeof av); av->data |= 1U << (perm->s.value - 1); ret = avtab_insert(&policy->te_avtab, &key, av); if (ret) { fprintf(stderr, "Error inserting into avtab\n"); return 1; } } av->data |= 1U << (perm->s.value - 1); return 0; }
static struct manifest_entry *manifest_entry_copy(struct manifest_entry *src) { struct manifest_entry *dest; size_t name_len; dest = cmalloc(sizeof(struct manifest_entry)); name_len = strlen(src->name); dest->name = cmalloc(name_len + 1); strncpy(dest->name, src->name, name_len); dest->name[name_len] = 0; memcpy(dest->sha256, src->sha256, sizeof(Uint32) * 8); dest->size = src->size; dest->next = NULL; return dest; }
void font_box_fill_menu (Widget **menu_buttons, Widget menu, int *number, char ***menu_list) { int i; *menu_buttons = (Widget *) cmalloc ((*number)*sizeof (Widget)); for (i = 0; i < *number; i++) { (*menu_buttons) [i] = XmCreatePushButtonGadget (menu, (*menu_list) [i], NULL, 0); XtManageChild ((*menu_buttons) [i]); } }
/* Send count characters directly to the command. */ void send_string(unsigned char* buf, int count) { unsigned char* s; register unsigned char* s1, *s2; register int i; if (count == 0) { return; } if (send_count == 0) { if (send_buf != NULL) { free(send_buf); send_buf = NULL; } send_buf = (unsigned char*)cmalloc(count); s2 = send_buf; s1 = buf; for (i = 0; i < count; i++, s1++, s2++) { *s2 = *s1; } send_nxt = send_buf; send_count = count; } else { s = (unsigned char*)cmalloc(send_count + count); memcpy(s, send_nxt, send_count); s2 = s + send_count; s1 = buf; for (i = 0; i < count; i++, s1++, s2++) { *s2 = *s1; } free(send_buf); send_buf = send_nxt = s; send_count += count; } }
struct audio_stream *construct_mikmod_stream(char *filename, Uint32 frequency, Uint32 volume, Uint32 repeat) { FILE *input_file; char *input_buffer; Uint32 file_size; struct audio_stream *ret_val = NULL; input_file = fopen_unsafe(filename, "rb"); if(input_file) { MODULE *open_file; file_size = ftell_and_rewind(input_file); input_buffer = cmalloc(file_size); fread(input_buffer, file_size, 1, input_file); open_file = MikMod_LoadSongRW(SDL_RWFromMem(input_buffer, file_size), 64); if(open_file) { struct mikmod_stream *mm_stream = cmalloc(sizeof(struct mikmod_stream)); mm_stream->module_data = open_file; Player_Start(mm_stream->module_data); initialize_sampled_stream((struct sampled_stream *)mm_stream, mm_set_frequency, mm_get_frequency, frequency, 2, 0); ret_val = (struct audio_stream *)mm_stream; construct_audio_stream((struct audio_stream *)mm_stream, mm_mix_data, mm_set_volume, mm_set_repeat, mm_set_order, mm_set_position, mm_get_order, mm_get_position, mm_destruct, volume, repeat); } fclose(input_file); free(input_buffer); } return ret_val; }
void extend_string_storage(void) { size_t new_length = string_storage_length * 2; char *new_string_storage = cmalloc(new_length); printf("Extending string storage from %dM to %dM\n", meg(string_storage_length), meg(new_length)); memcpy(new_string_storage, string_storage, string_storage_length); crfree(string_storage, string_storage_length); string_storage = new_string_storage; string_storage_length = new_length; }
void inserer_symbole(char *nom, int val, char *str, int ch) { //printf("inserer_symbole(%s, %d, %s, %d)\n", nom, val, str, ch); /*printf("avant\n"); print_table_symboles();*/ liste_symboles *aux = table_symboles; if (aux != NULL) { while (aux->suivant != NULL) { aux = aux->suivant; } aux->suivant = (liste_symboles *)cmalloc(sizeof(liste_symboles)); aux = aux->suivant; aux->nom = strdup(nom); if (ch) { aux->val_chaine = strdup(str); } else { aux->valeur = val; aux->val_chaine = strdup(""); } aux->chaine = ch; aux->suivant = NULL; } else { table_symboles = (liste_symboles *)cmalloc(sizeof(liste_symboles)); table_symboles->nom = strdup(nom); if (ch) { table_symboles->val_chaine = strdup(str); } else { table_symboles->valeur = val; table_symboles->val_chaine = strdup(""); } table_symboles->chaine = ch; table_symboles->suivant = NULL; } /*printf("après\n"); print_table_symboles();*/ }
void set_fallback_res (EIF_POINTER w, EIF_OBJ res, EIF_INTEGER count) { int counter = 0; if (fallback_list != (String *) 0) { String * temp = fallback_list; while (temp) eif_rt_xfree (*(temp++)); eif_rt_xfree (fallback_list); fallback_list = (String *) 0; } if (res != (EIF_OBJ) 0) { fallback_list = (String *) cmalloc (count * sizeof (String) + 1); while (count > counter) { *(fallback_list + counter) = (String) cmalloc (strlen (*((char **)eif_access(res) + counter)) + 1); strcpy (*(fallback_list + counter), *((char **)(eif_access (res)) + counter)); counter++; } *(fallback_list + counter) = (String) 0; } XtAppSetFallbackResources ((XtAppContext) w, fallback_list); }
void title_screen(context *parent) { struct config_info *conf = get_config(); struct game_context *title; struct context_spec spec; if(edit_world) { conf->standalone_mode = false; } if(conf->standalone_mode && conf->no_titlescreen) { struct game_context dummy; dummy.ctx.world = parent->world; if(load_world_gameplay(&dummy, curr_file)) { play_game(parent, NULL); return; } conf->standalone_mode = false; } title = cmalloc(sizeof(struct game_context)); title->fade_in = true; title->need_reload = true; title->load_dialog_on_failed_load = true; title->is_title = true; memset(&spec, 0, sizeof(struct context_spec)); spec.resume = title_resume; spec.draw = game_draw; spec.idle = game_idle; spec.key = title_key; spec.joystick = title_joystick; spec.destroy = game_destroy; create_context((context *)title, parent, &spec, CTX_TITLE_SCREEN); default_palette(); if(edit_world && conf->startup_editor) { title->load_dialog_on_failed_load = false; edit_world((context *)title, true); } clear_screen(); }
int thread_init(int num) { if (cmalloc((void**)&wet, (sizeof(WRITE_EV_THREAD) + num * sizeof(WEVENT_T))) < 0 || wet == NULL) { error(EXIT_FAILURE, errno, "not enough memory\n"); return -1; } // wet = (WRITE_EV_THREAD*)cmalloc(sizeof(WRITE_EV_THREAD) + num * sizeof(WEVENT_T)); wet->base = event_init(); wet->evno = num; wet->st = STAT_READ_MORE; memset(&wet->ev, 0, num * sizeof(WEVENT_T)); create_stream(&wet->stream, 4096 * 1024); wet->stream.fd = STDIN_FILENO; // ret = (READ_EV_THREAD*)cmalloc(sizeof(READ_EV_THREAD) + num * sizeof(struct fdev_t)); if (cmalloc((void**)&ret, (sizeof(READ_EV_THREAD) + num * sizeof(struct fdev_t))) < 0 || ret == NULL) { error(EXIT_FAILURE, errno, "not enough memory\n"); return -1; } ret->base = event_init(); ret->evno = num; return 0; }
/******************************************************************************** * Specifies when the automata should change the state. If the automata is in * state "from_state" and reads the word "keyword" it changes to state "to_state" ********************************************************************************/ void add_change_state(int from_state, char *keyword, int to_state) { struct s_change *change; change = &change_head; while(change->next != NULL) change = change->next; change->next = cmalloc(sizeof(struct s_change)); change = change->next; change->from_state = from_state; change->keyword = keyword; change->to_state = to_state; change->next = NULL; }
bool yuv_init_video(struct graphics_data *graphics, struct config_info *conf) { struct yuv_render_data *render_data = cmalloc(sizeof(struct yuv_render_data)); if(!render_data) return false; graphics->render_data = render_data; graphics->allow_resize = conf->allow_resize; render_data->ratio = conf->video_ratio; if(!set_video_mode()) return false; return true; }
void init_string_hash (void) { string_storage = cmalloc(string_storage_length); string_storage_table = (size_t*)cmalloc(STRING_STORAGE_TABLE_LENGTH * sizeof(size_t)); #ifdef USAGE printf("Allocating %dM for string storage\n", meg(string_storage_length)); printf("Allocating %dM for string hash table\n", meg(STRING_STORAGE_TABLE_LENGTH * sizeof(size_t))); #endif if ((string_storage_file = open64(index_file_name(STRING_STORAGE_FILE), O_RDWR|O_CREAT, 0644)) == -1) { fprintf(stderr, "Couldn't open %s\n", index_file_name(STRING_STORAGE_FILE)); merror("Opening the string storage file."); } if (file_size(string_storage_file) == 0) { write_from(string_storage_file, "@@@", 4); next_string = 4; } else smart_populate_string_table_from_file(string_storage_file); }
void font_box_set_font (char *font_name, EIF_POINTER client) { font_box_data *temp; char *f_name; if ((char *) 0 == (f_name = cmalloc(strlen(font_name)))) enomem(); strcpy(f_name, font_name); temp = (font_box_data *) client; temp->current_font_name = f_name; font_box_update_family ((font_box_data*)client); temp->current_stand_font = font_box_match_stand_font (temp); temp->current_font_name = temp->stand_fonts_list [temp->current_stand_font]->name; font_box_show_font (temp); }
// createSocketAddress -------------------------------------------------------- // This function create a SOCKADDR structure resolving given ADDRESS and PORT. // A pointer to this structure is returned. // ---------------------------------------------------------------------------- struct sockaddr *createSocketAddress(char *address, short port) { struct sockaddr_in *sa=NULL; struct in_addr *ia=NULL; sa = cmalloc(sizeof(struct sockaddr_in)); sa->sin_family = AF_INET; sa->sin_port = htons(port); if (isdigit(address[0])) // check if the address is "dotted" inet_pton(sa->sin_family, address, &sa->sin_addr); else { // if not, resolve the domain address ia = getHostEntryAddress(address); memcpy(&sa->sin_addr, ia, sizeof(struct in_addr)); } return (struct sockaddr *) sa; }
static void delete_hook(const char *file) { struct manifest_entry *new_entry; struct SHA256_ctx ctx; bool ret; FILE *f; new_entry = ccalloc(1, sizeof(struct manifest_entry)); if(!new_entry) goto err_out; if(delete_p) { delete_p->next = new_entry; delete_p = delete_p->next; } else delete_list = delete_p = new_entry; delete_p->name = cmalloc(strlen(file) + 1); if(!delete_p->name) goto err_delete_p; strcpy(delete_p->name, file); f = fopen_unsafe(file, "rb"); if(!f) goto err_delete_p_name; delete_p->size = (unsigned long)ftell_and_rewind(f); ret = manifest_compute_sha256(&ctx, f, delete_p->size); fclose(f); if(!ret) goto err_delete_p_name; memcpy(delete_p->sha256, ctx.H, sizeof(Uint32) * 8); return; err_delete_p_name: free(delete_p->name); err_delete_p: free(delete_p); delete_p = NULL; err_out: return; }
individual *newperson (void) { individual *ind; ind = cmalloc (sizeof (individual)); memset (ind,0,sizeof (individual)); ind->sex = S_UNKNOWN; if (findperson(ind->id)) { printf("Not possible to create a new person as ID already exists\n"); return findperson(ind->id); } else addlist (&individuals,ind); return ind; }
/* Creates a schedule of mergers for processes during distributed merge sort. */ int* create_merge_schedule(int world_size, int world_rank, int* num_merges_ret) { int i; /* Find the closest power of two to determine the size of the swap schedule */ i = 0; while ((1 << i) < world_size) { i++; } *num_merges_ret = (1 << i) - 1; int* swap_schedule = (int*)cmalloc(sizeof(int) * (*num_merges_ret)); for (i = 0; i < (*num_merges_ret); i++) { swap_schedule[i] = (world_rank & ~(i + 1)) | (~world_rank & (i + 1)); } return swap_schedule; }
void init_group_hash (void) { group_table = (int*)cmalloc(MAX_GROUPS * sizeof(int)); #ifdef USAGE printf("Allocating %dM for group hash table\n", meg(MAX_GROUPS * sizeof(int))); #endif if ((group_file = open64(index_file_name(GROUP_FILE), O_RDWR|O_CREAT, 0644)) == -1) merror("Opening the group file."); next_group_id = 1; if (file_size(group_file) == 0) { write_from(group_file, (char*)(&groups[0]), sizeof(group)); } else populate_group_table_from_file(group_file); }
/******************************************************************************** * Adds a state to the automata. "new_state" is a unique value. The three parametes * "init_f", "read_f" and "check_f" spefify pointer to functions. "init_f" is called * when the state "new_state" is entered, "read_f" is called for execution the * the state and "check_f" is called when the state is exited. ********************************************************************************/ void add_state(int new_state, void *init_f, void *read_f, void *check_f) { struct s_node *node; node = &head; /* goto end of link list */ while(node->next != NULL) node = node->next; node->next = cmalloc(sizeof(struct s_node)); node = node->next; node->state = new_state; node->init = init_f; node->read = read_f; node->check = check_f; node->next = NULL; }
rt_shared void ufill(void) { /* Fill in the urgent chunk array as far as possible. At the time this * routine is called, it is safe to call the GC if we get short in memory, * hence we may call cmalloc directly. */ int i; /* Location to be filled in */ char *chunk; /* Allocated chunk */ for (i = urgent_index + 1; i < URGENT_NBR; i++) { chunk = cmalloc(URGENT_CHUNK); /* Attempt allocation */ if (chunk == (char *) 0) /* Could not get memory */ break; urgent_mem[i] = chunk; /* Record chunk for later perusal */ } urgent_index = i - 1; /* Points on last available chunk */ }