Elaboradar  0.1
 Tutto Classi Namespace File Funzioni Variabili Tipi enumerati (enum) Gruppi
void radarelab::File::read_lines ( std::function< void(char *, size_t)>  line_cb)

Read the file line by line, calling line_cb on each line read.

Definizione alla linea 75 del file utils.cpp.

76 {
77  char *line = NULL;
78  size_t len = 0;
79 
80  while (true)
81  {
82  errno = 0;
83  ssize_t read = getline(&line, &len, fd);
84  if (read == -1)
85  {
86  if (errno == 0)
87  {
88  break;
89  } else {
90  string errmsg("cannot read ");
91  errmsg += fname;
92  errmsg += ": ";
93  errmsg += strerror(errno);
94  if (line) free(line);
95  throw runtime_error(errmsg);
96  }
97  }
98  try {
99  line_cb(line, read);
100  } catch (...) {
101  if (line) free(line);
102  throw;
103  }
104  }
105 
106  if (line) free(line);
107 }