本文整理汇总了C++中MFILE::open方法的典型用法代码示例。如果您正苦于以下问题:C++ MFILE::open方法的具体用法?C++ MFILE::open怎么用?C++ MFILE::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MFILE
的用法示例。
在下文中一共展示了MFILE::open方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char * argv[]) {
int i, retval, lastInversion=0, checkpointExists=0, matrixSize=0;
double fd;
char input_path[512], output_path[512], chkpt_path[512], buf[256];
MFILE out;
FILE* state, *infile;
generate_random_input_file(MATRIX_SIZE); //call this if you don't want to
//construct the input file manually
for (i=0; i<argc; i++) {
if (!strcmp(argv[i], "-early_exit")) early_exit = true;
if (!strcmp(argv[i], "-early_crash")) early_crash = true;
if (!strcmp(argv[i], "-early_sleep")) early_sleep = true;
if (!strcmp(argv[i], "-run_slow")) run_slow = true;
if (!strcmp(argv[i], "-cpu_time")) {
cpu_time = atof(argv[++i]);
}
}
retval = boinc_init();
if (retval) {
fprintf(stderr,
"%s boinc_init returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
// open the input file (resolve logical name first)
//
boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
infile = boinc_fopen(input_path, "r");
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file in boinc\\win_build, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
getchar();
exit(-1);
}
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so retrieve the current matrix and inversion number
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
printf("Checkpoint file is detected. Read from checkpoint file ... \n");
checkpointExists=fscanf(state, "%d", &lastInversion);
if (checkpointExists == 1) {
isStateFileInUse=true;
printf("Last inversion # is : %d\n",lastInversion);
fscanf(state,"%d",&matrixSize);
width=height=matrixSize;
printf("Initialize host ....\n");
initialize_host(state);
}
fclose(state);
} else {
printf("There's no valid checkpoint file!\n");
}
retval = out.open(output_path, "wb");
if (retval) {
fprintf(stderr,
"%s APP: matrix_inversion output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr,
"%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
#ifdef APP_GRAPHICS
// create shared mem segment for graphics, and arrange to update it
//
shmem = (UC_SHMEM*)boinc_graphics_make_shmem("matrix_inversion", sizeof(UC_SHMEM));
if (!shmem) {
fprintf(stderr,
"%s failed to create shared mem segment\n",
boinc_msg_prefix(buf, sizeof(buf))
);
}
update_shmem();
boinc_register_timer_callback(update_shmem);
#endif
if (checkpointExists != 1) { //checkpoint file is not found.
matrixSize=get_matrix_size(infile);
printf("Matrix Size: width = height = %d\n",matrixSize);
width=height=matrixSize;
// Initialize Host application
printf("Initialize host ....\n");
//.........这里部分代码省略.........
示例2: main
int main(int argc, char **argv) {
int i;
int c, nchars = 0, retval, n;
double fsize, fd;
char input_path[512], output_path[512], chkpt_path[512], buf[256];
MFILE out;
FILE* state, *infile;
for (i=0; i<argc; i++) {
if (!strcmp(argv[i], "-early_exit")) early_exit = true;
if (!strcmp(argv[i], "-early_crash")) early_crash = true;
if (!strcmp(argv[i], "-early_sleep")) early_sleep = true;
if (!strcmp(argv[i], "-run_slow")) run_slow = true;
if (!strcmp(argv[i], "-cpu_time")) {
cpu_time = atof(argv[++i]);
}
}
retval = boinc_init();
if (retval) {
fprintf(stderr, "%s boinc_init returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
// open the input file (resolve logical name first)
//
boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
infile = boinc_fopen(input_path, "r");
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
exit(-1);
}
// get size of input file (used to compute fraction done)
//
file_size(input_path, fsize);
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so seek input file and truncate output file
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
n = fscanf(state, "%d", &nchars);
fclose(state);
}
if (state && n==1) {
fseek(infile, nchars, SEEK_SET);
boinc_truncate(output_path, nchars);
retval = out.open(output_path, "ab");
} else {
retval = out.open(output_path, "wb");
}
if (retval) {
fprintf(stderr, "%s APP: upper_case output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr, "%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
#ifdef APP_GRAPHICS
// create shared mem segment for graphics, and arrange to update it
//
shmem = (UC_SHMEM*)boinc_graphics_make_shmem("uppercase", sizeof(UC_SHMEM));
if (!shmem) {
fprintf(stderr, "%s failed to create shared mem segment\n",
boinc_msg_prefix(buf, sizeof(buf))
);
}
update_shmem();
boinc_register_timer_callback(update_shmem);
#endif
// main loop - read characters, convert to UC, write
//
for (i=0; ; i++) {
c = fgetc(infile);
if (c == EOF) break;
c = toupper(c);
out._putchar(c);
nchars++;
if (run_slow) {
boinc_sleep(1.);
}
if (early_exit && i>30) {
exit(-10);
}
//.........这里部分代码省略.........
示例3: main
int main(int argc, char **argv) {
int i;
int c, nchars = 0, retval, n;
double fsize, fd;
char input_path[512], output_path[512], chkpt_path[512], buf[256];
MFILE out;
FILE* state, *infile;
for (i=0; i<argc; i++) {
if (strstr(argv[i], "early_exit")) early_exit = true;
if (strstr(argv[i], "early_crash")) early_crash = true;
if (strstr(argv[i], "early_sleep")) early_sleep = true;
if (strstr(argv[i], "run_slow")) run_slow = true;
if (strstr(argv[i], "critical_section")) critical_section = true;
if (strstr(argv[i], "network_usage")) network_usage = true;
if (strstr(argv[i], "cpu_time")) {
cpu_time = atof(argv[++i]);
}
if (strstr(argv[i], "trickle_up")) trickle_up = true;
if (strstr(argv[i], "trickle_down")) trickle_down = true;
}
retval = boinc_init();
if (retval) {
fprintf(stderr, "%s boinc_init returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
fprintf(stderr, "%s app started; CPU time %f, flags:%s%s%s%s%s%s%s\n",
boinc_msg_prefix(buf, sizeof(buf)),
cpu_time,
early_exit?" early_exit":"",
early_crash?" early_crash":"",
early_sleep?" early_sleep":"",
run_slow?" run_slow":"",
critical_section?" critical_section":"",
trickle_up?" trickle_up":"",
trickle_down?" trickle_down":""
);
// open the input file (resolve logical name first)
//
boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
infile = boinc_fopen(input_path, "r");
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
exit(-1);
}
// get size of input file (used to compute fraction done)
//
file_size(input_path, fsize);
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so seek input file and truncate output file
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
n = fscanf(state, "%d", &nchars);
fclose(state);
}
if (state && n==1) {
fseek(infile, nchars, SEEK_SET);
boinc_truncate(output_path, nchars);
retval = out.open(output_path, "ab");
} else {
retval = out.open(output_path, "wb");
}
if (retval) {
fprintf(stderr, "%s APP: upper_case output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr, "%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
#ifdef APP_GRAPHICS
// create shared mem segment for graphics, and arrange to update it
//
shmem = (UC_SHMEM*)boinc_graphics_make_shmem("uppercase", sizeof(UC_SHMEM));
if (!shmem) {
fprintf(stderr, "%s failed to create shared mem segment\n",
boinc_msg_prefix(buf, sizeof(buf))
);
}
update_shmem();
boinc_register_timer_callback(update_shmem);
#endif
if (network_usage) {
//.........这里部分代码省略.........
示例4: write_state_file
// Write the client_state.xml file
//
int CLIENT_STATE::write_state_file() {
MFILE mf;
int retval, ret1, ret2, attempt;
#ifdef _WIN32
char win_error_msg[4096];
#endif
for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) {
if (attempt > 1) boinc_sleep(1.0);
if (log_flags.statefile_debug) {
msg_printf(0, MSG_INFO,
"[statefile] Writing state file"
);
}
#ifdef _WIN32
retval = mf.open(STATE_FILE_NEXT, "wc");
#else
retval = mf.open(STATE_FILE_NEXT, "w");
#endif
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
msg_printf(0, MSG_INTERNAL_ERROR,
"Can't open %s: %s",
STATE_FILE_NEXT, boincerror(retval)
);
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ERR_FOPEN;
}
MIOFILE miof;
miof.init_mfile(&mf);
ret1 = write_state(miof);
ret2 = mf.close();
if (ret1) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Couldn't write state file: %s", boincerror(retval)
);
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ret1;
}
if (ret2) {
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ret2;
}
// only attempt to rename the current state file if it exists.
//
if (boinc_file_exists(STATE_FILE_NAME)) {
if (boinc_file_exists(STATE_FILE_PREV)) {
retval = boinc_delete_file(STATE_FILE_PREV);
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
#ifdef _WIN32
msg_printf(0, MSG_INFO,
"Can't delete previous state file; %s",
windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg))
);
#else
msg_printf(0, MSG_INFO,
"Can't delete previous state file: %s",
strerror(errno)
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
}
retval = boinc_rename(STATE_FILE_NAME, STATE_FILE_PREV);
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
#ifdef _WIN32
msg_printf(0, MSG_INFO,
"Can't rename current state file to previous state file; %s",
windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg))
);
#else
msg_printf(0, MSG_INFO,
"Can't rename current state file to previous state file: %s",
strerror(errno)
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
}
retval = boinc_rename(STATE_FILE_NEXT, STATE_FILE_NAME);
if (log_flags.statefile_debug) {
msg_printf(0, MSG_INFO,
"[statefile] Done writing state file"
);
}
if (!retval) break; // Success!
//.........这里部分代码省略.........
示例5: main
int main(int argc, char **argv) {
int i,p,q,pq;
int c, nchars = 0, retval, n;
double fsize, fd;
char input_path[512], output_path[512], chkpt_path[512], buf[256],sentence[1025];
MFILE out;
FILE* state, *infile;
for (i=0; i<argc; i++) {
if (!strcmp(argv[i], "-early_exit")) early_exit = true;
if (!strcmp(argv[i], "-early_crash")) early_crash = true;
if (!strcmp(argv[i], "-early_sleep")) early_sleep = true;
if (!strcmp(argv[i], "-run_slow")) run_slow = true;
if (!strcmp(argv[i], "-cpu_time")) {
cpu_time = atof(argv[++i]);
}
}
retval = boinc_init();
if (retval) {
fprintf(stderr, "%s boinc_init returned %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
// open the input file (resolve logical name first)
//
boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
infile = boinc_fopen(input_path, "r");
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
exit(-1);
}
// get size of input file (used to compute fraction done)
//
file_size(input_path, fsize);
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so seek input file and truncate output file
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
n = fscanf(state, "%d", &nchars);
fclose(state);
}
if (state && n==1) {
fseek(infile, nchars, SEEK_SET);
boinc_truncate(output_path, nchars);
retval = out.open(output_path, "ab");
} else {
retval = out.open(output_path, "wb");
}
if (retval) {
fprintf(stderr, "%s APP: encrypt output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr, "%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
for(i=0; ;i++){
c = fgetc(infile);
if(c==EOF) break;
sentence[i]=c;
}
sentence[i]='\0';
p=43;
q=3;
pq=p*q;
//e=19 d=31
strcpy(sentence,rsaencrypt(sentence,19,pq));
for (i=0;sentence[i]!='\0'; i++) {
c=sentence[i];
out._putchar(c);
nchars++;
if (run_slow) {
boinc_sleep(1.);
}
if (early_exit && i>30) {
exit(-10);
}
if (early_crash && i>30) {
boinc_crash();
}
if (early_sleep && i>30) {
boinc_disable_timer_thread = true;
//.........这里部分代码省略.........