When I run the output program using gdb from the terminal it always ends with a segmentation fault at this function. But running this with eclipse debugger works fine.
ssize_t
read_from_file(char *arg, unsigned char *buf, size_t max_buf_len) {
  ssize_t result = 0;
  FILE *f = fopen(arg, "r");
  int c;
  while (!feof(f)) {
    size_t bytes_read;
    bytes_read = fread(buf, 1, max_buf_len, f);
    if (ferror(f)) {
      result = -1;
      break;
    }
    buf += bytes_read;
    result += bytes_read;
    max_buf_len -= bytes_read;
  }
  fclose(f);
  return result;
}
Error message from gdb
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
_IO_feof (fp=0x0) at feof.c:35
35      feof.c: No such file or directory.
I tried using alternatives to feof() Like
while((c = fgetc(file)) != EOF)
But I get the same results
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
_IO_getc (fp=0x0) at getc.c:37
37      getc.c: No such file or directory.
Does anyone know where this error is originating from?
 
     
    