int mysql_pool_get(struct mysql_login_info *info, struct mysql_pool_entry **mysql) { if (0 > make_ht_key(&misc, info)) return -1; char *ht_key = vmbuf_data(&misc); size_t key_len = vmbuf_wlocpos(&misc); uint32_t ofs = hashtable_lookup(&ht_idle_connections, ht_key, key_len); if (0 == ofs) { struct list *l = (struct list *)calloc(1, sizeof(struct list)); list_init(l); ofs = hashtable_insert(&ht_idle_connections, ht_key, key_len, &l, sizeof(struct list *)); if (0 == ofs) // unable to insert return -1; // add one element since we know there isn't any if (0 > create_entry(l)) return -1; // get first free element if (0 > get_free_entry(info, l, mysql)) return -1; } struct list *l = *(struct list **)hashtable_get_val(&ht_idle_connections, ofs); if (list_empty(l)) { LOGGER_INFO("adding one more entry in the list"); if (0 > create_entry(l)) return -1; } if (0 > get_free_entry(info, l, mysql)) return -1; return 0; }
int ghostfs_rename(struct ghostfs *gfs, const char *path, const char *newpath) { struct dir_iter it; struct dir_entry *entry; int ret; ret = dir_iter_lookup(gfs, &it, path, false); if (ret < 0) return ret; if (it.entry == &gfs->root_entry) return -EINVAL; remove_entry(gfs, newpath, false); ret = create_entry(gfs, newpath, false, &entry); if (ret < 0) return ret; // remove old entry it.entry->filename[0] = '\0'; cluster_set_dirty(it.cluster, true); // fix new entry entry->size = it.entry->size; entry->cluster = it.entry->cluster; return 0; }
sid symboltable::reg_type(s_ptr<ast_type_id> t) { sid i = create_entry(symbolref::t_type, types.size()); t->assign(i); types.push_back(t); return i; }
void rl_add_seq(uint8_t src_addr[ETH_ALEN], uint8_t dest_addr[ETH_ALEN], uint16_t seq_num) { uint8_t key[ETH_ALEN * 2]; memcpy(key, src_addr, ETH_ALEN); memcpy(key + ETH_ALEN, dest_addr, ETH_ALEN); rl_packet_id_t* entry = NULL; HASH_FIND(hh, rl_entrys, key, ETH_ALEN * 2, entry); if(entry == NULL) { entry = create_entry(key); if(entry == NULL) { return; } HASH_ADD_KEYPTR(hh, rl_entrys, entry->src_dest_addr, ETH_ALEN * 2, entry); } sw_addsn(entry->sw, seq_num); struct timeval purge_time; gettimeofday(&purge_time, NULL); struct timeval timeout; timeout.tv_sec = window_size; timeout.tv_usec = 0; hf_add_tv(&purge_time, &timeout, &purge_time); timeslot_addobject(rl_ts, &purge_time, entry); }
sid symboltable::reg_arg(s_ptr<ast_f_arg> a) { sid i = create_entry(symbolref::t_arg, args.size()); a->assign(i); args.push_back(a); return i; }
sid symboltable::reg_lvar(s_ptr<ast_var_decl> lv) { sid i = create_entry(symbolref::t_local_var, local_vars.size()); lv->assign(i); local_vars.push_back(lv); return i; }
sid symboltable::reg_cons(s_ptr<ast_construct> cons) { sid i = create_entry(symbolref::t_construct, conss.size()); cons->assign(i); conss.push_back(cons); return i; }
sid symboltable::reg_var(s_ptr<ast_var_decl> v) { sid i = create_entry(symbolref::t_var, vars.size()); v->assign(i); vars.push_back(v); return i; }
sid symboltable::reg_fun(s_ptr<ast_fun_decl> f) { sid i = create_entry(symbolref::t_fun, funs.size()); f->assign(i); funs.push_back(f); return i; }
gboolean refresh(PROC_T *p){ if(!p->entry_iseed) create_entry(p); switch(p->status.info){ case 0: break; case S_RUNNING: break; case S_WAIT: /*waiting to start */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Waiting"); break; case S_START: /*just started. */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Started"); { char lb[12]; char stime[80]; snprintf(lb,12," %5d",p->pid); struct tm *tim=localtime(&(p->status.timstart)); strftime(stime,80,"[%F %k:%M:%S]",tim); strcat(stime,lb); gtk_label_set_text(GTK_LABEL(p->entry_pid), stime); } notify_user(p); break; case S_QUEUED: /*queued in scheduler */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Queued"); break; case S_FINISH:/*Finished */ p->frac=1; change_button(p,GTK_STOCK_APPLY,(GCallback)delete_hbox_event); /*progress bar color. */ gtk_widget_modify_bg(p->entry_timing,GTK_STATE_SELECTED,&green); notify_user(p); break; case S_CRASH:/*Error */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Error"); change_button(p,GTK_STOCK_CLOSE,(GCallback)delete_hbox_event); gtk_widget_modify_base(p->entry_timing,GTK_STATE_NORMAL,&red); notify_user(p); break; case S_TOKILL:/*kill command sent */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Kill command sent"); change_button(p,GTK_STOCK_CLOSE,(GCallback)delete_hbox_event); gtk_widget_modify_base(p->entry_timing,GTK_STATE_NORMAL,&yellow); break; case S_KILLED: gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Killed"); change_button(p,GTK_STOCK_CLOSE,(GCallback)delete_hbox_event); gtk_widget_modify_base(p->entry_timing,GTK_STATE_NORMAL,&red); notify_user(p); break; default: warning("Unknown info\n"); } update_prog(p); return 0; }
void parse_lumpy(std::string lumpy_bede, std::vector<strvcfentry> & entries, int min_number_supporting, double max_eval) { size_t buffer_size = 2000000; char*buffer = new char[buffer_size]; std::ifstream myfile; myfile.open(lumpy_bede.c_str(), std::ifstream::in); if (!myfile.good()) { std::cout << "Lumpy Parser: could not open file: " << lumpy_bede.c_str() << std::endl; exit(0); } int call_id=entries.size(); myfile.getline(buffer, buffer_size); while (!myfile.eof()) { int count = 0; short type = -1; double eval = 99; strregion region; int support = 0; for (size_t i = 0; i < buffer_size && buffer[i] != '\0' && buffer[i] != '\n'; i++) { if (count == 7 && buffer[i - 1] == '\t') { eval = atof(&buffer[i]); } if (count >9 && strncmp(&buffer[i], "TYPE:", 5) == 0) { //get type; type = get_type(&buffer[i + 5]); } if (count > 10 && strncmp(&buffer[i], "STRANDS", 7) == 0) { //get support val; support = get_support(&buffer[i + 7]); } if (count > 10 && strncmp(&buffer[i], "MAX:", 4) == 0) { //get positions; region = get_coords(&buffer[i + 4]); } if (buffer[i] == '\t') { count++; } } //filter the parsed SV: if (support > min_number_supporting && eval < max_eval) { //std::cout<<eval<<" "<<type<<" "<<region.start.pos<<" "<<region.stop.pos<<std::endl; //detect overlap with delly: //if no overlap construct vcf entry for Lumpy: entries.push_back(create_entry(region,eval,support,type,call_id)); call_id++; } myfile.getline(buffer, buffer_size); } myfile.close(); }
int main (int argc, char **argv) { GtkWidget *main_window; GtkTreeModel *main_model; GtkTreeIter iter; RBEntryView *view; RhythmDB *db; RhythmDBEntry *entry; gtk_init (&argc, &argv); gdk_threads_init (); rb_thread_helpers_init (); rb_file_helpers_init (TRUE); rb_stock_icons_init (); rb_debug_init (TRUE); GDK_THREADS_ENTER (); db = rhythmdb_tree_new ("test"); rhythmdb_write_lock (db); entry = create_entry (db, "file:///sin.mp3", "Sin", "Pretty Hate Machine", "Nine Inch Nails", "Rock"); rhythmdb_write_unlock (db); rhythmdb_read_lock (db); main_model = GTK_TREE_MODEL (rhythmdb_query_model_new_empty (db)); rhythmdb_do_full_query (db, main_model, RHYTHMDB_QUERY_PROP_EQUALS, RHYTHMDB_PROP_TYPE, RHYTHMDB_ENTRY_TYPE_IGNORE, RHYTHMDB_QUERY_END); wait_for_model_completion (RHYTHMDB_QUERY_MODEL (main_model)); g_assert (gtk_tree_model_get_iter_first (main_model, &iter)); main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); view = rb_entry_view_new (db, rb_file ("rb-entry-view-library.xml")); rb_entry_view_set_query_model (view, RHYTHMDB_QUERY_MODEL (main_model)); gtk_container_add (GTK_CONTAINER (main_window), GTK_WIDGET (view)); g_signal_connect (G_OBJECT (main_window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show_all (GTK_WIDGET (main_window)); gtk_main (); rhythmdb_shutdown (db); g_object_unref (G_OBJECT (db)); GDK_THREADS_LEAVE (); exit (0); }
void parse_pindel(std::string pindel_vcf, std::vector<strvcfentry> & entries, int min_number_supporting, int min_length) { size_t buffer_size = 2000000; char*buffer = new char[buffer_size]; std::ifstream myfile; myfile.open(pindel_vcf.c_str(), std::ifstream::in); if (!myfile.good()) { std::cout << "Pindel Parser: could not open file: " << pindel_vcf.c_str() << std::endl; exit(0); } int call_id = entries.size(); myfile.getline(buffer, buffer_size); while (!myfile.eof()) { if(buffer[0]!='#'){ int count=0; strregion region; int support = 0; short type=-2; bool flag=false; for (size_t i = 0;i < buffer_size && buffer[i] != '\0' && buffer[i] != '\n';i++) { if(count==0 && buffer[i]!='\t'){ region.start.chr+=buffer[i]; region.stop.chr+=buffer[i]; } if(count==1 && buffer[i-1]=='\t'){ region.start.pos=atoi(&buffer[i]); } if(count==7 && strncmp(&buffer[i],"END=",4)==0){ region.stop.pos=atoi(&buffer[i+4]); } if(count==7 && strncmp(&buffer[i],"SVLEN=0",7)==0){ flag=true; } if(count==7 && strncmp(&buffer[i],"SVTYPE=",7)==0){ type=get_type_pind(&buffer[i+7]); } if(count==9 && (buffer[i-1]==',' || (flag && buffer[i-1]==':'))){ support=atoi(&buffer[i]); } if(buffer[i]=='\t'){ count++; } } //std::cout<<support<<" "<<region.stop.pos-region.start.pos<<std::endl; if(support>min_number_supporting && (region.stop.pos-region.start.pos > min_length || flag) ){ entries.push_back(create_entry(region,support,type,call_id)); call_id++; } } myfile.getline(buffer, buffer_size); } }
static bool set_entry_at(char** environ, size_t position, const char* name, size_t name_length, const char* value, size_t value_length) { char* new_entry = create_entry(name, name_length, value, value_length); if ( !new_entry) return false; free(environ[position]); environ[position] = new_entry; return true; }
int main() { UserStruct structvar = {'a', 3.5}; UserStruct *structvar2 = (UserStruct*)malloc(sizeof(UserStruct)); VoidStr structvar2_structed; create_entry(structvar2, structvar2_structed); structvar2->var2 = 'a'; structvar2->var3 = 3.5; if (structvar2->var2 == 'a') free(structvar2); return 0; }
/* * Function: Bt* init_bt( Bt* bt, void** array, int size, compare_item cmp ) * Description: init one bt with the array of two dimensions * Input: bt: the bt to be inited * array: the initial array for bt * size: array size * cmp: item field comparing function * Output: none * Return: the bt that has been inited * Others: none */ Bt* init_bt( Bt* bt, void** array, int size, compare_item cmp ) { int i = 0; Bt_Entry* entry; for( i = 0; i < size; i++ ) { entry = create_entry( array[i] ); bt->root = insert_entry( bt->root, entry, cmp ); } return bt; }
static void resolve(const struct traverse_info *info, struct name_entry *branch1, struct name_entry *result) { struct merge_list *orig, *final; const char *path; /* If it's already branch1, don't bother showing it */ if (!branch1) return; path = traverse_path(info, result); orig = create_entry(2, branch1->mode, branch1->sha1, path); final = create_entry(0, result->mode, result->sha1, path);
static void resolve(const struct traverse_info *info, struct name_entry *ours, struct name_entry *result) { struct merge_list *orig, *final; const char *path; /* If it's already ours, don't bother showing it */ if (!ours) return; path = traverse_path(info, result); orig = create_entry(2, ours->mode, &ours->oid, path); final = create_entry(0, result->mode, &result->oid, path);
/**************************************************************************** * process_entry * * Get an entry from "entries" section of file and add it to our repository * of layout information. Return 0 if an entry was found and processed. * Return 1 if there are no more entries. ****************************************************************************/ static int process_entry(FILE * f, int skip_add) { static const size_t N_MATCHES = 6; char line[LINE_BUF_SIZE]; regmatch_t match[N_MATCHES]; cmos_entry_t cmos_entry; int result; result = 1; for (;; line_num++) { if (get_layout_file_line(f, line, LINE_BUF_SIZE)) { fprintf(stderr, "%s: Unexpected end of CMOS layout file reached while " "reading \"entries\" section.\n", prog_name); exit(1); } if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0)) continue; if (regexec(&entries_line_expr, line, N_MATCHES, match, 0)) { if (regexec(&start_enums_expr, line, 0, NULL, 0)) { fprintf(stderr, "%s: Syntax error on line %d of CMOS layout " "file.\n", prog_name, line_num); exit(1); } break; /* start of enumerations reached: no more entries */ } result = 0; /* next layout entry found */ if (skip_add) break; line[match[1].rm_eo] = '\0'; line[match[2].rm_eo] = '\0'; line[match[3].rm_eo] = '\0'; line[match[4].rm_eo] = '\0'; line[match[5].rm_eo] = '\0'; create_entry(&cmos_entry, &line[match[1].rm_so], &line[match[2].rm_so], &line[match[3].rm_so], &line[match[4].rm_so], &line[match[5].rm_so]); try_add_layout_file_entry(&cmos_entry); break; } line_num++; return result; }
static int sock_accept( Entry *e, int *newfd, selwakeupfx fx, xsockaddr_in *addr, int *addrlen) { int ipid; Word t; Entry *child; IncBusy(); ipid = TCPIPAcceptTCP(e->ipid, 0); t = _toolErr; DecBusy(); if (t == terrNOINCOMING) return EAGAIN; if (t == terrNOTSERVER) return EINVAL; if (t) return ENETDOWN; // ? child = create_entry(ipid); if (!child) { TCPIPAbortTCP(ipid); TCPIPLogout(ipid); return ENOMEM; } // set up child options. child->_TYPE = SOCK_STREAM; child->select_fx = fx; // address... if (addr && addrlen && *addrlen) { destRec dr; xsockaddr_in tmp; IncBusy(); TCPIPGetDestination(ipid, &dr); DecBusy(); tmp.sin_family = AF_INET; tmp.sin_port = dr.drDestPort; tmp.sin_addr = dr.drDestIP; copy_addr(&tmp, addr, addrlen); } *newfd = ipid; return 0; }
int list_insert_value(linked_list_t *list, void *val, size_t pos) { int res; list_entry_t *new_entry = create_entry(); if(!new_entry) return -1; new_entry->value = val; res=insert_entry(list, new_entry, pos); if(res != 0) destroy_entry(new_entry); return res; }
int list_unshift_value(linked_list_t *list, void *val) { int res; list_entry_t *new_entry = create_entry(); if(!new_entry) return -1; new_entry->value = val; res = unshift_entry(list, new_entry); if(res != 0) destroy_entry(new_entry); return res; }
/*====================== * insert_hashtab -- Add new value to hash table * return previous value for this key, if any *====================*/ HVALUE insert_hashtab (HASHTAB tab, CNSTRING key, HVALUE val) { HASHENT entry=0; INT hval=0; ASSERT(tab); ASSERT(tab->magic == hashtab_magic); /* find appropriate has chain */ hval = hash(tab, key); if (!tab->entries[hval]) { /* table lacks entry for this key, create it */ entry = create_entry(key, val); tab->entries[hval] = entry; ++tab->count; return 0; /* no old value */ } entry = tab->entries[hval]; while (TRUE) { ASSERT(entry->magic == hashent_magic); if (eqstr(key, entry->ekey)) { /* table already has entry for this key, replace it */ HVALUE old = entry->val; entry->val = val; return old; } if (!entry->enext) { /* table lacks entry for this key, create it */ HASHENT newent = create_entry(key, val); entry->enext = newent; ++tab->count; return 0; /* no old value */ } entry = entry->enext; } }
int node_put_data_packet(struct node *node, struct packet *pkt) { struct entry *e; e = create_entry(pkt); if(e == NULL) { return -1; } if(queue_put(e, node->data_q) < 0){ free_entry(e); return -1; } return 0; }
int node_put_meta_packet(struct node *node, struct packet *pkt) { struct entry *e; e = create_entry(pkt); if(e == NULL) { log_error("Error: %s node %d alloc entry failed", __func__, node->id); return -1; } if(queue_put(e, node->meta_q) < 0){ free_entry(e); return -1; } return 0; }
/* * Instert an entry at a specified position in a linked_list_t */ static inline int insert_entry(linked_list_t *list, list_entry_t *entry, size_t pos) { list_entry_t *prev, *next; int ret = -1; MUTEX_LOCK(list->lock); if(pos == 0) { ret = unshift_entry(list, entry); } else if(pos == list->length) { ret = push_entry(list, entry); } else if (pos > list->length) { unsigned int i; for (i = list->length; i < pos; i++) { list_entry_t *emptyEntry = create_entry(); if (!emptyEntry || push_entry(list, emptyEntry) != 0) { if (emptyEntry) destroy_entry(emptyEntry); MUTEX_UNLOCK(list->lock); return -1; } } ret = push_entry(list, entry); } if (ret == 0) { MUTEX_UNLOCK(list->lock); return ret; } prev = pick_entry(list, pos-1); if(prev) { next = prev->next; prev->next = entry; entry->prev = prev; entry->next = next; if (next) next->prev = entry; list->length++; ret = 0; } MUTEX_UNLOCK(list->lock); return ret; }
int list_insert_tagged_value(linked_list_t *list, tagged_value_t *tval, size_t pos) { int res = 0; list_entry_t *new_entry; if(tval) { new_entry = create_entry(); if(new_entry) { new_entry->tagged = 1; new_entry->value = tval; res = insert_entry(list, new_entry, pos); if(res != 0) destroy_entry(new_entry); } } return res; }
int list_unshift_tagged_value(linked_list_t *list, tagged_value_t *tval) { int res = 0; list_entry_t *new_entry; if(tval) { new_entry = create_entry(); if(new_entry) { new_entry->tagged = 1; new_entry->value = tval; res = unshift_entry(list, new_entry); if(res != 0) destroy_entry(new_entry); } } return res; }
/* insert a key-value pair into a hash table. */ void insert_pair( hashtable *hash_table, char *key, char *value ) { int bin = 0; entry *pair = NULL; entry *next = NULL; entry *last = NULL; bin = hash(key )%hash_table->size; next = hash_table->table[ bin ]; /* in this boucle we serch the place we want to pose the new entry */ while( next != NULL && next->key != NULL && strcmp( key, next->key ) > 0 ) { last = next; next = next->next; } /* if there's already an existing key we replace its value by the newest value. */ if( next != NULL && next->key != NULL && strcmp( key, next->key ) == 0 ) { free( next->value ); next->value = strdup( value ); /* no , could't find it. here we have to insert a pair in the linked list *three cases : in the start,end or the middle of the linked list. */ } else { pair = create_entry( key, value ); /* we're at the start of the linked list in this bin. */ if( next == hash_table->table[ bin ] ) { pair->next = next; hash_table->table[ bin ] = pair; /* we're at the end of the linked list in this bin. */ } else if ( next == NULL ) { last->next = pair; /* we're in the middle of the list. */ } else { pair->next = next; last->next = pair; } } }
/* SYNOPSYS : * int syr1_fopen_write(char *name, SYR1_FILE *file) { * DESCRIPTION : * Ce sous-programme gère l'ouverture d'un fichier logique en mode écriture. * PARAMETRES : * name : chaîne de caratère contenant le nom externe du fichier à ouvrir * file : pointeur sur un Bloc Control Fichier (File Control Bloc) * RESULTAT : * 0 : ouverture réussie * -1 : autre erreur */ int syr1_fopen_write(char *name, SYR1_FILE *file) { int error = 0; //Si le fichier existe déjà, suppression if(search_entry(name, &(file->descriptor)) == 0) remove_entry(name); //initialisation du descripteur strcpy(file->descriptor.name, name); file->descriptor.size = 0; file->descriptor.alloc[0] = get_allocation_unit(); //création du fichier sur disque create_entry(name, &(file->descriptor)); //initialisation du BCF strcpy(file->mode, "w"); file->current_block = 0; file->file_offset = 0; file->block_offset = 0; file->buffer = malloc(512*sizeof(unsigned char)); return -1; }