当前位置: 首页>>代码示例>>C++>>正文


C++ read_from_file函数代码示例

本文整理汇总了C++中read_from_file函数的典型用法代码示例。如果您正苦于以下问题:C++ read_from_file函数的具体用法?C++ read_from_file怎么用?C++ read_from_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了read_from_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: message_complete_cb

int
message_complete_cb(http_parser* parser)
{
  struct request_info *r = parser->data;
  struct stat file_stat;
  int exists;
  char datestring[256];
  struct tm *tm;

  if (strstr(r->file, "..") != NULL) {
    send_error(r, 404);
    return 0;
  }

  exists = stat(r->file, &file_stat);
  if (exists != 0){
    switch (errno){
    case EACCES:
      send_error(r, 403);
      break;
    default:
      send_error(r, 404);
      break;
    }
    return 0;

  } else { /* The file exists */
    /* Test if it's a folder */
    if (S_ISDIR(file_stat.st_mode) > 0) {
      send_error(r, 404);
      return 0;
    }

    tm = localtime(&file_stat.st_mtime);

    /* Get localized date string. */
    strftime(datestring, sizeof(datestring), DATE_FORMAT, tm);
    evbuffer_add_printf(r->buf, "HTTP/1.0 200 OK\r\n");
    evbuffer_add_printf(r->buf, "Content-Length: %9jd\r\n",
        (intmax_t)file_stat.st_size);
    evbuffer_add_printf(r->buf, "Last-Modified: %s\r\n", datestring);
    add_headers(r->buf);
  }

  if (parser->method == HTTP_HEAD) {
    event_add(&r->wr_ev, NULL);
  } else {
    // Open the file for parsing to body
    if (read_from_file(r) == -1) {
      evbuffer_drain(r->buf, EVBUFFER_LENGTH(r->buf));
      send_error(r, 500);
      return 0;
    }
    // Send reponse with body now :)
    event_add(&r->wr_ev, NULL);
  }

  printf("complete\n");
  return 0;
}
开发者ID:cavejay,项目名称:3301httpserver,代码行数:60,代码来源:http_callbacks.c

示例2: read_cpu_scaling_governor

static void read_cpu_scaling_governor(void)
{
    nominal_cpu_scaling_governor =
        read_from_file(config_file.cpufreq_file_paths[SCALING_GOVERNOR_PATH]);

    /*
     * FIXME : Should be fully useless. But without this, the
     * value of nominal_cpu_scaling_governor is not correct when used
     */
    if (strcmp(nominal_cpu_scaling_governor, ("hotplug")) == 0)
        nominal_cpu_scaling_governor = "hotplug";
    else if (strcmp(nominal_cpu_scaling_governor, ("conservative")) == 0)
        nominal_cpu_scaling_governor = "conservative";
    else if (strcmp(nominal_cpu_scaling_governor, ("ondemand")) == 0)
        nominal_cpu_scaling_governor = "ondemand";
    else if (strcmp(nominal_cpu_scaling_governor, ("userspace")) == 0)
        nominal_cpu_scaling_governor = "userspace";
    else if (strcmp(nominal_cpu_scaling_governor, ("performance")) == 0)
        nominal_cpu_scaling_governor = "performance";

#ifdef DEBUG
    LOGD("nominal_cpu_scaling_governor is %s\n",
        nominal_cpu_scaling_governor);
    fflush(stdout);
#endif
}
开发者ID:CM7lu3000,项目名称:android_hardware_ti_omap3,代码行数:26,代码来源:cpu_thermal_governor.c

示例3: pm_run_process

/**
* Run the process
**/
process_return_t* pm_run_process(process_t *process)
{
  process_return_t* ret = pm_new_process_return();
  // Setup the stdin
  int child_stdin;
  if (ret == NULL) return NULL;
  
  if (process->env) process->env[process->env_c] = NULL;
  
  // Run afterhook
  if (process->before) {
    if (run_hook(BEFORE_HOOK, process, ret)) return ret;
  }
    
  ret->stage = PRS_COMMAND;
  pid_t pid = pm_execute(1,   (const char*)process->command, 
                              (const char*)process->cd, 
                              (int)process->nice, 
                              (const char**)process->env, 
                              &child_stdin,
                              (const char*)process->stdout, (const char*)process->stderr);
  
  ret->pid = pid;
  ret->exit_status = wait_for_pid(pid, 0);
  
  if (ret->exit_status) {
    if (errno) {
      if (process->stdout) ret->stdout = read_from_file((const char*)process->stdout);

      if (process->stderr) ret->stderr = read_from_file((const char*)process->stderr);
      else {
        ret->stderr = (char*)calloc(1, sizeof(char)*strlen(strerror(errno)));
        strncpy(ret->stderr, strerror(errno), strlen(strerror(errno)));
      }
    }
    return ret;
  }
  
  // Run afterhook
  if (process->after) {
    if (run_hook(AFTER_HOOK, process, ret)) return ret;
  }
  
  // Yay, we finished properly
  ret->stage = PRS_OKAY;
  return ret;
}
开发者ID:alepharchives,项目名称:babysitter,代码行数:50,代码来源:process_manager.c

示例4: read_from_file_optional

bool read_from_file_optional( const std::string &path,
                              const std::function<void( std::istream & )> &reader )
{
    // Note: slight race condition here, but we'll ignore it. Worst case: the file
    // exists and got removed before reading it -> reading fails with a message
    // Or file does not exists, than everything works fine because it's optional anyway.
    return file_exist( path ) && read_from_file( path, reader );
}
开发者ID:Wuzzy2,项目名称:Cataclysm-DDA,代码行数:8,代码来源:cata_utility.cpp

示例5: init_cpu_thermal_governor

/*
 * Initialize some internal parameters.
 */
void init_cpu_thermal_governor(u32 omap_temp)
{
    int i;

    /* Initialize the nominal_cpu_scaling_max_freq variable */
    current_scaling_max_freq = atoi(read_from_file(
        config_file.cpufreq_file_paths[SCALING_MAX_FREQ_PATH]));

    /* Initialize the nominal_cpu_scaling_governor variable */
    read_cpu_scaling_governor();

    /* Initialize the available_freq[] int array */
    read_cpu_scaling_available_freq();

    /* Initialize the nominal maximum CPU frequency from the available_freq array */
    nominal_cpu_scaling_max_freq = available_freq[0];
    for (i = 1; i < OPPS_NUMBER; i++) {
        if (available_freq[i] > nominal_cpu_scaling_max_freq)
            nominal_cpu_scaling_max_freq = available_freq[i];
    }
#ifdef DEBUG
    LOGD("nominal/current_scaling_max_freq is %ld / %ld\n",
          nominal_cpu_scaling_max_freq, current_scaling_max_freq);
#endif

    /* Initialize the available_governors[] string array */
    read_cpu_scaling_available_governors();

    /* Check if "conservative" governor is available */
    for (i = 0; i < GOVS_NUMBER; i++) {
        if (strcmp(available_governors[i],("conservative")) == 0) {
            is_conservative_available = true;
        }
    }
#ifdef DEBUG
    if (is_conservative_available == true) {
        LOGD("conservative governor is available\n");
        fflush(stdout);
    } else {
        LOGD("conservative governor is not available\n");
        fflush(stdout);
    }
#endif

    /*
     * Force to initialize all temperature thresholds according to
     * the current thermal zone */
    cpu_thermal_governor(omap_temp);

#ifdef DEBUG
    for (i = 0; i < OPPS_NUMBER; i++) {
        LOGD("available_freq[%d] = %ld\n",
                i,
                available_freq[i]);
        fflush(stdout);
    }
#endif
}
开发者ID:CM7lu3000,项目名称:android_hardware_ti_omap3,代码行数:61,代码来源:cpu_thermal_governor.c

示例6: get_config_value

int get_config_value(char *config_key, char *reference)
{
    char config_path[60];

    strcpy(config_path, CONFIG_ROOT);
    strcat(config_path, config_key);

    return read_from_file(config_path, 30, reference);
}
开发者ID:bmourit,项目名称:oc_daemon,代码行数:9,代码来源:virtuous_oc.c

示例7: Configuration

Peer::Peer(const string &configFile) {
	config = new Configuration(configFile);
	set_id(get_host_id(config->hostIdType));
	schedulerVec = read_from_file(config->schedulerMemFile);
	set_index(get_self_idx(get_id(), schedulerVec));
	running = true;
	numZHTMsg = 0;
	init_zht_client(config->zhtConfigFile, config->zhtMemFile);
}
开发者ID:aalayach,项目名称:zebra,代码行数:9,代码来源:util.cpp

示例8: file

bool session_file_storage::load(std::string const &sid,time_t &timeout,std::string &out)
{
	locked_file file(this,sid);
	if(!read_from_file(file.handle(),timeout,out)) {
		::DeleteFile(file.name().c_str());
		return false;
	}
	return true;
}
开发者ID:Kaoschuks,项目名称:cppcms,代码行数:9,代码来源:session_win32_file_storage.cpp

示例9: android_main

void android_main(android_app* state)
{
    app_dummy();

    LOGW("entered main");

    state->userData = NULL;
    state->onAppCmd = engine_handle_cmd;
    state->onInputEvent = engine_handle_input;

    // sdcard example

    std::string file("/sdcard/text.txt");
    LOGW("test file : %s", file.c_str());

    write_to_file(file, "simple text");
    read_from_file(file);

    // device memory example
    /// @todo : fix error

    file = std::string("std_text.txt");
    LOGW("test file : %s", file.c_str());

    write_to_file(file, "simple text");
    read_from_file(file);

    while (true) {
        int ident;
        int events;
        android_poll_source* source;

        while ((ident = ALooper_pollAll(-1, NULL, &events, (void**) &source)) >= 0) {
            if (source != NULL) {
                source->process(state, source);
            }

            if (state->destroyRequested != 0) {
                LOGW("exited main");
                return;
            }
        }
    }
}
开发者ID:proydakov,项目名称:androidzone,代码行数:44,代码来源:main.cpp

示例10: Show_rate

void __fastcall TForm1::Button2Click(TObject *Sender)
{
 start=1;
 //ответ не выбран
 Panel1->BevelInner=bvNone;
 Panel2->BevelInner=bvNone;

 if (answer==-1)
    {
    Application->MessageBox("Выберите вариант ответа","Ошибка",MB_OK);
    return;
    }
 if (answer==1)
    {
    Show_rate(Form1);
    return;
    }
 if (answer==0)
  {
   answer=-1;
   current_q++;
   String q=read_from_file(rates[current_rate],current_q);
   if (q!="")//если есть ещё вопросы в этом возрасте
      Memo1->Text=q; //вывод вопроса
   else
      {
       if (current_rate!=num_of_rates-1)
         {
           current_rate++;//в следующую возраст. группу
           current_q=1; //с первого вопроса
           String q=read_from_file(rates[current_rate],current_q);
           //дошли до 0+
           if (current_rate==4)
             Show_rate(Form1);
           else
            Memo1->Text=q;
         }
       else
         Show_rate(Form1);
      }

  }
 start=0;
}
开发者ID:D3vills,项目名称:Programm,代码行数:44,代码来源:Unit1.cpp

示例11: main

int main(int argc, char *argv[]) {
  if (argc < 4) {
    fprintf(stderr, "Usage %s infile outfile threads\n", argv[0]);
    exit(-1);
  }
  int fd_in = open(argv[1], O_RDONLY);
  int fd_out = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRWXU);

  unsigned long uncomp_array_size = atol(argv[3]);
  lz4_uncompression_work *uncomp_array;
  pthread_t lz4uncomp_thread[uncomp_array_size];
  unsigned long uncomp_ptr;
  unsigned long total_bytes = 0;
  uncomp_array = new lz4_uncompression_work[uncomp_array_size];
  for (unsigned long i = 0; i < uncomp_array_size; i++) {
    uncomp_array[i].fd_in = fd_in;
    if(pthread_create(&lz4uncomp_thread[i],
		      NULL,
		      lz4_uncomp_service_start,
		      &uncomp_array[i]) != 0) {
      printf("failed to launch exec thread\n");
      exit(-1);
    }
  }
  unsigned long nextbytes;
  unsigned char header[11];
  read_from_file(fd_in, header, 11);
  nextbytes = uncomp_array[0].startup(header);
  for (unsigned long i = 1; i < uncomp_array_size; i++) {
    (void) uncomp_array[i].startup(header);
  }
  for (unsigned long i = 0; i < uncomp_array_size; i++) {
    total_bytes += nextbytes;
    nextbytes = uncomp_array[i].fill(nextbytes);
    uncomp_array[i].busy = true;
  }
  uncomp_ptr = 0;
  while (uncomp_array[uncomp_ptr].fillbytes) {
    while (uncomp_array[uncomp_ptr].busy);
    /* Write Block */
    flush_output(fd_out,
                 (char *) uncomp_array[uncomp_ptr].uncomp_data,
                 uncomp_array[uncomp_ptr].uncomp_bytes);
    total_bytes += nextbytes;
    nextbytes = uncomp_array[uncomp_ptr].fill(nextbytes);
    uncomp_array[uncomp_ptr].busy = true;
    uncomp_ptr = (uncomp_ptr + 1) % uncomp_array_size;
  }
  for (unsigned long i = 0; i < uncomp_array_size; i++) {
    uncomp_array[i].shutdown();
    uncomp_array[i].terminate = true;
    pthread_join(lz4uncomp_thread[i], NULL);
  }
  printf("Decompressed %lu\n", total_bytes);
  return 0;
}
开发者ID:ar104,项目名称:cbdma,代码行数:56,代码来源:lz4uncomp_mt.cpp

示例12: main

int
main(int argc, char **argv)
{
    FILE *in = argc > 1 ? fopen(argv[1], "r") : NULL;
    int n = argc > 2 ? atoi(argv[2]) : 20;
    int step = argc > 3 ? atoi(argv[3]) : 1;
    int i;
    char *base = argc > 4 ? argv[4] : "output/life";
    char filename[255];
    char *filenametemp = base;
    strcpy(filename, filenametemp);
    //int basenamel = strlen(filename);
#ifdef DEBUG
    //printf("basenamel = %d\n", basenamel);
#endif
    char basename[255];
    strcpy(basename, filename);

    if(in == NULL) {
        if(argc > 1)
            fprintf(stderr, "%s: problem z otwarciem pliku %s.\n", argv[0], argv[1]);
        else
            fprintf(stderr, "%s: prosze podac plik z danymi.\n", argv[0]);
        return 1;
    }

    board_t *b = read_from_file(in);

    //write_to_file(b, stdout);

    board_t *backb = prepare_backstage_board(b);

    for(i = 0; i < n; i++) {
        if(i % step == 0) {

            /* tworzenie nazwy pliku */
            filename[0] = '\0';
            strcat(filename, basename);
            strcat(filename, "_");          // dopisanie do filename znaku _
            char buf[20];
            sprintf(buf, "%03d", i);          // zamiana i na const char*
            char* c = buf;
            strcat(filename, c);            // dopisanie do filename numeru generacji
            strcat(filename, ".bmp");       // dopisanie do filename .bmp

            write_to_bmp(b, filename);
        }
        prepare_next_states(b, backb); // to, co w momencie rozpoczecia tej funkcji jest na backb nas nie obchodzi
        swap_boards(&b, &backb);
    }

    //printf("Stan planszy %d generacji pozniej:\n", n);
    //write_to_file(b, stdout);

    return 0;
}
开发者ID:aknj,项目名称:cellaut,代码行数:56,代码来源:main.c

示例13: read_from_textfile

void read_from_textfile(char *filename) {
    FILE *fp = NULL;
    fp = fopen(filename, "r");
    if (fp == NULL) {
        fprintf(stderr, "Can't open file %s\n", filename);
        exit(1);
    }

    read_from_file(fp);
    fclose(fp);
}
开发者ID:lgrangeia,项目名称:ttwatch,代码行数:11,代码来源:ttdiag.c

示例14: read_from_files

	std::pair<configuration_parameters, std::vector<run_result> > read_from_files(const typename run_result::time_t &now,
																																								std::size_t count, char ** fnames){
		std::pair<configuration_parameters, std::vector<run_result> > result;
		for (std::size_t i = 0; i < count; ++i){
			auto partial = read_from_file(now,fnames[i]);
			if (i > 0) assert (same_run(result.first,partial.first));
			result.first = partial.first;
			result.second.insert(result.second.end(),partial.second.begin(),partial.second.end());
		}
		return result;
	}
开发者ID:mpmilano,项目名称:consistency-tester,代码行数:11,代码来源:read_file.hpp

示例15: read_old_scan

void
read_old_scan(const char *path)
{
	size_t i;
	int fd;
	char *buf;
	struct stat sb;
	const char *entry_start;
	const char *l_start, *l_end;
	const char *s_start, *s_end;
	const char *line, *eol;

	for (i = 0; i < HASH_SIZE; ++i)
		SLIST_INIT(&hash_table[i]);

	if (path == NULL)
		return;
	if ((fd = open(path, O_RDONLY)) == -1)
		return;
	if (fstat(fd, &sb) == -1) {
		close(fd);
		return;
	}
	scan_mtime = sb.st_mtime;
	buf = read_from_file(fd);
	entry_start = buf;
	l_start = l_end = NULL;
	entry_start = buf;
	s_start = s_end = NULL;
	for (line = buf; *line; line = eol) {
		eol = strchr(line, '\n');
		if (eol == NULL)
			errx(1, "Incomplete old scan");
		++eol;
		if (strncmp(line, "PKGNAME=", 8) == 0) {
			if (line == buf)
				continue;
			add_entry(l_start, l_end, s_start, s_end,
			    entry_start, line);
			l_start = l_end = NULL;
			entry_start = line;
			s_start = s_end = NULL;
		} else if (strncmp(line, "PKG_LOCATION=", 13) == 0) {
			l_start = line + 13;
			l_end = eol - 1;
		} else if (strncmp(line, "SCAN_DEPENDS=", 13) == 0) {
			s_start = line + 13;
			s_end = eol - 1;
		}
	}
	if (entry_start != line)
		add_entry(l_start, l_end, s_start, s_end,
		    entry_start, line);
}
开发者ID:petabi,项目名称:pkgsrc,代码行数:54,代码来源:jobs.c


注:本文中的read_from_file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。