static int checkobjs() { int ret = 0; do { CHK2((g_tab = g_dic->getTable(g_tabname)) != 0, g_tabname << ": " << g_dic->getNdbError()); if (g_indcount == 0) { NdbDictionary::Dictionary::List list; CHK2(g_dic->listIndexes(list, g_tabname) == 0, g_dic->getNdbError()); const int count = list.count; g_indnames = (const char**)my_malloc(sizeof(char*) * count, MYF(0)); CHK2(g_indnames != 0, "out of memory"); for (int i = 0; i < count; i++) { const NdbDictionary::Dictionary::List::Element& e = list.elements[i]; if (e.type == NdbDictionary::Object::OrderedIndex) { g_indcount++; g_indnames[i] = my_strdup(e.name, MYF(0)); CHK2(g_indnames[i] != 0, "out of memory"); } } CHK1(ret == 0); } g_indlist = (const NdbDictionary::Index**)my_malloc(sizeof(NdbDictionary::Index*) * g_indcount, MYF(0)); CHK2(g_indlist != 0, "out of memory"); for (int i = 0; i < g_indcount; i++) { CHK2((g_indlist[i] = g_dic->getIndex(g_indnames[i], g_tabname)) != 0, g_tabname << "." << g_indnames[i] << ": " << g_dic->getNdbError()); } } while (0); return ret; }
int home_dir(t_cd *ptr, char ***env) { if (my_recup_var_env("HOME", ptr, env) == 0) { my_putstr("HOME not found, please check the environnement\n"); return (0); } if (my_recup_var_env("PWD", ptr, env) == 0) return (0); free(ptr->previous); if ((ptr->previous = my_strdup(ptr->recup_getenv)) == 0) return (0); my_recup_var_env("HOME", ptr, env); if (chdir(ptr->recup_getenv) == 0) modif_path(env, "PWD", ptr->recup_getenv); else { my_putstr("Error with chdir\n"); return (0); } return (1); }
int server_client_add_trame(t_trame **list, int size, \ char *buffer) { t_trame *ptr; t_trame *tmp; tmp = *list; if ((ptr = malloc(sizeof(*ptr))) == NULL) return (EXIT_FAILURE); ptr->size = size; ptr->buffer = my_strdup(buffer); ptr->next = NULL; if (*list == NULL) *list = ptr; else { while (tmp->next) tmp = tmp->next; tmp->next = ptr; } return (EXIT_SUCCESS); }
struct tnode *addtree(struct tnode *p, char *w) { int cond; if (p == NULL) { // A new word has arrived p = talloc(); // Make a new node p->word = my_strdup(w); p->count = 1; p->left = p->right = NULL; printf("added word: %s \n", w); } else if ((cond = strcmp(w, p->word)) == 0) // Husk på ordinality og characters! A < B < C < D ... etc! p->count++; // Repeated word else if (cond < 0) { // Less than: into left subtree printf("going left: %s\n", w); p->left = addtree(p->left, w);} else { printf("going right: %s\n", w); p->right = addtree(p->right, w);} return p; }
static void parse_diskswapper (const TCHAR *s) { TCHAR *tmp = my_strdup (s); const TCHAR *delim = _T(","); TCHAR *p1, *p2; int num = 0; p1 = tmp; for (;;) { p2 = _tcstok (p1, delim); if (!p2) break; p1 = NULL; if (num >= MAX_SPARE_DRIVES) break; if (!zfile_zopen (p2, diskswapper_cb, &num)) { _tcsncpy (currprefs.dfxlist[num], p2, 255); num++; } } free (tmp); }
t_err autocomplete_path(int i, t_autocomp *autoc, char *arg) { char **pathes; t_err err; if (!(pathes = malloc(sizeof(char *) * 2)) || !(pathes[0] = my_strndup(arg, i))) return (print_error(ERROR_MALLOC_FAILED)); pathes[1] = NULL; if (arg[i + 1]) { if (!(autoc->buf = my_strdup(&arg[i + 1]))) return (print_error(ERROR_MALLOC_FAILED)); } else autoc->buf = NULL; if ((err = file_list(autoc, pathes))) return (err); free(pathes[0]); free(pathes); return (0); }
/** * set the description of the payee * the value is dupplicate in memory * * \param no_payee the number of the payee * \param description the description of the payee * * \return TRUE if ok or FALSE if problem * */ gboolean gsb_data_payee_set_description ( gint no_payee, const gchar *description ) { struct_payee *payee; payee = gsb_data_payee_get_structure ( no_payee ); if (!payee) return FALSE; /* we free the last name */ if ( payee -> payee_description ) g_free (payee -> payee_description); /* and copy the new one */ if (description) payee -> payee_description = my_strdup (description); else payee -> payee_description = NULL; return TRUE; }
void setup_elem(int argc, char** argv) { glob_t gt; int i; //my_str("before glob"); glob(argv[1], GLOB_NOCHECK | GLOB_ERR, NULL, >);// for (i = 2; i < argc; i++) { glob(argv[i], GLOB_NOCHECK | GLOB_ERR | GLOB_APPEND, NULL, >); } gl_env.elements =(t_elem*)my_xmalloc(gt.gl_pathc*sizeof(t_elem)); //my_int(gl_env.win.ws_row); //my_int(gt.gl_pathc); for(i=0; i<gt.gl_pathc; i++) { //my_str(gt.gl_pathv[i]); //my_str("0"); gl_env.elements[i].elem = my_strdup(gt.gl_pathv[i]); //my_str("1"); gl_env.elements[i].size = my_strlen(gt.gl_pathv[i]); //my_str("2"); gl_env.elements[i].x = 0; //my_str("3"); gl_env.elements[i].y = i%(gl_env.win.ws_row); //my_str("4"); gl_env.elements[i].mode = 0; //my_str("5"); } //my_int(gt.gl_pathc); gl_env.nbelems=gt.gl_pathc; //my_str("after blob setup"); gl_env.pos = 0; //my_char('l'); //my_str(gl_env.elements[4].elem); //my_int(gl_env.elements[1].y); }
int check_opts(char **av, t_gen *gen) { int verif; char *param; get_next_params(av, 1); for (verif = 0; (param = get_next_params(av, 0)); ) { if (param[0] == '-') fill_opts(param + 1, gen->opts); else { ++verif; if (test_before_add(param)) gen->path[(gen->nb_path)++] = my_strdup(param); } } order_args(gen); if (!gen->nb_path && verif) return (0); return (1); }
void check_return_value (struct command *cmd) /* check return value of function */ { int is, should; struct stackentry *s; is = cmd->args; should = cmd->tag; if (is == should) { /* okay, function returns expected type */ } else if (is == ftNONE) { /* no element on stack, create one */ s = push (); if (should == ftNUMBER) { s->type = stNUMBER; s->value = 0.0; } else { s->type = stSTRING; s->pointer = my_strdup (""); } } else { sprintf (string, "subroutine returns %s but should return %s", (is == ftSTRING) ? "a string" : "a number", (should == ftSTRING) ? "a string" : "a number"); error (ERROR, string); } if (infolevel >= DEBUG) { s = stackhead->prev; if (s->type == stNUMBER) { sprintf (string, "subroutine returns number %g", s->value); } else if (s->type == stSTRING) sprintf (string, "subroutine returns string '%s'", (char *) s->pointer); else sprintf (string, "subroutine returns something strange (%d)", s->type); error (DEBUG, string); } }
/** * create a new archive, give him a number, append it to the list * and return the number * * \param name the name of the archive (can be freed after, it's a copy) or NULL * * \return the number of the new archive * */ gint gsb_data_archive_new ( const gchar *name ) { struct_archive *archive; archive = g_malloc0 ( sizeof ( struct_archive )); if (!archive) { dialogue_error_memory (); return 0; } archive -> archive_number = gsb_data_archive_max_number () + 1; if (name) archive -> archive_name = my_strdup (name); else archive -> archive_name = NULL; archive_list = g_slist_append ( archive_list, archive ); archive_buffer = archive; return archive -> archive_number; }
static SFLPoller *getPoller(HSP *sp, SFLAdaptor *adaptor) { HSPAdaptorNIO *adaptorNIO=(HSPAdaptorNIO *)adaptor->userData; if(adaptorNIO) { if(adaptorNIO->poller == NULL) { SFLDataSource_instance dsi; SFL_DS_SET(dsi, 0, adaptor->ifIndex, 0); // ds_class,ds_index,ds_instance HSPSFlow *sf = sp->sFlow; uint32_t pollingInterval = sf->sFlowSettings ? sf->sFlowSettings->pollingInterval : SFL_DEFAULT_POLLING_INTERVAL; adaptorNIO->poller = sfl_agent_addPoller(sf->agent, &dsi, sp, agentCB_getCounters_interface); sfl_poller_set_sFlowCpInterval(adaptorNIO->poller, pollingInterval); sfl_poller_set_sFlowCpReceiver(adaptorNIO->poller, HSP_SFLOW_RECEIVER_INDEX); // remember the device name to make the lookups easier later. // Don't want to point directly to the SFLAdaptor or SFLAdaptorNIO object // in case it gets freed at some point. The device name is enough. adaptorNIO->poller->userData = (void *)my_strdup(adaptor->deviceName); } return adaptorNIO->poller; } return NULL; }
gint category_add_sub_div ( int div_id ) { gint new_sub_category_number; gchar * name; int i = 1; if ( !div_id ) return 0; /** Find a unique name for category */ name = my_strdup (_("New sub-category")); while ( gsb_data_category_get_sub_category_number_by_name ( div_id, name, FALSE )) { g_free (name); i++; name = g_strdup_printf ( _("New sub-category #%d"), i ); } new_sub_category_number = gsb_data_category_get_sub_category_number_by_name ( div_id, name, TRUE ); return new_sub_category_number; }
int aby_rename(const char *old_name, const char *new_name) { reg1 HPA_SHARE *info; char *name_buff; DBUG_ENTER("aby_rename"); if(ABY_LOCK == ABY_HEAP) mysql_mutex_lock(&THR_LOCK_heap); if ((info = hpa_find_named_aby(old_name))) { if (!(name_buff=(char*) my_strdup(new_name,MYF(MY_WME)))) { if(ABY_LOCK == ABY_HEAP) mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(my_errno); } my_free(info->name); info->name=name_buff; } if(ABY_LOCK == ABY_HEAP) mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(0); }
char *get_next_line_socket(int cs) { char *res; int size; int i; int j; init_var_gnls(&size, &res, &i); while (!(gnls_is_in(res, '\n'))) { j = recv(cs, res + i, 1, 0); i += j; res[i] = '\0'; if (j == 0) { free(res); return (NULL); } if (i == size) get_biger(&res, &size); } return (my_strdup(res)); }
void testMY_STR2VECT(void){ char* str = NULL; char** strVect = NULL; int i; if(temp_file != NULL){ str = my_strdup("testing was successful"); strVect = my_str2vect(str); CU_ASSERT_STRING_EQUAL(strVect[0], "testing"); CU_ASSERT_STRING_EQUAL(strVect[1], "was"); CU_ASSERT_STRING_EQUAL(strVect[2], "successful"); CU_ASSERT(strVect[3] == NULL); for(i = 0; strVect[i]; ++i){ free(strVect[i]); strVect[i] = NULL; } free(strVect); strVect = NULL; strVect = my_str2vect(NULL); CU_ASSERT(strVect == NULL); free(str); } }
int gere_instruction(char **words, char *s, t_asmline *line) { char *lbl; if (words[0] && is_label(words[0])) { line->code = -1; lbl = my_strdup(words[0]); get_command_args(words, line->argv); line->argv[0] = lbl; } else if (words[0] && words[1]) { line->code = get_command_id(words[0]); get_command_arg_type(words + 1, line->type); get_command_args(words + 1, line->argv); } else return (0); if (line->code > 0) verif_args(line, s); return (1); }
static SFLSampler *getSampler(HSP *sp, char *devName, uint32_t ifIndex) { SFLSampler *sampler = sfl_agent_getSamplerByIfIndex(sp->sFlow->agent, ifIndex); if(sampler == NULL) { SFLDataSource_instance dsi; SFL_DS_SET(dsi, 0, ifIndex, 0); // ds_class,ds_index,ds_instance HSPSFlow *sf = sp->sFlow; // add sampler (with sub-sampling rate), and poller too uint32_t samplingRate = sf->sFlowSettings->ulogSubSamplingRate; uint32_t pollingInterval = sf->sFlowSettings ? sf->sFlowSettings->pollingInterval : SFL_DEFAULT_POLLING_INTERVAL; sampler = sfl_agent_addSampler(sf->agent, &dsi); sfl_sampler_set_sFlowFsPacketSamplingRate(sampler, samplingRate); sfl_sampler_set_sFlowFsReceiver(sampler, HSP_SFLOW_RECEIVER_INDEX); SFLPoller *poller = sfl_agent_addPoller(sf->agent, &dsi, sp, agentCB_getCounters_interface); sfl_poller_set_sFlowCpInterval(poller, pollingInterval); sfl_poller_set_sFlowCpReceiver(poller, HSP_SFLOW_RECEIVER_INDEX); // remember the device name to make the lookups easier later. // Don't want to point directly to the SFLAdaptor or SFLAdaptorNIO object // in case it gets freed at some point. The device name is enough. poller->userData = (void *)my_strdup(devName); } return sampler; }
/** * If the polling interval is > 0, adds an interface counter poller to * sp->sFlow->agent or the adaptor representing the switch port. Returns * the added poller, or NULL if a poller was not added. */ static SFLPoller *addPoller(HSP *sp, SFLAdaptor *adaptor) { uint32_t pollingInterval = sp->sFlow->sFlowSettings ? sp->sFlow->sFlowSettings->pollingInterval : SFL_DEFAULT_POLLING_INTERVAL; if (pollingInterval <= 0) { return NULL; } SFLDataSource_instance switchDsi; SFL_DS_SET(switchDsi, SFL_DSCLASS_IFINDEX, adaptor->ifIndex, 0); SFLPoller *poller = sfl_agent_addPoller(sp->sFlow->agent, &switchDsi, sp, agentCB_getCounters); // remember the deviceName to make the lookups easier later. // We don't point directly to the SFLAdaptor object // in case it gets freed at some point. The deviceName is enough. poller->userData = my_strdup(adaptor->deviceName); myLog(LOG_INFO, "addPoller: added counter poller for %lu %s", adaptor->ifIndex, adaptor->deviceName); sfl_poller_set_sFlowCpInterval(poller, pollingInterval); sfl_poller_set_sFlowCpReceiver(poller, HSP_SFLOW_RECEIVER_INDEX); return poller; }
char *get_bin_path(char *bin, char *str_path) { char **path; char *correct_bin; if (is_relative_dir(bin)) return (my_strdup(bin)); if (str_path == NULL) { my_puterr("There aren't PATH in the env variable\n"); return (NULL); } path = my_str_split(str_path, ':'); check_malloc(path); correct_bin = get_bin_path_search(path, bin); if (correct_bin == NULL) { my_puterr(bin); my_puterr(": command not found.\n"); } free(path); return (correct_bin == NULL ? NULL : correct_bin); }
static int my_name_object(t_object *object, char *str) { char *object_name[NBR_OBJ]; int i; object_name[0] = "sphere"; object_name[1] = "eye"; object_name[2] = "cylinder"; object_name[3] = "cone"; object_name[4] = "plan"; object_name[5] = "light"; i = 0; while (i < NBR_OBJ) if (my_strcmp(object_name[i++], str) == 0) { if ((object->name = my_strdup(str)) == NULL) return (1); return (0); } my_putstr(str, 2); my_putstr(" : is not a valide object\n", 2); return (1); }
int main(int ac, char **av) { int i; t_dnode *node; signal(SIGWINCH, sigwinch); i = ac - 1; my_clearscreen(); set_color(0, 2); g_list = mk_dclist(); while (i > 0) { node = mk_node(); node->data = my_strdup(av[i]); node->selected = 0; node->underline = 0; my_put_in_dclist(&g_list, node); i--; } my_select(); my_free_dclist(&g_list); return (0); }
/** * do the same as g_strdelimit but new_delimiters can containes several characters or none * ex my_strdelimit ("a-b", "-", "123") returns a123b * my_strdelimit ("a-b", "-", "") returns ab * * \param string the string we want to modify * \param delimiters the characters we need to change to new_delimiters * \param new_delimiters the replacements characters for delimiters * * \return a newly allocated string or NULL * */ gchar *my_strdelimit ( const gchar *string, const gchar *delimiters, const gchar *new_delimiters ) { gchar **tab_str; gchar *retour; if ( !( string && delimiters && new_delimiters )) return my_strdup (string); tab_str = g_strsplit_set ( string, delimiters, 0 ); retour = g_strjoinv ( new_delimiters, tab_str ); g_strfreev ( tab_str ); return ( retour ); }
FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) { FILE *fd; char type[5]; DBUG_ENTER("my_fdopen"); DBUG_PRINT("my",("Fd: %d Flags: %d MyFlags: %d", Filedes, Flags, MyFlags)); make_ftype(type,Flags); if ((fd = fdopen(Filedes, type)) == 0) { my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) my_error(EE_CANT_OPEN_STREAM, MYF(ME_BELL+ME_WAITTANG),errno); } else { pthread_mutex_lock(&THR_LOCK_open); my_stream_opened++; if ((uint) Filedes < (uint) my_file_limit) { if (my_file_info[Filedes].type != UNOPEN) { my_file_opened--; /* File is opened with my_open ! */ } else { my_file_info[Filedes].name= my_strdup(name,MyFlags); } my_file_info[Filedes].type = STREAM_BY_FDOPEN; } pthread_mutex_unlock(&THR_LOCK_open); } DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); DBUG_RETURN(fd); } /* my_fdopen */
void romlist_clear (void) { int i; int mask = 0; struct romdata *parent; TCHAR *pn; xfree (rl); rl = 0; romlist_cnt = 0; parent = 0; pn = NULL; for (i = 0; roms[i].name; i++) { struct romdata *rd = &roms[i]; if (rd->group == 0) { parent = rd; mask = rd->type; pn = parent->partnumber; } else { rd->type &= ~ROMTYPE_MASK; rd->type |= mask & ROMTYPE_MASK; if (rd->partnumber && !pn) { TCHAR *newpn; if (parent->partnumber == NULL) parent->partnumber = my_strdup (L""); newpn = xcalloc (TCHAR, _tcslen (parent->partnumber) + 1 + _tcslen (rd->partnumber) + 1); if (_tcslen (parent->partnumber) > 0) { _tcscpy (newpn, parent->partnumber); _tcscat (newpn, L"/"); } _tcscat (newpn, rd->partnumber); xfree (parent->partnumber); parent->partnumber = newpn; } } } }
static int find_errcode(char *string, ErtsSysDdllError* err) { int i; if (err != NULL) { erts_sys_ddll_free_error(err); /* in case we ignored an earlier error */ err->str = my_strdup_in(ERTS_ALC_T_DDLL_TMP_BUF, string); return 0; } for(i=0;i<num_errcodes;++i) { if (!strcmp(string, errcodes[i])) { return i; } } if (num_errcodes_allocated == num_errcodes) { errcodes = (num_errcodes_allocated == 0) ? erts_alloc(ERTS_ALC_T_DDLL_ERRCODES, (num_errcodes_allocated = 10) * sizeof(char *)) : erts_realloc(ERTS_ALC_T_DDLL_ERRCODES, errcodes, (num_errcodes_allocated += 10) * sizeof(char *)); } errcodes[num_errcodes++] = my_strdup(string); return (num_errcodes - 1); }
int dir_no_slash(t_mysh *ptr) { int flag; char *line; if ((flag = check_cd(ptr, 0)) == 3) return (0); if (flag == 1) { if (my_getenv("PWD", ptr) == 0) return (0); free(ptr->previous); if ((ptr->previous = my_strdup(ptr->recup_getenv)) == NULL) return (0); if ((line = my_strcat_three(ptr->recup_getenv, "/", ptr->param[1])) == 0) return (0); if (chdir(line) == -1) return (2); if (for_two_point(ptr, &line) == 0) return (0); return (1); } return (0); }
int home_and_next_dir(t_mysh *ptr) { char *line; if (my_getenv("HOME", ptr) == 0) { my_putstr("HOME not found, please check the environnement\n"); return (0); } if (my_getenv("PWD", ptr) == 0) return (0); free(ptr->previous); if ((ptr->previous = my_strdup(ptr->recup_getenv)) == 0) return (0); my_getenv("HOME", ptr); if ((line = my_strcat_three(ptr->recup_getenv, "/", ptr->param[1] + 2)) == 0) return (0); if (chdir(line) == 0) modif_path(ptr, "PWD", ptr->param[1]); else my_putstr("Error with chdir\n"); free(line); return (1); }
/** * Callback triggered when separator is changed in the GtkEntry * containing it. * * \param entry Entry that triggered event. * \param value New value of entry (not used). * \param length Length of the change (not used). * \param position Position of the change (not used). * * \return FALSE */ gboolean csv_import_change_separator ( GtkEntry * entry, GtkWidget *assistant ) { GtkWidget *combobox; gchar *separator; int i = 0; combobox = g_object_get_data ( G_OBJECT(entry), "combobox" ); separator = g_strdup ( gtk_entry_get_text ( GTK_ENTRY (entry) ) ); if ( strlen ( separator ) > 0 ) { g_object_set_data ( G_OBJECT(assistant), "separator", separator ); csv_import_update_preview ( assistant ); etat.csv_separator = my_strdup ( separator ); } else { etat.csv_separator = ""; g_object_set_data ( G_OBJECT(assistant), "separator", NULL ); } /* Update combobox if we can. */ while ( csv_separators [ i ] . value ) { if ( strcmp ( csv_separators [ i ] . value, separator ) == 0 ) { break; } i ++ ; } g_signal_handlers_block_by_func ( combobox, csv_import_combo_changed, entry ); gtk_combo_box_set_active ( GTK_COMBO_BOX(combobox), i ); g_signal_handlers_unblock_by_func ( combobox, csv_import_combo_changed, entry ); return FALSE; }
void md5_read_joints(FILE *f, Md5_joint *joints) { char s[200]; int no = 0; while (fgets(s, 200, f) != NULL) { if (s[0] == '}') { /*puts("}..");*/ return; } else { /*puts("\tjoint...");*/ Md5_joint *j; V3f pos; int index; Quat q; char name[40]; sscanf(s + 1, "%s %d ( %f %f %f ) ( %f %f %f )\n", name, &index, &pos.x, &pos.y, &pos.z, &(q.x), &(q.y), &(q.z)); quat_renormalize(&q); j = joints + no; j->name = my_strdup(name); j->parent_index = index; j->parent = (index >= 0) ? (joints + index) : NULL; j->pos.x = pos.x; j->pos.y = pos.y; j->pos.z = pos.z; j->orient.x = q.x; j->orient.y = q.y; j->orient.z = q.z; j->orient.w = q.w; no++; } } }