Advertisement
rfmonk

handle_failure.c

Jul 23rd, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include<errno.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5.  
  6. FILE *
  7. open_sesame (char *name)
  8. {
  9.      FILE *stream;
  10.  
  11.      errno = 0;
  12.      stream = fopen (name, "r");
  13.      if (stream == NULL)
  14.      {  
  15.          fprint (stderr, "%s: Couldn't open file %s; %s\n",
  16.                  program_invocation_short_name, name, strerror (errno));
  17.          exit (EXIT_FAILURE);
  18.      }  
  19.      else
  20.          return stream;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement