int main(int argc, char **argv) { int fd_rd = -1, fd_wr = -1; test_init(argc, argv); snprintf(filename_rd, sizeof(filename_rd), "%s.0", filename); snprintf(filename_wr, sizeof(filename_wr), "%s.1", filename); if (open_files(&fd_rd, &fd_wr)) { pr_err("Can't open files\n"); return -1; } if (fcntl(fd_rd, F_SETLEASE, F_RDLCK) < 0 || fcntl(fd_wr, F_SETLEASE, F_WRLCK) < 0) { pr_perror("Can't set leases\n"); close_files(fd_rd, fd_wr); return -1; } test_daemon(); test_waitsig(); if (check_lease_type(fd_rd, F_RDLCK)) fail("Read lease check failed\n"); else if (check_lease_type(fd_wr, F_WRLCK)) fail("Write lease check failed\n"); else pass(); close_files(fd_rd, fd_wr); return 0; }
int main(int argc,char *argv[]) { //check number of command line arguments if(argc < 3) { printf("usage: %s infile outfile [loader]\n",argv[0]); return(-1); } //save pointers to the filename in_filename = argv[1]; out_filename = argv[2]; if(argc > 3) { loader_filename = argv[3]; } //open all necessary files in = fopen(in_filename,"rb"); out = fopen(out_filename,"wb"); loader = fopen(loader_filename,"rb"); //check for errors if(in == 0 || out == 0 || loader == 0) { if(in == 0) printf("error opening input file '%s'\n",in_filename); if(out == 0) printf("error opening output file '%s'\n",out_filename); if(loader == 0) printf("error opening loader '%s'\n",loader_filename); close_files(); return(1); } convert_rom(); //close all open files and exit close_files(); return(0); }
int main(int argc, char *argv[]) { int file_count, opt; char *opath = NULL; int targetfd; struct file_stripe_info *finfo; while ((opt = getopt(argc, argv, "o:")) != -1) { switch (opt) { case 'o': opath = optarg; break; default: usage(argv[0]); return -1; } } file_count = argc - optind; if (!opath || !file_count) { usage(argv[0]); return -1; } finfo = validate_and_open_files(&argv[optind], file_count); if (!finfo) goto err; targetfd = open(opath, O_RDWR|O_CREAT, finfo->mode); if (targetfd < 0) goto err; if (generate_file(targetfd, finfo) < 0) goto err; if (fsync(targetfd) < 0) fprintf(stderr, "ERROR: %s\n", strerror(errno)); if (close(targetfd) < 0) fprintf(stderr, "ERROR: %s\n", strerror(errno)); close_files(finfo); free(finfo); return 0; err: if (finfo) { close_files(finfo); free(finfo); } return -1; }
/* Print the quantum yield (QY) values obtained by using the 2MM measurement * method and by using the 3MM method. 2MM will be obtained for each of * IN_BEAM_DATA and OUT_DATA that are provided, 3MM will be obtained only if * both are provided. LMIN, LMAX, PMIN, and PMAX set bounds on peak integration. * Emission correction for the sensitivity of the detector is specified as * EMISSION_CORRECTION, and can be either "default" or "quanta" or any prefix * of them. */ void QuantumYield(char* solvent_data_file = "", char* in_beam_data = "", int lmin = 0, int lmax = 0, int pmin = 0, int pmax = 0, char* out_beam_data = "", char* emission_correction = "d") { double QY; double error; FILE* solvent = open_data(solvent_data_file); FILE* in_data = open_data(in_beam_data); FILE* out_data = open_data(out_beam_data); FILE* correction = open_correction(emission_correction); if (!solvent || (!in_data && !out_data)) { printf("Invalid data file.\n"); printf("Arguments: reference data file, in-beam data file, lmin, lmax, pmin, pmax, indirect data file, correction name.\n"); close_files(solvent, in_data, out_data, correction); return; } if (is_corr) { read_correction(correction); } get_L_a(solvent, lmin, lmax); if (in_data) { QY = TwoMMQY(in_data, lmin, lmax, pmin, pmax); error = get_error(); printf("\n\nL_a %f\nL_b %f\nP_b %f\n2MMQY %f +/- %f\n", L_a, L_b, P_b, QY, error); printf("L_a - L_b = %f\n", L_a - L_b); if (out_data) { QY = ThreeMMQY(out_data, lmin, lmax, pmin, pmax); error = get_error(); printf("L_c %f\nP_c %f\n3MMQY %f +/- %f\n", L_c, P_c, QY, error); printf("L_a - L_c = %f\n", L_a - L_c); } } if (out_data) { rewind(out_data); L_b = 0; P_b = 0; QY = TwoMMQY(out_data, lmin, lmax, pmin, pmax); error = get_error(); printf("2MMQY (out data) %f +/- %f\n", QY, error); } printf("\n"); close_files(solvent, in_data, out_data, correction); }
int C_Errors::execute() { int result; if (!isOk()) { fprintf( stderr, _("Class did not initialize properly.\n") ); return( 1 ); } result=create_files(); if (result) return( result ); result=parse_errors(); if (result) { close_files(); return( result ); } return( close_files() ); }
static void remove_cb(GtkWidget * w, gpointer data) { vcedit_state *state; vorbis_comment *comment; if (!g_strncasecmp(vte.filename, "http://", 7)) return; state = vcedit_new_state(); pthread_mutex_lock(&vf_mutex); if (init_files(state) < 0) { fail(_("Failed to modify tag")); goto close; } comment = vcedit_comments(state); vorbis_comment_clear(comment); if (close_files(state) < 0) fail(_("Failed to modify tag")); close: vcedit_clear(state); pthread_mutex_unlock(&vf_mutex); gtk_widget_destroy(window); }
bool runReachability(double* start, double simTime, double wallTimeMs, double startMs) { LiftingSettings set; for (int d = 0; d < NUM_DIMS; ++d) { set.init.dims[d].min = start[d]; set.init.dims[d].max = start[d]; } set.reachTime = simTime; set.maxRuntimeMilliseconds = wallTimeMs; set.initialStepSize = set.reachTime / 10; set.maxRectWidthBeforeError = 100; set.reachedAtFinalTime = finalState; set.reachedAtIntermediateTime = intermediateState; set.restartedComputation = restartedComputation; open_files(true); hyperrectangle_to_file(f_initial, &set.init, 0); bool safe = face_lifting_iterative_improvement(startMs, &set); close_files(true); return safe; }
static void fortran_prescanner_process(prescanner_t* prescanner) { file_lines = NULL; last_line = file_lines; // Load all the file into memory read_lines(prescanner); // Cut lines to be of width 'prescanner.width' cut_lines(prescanner); // We used to remove comments here but it is better to convert them convert_whole_line_comments(); // Join continuated lines join_continuated_lines(prescanner); #if 0 // Lines that were not appended any continuation line have not been trimmed // their inline comments remove_inlined_comments(); #endif convert_lines(prescanner); if (!prescanner->append) { continuate_lines(prescanner); } print_lines(prescanner); close_files(prescanner); }
int spell_check(struct sc_config const *config) { int i = 0; int ret = -1; char ch; char buf[MAX_WORD_LENGTH]; FILE *files[FILE_COUNT]; if (open_files(config, files)) goto ERROR; while ((ch = getc(files[FILE_DOC])) != EOF) { if (isspace(ch)) { buf[i] = '\0'; if (i != 0) { if (handle_word(buf, files, config)) goto ERROR; i = 0; } fprintf(files[FILE_OUT], "%c", ch); } else { buf[i++] = ch; } } ret = 0; ERROR: close_files(files); return ret; }
main(int argc,char *argv[]) { if (argc<2) { puts("\nPouziti: MGFSOUND film.mgf zvuk.wav [i]"); puts("\nnebo: MGFSOUND script.scr"); puts("\nKde _i_ je komprimacni krivka (viz SNDPACK) (default:4)"); exit(0); } if (argc>3) { sscanf(argv[3],"%d",&difftype); } Create_table_16(); if (argc==2) call_script(argv[1]); else { open_wav(argv[2]); open_files(argv[1]); ozvuceni(); } close_files(); }
static void get_options(int argc, char *argv[]) { char ch; struct stat sb; i_opt = o_opt = f_opt = v_opt = t_opt = 0; while ((ch = getopt(argc, argv, "i:o:f:t:v")) != -1) { switch (ch) { case 'v': v_opt = 1; break; case 'i': if ((fmr_fp = fopen(optarg, "rb")) == NULL) OPEN_ERR_EXIT(optarg); i_opt = 1; break; case 'f': // Fingerprint image list file if ((img_fp = fopen(optarg, "r")) == NULL) OPEN_ERR_EXIT(optarg); f_opt = 1; break; case 'o': if (stat(optarg, &sb) == 0) { fprintf(stderr, "File '%s' exists, remove it first.\n", optarg); exit(EXIT_FAILURE); } if ((an2k_fp = fopen(optarg, "wb")) == NULL) OPEN_ERR_EXIT(optarg); o_opt = 1; break; case 't': if ((text_fp = fopen(optarg, "r")) == NULL) OPEN_ERR_EXIT(optarg); t_opt = 1; break; case '?': default: usage(); break; } } if ((i_opt && o_opt) == 0) { usage(); goto err_out; } return; err_out: close_files(); exit(EXIT_FAILURE); }
struct runner * runner_new(const char *filename) { struct runner *r; const char *buf; size_t size; int err; SOL_NULL_CHECK(filename, NULL); r = calloc(1, sizeof(*r)); SOL_NULL_CHECK(r, NULL); sol_ptr_vector_init(&r->file_readers); r->parser_client.api_version = SOL_FLOW_PARSER_CLIENT_API_VERSION; r->parser_client.data = r; r->parser_client.read_file = read_file; r->parser = sol_flow_parser_new(&r->parser_client, NULL); if (!r->parser) goto error; r->filename = filename; r->dirname = strdup(dirname(strdupa(filename))); r->basename = strdup(basename(strdupa(filename))); err = read_file(r, r->basename, &buf, &size); if (err < 0) { errno = -err; goto error; } r->root_type = sol_flow_parse_buffer(r->parser, buf, size, filename); if (!r->root_type) goto error; close_files(r); return r; error: close_files(r); runner_del(r); return NULL; }
void regenerate_fds(void) { if (no_files == TRUE) return; close_files(); open_files(); }
/* Runs the two-pass assembler. Most of the actual work is done in pass_one() and pass_two(). */ int assemble(const char* in_name, const char* tmp_name, const char* out_name) { FILE *src, *dst; int err = 0; SymbolTable* symtbl = create_table(SYMTBL_UNIQUE_NAME); SymbolTable* reltbl = create_table(SYMTBL_NON_UNIQUE); if (in_name) { printf("Running pass one: %s -> %s\n", in_name, tmp_name); if (open_files(&src, &dst, in_name, tmp_name) != 0) { free_table(symtbl); free_table(reltbl); exit(1); } if (pass_one(src, dst, symtbl) != 0) { err = 1; } close_files(src, dst); } if (out_name) { printf("Running pass two: %s -> %s\n", tmp_name, out_name); if (open_files(&src, &dst, tmp_name, out_name) != 0) { free_table(symtbl); free_table(reltbl); exit(1); } fprintf(dst, ".text\n"); if (pass_two(src, dst, symtbl, reltbl) != 0) { err = 1; } fprintf(dst, "\n.symbol\n"); write_table(symtbl, dst); fprintf(dst, "\n.relocation\n"); write_table(reltbl, dst); close_files(src, dst); } free_table(symtbl); free_table(reltbl); return err; }
/* * grpck - verify group file integrity */ int main (int argc, char **argv) { int errors = 0; bool changed = false; /* * Get my name so that I can use it to report errors. */ Prog = Basename (argv[0]); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); process_root_flag ("-R", argc, argv); OPENLOG ("grpck"); /* Parse the command line arguments */ process_flags (argc, argv); open_files (); if (sort_mode) { gr_sort (); #ifdef SHADOWGRP if (is_shadow) { sgr_sort (); } changed = true; #endif } else { check_grp_file (&errors, &changed); #ifdef SHADOWGRP if (is_shadow) { check_sgr_file (&errors, &changed); } #endif } /* Commit the change in the database if needed */ close_files (changed); nscd_flush_cache ("group"); /* * Tell the user what we did and exit. */ if (0 != errors) { if (changed) { printf (_("%s: the files have been updated\n"), Prog); } else { printf (_("%s: no changes\n"), Prog); } } return ((0 != errors) ? E_BAD_ENTRY : E_OKAY); }
void print_unity_x( project_info_table& info ) { FILE* arr[UNITY_NUM] = {NULL,}; char fname[MAX_PATH]; for (int i=0; i<UNITY_NUM; ++i) { std::string name = util::string::wc2mb( info.project_dir_path.c_str() ); sprintf_s(fname, "%sUnity_%d.cpp", name.c_str() , i+1); fopen_s(&arr[i], fname, "wt"); if (!arr[i]) { close_files(arr); return; } fputs("#include \"stdafx.h\"\n\n", arr[i]); } typedef vector<std::string>::const_iterator iterator; int i=0; for (iterator itr=info.filepath_table.begin(); itr!=info.filepath_table.end(); ++itr) { bool val = false; for( iterator except = g_except_file_table.begin(); except!=g_except_file_table.end(); ++except) { if( *except == *itr ) { val = true; break; } } if( !val ) fprintf(arr[i], "#include \"%s\"\n", (*itr).c_str()); ++i; if (i>=UNITY_NUM) i=0; } close_files(arr); }
/* * main - groupadd command */ int main (int argc, char **argv) { /* * Get my name so that I can use it to report errors. */ Prog = Basename (argv[0]); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); process_root_flag ("-R", argc, argv); prefix = process_prefix_flag ("-P", argc, argv); OPENLOG ("groupadd"); #ifdef WITH_AUDIT audit_help_open (); #endif if (atexit (do_cleanups) != 0) { fprintf (stderr, _("%s: Cannot setup cleanup service.\n"), Prog); exit (1); } /* * Parse the command line options. */ process_flags (argc, argv); check_perms (); #ifdef SHADOWGRP is_shadow_grp = sgr_file_present (); #endif /* * Do the hard stuff - open the files, create the group entries, * then close and update the files. */ open_files (); if (!gflg) { if (find_new_gid (rflg, &group_id, NULL) < 0) { exit (E_GID_IN_USE); } } grp_update (); close_files (); nscd_flush_cache ("group"); return E_SUCCESS; }
//------------------------------open_file------------------------------------ int ArchDesc::open_file(bool required, ADLFILE & ADF, const char *action) { if (required && (ADF._fp = fopen(ADF._name, action)) == NULL) { printf("ERROR: Cannot open file for %s: %s\n", action, ADF._name); close_files(1); return 0; } return 1; }
void process(List *from, List *to) { List *l; /* ** Initialise read */ open_for_read(from); open_for_write(to); l = read_header(from); write_header(to,l); destroy_list(l); /* ** Process Gels */ for (l = read_gel_data(from); !isNil(l); l = read_gel_data(from)) { write_gel_data(to,l); destroy_list(l); } /* ** Process Contigs */ for (l = read_contig_data(from); !isNil(l); l = read_contig_data(from)) { write_contig_data(to,l); destroy_list(l); } /* ** Tidy up read */ close_files(from); close_files(to); }
static int open_files(int *fd_rd, int *fd_wr) { *fd_rd = open(filename_rd, O_RDONLY | O_CREAT, 0666); *fd_wr = open(filename_wr, O_WRONLY | O_CREAT, 0666); if (*fd_rd < 0 || *fd_wr < 0) { close_files(*fd_rd, *fd_wr); return -1; } return 0; }
/* Interrupt signal handling */ static void interrupt_record(int signum) { fprintf(stderr, "[Interrupt]"); if (speech_output == SPOUT_FILE) { /* close files */ close_files(); } /* terminate program */ exit(1); }
void clear_io_state(struct thread_data *td, int all) { struct fio_file *f; unsigned int i; reset_io_counters(td, all); close_files(td); for_each_file(td, f, i) { fio_file_clear_done(f); f->file_offset = get_start_offset(td, f); }
static void genfailure( int signo ) /*********************************/ { #if CATCHBREAK if (signo != SIGBREAK) #else if (signo != SIGTERM) #endif EmitError( GENERAL_FAILURE ); close_files(); exit( EXIT_FAILURE ); }
int main(int argc, char *argv[]) { get_exec_name(argv[0]); get_options(argc, argv); /* may exit */ open_files(); /* may exit */ read_input_file(); /* may exit */ validate_input_file(); /* may exit */ generate_interrupt_vector_bitmap(); /* may exit */ generate_idt(); /* may exit */ close_files(); return 0; }
int main(int argc, char **argv) { FILE* cfiles[BUFSIZ]; FILE *asmfile = NULL; char errstr[BUFSIZ]; char line[BUFSIZ]; int i; handle_args(argc, argv); for (i = 0; i < opts.c_fcount; ++i) { printf("C file[%d]: '%s'\n", i + 1, opts.c_fname[i]); cfiles[i] = fopen(opts.c_fname[i], "r"); if (cfiles[i] == NULL) { sprintf(errstr, "couldn't open '%s'", opts.c_fname[i]); error(errstr); error("perhaps it doesn't exist?"); opts.c_fcount = i; goto exit; } } if (opts.asm_name_spec) printf("asm file: '%s'\n", opts.asm_fname); else printf("asm file: '%s'\n", defout); for (i = 0; i < opts.c_fcount; ++i) { cfiles[i] = comment_preprocessor_notes(cfiles[i], opts.c_fname[i]); } for (i = 0; i < opts.c_fcount; ++i) { while (fgets(line, BUFSIZ, cfiles[i]) != NULL) printf("%s", line); rewind(cfiles[i]); } for (i = 0; i < opts.c_fcount; ++i) { yyin = cfiles[i]; yyparse(); } if (scc_error == 0) { asmfile = fopen(opts.asm_fname, "w"); if (asmfile == NULL) { sprintf(errstr, "couldn't open '%s' for output", opts.asm_fname); error(errstr); } else { fclose(asmfile); } } exit: close_files(cfiles, opts.c_fcount); opts_free(); exit(EXIT_SUCCESS); }
void do_conversion(m00data_t* data) { debug_print("Beginning file conversion.\n"); open_files(data); fputs(file_head, data->out_file); convert_files(data); fputs(file_end, data->out_file); close_files(data); }
/* threads: Each thread opens the files specified */ void * threads(void* thread_id_) { int thread_id = (uintptr_t) thread_id_; char errmsg[80]; FILE *fd_list[MAXFILES]; int i; /* Open files */ for (i = 0; i < numfiles; i++) { if (debug) printf("Thread %d : Opening file number %d \n", thread_id, i); if ((fd_list[i] = fopen(filename, "rw")) == NULL) { sprintf(errmsg, "FAIL - Couldn't open file #%d", i); perror(errmsg); if (i > 0) { close_files(fd_list, i-1); } unlink(filename); pthread_exit((void*) 1); } } /* Grab mutex lock */ if (pthread_mutex_lock(&c.m)) { perror("FAIL - failed to grab mutex lock"); close_files(fd_list, numfiles); unlink(filename); pthread_exit((void*) 1); } /* Check if you should wake up main thread */ if (++c.thr_sleeping == numthreads) if (pthread_cond_signal(&c.init_cv)) { perror("FAIL - failed to signal main thread"); close_files(fd_list, numfiles); unlink(filename); pthread_exit((void*) 1); } /* Sleep until woken up */ if (pthread_cond_wait(&c.thr_cv, &c.m)) { perror("FAIL - failed to wake up correctly"); close_files(fd_list, numfiles); unlink(filename); pthread_exit((void*) 1); } /* Release mutex lock */ if (pthread_mutex_unlock(&c.m)) { perror("FAIL - failed to release mutex lock"); close_files(fd_list, numfiles); unlink(filename); pthread_exit((void*) 1); } /* Close file handles and exit */ close_files(fd_list, numfiles); unlink(filename); pthread_exit((void*) 0); }
void test_database_is_valid(int fd) { int fd_1; int fd_2; fd_1 = open("test/good.csv", O_RDONLY); fd_2 = open("test/bad.csv", O_RDONLY); if (database_is_valid(fd_1) != 1) { ft_putendl_fd("database_is_valid test 1 failed!", fd); close_files(fd_1, fd_2); return ; } if (database_is_valid(fd_2) != 0) { ft_putendl_fd("database_is_valid test 1 failed!", fd); close_files(fd_1, fd_2); return ; } close_files(fd_1, fd_2); ft_putendl_fd("database_is_valid OK", fd); }
int InternalError( const char *file, unsigned line ) /**************************************************/ // it's used by myassert() function in debug version { char buffer[MAX_LINE_LEN]; DebugMsg(("InternalError enter\n")); ModuleInfo.error_count++; GetCurrSrcPos( buffer ); fprintf( errout, "%s", buffer ); fprintf( errout, MsgGetEx( INTERNAL_ERROR ), file, line ); close_files(); exit( EXIT_FAILURE ); return(0); }
static void get_options(int argc, char *argv[]) { int ch; int i_opt; i_opt = v_opt = 0; r_opt = 0; while ((ch = getopt(argc, argv, "i:r:v")) != -1) { switch (ch) { case 'i': if (i_opt == 2) { usage(); goto err_out; } if ((in_fp[i_opt] = fopen(optarg, "rb")) == NULL) OPEN_ERR_EXIT(optarg); i_opt++; break; case 'r': r_opt = strtol(optarg, NULL, 10); if (r_opt == 0 && errno == EINVAL) ERR_OUT("Radius must be numeric"); if (r_opt < 0) ERR_OUT("Radius must be greater than 0"); break; case 'v': v_opt++; break; default: usage(); break; } } if ((i_opt != 2) | (r_opt == 0)) { usage(); goto err_out; } return; err_out: close_files(); exit(EXIT_FAILURE); }