这篇教程C++ strtok_r函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中strtok_r函数的典型用法代码示例。如果您正苦于以下问题:C++ strtok_r函数的具体用法?C++ strtok_r怎么用?C++ strtok_r使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了strtok_r函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: lirc_readconfig_only_internalstatic int lirc_readconfig_only_internal(const struct lirc_state *state, const char *file, struct lirc_config **config, int (check)(char *s), char **full_name, char **sha_bang){ char *string,*eq,*token,*token2,*token3,*strtok_state = NULL; struct filestack_t *filestack, *stack_tmp; int open_files; struct lirc_config_entry *new_entry,*first,*last; char *mode,*remote; int ret=0; int firstline=1; char *save_full_name = NULL; filestack = stack_push(state, NULL); if (filestack == NULL) { return -1; } filestack->file = lirc_open(state, file, NULL, &(filestack->name)); if (filestack->file == NULL) { stack_free(filestack); return -1; } filestack->line = 0; open_files = 1; first=new_entry=last=NULL; mode=NULL; remote=LIRC_ALL; while (filestack) { if((ret=lirc_readline(state,&string,filestack->file))==-1 || string==NULL) { fclose(filestack->file); if(open_files == 1 && full_name != NULL) { save_full_name = filestack->name; filestack->name = NULL; } filestack = stack_pop(filestack); open_files--; continue; } /* check for sha-bang */ if(firstline && sha_bang) { firstline = 0; if(strncmp(string, "#!", 2)==0) { *sha_bang=strdup(string+2); if(*sha_bang==NULL) { lirc_printf(state, "%s: out of memory/n", state->lirc_prog); ret=-1; free(string); break; } } } filestack->line++; eq=strchr(string,'='); if(eq==NULL) { token=strtok_r(string," /t",&strtok_state); if(token==NULL) { /* ignore empty line */ } else if(token[0]=='#') { /* ignore comment */ } else if(strcasecmp(token, "include") == 0) { if (open_files >= MAX_INCLUDES) { lirc_printf(state, "%s: too many files " "included at %s:%d/n", state->lirc_prog, filestack->name, filestack->line); ret=-1; } else { token2 = strtok_r(NULL, "", &strtok_state); token2 = lirc_trim(token2); lirc_parse_include (token2, filestack->name, filestack->line); stack_tmp = stack_push(state, filestack); if (stack_tmp == NULL) { ret=-1;//.........这里部分代码省略.........
开发者ID:DaveDaCoda,项目名称:mythtv,代码行数:101,
示例2: parse_args/** * Parse and store the command line arguments * * @param argc argument count * @param argv[] argument vector * @param appl_args Store application arguments here */static void parse_args(int argc, char *argv[], appl_args_t *appl_args){ int opt; int long_index; char *names, *str, *token, *save; size_t len; int i; static struct option longopts[] = { {"count", required_argument, NULL, 'c'}, {"interface", required_argument, NULL, 'i'}, /* return 'i' */ {"help", no_argument, NULL, 'h'}, /* return 'h' */ {"configuration file", required_argument, NULL, 'f'},/* return 'f' */ {NULL, 0, NULL, 0} }; memset(appl_args, 0, sizeof(*appl_args)); while (1) { opt = getopt_long(argc, argv, "+c:i:hf:", longopts, &long_index); if (opt == -1) break; /* No more options */ switch (opt) { case 'c': appl_args->core_count = atoi(optarg); break; /* parse packet-io interface names */ case 'i': len = strlen(optarg); if (len == 0) { usage(argv[0]); exit(EXIT_FAILURE); } len += 1; /* add room for '/0' */ names = malloc(len); if (names == NULL) { usage(argv[0]); exit(EXIT_FAILURE); } /* count the number of tokens separated by ',' */ strcpy(names, optarg); for (str = names, i = 0;; str = NULL, i++) { token = strtok_r(str, ",", &save); if (token == NULL) break; } appl_args->if_count = i; if (appl_args->if_count == 0) { usage(argv[0]); exit(EXIT_FAILURE); } /* allocate storage for the if names */ appl_args->if_names = calloc(appl_args->if_count, sizeof(char *)); /* store the if names (reset names string) */ strcpy(names, optarg); for (str = names, i = 0;; str = NULL, i++) { token = strtok_r(str, ",", &save); if (token == NULL) break; appl_args->if_names[i] = token; } break; case 'h': usage(argv[0]); exit(EXIT_SUCCESS); break; case 'f': len = strlen(optarg); if (len == 0) { usage(argv[0]); exit(EXIT_FAILURE); } len += 1; /* add room for '/0' */ appl_args->conf_file = malloc(len); if (appl_args->conf_file == NULL) { usage(argv[0]); exit(EXIT_FAILURE); } strcpy(appl_args->conf_file, optarg); break;//.........这里部分代码省略.........
开发者ID:babubalu,项目名称:ofp,代码行数:101,
示例3: recv_timeout/* Receive data in multiple chunks by checking a non-blocking socket Timeout in seconds*/int recv_timeout(int s ,int fileFd, int timeout){ int size_recv , total_size= 0; struct timeval begin , now; char chunk[CHUNK_SIZE], *data; double timediff; char *token; char *saveptr,*saveptr2; char header[200]; int loop =0; int http_status,contentLength; //make socket non blocking fcntl(s, F_SETFL, O_NONBLOCK); //beginning time gettimeofday(&begin , NULL); while(1) { gettimeofday(&now , NULL); //time elapsed in seconds timediff = (now.tv_sec - begin.tv_sec) + 1e-6 * (now.tv_usec - begin.tv_usec); //if you got some data, then break after timeout if( total_size > 0 && timediff > timeout ) { break; } //if you got no data at all, wait a little longer, twice the timeout else if( timediff > timeout*2) { break; } memset(chunk ,0 , CHUNK_SIZE); //clear the variable if((size_recv = recv(s , chunk , CHUNK_SIZE , 0) ) < 0) { //if nothing was received then we want to wait a little before trying again, 0.1 seconds usleep(100000); } else { //PRINTF_FL("Received Size:%d",size_recv); data = chunk; //PRINTF_FL("data:%s",chunk); total_size += size_recv; //PRINTF_FL("%s" , chunk); if(loop == 0) { while((token = strtok_r(data,"/r",&saveptr))) { /* code to retieve the http response status * example : HTTP/1.1 200 OK */ if(token == NULL || strcmp(&token[0],"/n") == 0) { data = saveptr+1; break; } strncpy(header,&token[0],199); //PRINTF_FL("Header msg: %s",header); if(loop == 0) { token = strtok_r(header," ",&saveptr2); if(token == NULL) { PRINTF_FL("Wrong Response Header .. Returning1"); return; } else if(strcmp("HTTP/1.1",token) != 0) { PRINTF_FL("Wrong Response Header .. Returning "); return; } token = strtok_r(NULL," ",&saveptr2); if(token == NULL) { PRINTF_FL("Wrong Response Header .. Returning "); return; } http_status = atoi(&token[0]); PRINTF_FL("HTTP response status : %d",http_status); loop = 1; if(http_status != 200) return; } else { if((token = strstr(header,"Content-Length:"))) { contentLength = atoi(token+16); PRINTF_FL("Content Length:%d",contentLength); } } data = NULL;//.........这里部分代码省略.........
开发者ID:PraveenSubramaniyam,项目名称:CCS,代码行数:101,
示例4: rrd_create_r//.........这里部分代码省略......... break; case DST_CDEF: parseCDEF_DS(&argv[i][offset + 3], &rrd, rrd.stat_head->ds_cnt); break; default: rrd_set_error("invalid DS type specified"); break; } if (rrd_test_error()) { rrd_free2(&rrd); return -1; } rrd.stat_head->ds_cnt++; } else if (strncmp(argv[i], "RRA:", 4) == 0) { char *argvcopy; char *tokptr = ""; int cf_id = -1; size_t old_size = sizeof(rra_def_t) * (rrd.stat_head->rra_cnt); int row_cnt; int token_min = 4; if ((rrd.rra_def = (rra_def_t*)rrd_realloc(rrd.rra_def, old_size + sizeof(rra_def_t))) == NULL) { rrd_set_error("allocating rrd.rra_def"); rrd_free2(&rrd); return (-1); } memset(&rrd.rra_def[rrd.stat_head->rra_cnt], 0, sizeof(rra_def_t)); argvcopy = strdup(argv[i]); token = strtok_r(&argvcopy[4], ":", &tokptr); token_idx = error_flag = 0; while (token != NULL) { switch (token_idx) { case 0: if (sscanf(token, CF_NAM_FMT, rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam) != 1) rrd_set_error("Failed to parse CF name"); cf_id = cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam); switch (cf_id) { case CF_MHWPREDICT: strcpy(rrd.stat_head->version, RRD_VERSION); /* MHWPREDICT causes Version 4 */ case CF_HWPREDICT: token_min = 5; /* initialize some parameters */ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_alpha]. u_val = 0.1; rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_beta]. u_val = 1.0 / 288; rrd.rra_def[rrd.stat_head->rra_cnt]. par[RRA_dependent_rra_idx].u_cnt = rrd.stat_head->rra_cnt; break; case CF_DEVSEASONAL: token_min = 3; case CF_SEASONAL: if (cf_id == CF_SEASONAL){ token_min = 4; } /* initialize some parameters */ rrd.rra_def[rrd.stat_head->rra_cnt].
开发者ID:AudriusButkevicius,项目名称:python-rrdtool,代码行数:67,
示例5: strlenchar*transcode_query(const char *query, const char *username, char *transcoded_query){ char *saveptr = NULL, *token; int i, j, len, replacements; int namelen = strlen(username); int querylen = strlen(query); char *str = malloc (querylen); /* count aprox. the number of replacements. * %% escaping is also accounted and shouldn't * in the TODO */ for (replacements = 0, str=strdup(query); ; str = NULL) { token = strtok_r(str, "%", &saveptr); if (token == NULL) break; if (token[0] == 'u') { replacements++; } } free(str); len = querylen + namelen * replacements - 2 * replacements + 1; transcoded_query = malloc (len); memset(transcoded_query, 0, len); for (i=j=0;j<len && query[i]; ){ if (query[i] == '%') { switch (query[i+1]) { case '%': /* escaped '%' character */ transcoded_query[j++] = '%'; break; case 'u': /* paste in the username */ if (j+namelen>=len) { LOG(LOG_ERR, "%s: check ExtLookupQuery", ERR_EXT_LOOKUP_MISCONFIGURED); return NULL; } memcpy (transcoded_query+j, username, namelen); j += namelen; break; default: /* unrecognised formatting, abort! */ LOG(LOG_ERR, "%s: check ExtLookupQuery", ERR_EXT_LOOKUP_MISCONFIGURED); return NULL; } i += 2; } else { transcoded_query[j++] = query[i++]; } } if (j>=len) { LOG(LOG_ERR, "%s: check ExtLookupQuery", ERR_EXT_LOOKUP_MISCONFIGURED); return NULL; } /* and finally zero terminate string */ transcoded_query[j] = 0; return transcoded_query;}
开发者ID:toddfries,项目名称:dspam,代码行数:62,
示例6: process_request/* * Processes the incoming request */void process_request(gnutls_session_t session) { char buffer[MAX_BUF + 1]; char header[MAX_BUF]; /* * Reset mem, read the client header into * the buffer. */ memset (buffer, 0, MAX_BUF + 1); char *buf = read_line(session, buffer, MAX_BUF); printf("/t%s/n", buf); /* * Sepearate our first line request header * into separate parts, specifically we need * the file path its requesting */ char *token; char *tokenizer; token = strtok_r(buf, " ", &tokenizer); token = strtok_r(NULL, " ", &tokenizer); char *file_name = strdup(token); /* * If no file is listed, we default to * index.html */ if (strcmp(file_name, "/") == 0) strcpy(file_name, "/index.html"); /* * Setting where to serve content form */ char path[MAX_BUF]; snprintf(path, MAX_BUF, "content%s", file_name); /* * Opening the file, if it doesn't exist we stop here * and send a 404 Not found header to the client */ FILE *file = fopen(path, "r"); if (file == NULL) { fprintf(stderr, "/tFile not found./n"); snprintf(header, MAX_BUF, "HTTP/1.1 404 Not Found/r/n/r/n"); if (gnutls_record_send(session, header, strlen(header)) < 0) err_exit(); } else { /* * File found, get the mime type */ char content_buffer[MAX_BUF]; char *mime = get_content_type(path, content_buffer, MAX_BUF); printf("/tContent type detected: %s/n", mime); /* * If it is PHP, we will close the currentl file descriptor * and set it to the execution of the script. The output * of the command is now our file descriptor */ if (strcmp(mime, "application/php") == 0) { printf("/tExecuting PHP file./n"); fclose(file); snprintf(path, MAX_BUF, "php content%s", file_name); file = popen(path, "r"); if (file == NULL) err_exit(); // change the mime type. strcpy(mime, "text/html"); } /* * Check to see how big the file is */ fseek(file, 0, SEEK_END); int file_size = ftell(file); fseek(file, 0, SEEK_SET); /* * Read the content into here */ char *file_string = malloc(file_size+1); fread(file_string, 1, file_size, file); /* * Hotfix, PHP gives us a filesize of -1 apparently, * we need to use strlen to actually read the size of//.........这里部分代码省略.........
开发者ID:sjlu,项目名称:httpd,代码行数:101,
示例7: video_shader_parse_imports/** * video_shader_parse_imports: * @conf : Preset file to read from. * @shader : Shader passes handle. * * Resolves import parameters belonging to shaders. * * Returns: true (1) if successful, otherwise false (0). **/static bool video_shader_parse_imports(config_file_t *conf, struct video_shader *shader){ size_t path_size = PATH_MAX_LENGTH * sizeof(char); const char *id = NULL; char *save = NULL; char *tmp_str = NULL; char *imports = (char*)malloc(1024 * sizeof(char)); imports[0] = '/0'; if (!config_get_array(conf, "imports", imports, 1024 * sizeof(char))) { free(imports); return true; } for (id = strtok_r(imports, ";", &save); id && shader->variables < GFX_MAX_VARIABLES; shader->variables++, id = strtok_r(NULL, ";", &save)) { char semantic_buf[64]; char wram_buf[64]; char input_slot_buf[64]; char mask_buf[64]; char equal_buf[64]; char semantic[64]; unsigned addr = 0; unsigned mask = 0; unsigned equal = 0; struct state_tracker_uniform_info *var = &shader->variable[shader->variables]; semantic_buf[0] = wram_buf[0] = input_slot_buf[0] = mask_buf[0] = equal_buf[0] = semantic[0] = '/0'; strlcpy(var->id, id, sizeof(var->id)); snprintf(semantic_buf, sizeof(semantic_buf), "%s_semantic", id); if (!config_get_array(conf, semantic_buf, semantic, sizeof(semantic))) { RARCH_ERR("No semantic for import variable./n"); goto error; } snprintf(wram_buf, sizeof(wram_buf), "%s_wram", id); snprintf(input_slot_buf, sizeof(input_slot_buf), "%s_input_slot", id); snprintf(mask_buf, sizeof(mask_buf), "%s_mask", id); snprintf(equal_buf, sizeof(equal_buf), "%s_equal", id); if (string_is_equal(semantic, "capture")) var->type = RARCH_STATE_CAPTURE; else if (string_is_equal(semantic, "transition")) var->type = RARCH_STATE_TRANSITION; else if (string_is_equal(semantic, "transition_count")) var->type = RARCH_STATE_TRANSITION_COUNT; else if (string_is_equal(semantic, "capture_previous")) var->type = RARCH_STATE_CAPTURE_PREV; else if (string_is_equal(semantic, "transition_previous")) var->type = RARCH_STATE_TRANSITION_PREV; else if (string_is_equal(semantic, "python")) var->type = RARCH_STATE_PYTHON; else { RARCH_ERR("Invalid semantic./n"); goto error; } if (var->type != RARCH_STATE_PYTHON) { unsigned input_slot = 0; if (config_get_uint(conf, input_slot_buf, &input_slot)) { switch (input_slot) { case 1: var->ram_type = RARCH_STATE_INPUT_SLOT1; break; case 2: var->ram_type = RARCH_STATE_INPUT_SLOT2; break; default: RARCH_ERR("Invalid input slot for import./n"); goto error; } }//.........这里部分代码省略.........
开发者ID:RobLoach,项目名称:RetroArch,代码行数:101,
示例8: ac_load_configstatic void ac_load_config(void){ FILE *fp = open_config_file(cs_ac); if(!fp) { return; } int32_t nr; char *saveptr1 = NULL, *token; if(!cs_malloc(&token, MAXLINESIZE)) { return; } struct s_cpmap *cur_cpmap, *first_cpmap = NULL, *last_cpmap = NULL; for(nr = 0; fgets(token, MAXLINESIZE, fp);) { int32_t i, skip; uint16_t caid, sid, chid, dwtime; uint32_t provid; char *ptr, *ptr1; if(strlen(token) < 4) { continue; } caid = sid = chid = dwtime = 0; provid = 0; skip = 0; ptr1 = 0; for(i = 0, ptr = strtok_r(token, "=", &saveptr1); (i < 2) && (ptr); ptr = strtok_r(NULL, "=", &saveptr1), i++) { trim(ptr); if(*ptr == ';' || *ptr == '#' || *ptr == '-') { skip = 1; break; } switch(i) { case 0: ptr1 = ptr; break; case 1: dwtime = atoi(ptr); break; } } if(!skip) { for(i = 0, ptr = strtok_r(ptr1, ":", &saveptr1); (i < 4) && (ptr); ptr = strtok_r(NULL, ":", &saveptr1), i++) { trim(ptr); switch(i) { case 0: if(*ptr == '*') { caid = 0; } else { caid = a2i(ptr, 4); } break; case 1: if(*ptr == '*') { provid = 0; } else { provid = a2i(ptr, 6); } break; case 2: if(*ptr == '*') { sid = 0; } else { sid = a2i(ptr, 4); } break; case 3: if(*ptr == '*') { chid = 0; } else { chid = a2i(ptr, 4); } break; } } if(!cs_malloc(&cur_cpmap, sizeof(struct s_cpmap))) { for(cur_cpmap = first_cpmap; cur_cpmap;) { last_cpmap = cur_cpmap; cur_cpmap = cur_cpmap->next; free(last_cpmap); } free(token); return; } if(last_cpmap) { last_cpmap->next = cur_cpmap; } else { first_cpmap = cur_cpmap; } last_cpmap = cur_cpmap; cur_cpmap->caid = caid; cur_cpmap->provid = provid; cur_cpmap->sid = sid; cur_cpmap->chid = chid; cur_cpmap->dwtime = dwtime; cur_cpmap->next = 0; cs_debug_mask(D_CLIENT, "nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d", nr, caid, provid, sid, chid, dwtime); nr++; } } free(token); fclose(fp);//.........这里部分代码省略.........
开发者ID:StbLinux,项目名称:oscam,代码行数:101,
示例9: mtd_writestatic intmtd_write(int imagefd, const char *mtd, char *fis_layout, size_t part_offset){ char *next = NULL; char *str = NULL; int fd, result; ssize_t r, w, e; ssize_t skip = 0; uint32_t offset = 0; int jffs2_replaced = 0; int skip_bad_blocks = 0;#ifdef FIS_SUPPORT static struct fis_part new_parts[MAX_ARGS]; static struct fis_part old_parts[MAX_ARGS]; int n_new = 0, n_old = 0; if (fis_layout) { const char *tmp = mtd; char *word, *brkt; int ret; memset(&old_parts, 0, sizeof(old_parts)); memset(&new_parts, 0, sizeof(new_parts)); do { next = strchr(tmp, ':'); if (!next) next = (char *) tmp + strlen(tmp); memcpy(old_parts[n_old].name, tmp, next - tmp); n_old++; tmp = next + 1; } while(*next); for (word = strtok_r(fis_layout, ",", &brkt); word; word = strtok_r(NULL, ",", &brkt)) { tmp = strtok(word, ":"); strncpy((char *) new_parts[n_new].name, tmp, sizeof(new_parts[n_new].name) - 1); tmp = strtok(NULL, ":"); if (!tmp) goto next; new_parts[n_new].size = strtoul(tmp, NULL, 0); tmp = strtok(NULL, ":"); if (!tmp) goto next; new_parts[n_new].loadaddr = strtoul(tmp, NULL, 16);next: n_new++; } ret = fis_validate(old_parts, n_old, new_parts, n_new); if (ret < 0) { fprintf(stderr, "Failed to validate the new FIS partition table/n"); exit(1); } if (ret == 0) fis_layout = NULL; }#endif if (strchr(mtd, ':')) { str = strdup(mtd); mtd = str; } r = 0;resume: next = strchr(mtd, ':'); if (next) { *next = 0; next++; } fd = mtd_check_open(mtd); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s/n", mtd); exit(1); } if (part_offset > 0) { fprintf(stderr, "Seeking on mtd device '%s' to: %zu/n", mtd, part_offset); lseek(fd, part_offset, SEEK_SET); } indicate_writing(mtd); w = e = 0; for (;;) { /* buffer may contain data already (from trx check or last mtd partition write attempt) */ while (buflen < erasesize) { r = read(imagefd, buf + buflen, erasesize - buflen); if (r < 0) { if ((errno == EINTR) || (errno == EAGAIN))//.........这里部分代码省略.........
开发者ID:zcutlip,项目名称:con-demos,代码行数:101,
示例10: powerdns_read_recursorstatic int powerdns_read_recursor (list_item_t *item) /* {{{ */{ char *buffer = NULL; size_t buffer_size = 0; int status; char *dummy; char *keys_list; char *key; char *key_saveptr; char *value; char *value_saveptr; if (item->command == NULL) { status = powerdns_update_recursor_command (item); if (status != 0) { ERROR ("powerdns plugin: powerdns_update_recursor_command failed."); return (-1); } DEBUG ("powerdns plugin: powerdns_read_recursor: item->command = %s;", item->command); } assert (item->command != NULL); status = powerdns_get_data (item, &buffer, &buffer_size); if (status != 0) { ERROR ("powerdns plugin: powerdns_get_data failed."); return (-1); } keys_list = strdup (item->command); if (keys_list == NULL) { FUNC_ERROR ("strdup"); sfree (buffer); return (-1); } key_saveptr = NULL; value_saveptr = NULL; /* Skip the `get' at the beginning */ strtok_r (keys_list, " /t", &key_saveptr); dummy = buffer; while ((value = strtok_r (dummy, " /t/n/r", &value_saveptr)) != NULL) { dummy = NULL; key = strtok_r (NULL, " /t", &key_saveptr); if (key == NULL) break; submit (item->instance, key, value); } /* while (strtok_r) */ sfree (buffer); sfree (keys_list); return (0);} /* }}} int powerdns_read_recursor */
开发者ID:ninokop,项目名称:collectd,代码行数:66,
示例11: oP_Tab_mainint oP_Tab_main(opcd **pHead){ FILE *fp; char *input,*str1, *str2, *subtoken, *type, *temp,*saveptr2, *buffer; int j, count=0; input = (char *) malloc(sizeof(char) * 70); fp=fopen("myInput.text","r"); if(fp==NULL) printf("File Does Not Exist."); while(fgets(input, 70, fp) != NULL) { count++; str1=(char*)malloc(sizeof(char)*(strlen(input)+1)); buffer=(char*)malloc(sizeof(char)*(strlen(input)+1)); strcpy(str1,input); ///////////// input = strtok(str1, ";"); subtoken = strtok_r(input, " /t",&saveptr2); str2 = NULL; for (; ;str2 = NULL) { subtoken = strtok_r(str2, " /t", &saveptr2); if (subtoken == NULL) break; str1 = strtok_r(str2, " /t", &saveptr2); if (str1 == NULL) break; buffer = strtok_r(str2, " /t", &saveptr2); if (buffer == NULL) break; j=strlen(buffer); if(buffer[j-1]==':') buffer = strtok_r(str2, " /t", &saveptr2); if (buffer == NULL) break; type = strtok_r(str2, " ,/t", &saveptr2); if (type == NULL) break; temp = strtok_r(str2, " ,/t", &saveptr2); if (temp == NULL) break; optable(pHead,str1,buffer,type,temp); str1=buffer=type=temp=NULL; } free(input); input = (char *) malloc(sizeof(char) * 70); } //prnt_opcd(pHead); fclose(fp); return 0;}
开发者ID:vishal-chillal,项目名称:Symbol_Table,代码行数:66,
示例12: powerdns_read_serverstatic int powerdns_read_server (list_item_t *item) /* {{{ */{ char *buffer = NULL; size_t buffer_size = 0; int status; char *dummy; char *saveptr; char *key; char *value; const char* const *fields; int fields_num; if (item->command == NULL) item->command = strdup (SERVER_COMMAND); if (item->command == NULL) { ERROR ("powerdns plugin: strdup failed."); return (-1); } status = powerdns_get_data (item, &buffer, &buffer_size); if (status != 0) return (-1); if (item->fields_num != 0) { fields = (const char* const *) item->fields; fields_num = item->fields_num; } else { fields = default_server_fields; fields_num = default_server_fields_num; } assert (fields != NULL); assert (fields_num > 0); /* corrupt-packets=0,deferred-cache-inserts=0,deferred-cache-lookup=0,latency=0,packetcache-hit=0,packetcache-miss=0,packetcache-size=0,qsize-q=0,query-cache-hit=0,query-cache-miss=0,recursing-answers=0,recursing-questions=0,servfail-packets=0,tcp-answers=0,tcp-queries=0,timedout-packets=0,udp-answers=0,udp-queries=0,udp4-answers=0,udp4-queries=0,udp6-answers=0,udp6-queries=0, */ dummy = buffer; saveptr = NULL; while ((key = strtok_r (dummy, ",", &saveptr)) != NULL) { int i; dummy = NULL; value = strchr (key, '='); if (value == NULL) break; *value = '/0'; value++; if (value[0] == '/0') continue; /* Check if this item was requested. */ for (i = 0; i < fields_num; i++) if (strcasecmp (key, fields[i]) == 0) break; if (i >= fields_num) continue; submit (item->instance, key, value); } /* while (strtok_r) */ sfree (buffer); return (0);} /* }}} int powerdns_read_server */
开发者ID:ninokop,项目名称:collectd,代码行数:74,
示例13: mainint main(int argc, char *argv[]){ /* System call shell command */ system("ls -l >> assignment.txt"); /* Read shell command results */ char temp_hold[LENGTH]; char permission_hold[LENGTH]; char *filesize_hold; int permission_check = 0; int filesize_check = 0; char *delim = " "; int loop_control; char *permission_argv; int condition = 0; char *filesize_temp; int temp_int = 0; int flag = 0; FILE *fp; fp = fopen("./assignment.txt", "r"); if(fp == NULL) { printf("No Such File !!!/n"); } fgets(temp_hold, STRING, fp); char *num = "1234567890"; char *p; if(argc == 2) { p = strpbrk(argv[1], num); if(!p) { //Only Permission Check while(!feof(fp)) { flag = 2; fgets(temp_hold, STRING, fp); strcpy(permission_hold, strtok(temp_hold, delim)); permission_argv = strndup(permission_hold+1, 9); condition = check_permission(permission_argv, argv[1]); if(condition == 1) { permission_check += 1; } } } else { //Only Filesize Check while(!feof(fp)) { flag = 1; loop_control = 0; fgets(temp_hold, STRING, fp); filesize_hold = strtok_r(temp_hold, " ", &filesize_temp); while(filesize_hold != NULL) { if(loop_control == 4) { break; } filesize_hold = strtok_r(NULL, " ", &filesize_temp); loop_control++; } if(filesize_hold) { temp_int = atoi(filesize_hold); if(temp_int >= atoi(argv[1])) { filesize_check += 1; } } } } } else if(argc == 3) { while(!feof(fp)) { loop_control = 0; fgets(temp_hold, STRING, fp); filesize_hold = strtok_r(temp_hold, " ", &filesize_temp); while (filesize_hold != NULL) { if(loop_control == 4) { break; } filesize_hold = strtok_r(NULL, " ", &filesize_temp); loop_control++;//.........这里部分代码省略.........
开发者ID:royalchan2436,项目名称:C-BasicC,代码行数:101,
示例14: Curl_input_digestCURLdigest Curl_input_digest(struct connectdata *conn, bool proxy, const char *header) /* rest of the *-authenticate: header */{ bool more = TRUE; char *token = NULL; char *tmp = NULL; bool foundAuth = FALSE; bool foundAuthInt = FALSE; struct SessionHandle *data=conn->data; bool before = FALSE; /* got a nonce before */ struct digestdata *d; if(proxy) { d = &data->state.proxydigest; } else { d = &data->state.digest; } /* skip initial whitespaces */ while(*header && ISSPACE(*header)) header++; if(checkprefix("Digest", header)) { header += strlen("Digest"); /* If we already have received a nonce, keep that in mind */ if(d->nonce) before = TRUE; /* clear off any former leftovers and init to defaults */ Curl_digest_cleanup_one(d); while(more) { char value[MAX_VALUE_LENGTH]; char content[MAX_CONTENT_LENGTH]; while(*header && ISSPACE(*header)) header++; /* extract a value=content pair */ if(!get_pair(header, value, content, &header)) { if(Curl_raw_equal(value, "nonce")) { d->nonce = strdup(content); if(!d->nonce) return CURLDIGEST_NOMEM; } else if(Curl_raw_equal(value, "stale")) { if(Curl_raw_equal(content, "true")) { d->stale = TRUE; d->nc = 1; /* we make a new nonce now */ } } else if(Curl_raw_equal(value, "realm")) { d->realm = strdup(content); if(!d->realm) return CURLDIGEST_NOMEM; } else if(Curl_raw_equal(value, "opaque")) { d->opaque = strdup(content); if(!d->opaque) return CURLDIGEST_NOMEM; } else if(Curl_raw_equal(value, "qop")) { char *tok_buf; /* tokenize the list and choose auth if possible, use a temporary clone of the buffer since strtok_r() ruins it */ tmp = strdup(content); if(!tmp) return CURLDIGEST_NOMEM; token = strtok_r(tmp, ",", &tok_buf); while(token != NULL) { if(Curl_raw_equal(token, "auth")) { foundAuth = TRUE; } else if(Curl_raw_equal(token, "auth-int")) { foundAuthInt = TRUE; } token = strtok_r(NULL, ",", &tok_buf); } free(tmp); /*select only auth o auth-int. Otherwise, ignore*/ if(foundAuth) { d->qop = strdup("auth"); if(!d->qop) return CURLDIGEST_NOMEM; } else if(foundAuthInt) { d->qop = strdup("auth-int"); if(!d->qop) return CURLDIGEST_NOMEM; } } else if(Curl_raw_equal(value, "algorithm")) { d->algorithm = strdup(content); if(!d->algorithm) return CURLDIGEST_NOMEM; if(Curl_raw_equal(content, "MD5-sess"))//.........这里部分代码省略.........
开发者ID:JulianSpillane,项目名称:moai-dev,代码行数:101,
示例15: ExtractFileRequest/** * Reads and parses the file request lines received from the client. * @param req: location where this method writes the requested * filename or directory. * @param buff: buffer where the HTTP request is stored. * @param response: instance of Struct HTTP_Response which this method will * populate based on the HTTP request in buff. */void ExtractFileRequest(char *req, char *buff, HTTP_Response *response ) { int lastPos = (int)(strchr(buff, '/n') - buff) - 1; //Newline is /r/n /* We should now have the ending position to get the following line: * "GET / HTTP/1.0" * So split it based on space delimeter to get URL path * and HTTP version. */ //printf("entire buffer: %s/nLast pos: %d/n", buff, lastPos); //printf("End of first line position: %d/n", lastPos); char *tempBuff = malloc(strlen(buff)); strcpy(tempBuff, buff); char *split, *savePtr; int i = 0; int total = 0; while (total < lastPos) { if (total == 0) { split = strtok_r(tempBuff, " ", &savePtr); } else { split = strtok_r(NULL, " ", &savePtr); } int size = strlen(split); switch(i) { case 0: //Method (GET, POST, HEAD...) response->HTTP_Type = malloc(size + 1); strcpy(response -> HTTP_Type, split); break; case 1: //File content path strcpy(req, split); break; case 2: //HTTP Protocol (ex HTTP/1.1) /* There is no space after the version number, * only a newline character. So split again. */ split = strtok(split, "/r/n"); size = strlen(split); response->versionNum = malloc(size + 1); strcpy(response -> versionNum, split); break; } total += size + 1; //+1 to account for space i++; printf("Split string: %s, size: %d/n", split, size); } // Find the Accept: ... line in the get response strcpy(tempBuff, buff); split = strstr(tempBuff, "Accept: "); split = split + strlen("Accept: "); //Should put us right after Accept: statement char *content_type = strtok(split, "/n"); /* If content_type only contains one element, strtok will return NULL. * If content_type has multiple elements (seperated by commas), strtok will * null terminate the first comma, so content_type will point to only the first element */ strtok(content_type, ","); printf("Content-type: %s/n", content_type); response -> contentType = malloc(strlen(content_type) + 1); strcpy(response -> contentType, content_type); char *result = "200"; response -> resultCode = malloc(strlen(result) + 1); strcpy(response -> resultCode, result); char *stat = "OK"; response -> status = malloc(strlen(stat) + 1); strcpy(response -> status, stat); /* * Check if content requested (req) contains any user variables * GET request contains data in content URL, * POST containst data at the end of the buffer */ char *t = NULL; char *userVarStart = NULL; if (strcmp(response -> HTTP_Type, "POST") == 0) { //Print buffer for debug printf("Header:/n%s/n/n", buff); // Check if POST request with data AFTER the header//.........这里部分代码省略.........
开发者ID:allenc4,项目名称:WIT_OperatingSystems,代码行数:101,
示例16: apicmd_kvercmp2void apicmd_kvercmp2(int argc, char *argv[]){ int exit_value; struct tst_kern_exv vers[100]; unsigned int count; char *saveptr1 = NULL; char *saveptr2 = NULL; char *token1; if (TCID == NULL) TCID = "outoftest"; if (tst_cntstr == NULL) tst_count = 0; if (argc < 5) { fprintf(stderr, "Usage: %s NUM NUM NUM KVERS/n" "Compares to the running kernel version/n" "based on vanilla kernel version NUM NUM NUM/n" "or distribution specific kernel version KVERS/n/n" "/tNUM - A positive integer./n" "/tThe first NUM is the kernel VERSION/n" "/tThe second NUM is the kernel PATCHLEVEL/n" "/tThe third NUM is the kernel SUBLEVEL/n/n" "/tKVERS is a string of the form " "/"DISTR1:VERS1 DISTR2:VERS2/",/n" "/twhere DISTR1 is a distribution name/n" "/tand VERS1 is the corresponding kernel version./n" "/tExample: /"RHEL6:2.6.39-400.208/"/n/n" "/tIf running kernel matches a distribution in KVERS then/n" "/tcomparison is performed based on version in KVERS,/n" "/totherwise - based on NUM NUM NUM./n/n" "/tExit status is 0 if the running kernel is older./n" "/tExit status is 1 for kernels of the same age./n" "/tExit status is 2 if the running kernel is newer./n", cmd_name); exit(3); } count = 0; token1 = strtok_r(argv[3], " ", &saveptr1); while ((token1 != NULL) && (count < 99)) { vers[count].dist_name = strtok_r(token1, ":", &saveptr2); vers[count].extra_ver = strtok_r(NULL, ":", &saveptr2); if (vers[count].extra_ver == NULL) { fprintf(stderr, "Incorrect KVERS format/n"); exit(3); } count++; token1 = strtok_r(NULL, " ", &saveptr1); } vers[count].dist_name = NULL; vers[count].extra_ver = NULL; exit_value = tst_kvercmp2(atoi(argv[0]), atoi(argv[1]), atoi(argv[2]), vers); if (exit_value < 0) exit_value = 0; else if (exit_value == 0) exit_value = 1; else if (exit_value > 0) exit_value = 2; exit(exit_value);}
开发者ID:AbhiramiP,项目名称:ltp,代码行数:69,
示例17: runCommand/* Run a command. Commands are defined in commands.h */int runCommand() { int i = 0; char *p = argv1; char *str; int pid_args[4]; arg1 = atoi(argv1); arg2 = atoi(argv2); switch(cmd) { case GET_TICKS: Serial.println(ticks); break; case GET_BAUDRATE: Serial.println(BAUDRATE); break; case ANALOG_READ: Serial.println(analogRead(arg1)); break; case DIGITAL_READ: Serial.println(digitalRead(arg1)); break; case ANALOG_WRITE: analogWrite(arg1, arg2); Serial.println("OK"); break; case DIGITAL_WRITE: if (arg2 == 0) digitalWrite(arg1, LOW); else if (arg2 == 1) digitalWrite(arg1, HIGH); Serial.println("OK"); break; case PIN_MODE: if (arg2 == 0) pinMode(arg1, INPUT); else if (arg2 == 1) pinMode(arg1, OUTPUT); Serial.println("OK"); break; case PING: Serial.println(Ping(arg1)); break;#ifdef USE_SERVOS case SERVO_WRITE: servos[arg1].write(arg2); Serial.println("OK"); break; case SERVO_READ: Serial.println(servos[arg1].read()); break;#endif#ifdef USE_BASE case READ_ENCODERS: Serial.print(readEncoder(LEFT)); Serial.print(" "); Serial.println(readEncoder(RIGHT)); break; case RESET_ENCODERS: resetEncoders(); Serial.println("OK"); break; case READ_MOTORS: Serial.print(leftPID.output); Serial.print(" "); Serial.println(rightPID.output); break; case MOTOR_SPEEDS: /* Reset the auto stop timer */ lastMotorCommand = millis(); if (arg1 == 0 && arg2 == 0) { setMotorSpeeds(0, 0); moving = 0; resetPID(); } else moving = 1; leftPID.TargetTicksPerFrame = arg1; rightPID.TargetTicksPerFrame = arg2; Serial.println("OK"); break; case UPDATE_PID: while ((str = strtok_r(p, ":", &p)) != '/0') { pid_args[i] = atoi(str); i++; } Kp = pid_args[0]; Kd = pid_args[1]; Ki = pid_args[2]; Ko = pid_args[3]; Serial.println("OK"); break;#endif default: Serial.println("Invalid Command"); break; }}
开发者ID:jfstepha,项目名称:yertle-bot,代码行数:95,
示例18: search_pemapstatic int search_pemap(char *pecoremap, int pe){ int *map = (int *)malloc(CmiNumPesGlobal()*sizeof(int)); char *ptr = NULL; int h, i, j, k, count; int plusarr[128]; char *str; char *mapstr = (char*)malloc(strlen(pecoremap)+1); strcpy(mapstr, pecoremap); str = strtok_r(mapstr, ",", &ptr); count = 0; while (str && count < CmiNumPesGlobal()) { int hasdash=0, hascolon=0, hasdot=0, hasstar1=0, hasstar2=0, numplus=0; int start, end, stride=1, block=1; int iter=1; plusarr[0] = 0; for (i=0; i<strlen(str); i++) { if (str[i] == '-' && i!=0) hasdash=1; else if (str[i] == ':') hascolon=1; else if (str[i] == '.') hasdot=1; else if (str[i] == 'x') hasstar1=1; else if (str[i] == 'X') hasstar2=1; else if (str[i] == '+') { if (str[i+1] == '+' || str[i+1] == '-') { printf("Warning: Check the format of /"%s/"./n", str); } else if (sscanf(&str[i], "+%d", &plusarr[++numplus]) != 1) { printf("Warning: Check the format of /"%s/"./n", str); --numplus; } } } if (hasstar1 || hasstar2) { if (hasstar1) sscanf(str, "%dx", &iter); if (hasstar2) sscanf(str, "%dX", &iter); while (*str!='x' && *str!='X') str++; str++; } if (hasdash) { if (hascolon) { if (hasdot) { if (sscanf(str, "%d-%d:%d.%d", &start, &end, &stride, &block) != 4) printf("Warning: Check the format of /"%s/"./n", str); } else { if (sscanf(str, "%d-%d:%d", &start, &end, &stride) != 3) printf("Warning: Check the format of /"%s/"./n", str); } } else { if (sscanf(str, "%d-%d", &start, &end) != 2) printf("Warning: Check the format of /"%s/"./n", str); } } else { sscanf(str, "%d", &start); end = start; } if (block > stride) { printf("Warning: invalid block size in /"%s/" ignored./n", str); block=1; } //if (CmiMyPe() == 0) printf("iter: %d start: %d end: %d stride: %d, block: %d. plus %d /n", iter, start, end, stride, block, numplus); for (k = 0; k<iter; k++) { for (i = start; i<=end; i+=stride) { for (j=0; j<block; j++) { if (i+j>end) break; for (h=0; h<=numplus; h++) { map[count++] = i+j+plusarr[h]; if (count == CmiNumPesGlobal()) break; } if (count == CmiNumPesGlobal()) break; } if (count == CmiNumPesGlobal()) break; } if (count == CmiNumPesGlobal()) break; } str = strtok_r(NULL, ",", &ptr); } i = map[pe % count]; free(map); free(mapstr); return i;}
开发者ID:gitter-badger,项目名称:quinoa,代码行数:87,
示例19: video_shader_parse_textures/** * video_shader_parse_textures: * @conf : Preset file to read from. * @shader : Shader pass handle. * * Parses shader textures. * * Returns: true (1) if successful, otherwise false (0). **/static bool video_shader_parse_textures(config_file_t *conf, struct video_shader *shader){ size_t path_size = PATH_MAX_LENGTH * sizeof(char); const char *id = NULL; char *save = NULL; char *textures = (char*)malloc(1024 * sizeof(char)); textures[0] = '/0'; if (!config_get_array(conf, "textures", textures, 1024 * sizeof(char))) { free(textures); return true; } for (id = strtok_r(textures, ";", &save); id && shader->luts < GFX_MAX_TEXTURES; shader->luts++, id = strtok_r(NULL, ";", &save)) { char id_filter[64]; char id_wrap[64]; char wrap_mode[64]; char id_mipmap[64]; bool mipmap = false; bool smooth = false; char *tmp_path = NULL; id_filter[0] = id_wrap[0] = wrap_mode[0] = id_mipmap[0] = '/0'; if (!config_get_array(conf, id, shader->lut[shader->luts].path, sizeof(shader->lut[shader->luts].path))) { RARCH_ERR("Cannot find path to texture /"%s/" .../n", id); free(textures); return false; } tmp_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); tmp_path[0] = '/0'; strlcpy(tmp_path, shader->lut[shader->luts].path, path_size); path_resolve_realpath(tmp_path, path_size); if (filestream_exists(tmp_path)) strlcpy(shader->lut[shader->luts].path, tmp_path, sizeof(shader->lut[shader->luts].path)); free(tmp_path); strlcpy(shader->lut[shader->luts].id, id, sizeof(shader->lut[shader->luts].id)); snprintf(id_filter, sizeof(id_filter), "%s_linear", id); if (config_get_bool(conf, id_filter, &smooth)) shader->lut[shader->luts].filter = smooth ? RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST; else shader->lut[shader->luts].filter = RARCH_FILTER_UNSPEC; snprintf(id_wrap, sizeof(id_wrap), "%s_wrap_mode", id); if (config_get_array(conf, id_wrap, wrap_mode, sizeof(wrap_mode))) shader->lut[shader->luts].wrap = wrap_str_to_mode(wrap_mode); snprintf(id_mipmap, sizeof(id_mipmap), "%s_mipmap", id); if (config_get_bool(conf, id_mipmap, &mipmap)) shader->lut[shader->luts].mipmap = mipmap; else shader->lut[shader->luts].mipmap = false; } free(textures); return true;}
开发者ID:RobLoach,项目名称:RetroArch,代码行数:82,
示例20: memcached_readstatic int memcached_read (void) /* {{{ */{ char buf[1024]; char *fields[3]; char *ptr; char *line; char *saveptr; int fields_num; gauge_t bytes_used = NAN; gauge_t bytes_total = NAN; gauge_t hits = NAN; gauge_t gets = NAN; counter_t rusage_user = 0; counter_t rusage_syst = 0; counter_t octets_rx = 0; counter_t octets_tx = 0; /* get data from daemon */ if (memcached_query_daemon (buf, sizeof (buf)) < 0) { return -1; }#define FIELD_IS(cnst) / (((sizeof(cnst) - 1) == name_len) && (strcmp (cnst, fields[1]) == 0)) ptr = buf; saveptr = NULL; while ((line = strtok_r (ptr, "/n/r", &saveptr)) != NULL) { int name_len; ptr = NULL; fields_num = strsplit(line, fields, 3); if (fields_num != 3) continue; name_len = strlen(fields[1]); if (name_len == 0) continue; /* * For an explanation on these fields please refer to * <http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt> */ /* * CPU time consumed by the memcached process */ if (FIELD_IS ("rusage_user")) { rusage_user = atoll (fields[2]); } else if (FIELD_IS ("rusage_system")) { rusage_syst = atoll(fields[2]); } /* * Number of threads of this instance */ else if (FIELD_IS ("threads")) { submit_gauge2 ("ps_count", NULL, NAN, atof (fields[2])); } /* * Number of items stored */ else if (FIELD_IS ("curr_items")) { submit_gauge ("memcached_items", "current", atof (fields[2])); } /* * Number of bytes used and available (total - used) */ else if (FIELD_IS ("bytes")) { bytes_used = atof (fields[2]); } else if (FIELD_IS ("limit_maxbytes")) { bytes_total = atof(fields[2]); } /* * Connections */ else if (FIELD_IS ("curr_connections")) { submit_gauge ("memcached_connections", "current", atof (fields[2])); } /* * Commands */ else if ((name_len > 4) && (strncmp (fields[1], "cmd_", 4) == 0)) {//.........这里部分代码省略.........
开发者ID:nkazzaz,项目名称:collectd-freeswitch,代码行数:101,
示例21: mo_flags/*** mo_flags** parv[0] = sender prefix** parv[1] = parameter*/static intmo_flags(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]){ int i, j; int isadd; int setflags; int isgood; char *p; char *flag; if(parc < 2) { /* Generate a list of what flags you have and what you are missing, ** and send it to the user */ sendto_one(source_p, ":%s NOTICE %s :Current flags:%s", me.name, parv[0], set_flags_to_string(source_p)); sendto_one(source_p, ":%s NOTICE %s :Current missing flags:%s", me.name, parv[0], unset_flags_to_string(source_p)); return 1; } /* Preserve the current flags */ setflags = source_p->umodes;/* XXX - change this to support a multiple last parameter like ISON */ for(i = 1; i < parc; i++) { char *s = LOCAL_COPY(parv[i]); for(flag = strtok_r(s, " ", &p); flag; flag = strtok_r(NULL, " ", &p)) { /* We default to being in ADD mode */ isadd = 1; /* We default to being in BAD mode */ isgood = 0; if(!isalpha(flag[0])) { if(flag[0] == '-') isadd = 0; else if(flag[0] == '+') isadd = 1; flag++; } /* support ALL here */ if(!irccmp(flag, "ALL")) { if(isadd) source_p->umodes |= FL_ALL_OPER_FLAGS; else source_p->umodes &= ~FL_ALL_OPER_FLAGS; sendto_one(source_p, ":%s NOTICE %s :Current flags:%s", me.name, parv[0], set_flags_to_string(source_p)); sendto_one(source_p, ":%s NOTICE %s :Current missing flags:%s", me.name, parv[0], unset_flags_to_string(source_p)); send_umode_out(client_p, source_p, setflags); return 1; } if(!irccmp(flag, "NICKCHANGES")) { if(!IsOperN(source_p)) { sendto_one(source_p, ":%s NOTICE %s :*** You need oper and N flag for +n", me.name, parv[0]); continue; } if(isadd) source_p->umodes |= UMODE_NCHANGE; else source_p->umodes &= ~UMODE_NCHANGE; isgood = 1; continue; } if(!irccmp(flag, "OWALLOPS")) { if(!IsOperOperwall(source_p)) { sendto_one(source_p, ":%s NOTICE %s :*** You need oper and operwall flag for +z", me.name, parv[0]); continue; } if(isadd) source_p->umodes |= UMODE_OPERWALL; else source_p->umodes &= ~UMODE_OPERWALL; isgood = 1; continue; }//.........这里部分代码省略.........
开发者ID:thors,项目名称:ircd-ratbox,代码行数:101,
示例22: get_user_hashstatic int get_user_hash(const char *user, u8 *dst_hash, u32 dst_len){ int fd, rc; u32 len; size_t buf_rd; char buf[VFS_LOAD_BUF_SZ]; struct stat st; u32 tok_len; char *token, *save; const char *delim = "/n"; u32 end, cleanup = 0; const char *path = CONFIG_LIBAUTH_FILE; fd = vfs_open(path, O_RDONLY, 0); if (fd < 0) { return VMM_EFAIL; } rc = vfs_fstat(fd, &st); if (rc) { vfs_close(fd); return VMM_EFAIL; } if (!(st.st_mode & S_IFREG)) { vfs_close(fd); return VMM_EFAIL; } len = st.st_size; while (len) { memset(buf, 0, sizeof(buf)); buf_rd = (len < VFS_LOAD_BUF_SZ) ? len : VFS_LOAD_BUF_SZ; buf_rd = vfs_read(fd, buf, buf_rd); if (buf_rd < 1) { break; } end = buf_rd - 1; while (buf[end] != '/n') { buf[end] = 0; end--; cleanup++; } if (cleanup) { vfs_lseek(fd, (buf_rd - cleanup), SEEK_SET); cleanup = 0; } for (token = strtok_r(buf, delim, &save); token; token = strtok_r(NULL, delim, &save)) { tok_len = strlen(token); if (*token != '#' && *token != '/n') { if (process_auth_entry(token, user, dst_hash, dst_len) == VMM_OK) return VMM_OK; } len -= (tok_len + 1); } } rc = vfs_close(fd); if (rc) { return VMM_EFAIL; } return VMM_EFAIL;}
开发者ID:32bitmicro,项目名称:xvisor,代码行数:71,
示例23: ldap_lookup//.........这里部分代码省略......... ldap_msgfree( result ); ldap_unbind( ld ); return external_uid;}#endifchar*program_lookup(config_t agent_config, const char *username, char *external_uid){ pid_t wstatus, pid; int i, status; int fd[2]; char *output = malloc (1024); char **args = malloc (1024); char *token; char *saveptr; char *str; char *command_line = 0; /* build proper command line*/ command_line = strdup(transcode_query(_ds_read_attribute(agent_config, "ExtLookupServer"), username, command_line)); if (command_line == NULL) { LOG(LOG_ERR, ERR_EXT_LOOKUP_MISCONFIGURED); free(output); free(args); return NULL; } LOGDEBUG("command line is %s", command_line); /* break the command line into arguments */ for (i = 0, str = command_line; ; i++, str = NULL) { token = strtok_r(str, " ", &saveptr); if (token == NULL) break; args[i] = token; LOGDEBUG("args[%d] = %s",i,token); } args[i] = (char *) 0; if (pipe(fd) == -1) { LOG(LOG_ERR, "%s: errno=%i (%s)", ERR_EXT_LOOKUP_INIT_FAIL, errno, strerror(errno)); free(output); free(args); return NULL; } switch(pid=fork()) { case -1: /* couldn't fork - something went wrong */ LOG(LOG_ERR, "%s: errno=%i (%s)", ERR_EXT_LOOKUP_INIT_FAIL, errno, strerror(errno)); free(output); free(args); return NULL; case 0: /* execute the command and write to fd */ close(fd[0]); dup2(fd[1], fileno(stdout)); execve(args[0], args, 0); exit(EXIT_FAILURE); default: /* read from fd the first output line */ do { wstatus = waitpid( pid, &status, WUNTRACED | WCONTINUED); if (wstatus == -1) {
开发者ID:toddfries,项目名称:dspam,代码行数:67,
示例24: read_bg_conf//.........这里部分代码省略......... info("BridgeAPILogFile not configured in bluegene.conf"); else _reopen_bridge_log(); if (s_p_get_string(&tmp_char, "DenyPassthrough", tbl)) { if (strstr(tmp_char, "A")) ba_deny_pass |= PASS_DENY_A; if (strstr(tmp_char, "X")) ba_deny_pass |= PASS_DENY_X; if (strstr(tmp_char, "Y")) ba_deny_pass |= PASS_DENY_Y; if (strstr(tmp_char, "Z")) ba_deny_pass |= PASS_DENY_Z; if (!strcasecmp(tmp_char, "ALL")) ba_deny_pass |= PASS_DENY_ALL; bg_conf->deny_pass = ba_deny_pass; xfree(tmp_char); } if (!s_p_get_string(&tmp_char, "LayoutMode", tbl)) { info("Warning: LayoutMode was not specified in bluegene.conf " "defaulting to STATIC partitioning"); bg_conf->layout_mode = LAYOUT_STATIC; } else { if (!strcasecmp(tmp_char,"STATIC")) bg_conf->layout_mode = LAYOUT_STATIC; else if (!strcasecmp(tmp_char,"OVERLAP")) bg_conf->layout_mode = LAYOUT_OVERLAP; else if (!strcasecmp(tmp_char,"DYNAMIC")) bg_conf->layout_mode = LAYOUT_DYNAMIC; else { fatal("I don't understand this LayoutMode = %s", tmp_char); } xfree(tmp_char); } /* add blocks defined in file */ if (bg_conf->layout_mode != LAYOUT_DYNAMIC) { if (!s_p_get_array((void ***)&blockreq_array, &count, "MPs", tbl)) { if (!s_p_get_array((void ***)&blockreq_array, &count, "BPs", tbl)) { info("WARNING: no blocks defined in " "bluegene.conf, " "only making full system block"); /* create_full_system_block(NULL); */ if (bg_conf->sub_mp_sys || (bg_conf->mp_cnode_cnt == bg_conf->nodecard_cnode_cnt)) fatal("On a sub-midplane system you " "need to define the blocks you " "want on your system."); } } for (i = 0; i < count; i++) { add_bg_record(bg_lists->main, NULL, blockreq_array[i], 0, 0); } } else if (bg_conf->sub_mp_sys || (bg_conf->mp_cnode_cnt == bg_conf->nodecard_cnode_cnt)) /* we can't do dynamic here on a sub-midplane system */ fatal("On a sub-midplane system we can only do OVERLAP or " "STATIC LayoutMode. Please update your bluegene.conf.");#ifdef HAVE_BGQ if (s_p_get_string(&tmp_char, "RebootQOSList", tbl)) { bool valid; char *token, *last = NULL; slurmdb_qos_rec_t *qos = NULL; bg_conf->reboot_qos_bitmap = bit_alloc(g_qos_count); itr = list_iterator_create(assoc_mgr_qos_list); token = strtok_r(tmp_char, ",", &last); while (token) { valid = false; while((qos = list_next(itr))) { if (!strcasecmp(token, qos->name)) { bit_set(bg_conf->reboot_qos_bitmap, qos->id); valid = true; break; } } if (!valid) error("Invalid RebootQOSList value: %s", token); list_iterator_reset(itr); token = strtok_r(NULL, ",", &last); } list_iterator_destroy(itr); xfree(tmp_char); }#endif s_p_hashtbl_destroy(tbl); return SLURM_SUCCESS;}
开发者ID:mrhaoji,项目名称:slurm,代码行数:101,
示例25: options__process/* options__process * A snippet from main() to get all the options sent via CLI, then verifies them. */void options__process(int argc, char **argv) { /* Reset everything since there isn't an initialization function for Options structs. */ /* Page Information */ opts.page_directory = (char *)malloc(strlen("sample_data") + 1); strcpy(opts.page_directory, "sample_data"); opts.page_count = 0; opts.page_limit = MAX_PAGE_LIMIT; opts.smallest_page = UINT16_MAX; opts.biggest_page = 0; opts.dataset_size = 0; opts.dataset_max = MAX_DATASET_MAX; /* Resource Control */ opts.max_memory = 10 * 1024 * 1024; opts.fixed_ratio = -1; opts.workers = sysconf(_SC_NPROCESSORS_ONLN) > 0 ? (uint16_t)sysconf(_SC_NPROCESSORS_ONLN) : 1; opts.cpu_count = sysconf(_SC_NPROCESSORS_ONLN) > 0 ? (uint16_t)sysconf(_SC_NPROCESSORS_ONLN) : 1; /* Tyche Management */ opts.duration = 5; opts.compressor_id = LZ4_COMPRESSOR_ID; opts.compressor_level = 1; opts.min_pages_retrieved = 5; opts.max_pages_retrieved = 5; opts.bias_percent = 1.0; opts.bias_aggregate = 1.0; opts.update_frequency = 0.0; opts.delete_frequency = 0.0; /* Run Test? */ opts.test = NULL; opts.extended_test_options = NULL; /* Niceness Features */ opts.quiet = 0; opts.verbosity = 0; /* Process everything passed from CLI now. */ char *save_ptr = NULL; char *token = NULL; int c = 0; opterr = 0; while ((c = getopt(argc, argv, "b:B:c:Cd:D:f:hm:M:n:p:qt:U:w:X:v")) != -1) { switch (c) { case 'b': opts.dataset_max = (uint64_t)atoll(optarg); break; case 'B': token = strtok_r(optarg, ",", &save_ptr); if(token != NULL) opts.bias_percent = 1.0 * atof(token) / 100; token = strtok_r(NULL, ",", &save_ptr); if (token != NULL) opts.bias_aggregate = 1.0 * atof(token) / 100; break; case 'c': if(strcmp(optarg, "lz4") != 0 && strcmp(optarg, "zlib") != 0 && strcmp(optarg, "zstd")) show_error(E_BAD_CLI, "You must specify either 'lz4' or 'zlib' for compression (-c), not: %s", optarg); if(strcmp(optarg, "lz4") == 0) opts.compressor_id = LZ4_COMPRESSOR_ID; if(strcmp(optarg, "zlib") == 0) opts.compressor_id = ZLIB_COMPRESSOR_ID; if(strcmp(optarg, "zstd") == 0) opts.compressor_id = ZSTD_COMPRESSOR_ID; break; case 'C': opts.compressor_id = NO_COMPRESSOR_ID; break; case 'd': opts.duration = (uint16_t)atoi(optarg); if (atoi(optarg) > MAX_DURATION) opts.duration = MAX_DURATION; break; case 'D': opts.delete_frequency = 1.0 * atof(optarg) / 100; break; case 'f': opts.fixed_ratio = (int8_t)atoi(optarg); break; case 'h': options__show_help(); exit(E_OK); break; case 'm': opts.max_memory = (uint64_t)atoll(optarg); break; case 'M': token = strtok_r(optarg, ",", &save_ptr); if(token != NULL) opts.min_pages_retrieved = atoi(token); token = strtok_r(NULL, ",", &save_ptr); if (token != NULL) opts.max_pages_retrieved = atoi(token); break; case 'n': opts.page_limit = (uint32_t)atoll(optarg); break; case 'p': opts.page_directory = optarg; break; case 'q': opts.quiet = 1;//.........这里部分代码省略.........
开发者ID:KyleJHarper,项目名称:tyche,代码行数:101,
示例26: defined//.........这里部分代码省略......... StringUtils::Trim(m_cores[nCurrId].m_strRevision); } } else if (strncmp(buffer, "Serial", strlen("Serial"))==0) { char *needle = strstr(buffer, ":"); if (needle && strlen(needle)>3) { needle+=2; m_cpuSerial = needle; m_cores[nCurrId].m_strSerial = m_cpuSerial; StringUtils::Trim(m_cores[nCurrId].m_strSerial); } } else if (strncmp(buffer, "model name", strlen("model name"))==0) { char *needle = strstr(buffer, ":"); if (needle && strlen(needle)>3) { needle+=2; m_cpuModel = needle; m_cores[nCurrId].m_strModel = m_cpuModel; StringUtils::Trim(m_cores[nCurrId].m_strModel); } } else if (strncmp(buffer, "flags", 5) == 0) { char* needle = strchr(buffer, ':'); if (needle) { char* tok = NULL, * save; needle++; tok = strtok_r(needle, " ", &save); while (tok) { if (0 == strcmp(tok, "mmx")) m_cpuFeatures |= CPU_FEATURE_MMX; else if (0 == strcmp(tok, "mmxext")) m_cpuFeatures |= CPU_FEATURE_MMX2; else if (0 == strcmp(tok, "sse")) m_cpuFeatures |= CPU_FEATURE_SSE; else if (0 == strcmp(tok, "sse2")) m_cpuFeatures |= CPU_FEATURE_SSE2; else if (0 == strcmp(tok, "sse3")) m_cpuFeatures |= CPU_FEATURE_SSE3; else if (0 == strcmp(tok, "ssse3")) m_cpuFeatures |= CPU_FEATURE_SSSE3; else if (0 == strcmp(tok, "sse4_1")) m_cpuFeatures |= CPU_FEATURE_SSE4; else if (0 == strcmp(tok, "sse4_2")) m_cpuFeatures |= CPU_FEATURE_SSE42; else if (0 == strcmp(tok, "3dnow")) m_cpuFeatures |= CPU_FEATURE_3DNOW; else if (0 == strcmp(tok, "3dnowext")) m_cpuFeatures |= CPU_FEATURE_3DNOWEXT; tok = strtok_r(NULL, " ", &save); } } } } fclose(fCPUInfo); // /proc/cpuinfo is not reliable on some Android platforms // At least we should get the correct cpu count for multithreaded decoding#if defined(TARGET_ANDROID) if (CAndroidFeatures::GetCPUCount() > m_cpuCount)
开发者ID:0xheart0,项目名称:xbmc,代码行数:67,
示例27: _do_power_work/* Perform any power change work to nodes */static void _do_power_work(time_t now){ static time_t last_log = 0, last_work_scan = 0; int i, wake_cnt = 0, sleep_cnt = 0, susp_total = 0; time_t delta_t; uint32_t susp_state; bitstr_t *wake_node_bitmap = NULL, *sleep_node_bitmap = NULL; struct node_record *node_ptr; bool run_suspend = false; if (last_work_scan == 0) { if (exc_nodes && (node_name2bitmap(exc_nodes, false, &exc_node_bitmap))) { error("Invalid SuspendExcNodes %s ignored", exc_nodes); } if (exc_parts) { char *tmp = NULL, *one_part = NULL, *part_list = NULL; struct part_record *part_ptr = NULL; part_list = xstrdup(exc_parts); one_part = strtok_r(part_list, ",", &tmp); while (one_part != NULL) { part_ptr = find_part_record(one_part); if (!part_ptr) { error("Invalid SuspendExcPart %s ignored", one_part); } else if (exc_node_bitmap) { bit_or(exc_node_bitmap, part_ptr->node_bitmap); } else { exc_node_bitmap = bit_copy(part_ptr->node_bitmap); } one_part = strtok_r(NULL, ",", &tmp); } xfree(part_list); } if (exc_node_bitmap) { char *tmp = bitmap2node_name(exc_node_bitmap); info("power_save module, excluded nodes %s", tmp); xfree(tmp); } } /* Set limit on counts of nodes to have state changed */ delta_t = now - last_work_scan; if (delta_t >= 60) { suspend_cnt_f = 0.0; resume_cnt_f = 0.0; } else { float rate = (60 - delta_t) / 60.0; suspend_cnt_f *= rate; resume_cnt_f *= rate; } suspend_cnt = (suspend_cnt_f + 0.5); resume_cnt = (resume_cnt_f + 0.5); if (now > (last_suspend + suspend_timeout)) { /* ready to start another round of node suspends */ run_suspend = true; if (last_suspend) { bit_nclear(suspend_node_bitmap, 0, (node_record_count - 1)); bit_nclear(resume_node_bitmap, 0, (node_record_count - 1)); last_suspend = (time_t) 0; } } last_work_scan = now; /* Build bitmaps identifying each node which should change state */ for (i = 0, node_ptr = node_record_table_ptr; i < node_record_count; i++, node_ptr++) { susp_state = IS_NODE_POWER_SAVE(node_ptr); if (susp_state) susp_total++; /* Resume nodes as appropriate */ if (susp_state && ((resume_rate == 0) || (resume_cnt < resume_rate)) && (bit_test(suspend_node_bitmap, i) == 0) && (IS_NODE_ALLOCATED(node_ptr) || (node_ptr->last_idle > (now - idle_time)))) { if (wake_node_bitmap == NULL) { wake_node_bitmap = bit_alloc(node_record_count); } wake_cnt++; resume_cnt++; resume_cnt_f++; node_ptr->node_state &= (~NODE_STATE_POWER_SAVE); node_ptr->node_state |= NODE_STATE_POWER_UP; node_ptr->node_state |= NODE_STATE_NO_RESPOND; bit_clear(power_node_bitmap, i); bit_clear(avail_node_bitmap, i);//.........这里部分代码省略.........
开发者ID:adammoody,项目名称:slurm,代码行数:101,
示例28: blazer_statusstatic int blazer_status(const char *cmd){ const struct { const char *var; const char *fmt; double (*conv)(const char *, char **); } status[] = { { "input.voltage", "%.1f", strtod }, { "input.voltage.fault", "%.1f", strtod }, { "output.voltage", "%.1f", strtod }, { "ups.load", "%.0f", blazer_load }, { "input.frequency", "%.1f", strtod }, { "battery.voltage", "%.2f", blazer_battery }, { "ups.temperature", "%.1f", strtod }, { NULL } }; char buf[SMALLBUF], *val, *last = NULL; int i; /* * > [Q1/r] * < [(226.0 195.0 226.0 014 49.0 27.5 30.0 00001000/r] * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ if (blazer_command(cmd, buf, sizeof(buf)) < 46) { upsdebugx(2, "%s: short reply", __func__); return -1; } if (buf[0] != '(') { upsdebugx(2, "%s: invalid start character [%02x]", __func__, buf[0]); return -1; } for (i = 0, val = strtok_r(buf+1, " ", &last); status[i].var; i++, val = strtok_r(NULL, " /r/n", &last)) { if (!val) { upsdebugx(2, "%s: parsing failed", __func__); return -1; } if (strspn(val, "0123456789.") != strlen(val)) { upsdebugx(2, "%s: non numerical value [%s]", __func__, val); continue; } dstate_setinfo(status[i].var, status[i].fmt, status[i].conv(val, NULL)); } if (!val) { upsdebugx(2, "%s: parsing failed", __func__); return -1; } if (strspn(val, "01") != 8) { upsdebugx(2, "Invalid status [%s]", val); return -1; } if (val[7] == '1') { /* Beeper On */ dstate_setinfo("ups.beeper.status", "enabled"); } else { dstate_setinfo("ups.beeper.status", "disabled"); } if (val[4] == '1') { /* UPS Type is Standby (0 is On_line) */ dstate_setinfo("ups.type", "offline / line interactive"); } else { dstate_setinfo("ups.type", "online"); } status_init(); if (val[0] == '1') { /* Utility Fail (Immediate) */ status_set("OB"); online = 0; } else { status_set("OL"); online = 1; } if (val[1] == '1') { /* Battery Low */ status_set("LB"); } if (val[2] == '1') { /* Bypass/Boost or Buck Active */ double vi, vo; vi = strtod(dstate_getinfo("input.voltage"), NULL); vo = strtod(dstate_getinfo("output.voltage"), NULL); if (vo < 0.5 * vi) { upsdebugx(2, "%s: output voltage too low", __func__); } else if (vo < 0.95 * vi) { status_set("TRIM"); } else if (vo < 1.05 * vi) { status_set("BYPASS");//.........这里部分代码省略.........
开发者ID:JungleGenius,项目名称:nut,代码行数:101,
示例29: guava_router_mvc_routevoid guava_router_mvc_route(guava_router_mvc_t *router, guava_request_t *req, guava_handler_t *handler) { if (!router || !req || !handler) { return; } char *ptr = strstr(req->path, router->route.mount_point); if (!ptr) { return; } ptr += guava_string_len(router->route.mount_point); const char *sep = "/"; char *word, *save; guava_string_t module = NULL; guava_string_t cls = NULL; guava_string_t action = NULL; PyObject *args = NULL; PyObject *arg = NULL; size_t idx = 0; for (word = strtok_r(ptr, sep, &save); word; word = strtok_r(NULL, sep, &save), ++idx) { if (idx == 0) { module = guava_string_new(word); char s[1024]; snprintf(s, sizeof(s), "%c%sController", toupper(word[0]), word+1); cls = guava_string_new(s); } else if (idx == 1) { action = guava_string_new(word); } else { arg = PyString_FromString(word); if (!args) { args = PyList_New(0); } PyList_Append(args, arg); Py_DECREF(arg); } } if (!module) { module = guava_string_new("index"); } if (!cls) { cls = guava_string_new("IndexController"); } if (!action) { action = guava_string_new("index"); } handler->package = guava_string_new(router->route.package); handler->module = module; handler->cls = cls; handler->action = action; if (args) { handler->args = PyList_AsTuple(args); Py_DECREF(args); } guava_handler_mark_valid(handler);}
开发者ID:ebottabi,项目名称:guava,代码行数:63,
示例30: lirc_code2char_internalstatic int lirc_code2char_internal(const struct lirc_state *state, struct lirc_config *config,char *code, char **string, char **prog){ int rep; char *backup, *strtok_state = NULL; char *remote,*button; char *s=NULL; struct lirc_config_entry *scan; int exec_level; int quit_happened; *string=NULL; if(sscanf(code,"%*20x %20x %*5000s %*5000s/n",&rep)==1) { backup=strdup(code); if(backup==NULL) return(-1); strtok_r(backup," ",&strtok_state); strtok_r(NULL," ",&strtok_state); button=strtok_r(NULL," ",&strtok_state); remote=strtok_r(NULL,"/n",&strtok_state); if(button==NULL || remote==NULL) { free(backup); return(0); } scan=config->next; quit_happened=0; while(scan!=NULL) { exec_level = lirc_iscode(scan,remote,button,rep); if(exec_level > 0 && (scan->mode==NULL || (scan->mode!=NULL && config->current_mode!=NULL && strcasecmp(scan->mode,config->current_mode)==0)) && quit_happened==0 ) { if(exec_level > 1) { s=lirc_execute(state,config,scan); if(s != NULL && prog != NULL) { *prog = scan->prog; } } else { s = NULL; } if(scan->flags&quit) { quit_happened=1; config->next=NULL; scan=scan->next; continue; } else if(s!=NULL) { config->next=scan->next; break; } } scan=scan->next; } free(backup); if(s!=NULL) { *string=s; return(0); } } config->next=config->first; return(0);}
开发者ID:DaveDaCoda,项目名称:mythtv,代码行数:79,
注:本文中的strtok_r函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ strtok_s函数代码示例 C++ strtok函数代码示例 |