code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:
By using this code, you agree to the following terms...
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
/* +++Date last modified: 05-Jul-1997 */
/*
** FERRORF.C - Functions for formatted error messages
*/
/*
** ferrorf()
**
** Prints error message with printf() formatting syntax, then a colon,
** then a message corresponding to the value of errno, then a newline.
** Output is to filehandle.
**
** public Domain by Mark R. Devlin, free usage is permitted.
*/
#include
#include
#include
#include "errors.h"
int ferrorf(FILE *filehandle, const char *format, ...)
{
int vfp, fp;
va_list vargs;
vfp = fp = 0;
va_start(vargs, format);
vfp = vfprintf(filehandle, format, vargs);
va_end(vargs);
fp = fprintf(filehandle, ": %s\n", sys_errlist[errno]);
return ((vfp==EOF || fp==EOF) ? EOF : (vfp+fp));
}
/*
** cant() - An fopen() replacement with error trapping
**
** Call just as you would fopen(), but make sure your exit functions are
** registered with atexit().
**
** public domain by Bob Stout
*/
FILE *cant(char *fname, char *fmode)
{
FILE *fp;
if (NULL == (fp = fopen(fname, fmode)))
{
ferrorf(stderr, "Can't open %s", fname);
exit(EXIT_FAILURE);
}
return fp;
}
#ifdef TEST
main()
{
char badname[] = "????????.???";
FILE *fp;
fp = cant(badname, "r");
return 0;
}
#endif /* TEST */
Other 156 submission(s) by this author