/* This is not a complete program. */ FILE *file_open(char name[], char access_mode[]) { FILE *f; char message_buf[80]; f = fopen(name, access_mode); if (f == NULL) { /* error? */ int e = errno; /* Save any error number set by fopen. */ /* Library function perror prints an informative message. */ sprintf(message_buf, "Cannot open file \"%.60s\"", name); errno = e; /* Restore error number */ perror(message_buf); exit(EXIT_FAILURE); /* Terminate after printing error message. */ } return f; /* Only happens if fopen succeeded. */ }