home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 400-499 / ff473.lzh / CNewsSrc / cnews_src.lzh / libc / warning.c < prev   
C/C++ Source or Header  |  1990-12-25  |  776b  |  41 lines

  1. /*
  2.  * warning - print best error message possible and clear errno
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <errno.h>
  7. #ifndef __STDC__
  8. extern int errno;
  9. #endif
  10. #include <string.h>
  11.  
  12. #ifdef AMIGA
  13. # define GETENV    envparm
  14. #else
  15. # define GETENV getenv
  16. #endif /* AMIGA */
  17.  
  18. void
  19. warning(s1, s2)
  20. char *s1;
  21. char *s2;
  22. {
  23.     char *cmdname;
  24.     char *message = strerror(errno);
  25.     extern char *progname;
  26.     extern char *GETENV();
  27.  
  28.     (void) fflush(stdout);                /* hack */
  29.     cmdname = GETENV("CMDNAME");
  30.     if (cmdname != NULL && *cmdname != '\0')
  31.         fprintf(stderr, "%s:", cmdname);    /* No space after :. */
  32.     if (progname != NULL)
  33.         fprintf(stderr, "%s: ", progname);
  34.     fprintf(stderr, s1, s2);
  35.     if (message != NULL)
  36.         fprintf(stderr, " (%s)", message);
  37.     fprintf(stderr, "\n");
  38.     (void) fflush(stderr);
  39.     errno = 0;
  40. }
  41.