/* * Read a file from the File->Open dialog. */ gboolean ggcov_read_file(const char *filename) { if (file_is_directory(filename) == 0) { if (!cov_read_directory(filename, /*recursive*/FALSE)) return FALSE; } else if (errno != ENOTDIR) { perror(filename); } else if (file_is_regular(filename) == 0) { if (cov_is_source_filename(filename)) { if (!cov_read_source_file(filename)) return FALSE; } else { if (!cov_read_object_file(filename)) return FALSE; } } else { _log.error("%s: don't know how to handle this filename\n", filename); return FALSE; } return TRUE; }
bool EmacsFile::fio_open ( const EmacsString &name, int eof, const EmacsString &defnam, FIO_EOL_Attribute attr ) { expand_and_default( name, defnam, m_full_file_name ); if( !file_is_regular( m_full_file_name ) ) return false; if( eof ) { // open for append m_file = fopen( m_full_file_name, "a" BINARY_MODE SHARE_NONE ); m_eol_attr = attr; } else // open for read m_file = fopen( m_full_file_name, "r" BINARY_MODE SHARE_READ ); return m_file != NULL; }
int open_input(Opts *options, Input *in, SpillControl *spillage) { if (NULL == options->in_name || 0 == strcmp(options->in_name, "-")) { /* Read from stdin */ options->in_name = "stdin"; in->fd = fileno(stdin); } else { /* Read from named file */ in->fd = open(options->in_name, O_RDONLY); if (in->fd < 0) { fprintf(stderr, "Couldn't open %s : %s\n", options->in_name, strerror(errno)); return -1; } } /* Check if input is a regular file */ in->reg = file_is_regular(options->in_name, in->fd); if (in->reg < 0) return -1; if (!in->reg) { /* Set input pipes to non-blocking mode */ if (0 != setnonblock(options->in_name, in->fd)) return -1; /* Can't use input for spilling */ spillage->spill = NULL; } else { /* Use input file for spillage */ spillage->spill = malloc(sizeof(SpillFile)); if (NULL == spillage->spill) { perror("open_input"); return -1; } spillage->spill->offset = 0; spillage->spill->ref_count = 1; spillage->spill->fd = in->fd; spillage->spill->is_tmp = 0; } in->pos = 0; if (verbosity > 1) { fprintf(stderr, "%.3f Opened input (%s) on fd %d\n", get_time(), options->in_name, in->fd); } return 0; }
static int open_outputs(int n, char **names, Output *outputs, int *regular, int *pipes, int *nregular, int *npipes) { int i; *nregular = *npipes = 0; for (i = 0; i < n; i++) { if (0 == strcmp(names[i], "-")) { /* Send to stdout */ outputs[i].fd = fileno(stdout); outputs[i].name = "stdout"; } else { /* Open the given file */ outputs[i].fd = open(names[i], O_WRONLY|O_CREAT|O_TRUNC, 0666); if (outputs[i].fd < 0) { fprintf(stderr, "Couldn't open %s for writing : %s\n", names[i], strerror(errno)); return -1; } outputs[i].name = names[i]; } /* Check if the file is regular or not */ outputs[i].is_reg = file_is_regular(names[i], outputs[i].fd); if (outputs[i].is_reg < 0) return -1; /* Add it to the regular[] or pipes[] array as appropriate */ if (outputs[i].is_reg) { regular[(*nregular)++] = i; } else { pipes[(*npipes)++] = i; if (0 != setnonblock(names[i], outputs[i].fd)) return -1; } /* Initialize the pointer to the data to output */ outputs[i].curr_chunk = NULL; outputs[i].offset = 0; if (verbosity > 1) { fprintf(stderr, "%.3f Opened output #%d (%s) on fd %d.\n", get_time(), i, outputs[i].name, outputs[i].fd); } } return 0; }
/** * returns 1 if a given file is a p12 token, otherwise 0 */ static int is_token(const char *path, const char *file, UNUSED void *data) { char *location = mem_printf("%s/%s", path, file); char *ext; // regular file if (!file_is_regular(location)) return 0; // with fixed extesion if (!(ext = file_get_extension(file))) return 0; if (!strncmp(ext, TOKEN_DEFAULT_EXT, strlen(TOKEN_DEFAULT_EXT))) { DEBUG("Found token file: %s", location); mem_free(location); return 1; } mem_free(location); return 0; }