int parse_streams(Workgroup* group, const_bstring str, int numberOfStreams) { struct bstrList* tokens; struct bstrList* subtokens; tokens = bsplit(str,','); if (tokens->qty < numberOfStreams) { fprintf(stderr, "Error: Testcase requires at least %d streams\n", numberOfStreams); bstrListDestroy(tokens); return -1; } group->streams = (Stream*) malloc(numberOfStreams * sizeof(Stream)); if (group->streams == NULL) { bstrListDestroy(tokens); return -1; } for (int i=0; i<numberOfStreams; i++) { subtokens = bsplit(tokens->entry[i],':'); if (subtokens->qty >= 2) { int index = str2int(bdata(subtokens->entry[0])); if ((index < 0) && (index >= numberOfStreams)) { free(group->streams); bstrListDestroy(subtokens); bstrListDestroy(tokens); return -1; } group->streams[index].domain = bstrcpy(subtokens->entry[1]); group->streams[index].offset = 0; if (subtokens->qty == 3) { group->streams[index].offset = str2int(bdata(subtokens->entry[2])); if (group->streams[index].offset < 0) { free(group->streams); bstrListDestroy(subtokens); bstrListDestroy(tokens); return -1; } } } else { fprintf(stderr, "Error in parsing stream definition %s\n", bdata(tokens->entry[i])); bstrListDestroy(subtokens); bstrListDestroy(tokens); free(group->streams); return -1; } bstrListDestroy(subtokens); } bstrListDestroy(tokens); return 0; }
bKeyValues *get_key_values(const_bstring input) { int i = 0; struct bstrList *values; struct bstrList *keyvalue; bKeyValues *keyvalues; values = bsplit(input, '&'); keyvalues = malloc(sizeof(bKeyValues)); keyvalues->entry = malloc(values->qty * sizeof(bKeyValue)); keyvalues->qty = values->qty; for(i = 0; i < values->qty; i++) { keyvalue = bsplit(values->entry[i], '='); if(keyvalue->qty == 2) { keyvalues->entry[i].key = bstrcpy(keyvalue->entry[0]); keyvalues->entry[i].value = bstrcpy(keyvalue->entry[1]); } else { printf("Invalid keyvalue: %s", values->entry[i]->data); return NULL; } bstrListDestroy(keyvalue); } bstrListDestroy(values); return keyvalues; }
static void bsplit(arb_poly_t pol, const arb_t sqrtD, const slong * qbf, slong a, slong b, slong prec) { if (b - a == 0) { arb_poly_one(pol); } else if (b - a == 1) { acb_t z; acb_init(z); /* j((-b+sqrt(-D))/(2a)) */ arb_set_si(acb_realref(z), -FLINT_ABS(qbf[3 * a + 1])); arb_set(acb_imagref(z), sqrtD); acb_div_si(z, z, 2 * qbf[3 * a], prec); acb_modular_j(z, z, prec); if (qbf[3 * a + 1] < 0) { /* (x^2 - 2re(j) x + |j|^2) */ arb_poly_fit_length(pol, 3); arb_mul(pol->coeffs, acb_realref(z), acb_realref(z), prec); arb_addmul(pol->coeffs, acb_imagref(z), acb_imagref(z), prec); arb_mul_2exp_si(pol->coeffs + 1, acb_realref(z), 1); arb_neg(pol->coeffs + 1, pol->coeffs + 1); arb_one(pol->coeffs + 2); _arb_poly_set_length(pol, 3); } else { /* (x-j) */ arb_poly_fit_length(pol, 2); arb_neg(pol->coeffs, acb_realref(z)); arb_one(pol->coeffs + 1); _arb_poly_set_length(pol, 2); } acb_clear(z); } else { arb_poly_t tmp; arb_poly_init(tmp); bsplit(pol, sqrtD, qbf, a, a + (b - a) / 2, prec); bsplit(tmp, sqrtD, qbf, a + (b - a) / 2, b, prec); arb_poly_mul(pol, pol, tmp, prec); arb_poly_clear(tmp); } }
/* ---------------------------------------------------------- * FUNCTION : init_configuration * DESCRIPTION : This function will read in and process a * : specified configuration file. * INPUT : 0 - Config File * RETURN : None! * ---------------------------------------------------------- */ void init_configuration (bstring filename) { FILE *fp; bstring filedata; struct bstrList *lines; int i; verbose_message("config - Processing '%s'.", bdata(filename)); if ((fp = fopen(bdata(filename), "r")) == NULL) { err_message("Unable to open configuration file - %s", bdata(filename)); } /* Read file into 'filedata' and process it accordingly. */ filedata = bread ((bNread) fread, fp); if ((lines = bsplit(filedata, '\n')) != NULL) { for (i = 0; i < lines->qty; i++) { parse_line(lines->entry[i]); } } /* Clean Up */ bdestroy(filedata); bstrListDestroy(lines); fclose(fp); }
void Action_dependency_assign(void *value, void *data) { Action *action = (Action *)value; Action *target = NULL; tst_t *targets = (tst_t *)data; int i = 0; if(!action->depends) return; debug("Processed %s action depending on: %s", bdata(action->name), bdata(action->depends)); if(action->depends) { struct bstrList *dep_list = bsplit(action->depends, ' '); for(i = 0; i < dep_list->qty; i++) { bstring dep = dep_list->entry[i]; target = (Action *)tst_search(targets, bdata(dep), blength(dep)); if(target) { Action_depends(action, target); } else { log_err("Could not find dependency %s has on %s.", bdata(action->name), bdata(dep)); } } bstrListDestroy(dep_list); } }
char *test_getlines() { bstring str = bfromcstr("one\ntwo\nthree\nfour\nfive\n"); struct bstrList *file = bsplit(str, '\n'); DArray *lines = getlines(file, 2, 4); bstring two = bfromcstr("two"); bstring three = bfromcstr("three"); bstring four = bfromcstr("four"); mu_assert(DArray_count(lines) == 3, "Wrong number of lines."); mu_assert(bstrcmp((bstring)DArray_at(lines, 0), two) == 0, "First line is wrong."); mu_assert(bstrcmp((bstring)DArray_at(lines, 1), three) == 0, "Second line is wrong."); mu_assert(bstrcmp((bstring)DArray_at(lines, 2), four) == 0, "Third line is wrong."); bstrListDestroy(file); bdestroy(str); bdestroy(two); bdestroy(three); bdestroy(four); DArray_destroy(lines); return NULL; }
char *test_different_functions() { // create + length bstring string1 = bfromcstr("string"); mu_assert_equal(6, blength(string1)); // bassign, biseq bstring string2 = bfromcstr("foo"); bassign(string2, string1); mu_assert(strcmp(bdata(string1), bdata(string2)) == 0, "both strings should be equal"); mu_assert(biseq(string1, string2) == 1, "both strings should be equal"); // bconcat bstring string2 = bfromcstr("foo"); string1 = bfromcstr("Hello"); string2 = bfromcstr(", World!"); bconcat(string1, string2); mu_assert(strcmp("Hello, World!", bdata(string1)) == 0, "returned string not as expected"); // bsplit string1 = bfromcstr("foo, bar, baz"); struct bstrList *words; words = bsplit(string1, ','); mu_assert(strcmp("foo", bdata(words->entry[0])) == 0, "returned string not as expected"); return NULL; }
TSTree *add_route_data(TSTree *routes, bstring line) { struct bstrList *data = bsplit(line, ' '); // eg. /hello && Hello check(data->qty == 2, "Line '%s' does not have 2 columns", bdata(line)); // insert to routes, root is the first, the 2 and 3 is key anf length of key and value routes = TSTree_insert(routes, bdata(data->entry[0]), blength(data->entry[0]), bstrcpy(data->entry[1])); void *dl = load_dl(data->entry[1]); Handler *handler = Handler_create(bdata(data->entry[0]), dl); bstrListDestroy(data); return routes; error: return NULL; }
void str2BitMask(const char* str, BitMask* mask) { char* endptr; errno = 0; struct bstrList* tokens; bstring q = bfromcstralloc (60, str); tokens = bsplit(q,' '); for (int i=0; i<tokens->qty; i++) { uint64_t val = strtoull((char*) tokens->entry[i]->data, &endptr, 16); if ((errno == ERANGE && val == LONG_MAX ) || (errno != 0 && val == 0)) { ERROR; } if (endptr == str) { ERROR_PLAIN_PRINT(No digits were found); } mask->mask[i] = val; } bstrListDestroy(tokens); bdestroy(q); }
/* ---------------------------------------------------------- * FUNCTION : conf_module_plugin * DESCRIPTON : This function takes a string retrieved from * : the configuration file, breaks it in half * : at the ':', and then sends it to the * : appropriate function. * INPUT : 0 - Value * : 1 - Pointer to Function * RETURN : 0 - Success * : -1 - Error * ---------------------------------------------------------- */ int conf_module_plugin (bstring value, int (*ptrFunc)(bstring, bstring)) { struct bstrList *list; if (*ptrFunc == NULL) return -1; /* Split line in half. There should only be one ':'. */ if ((list = bsplit(value, ':')) != NULL) { if (list->qty > 1) { /* Input processor contains an argument. */ if ((btrim(list->entry[1])) == -1) log_message("warning: 'btrim' in function 'conf_module_processor' faild."); if (((*ptrFunc)(list->entry[0], list->entry[1])) == -1) log_message("warning: 'ptrFunc' in function 'conf_module_processor' failed."); } else { /* Input processor does not contain an argument. */ if (((*ptrFunc)(list->entry[0], bfromcstr(""))) == -1) log_message("warning: 'ptrFunc' in function 'conf_module_processor' failed."); } if (list != NULL) bstrListDestroy(list); } else { log_message("warning: 'split' in function 'conf_module_processor' failed."); } return 0; }
/* ---------------------------------------------------------- * FUNCTION : read_report_file * DESC : This function will read in a specified * : report CSV file. It will then break a part * : the line and add the assets to the * : specified asset data structure. * INPUT : None * RETURN : None * ---------------------------------------------------------- */ void read_report_file (output_plugin *log) { FILE *fp; bstring filedata; struct bstrList *lines; int i; printf("[*] Processing Assets from persistent file %s\n", log->path); /* Open Signature File */ if ((fp = fopen(log->path, "r")) == NULL) { printf("Unable to open CSV file - %s", log->path); } /* Read file into 'filedata' and process it accordingly. */ filedata = bread ((bNread) fread, fp); if ((lines = bsplit(filedata, '\n')) != NULL) { for (i = 0; i < lines->qty; i++) { parse_raw_report(lines->entry[i]); } } /* Clean Up */ bdestroy(filedata); bstrListDestroy(lines); fclose(fp); }
void acb_hypgeom_pfq_sum_bs_invz(acb_t s, acb_t t, acb_srcptr a, slong p, acb_srcptr b, slong q, const acb_t z, slong n, slong prec) { acb_t u, v, w; if (n < 4) { acb_init(u); acb_inv(u, z, prec); acb_hypgeom_pfq_sum_forward(s, t, a, p, b, q, u, n, prec); acb_clear(u); return; } acb_init(u); acb_init(v); acb_init(w); bsplit(u, v, w, a, p, b, q, z, 0, n, prec, 1); acb_div(t, u, w, prec); acb_div(s, v, w, prec); acb_clear(u); acb_clear(v); acb_clear(w); }
IDENT_MPTR_RAW * BetterString_$_split_$_char(IDENT_MPTR_RAW * b_, char c, IDENT_MPTR_RAW * $_mptr_in) { _$_VARIABLE(_$_temp_vector); _$_VARIABLE(_$_temp_vector_item); _$_VARIABLE(_$_temp_betterstring); const_bstring b = b_->obj; struct bstrList * result = bsplit(b,c); //printf("Parts %d ",result->qty); Vector_$_Vector_$_int(result->qty, _$_temp_vector, false, BetterString); /* Vector_$_putObjectAtIndex_$_Generic_$$_$_Generic_$$(_$v$_arr, _$v$_idx, _$v$_primIdx, _$v$_elem, _$v$_primElem,\ _$v$_mptr, _$v$_primRet, _$v$_typeRet) */ int i; for (i=0;i<result->qty;i++) { BetterString_$_BetterString_$_BetterString_$_(bstrcpy(result->entry[i]),_$_temp_betterstring); Vector_$_putObjectAtIndex_$_Generic_$$_$_Generic_$$(_$_temp_vector, i, true, _$_temp_betterstring, false, _$_temp_vector_item, false, _$_mptr); } _$_mptr_prepare(_$_temp_vector,$_mptr_in); bstrListDestroy(result); return $_mptr_in; }
Object* String_to_object(bstring string) { Object *obj = NULL; if (bchar(string, 0) == '"') { int len = blength(string) - 2; obj = Object_create_string(bmidstr(string, 1, len)); } else if (bchar(string, 0) == '[') { int strlen = blength(string) - 2; bstring inner_str = bmidstr(string, 1, strlen); struct bstrList *elements = bsplit(inner_str, ','); int len = elements->qty; int i = 0; DArray *array = DArray_create(sizeof(Object*), len); bstring *ptr = elements->entry; for(i = 0; i < len; i++) { btrimws(*ptr); DArray_push(array, String_to_object(*ptr)); ptr++; } obj = Object_create_array(array); } else { int value = atoi(bdata(string)); if (value != 0) { obj = Object_create_integer(atoi(bdata(string))); } else { return NULL; } } return obj; }
void arb_rising_fmpq_ui(arb_t y, const fmpq_t x, ulong n, long prec) { if (n == 0) { arb_one(y); } else if (n == 1) { arb_set_fmpq(y, x, prec); } else { long wp; wp = ARF_PREC_ADD(prec, FLINT_BIT_COUNT(n)); bsplit(y, fmpq_numref(x), fmpq_denref(x), 0, n, wp); if (fmpz_is_one(fmpq_denref(x))) { arb_set_round(y, y, prec); } else { arb_t t; arb_init(t); arb_set_fmpz(t, fmpq_denref(x)); arb_pow_ui(t, t, n, wp); arb_div(y, y, t, prec); arb_clear(t); } } }
void _arb_exp_sum_bs_simple(fmpz_t T, fmpz_t Q, mp_bitcnt_t * Qexp, const fmpz_t x, mp_bitcnt_t r, slong N) { fmpz_t P; fmpz_init(P); bsplit(P, T, Q, Qexp, x, r, 0, N, 0); fmpz_clear(P); }
static int parse_bind_address(allium_ptcfg *cfg, const char *addrs) { struct bstrList *l; struct tagbstring str; int i, j; assert(NULL != cfg); if (NULL == addrs) { fprintf(stdout, "ENV-ERROR No Bind Addresses\n"); return (-1); } btfromcstr(str, addrs); if (0 == btlength(str)) { fprintf(stdout, "ENV-ERROR Empty Bind Address\n"); return (-1); } l = bsplit(&str, ','); if (NULL == l) { fprintf(stdout, "ENV-ERROR OOM parsing Bind Addresses\n"); return (-1); } if (l->qty != cfg->nr_methods) { fprintf(stdout, "ENV-ERROR Malformed Bind Addresses\n"); bstrListDestroy(l); return (-1); } for (i = 0; i < l->qty; i++) { /* * Per pt-spec.txt, the order is identical to the transport * list. I have no idea what is supposed to happen when * the transport list is wildcarded, so this routine will * currently fail gracefully. */ j = bstrrchr(l->entry[i], '-'); if ((j != blength(cfg->methods[i].name)) || bstrncmp(l->entry[i], cfg->methods[i].name, j - 1)) { fprintf(stdout, "ENV-ERROR Unexpected method in Bind Address\n"); bstrListDestroy(l); return (-1); } cfg->methods[i].bind_addr_len = sizeof(cfg->methods[i].bind_addr); if (parse_addr(bdataofs(l->entry[i], j + 1), (struct sockaddr *)&cfg->methods[i].bind_addr, &cfg->methods[i].bind_addr_len)) { fprintf(stdout, "ENV-ERROR Invalid address in Bind Address (%s)\n", bdata(l->entry[i])); bstrListDestroy(l); return (-1); } cfg->methods[i].has_bind_addr = 1; } bstrListDestroy(l); return (0); }
static void bsplit(acb_t p, acb_t q, const acb_t x, ulong a, ulong b, slong prec) { if (b - a < 8) { ulong k; acb_t t; acb_one(p); acb_add_ui(q, x, a, prec); acb_init(t); for (k = a + 1; k < b; k++) { acb_add_ui(t, x, k, prec); acb_mul(p, p, t, prec); acb_add(p, p, q, prec); acb_mul(q, q, t, prec); } acb_clear(t); } else { acb_t r, s; ulong m; acb_init(r); acb_init(s); m = a + (b - a) / 2; bsplit(p, q, x, a, m, prec); bsplit(r, s, x, m, b, prec); acb_mul(p, p, s, prec); acb_mul(r, r, q, prec); acb_add(p, p, r, prec); acb_mul(q, q, s, prec); acb_clear(r); acb_clear(s); } }
static void bsplit(fmpz_t P, fmpz_t T, fmpz_t Q, mp_bitcnt_t * Qexp, const fmpz_t x, slong r, slong a, slong b, int cont) { if (b - a == 1) { fmpz_set(P, x); fmpz_set_ui(Q, a + 1); *Qexp = r; fmpz_set(T, P); } else { slong m; mp_bitcnt_t Q2exp[1]; fmpz_t P2, Q2, T2; m = a + (b - a) / 2; fmpz_init(P2); fmpz_init(Q2); fmpz_init(T2); bsplit(P, T, Q, Qexp, x, r, a, m, 1); bsplit(P2, T2, Q2, Q2exp, x, r, m, b, 1); fmpz_mul(T, T, Q2); fmpz_mul_2exp(T, T, *Q2exp); fmpz_addmul(T, P, T2); fmpz_mul(Q, Q, Q2); *Qexp = *Qexp + *Q2exp; if (cont) fmpz_mul(P, P, P2); fmpz_clear(P2); fmpz_clear(Q2); fmpz_clear(T2); } }
static void nodeMeminfo(int node, uint64_t* totalMemory, uint64_t* freeMemory) { FILE *fp; bstring filename; bstring totalString = bformat("MemTotal:"); bstring freeString = bformat("MemFree:"); int i; filename = bformat("/sys/devices/system/node/node%d/meminfo", node); if (NULL != (fp = fopen (bdata(filename), "r"))) { bstring src = bread ((bNread) fread, fp); struct bstrList* tokens = bsplit(src,(char) '\n'); for (i=0;i<tokens->qty;i++) { if (binstr(tokens->entry[i],0,totalString) != BSTR_ERR) { bstring tmp = bmidstr (tokens->entry[i], 18, blength(tokens->entry[i])-18 ); bltrimws(tmp); struct bstrList* subtokens = bsplit(tmp,(char) ' '); *totalMemory = str2int(bdata(subtokens->entry[0])); } else if (binstr(tokens->entry[i],0,freeString) != BSTR_ERR) { bstring tmp = bmidstr (tokens->entry[i], 18, blength(tokens->entry[i])-18 ); bltrimws(tmp); struct bstrList* subtokens = bsplit(tmp,(char) ' '); *freeMemory = str2int(bdata(subtokens->entry[0])); } } } else { ERROR; } fclose(fp); }
/* assumes y and x not aliased, the length is a positive multiple of 8 */ static void bsplit(fmprb_t y, const fmprb_t x, ulong a, ulong b, long prec) { fmprb_t t; fmprb_init(t); if (b - a == 8) { fmprb_add_ui(t, x, a, prec); rfac_eight(y, t, prec); } else { ulong m = a + ((b - a) / 16) * 8; bsplit(y, x, a, m, prec); bsplit(t, x, m, b, prec); fmprb_mul(y, y, t, prec); } fmprb_clear(t); }
static void bsplit(arb_t y, const fmpz_t p, const fmpz_t q, ulong a, ulong b, long prec) { if (b - a <= 8) { fmpz_t t, u; ulong c; fmpz_init(t); fmpz_init(u); fmpz_mul_ui(t, q, a); fmpz_add(t, t, p); fmpz_set(u, t); for (c = a + 1; c < b; c++) { fmpz_add(u, u, q); fmpz_mul(t, t, u); } arb_set_round_fmpz(y, t, prec); fmpz_clear(t); fmpz_clear(u); } else { arb_t w; ulong m = a + (b - a) / 2; arb_init(w); bsplit(y, p, q, a, m, prec); bsplit(w, p, q, m, b, prec); arb_mul(y, y, w, prec); arb_clear(w); } }
tor_pt_config_t * tor_pt_get_config(void) { tor_pt_config_t *cfg; char *s; bstring str; cfg = calloc(1, sizeof(tor_pt_config_t)); if (NULL == cfg) goto error_nomem; cfg->state_location = bfromcstr(getenv(TOR_PT_STATE_LOCATION)); str = bfromcstr(getenv(TOR_PT_MANAGED_TRANSPORT_VER)); if (NULL != str) { cfg->transport_ver = bsplit(str, ','); if (NULL == cfg->transport_ver) goto error_nomem; bdestroy(str); } else { cfg->transport_ver = NULL; } cfg->is_client = (NULL != (s = getenv(TOR_PT_CLIENT_TRANSPORTS))); if (cfg->is_client) { str = bfromcstr(s); if (NULL == str) goto error_nomem; cfg->client.methods = bsplit(str, ','); bdestroy(str); } else { /* Server */ } return cfg; error_nomem: fprintf(stdout, "ENV-ERROR Memory allocation failed\n"); exit(-1); }
char *test_bsplit() { bstring bstr = bfromcstr("aaaaLaaaaaaaL"); struct bstrList *list = bsplit(bstr, 'L'); mu_assert(list != NULL, "bsplit failed"); mu_assert(biseqStatic(list->entry[0], "aaaa") == 1, "bsplit first part should be aaaa"); mu_assert(biseqStatic(list->entry[1], "aaaaaaa") == 1, "bsplit second part should be aaaaaaa"); mu_assert(biseqStatic(list->entry[2], "") == 1, "bsplit third part is empty string"); mu_assert(list->qty == 3, "bsplit length error"); bdestroy(bstr); bstrListDestroy(list); return NULL; }
static int parse_transports(allium_ptcfg *cfg, const char *transports) { struct bstrList *l; struct tagbstring str; int i; assert(NULL != cfg); cfg->is_server = (NULL != transports); if (!cfg->is_server) transports = getenv(PTCFG_CLIENT_TRANSPORTS); if (NULL == transports) { fprintf(stdout, "ENV-ERROR No Transports\n"); return (-1); } btfromcstr(str, transports); if (0 == btlength(str)) { fprintf(stdout, "ENV-ERROR Empty Transport List\n"); return (-1); } l = bsplit(&str, ','); if (NULL == l) { fprintf(stdout, "ENV-ERROR OOM parsing Transports\n"); return (-1); } cfg->methods = calloc(l->qty, sizeof(*cfg->methods)); if (NULL == cfg->methods) { bstrListDestroy(l); fprintf(stdout, "ENV-ERROR OOM parsing Transports\n"); return (-1); } for (i = 0; i < l->qty; i++) { if (0 == blength(l->entry[i])) { fprintf(stdout, "ENV-ERROR Invalid Transport\n"); bstrListDestroy(l); return (-1); } cfg->methods[i].name = bstrcpy(l->entry[i]); if (NULL == cfg->methods[i].name) { fprintf(stdout, "ENV-ERROR OOM parsing Transports\n"); bstrListDestroy(l); return (-1); } cfg->nr_methods++; } return (0); }
TSTree* add_route_data(TSTree* routes, bstring line) { struct bstrList* data = bsplit(line, ' '); check(data->qty == 2, "Line '%s' does not have 2 columns", bdata(line)); routes = TSTree_insert(routes, bdata(data->entry[0]), blength(data->entry[0]), bstrcpy(data->entry[1])); bstrListDestroy(data); return routes; error: return NULL; }
char *test_bsplit(void) { struct bstrList *strlist = NULL; bstring b = bfromcstr("peter liu,, yahoo"); mu_assert(b != NULL, "Failed to create bstring on bsplit()."); strlist = bsplit(b, ' '); mu_assert(strlist->qty == 3, "Wrong split substring quy."); mu_assert(strcmp((const char *)strlist->entry[0]->data, "peter") == 0, "Wrong 1st split substring."); mu_assert(strcmp((const char *)strlist->entry[1]->data, "liu,,") == 0, "Wrong 2nd split substring."); mu_assert(strcmp((const char *)strlist->entry[2]->data, "yahoo") == 0, "Wrong 3nd split substring."); mu_assert(bstrListDestroy(strlist) == BSTR_OK, "Failed to destroy string list on bsplit()."); mu_assert(bdestroy(b) == BSTR_OK, "Failed to bdestroy() afetr bsplit()."); return NULL; }
static int nodeDistanceList(int node, int numberOfNodes, uint32_t** list) { FILE *fp; bstring filename; int count = 0; bstring src; struct bstrList* tokens; *list = (uint32_t*) malloc(numberOfNodes * sizeof(uint32_t)); if (!(*list)) { return -ENOMEM; } /* the distance interface should be always there */ filename = bformat("/sys/devices/system/node/node%d/distance", node); if (NULL != (fp = fopen (bdata(filename), "r"))) { src = bread ((bNread) fread, fp); tokens = bsplit(src,' '); for (int i=0; i<(tokens->qty); i++) { if (count < numberOfNodes) { (*list)[count] = (uint32_t)strtoul((char*) (tokens->entry[i]->data), NULL, 10); } else { ERROR_PRINT(Number Of nodes %d too large,count); return -EFAULT; } count++; } bstrListDestroy(tokens); bdestroy(src); bdestroy(filename); fclose(fp); return count; } /* something went wrong */ return -1; }
int bstr_to_workgroup(Workgroup* group, const_bstring str, DataType type, int numberOfStreams) { int parseStreams = 0; struct bstrList* tokens; tokens = bsplit(str,'-'); bstring domain; if (tokens->qty == 2) { domain = parse_workgroup(group, tokens->entry[0], type); if (domain == NULL) { bstrListDestroy(tokens); return 1; } parse_streams(group, tokens->entry[1], numberOfStreams); bdestroy(domain); } else if (tokens->qty == 1) { domain = parse_workgroup(group, tokens->entry[0], type); if (domain == NULL) { bstrListDestroy(tokens); return 1; } group->streams = (Stream*) malloc(numberOfStreams * sizeof(Stream)); if (group->streams == NULL) { bstrListDestroy(tokens); return 1; } for (int i = 0; i< numberOfStreams; i++) { group->streams[i].domain = bstrcpy(domain); group->streams[i].offset = 0; } bdestroy(domain); } else { fprintf(stderr, "Error in parsing workgroup string %s\n", bdata(str)); bstrListDestroy(tokens); return 1; } bstrListDestroy(tokens); group->size /= numberOfStreams; return 0; }
/* ---------------------------------------------------------- * FUNCTION : init_identification * DESCRIPTION : This function will read the signature file * : into the signature data structure. * INPUT : 0 - Data Structure * RETURN : -1 - Error * : 0 - Normal Return * ---------------------------------------------------------- */ int load_servicefp_file(char *sigfile, signature **db, int len) { FILE *fp; bstring filename; bstring filedata; struct bstrList *lines; int i; (void)(len); // doesn't matter /* * Check for a PADS_SIGNATURE_LIST file within the current directory. */ if ((fp = fopen(TCP_SIGNATURE_LIST, "r")) != NULL) { filename = bformat("%s", sigfile); fclose(fp); } else { filename = bformat(sigfile); } /* * Open Signature File */ if ((fp = fopen(bdata(filename), "r")) == NULL) { printf("Unable to open signature file - %s\n", bdata(filename)); return 1; } /* * Read file into 'filedata' and process it accordingly. */ filedata = bread((bNread) fread, fp); if ((lines = bsplit(filedata, '\n')) != NULL) { for (i = 0; i < lines->qty; i++) { parse_raw_signature(lines->entry[i], i + 1, db); } } /* * Clean Up */ bdestroy(filename); bdestroy(filedata); bstrListDestroy(lines); fclose(fp); return 0; }