// report_err.c from [Jumpstart] // // THIS CODE WILL COMPILE ON CYGWIN AND SOLARIS // BUT IT WILL NOT LINK on CYGWIN because the // extern errno is undefined. // // SOLUTION: in cygwin, you need to include another file // #include // // Somehow, cygwin gcc knows how to autoimport "sys_nerr" // and "sys_errlist". // #include //============================================ void report_err(char * prefix) { extern int errno; extern int sys_nerr; // size of array sys_errlist extern char *sys_errlist[]; if (prefix != NULL) printf("%s: ", prefix); if (0 < errno && errno < sys_nerr) printf("%s\n ", sys_errlist[errno]); else printf("unknown error\n"); exit(1); } main() { report_err("TESTING"); } //============================================