Read out Fortran unformatted file in C

So I just tried running this program directly:

/* Read Fortran unformatted file with record markers containing byte sizes */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
int recn,recl,nin; char buf[0x1000]; long offset;
FILE *fil=fopen(argv[1],"rb");
recn=0; offset = 0;
do{
   nin = fread(&recl,4,1,fil); // prefix marker
   if(nin < 1)break;
   offset+=4;
   if(nin > 0x1000){
      fprintf(stderr,"Buffer is too small, need more than 4096 bytes\n");
      exit(1);
      }
   nin=fread(buf,1,recl,fil);
   fread(&recl,4,1,fil); // postfix marker
   recn++; printf("%4d %8d %12ld\n",recn,nin,offset);
   offset+=nin+4;
   }while(1);
fclose(fil);
}

And as an output I got stack smashing and a segmentation error