Listing 3 The UNWIND_PROTECT macro

FILE *volatile file = NULL;
static int no_such_file;
static int read_failed;

UNWIND_PROTECT(
{
  int i;
  
  file = fopen("data", "r");
  if (file == NULL)
    THROW(no_such_file);
  
  if (fscanf(file, "%d", &i) != 1)
    THROW(read_failed);
  
  printf("%d\n", i);
},
{
  if (file)
    fclose(file);
});

/* End of File */