Changeset 4430


Ignore:
Timestamp:
Jan 21, 2015, 11:14:54 AM (4 years ago)
Author:
cameron
Message:

Skip rather than exit for various special file conditions; skip directories

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/do_grep.cpp

    r4358 r4430  
    2020#include <sys/types.h>
    2121#include <sys/stat.h>
     22#include <stdexcept>
    2223
    2324#include "include/simd-lib/carryQ.hpp"
     
    119120    fdSrc = open(infilename.c_str(), O_RDONLY);
    120121    if (fdSrc == -1) {
    121         std::cerr << "Error: cannot open " << infilename << " for processing.\n";
    122         exit(-1);
     122        std::cerr << "Error: cannot open " << infilename << " for processing. Skipped.\n";
     123        return;
    123124    }
    124125    if (fstat(fdSrc, &infile_sb) == -1) {
    125         std::cerr << "Error: cannot stat " << infilename << " for processing.\n";
    126         exit(-1);
    127     }
    128     if (infile_sb.st_size == 0) {
    129         if (mShowFileNameOption) {
    130             std::cout << currentFileName;
    131         }
    132         if (mCountOnlyOption) fprintf(outfile, "%d\n", 0);
    133         exit(0);
     126        std::cerr << "Error: cannot stat " << infilename << " for processing. Skipped.\n";
     127        return;
     128    }
     129    if (S_ISDIR(infile_sb.st_mode)) {
     130        // Silently ignore directories.
     131        // std::cerr << "Error: " << infilename << " is a directory. Skipped.\n";
     132        return;
    134133    }
    135134    infile_buffer = (char *) mmap(NULL, infile_sb.st_size, PROT_READ, MAP_PRIVATE, fdSrc, 0);
    136135    if (infile_buffer == MAP_FAILED) {
    137         std::cerr << "Error: mmap of " << infilename << "failed.\n";
    138         exit(-1);
    139     }
    140    
     136        std::cerr << "Error: mmap of " << infilename << " failed. Skipped.\n";
     137        return;
     138    }
    141139   
    142140    char * buffer_ptr;
Note: See TracChangeset for help on using the changeset viewer.