home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / libc / warning.c < prev   
C/C++ Source or Header  |  1991-01-09  |  697b  |  35 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. void
  13. warning(s1, s2)
  14. char *s1;
  15. char *s2;
  16. {
  17.     char *cmdname;
  18.     register int saverrno = errno;
  19.     extern char *progname;
  20.     extern char *getenv();
  21.  
  22.     (void) fflush(stdout);                /* hack */
  23.     cmdname = getenv("CMDNAME");
  24.     if (cmdname != NULL && *cmdname != '\0')
  25.         fprintf(stderr, "%s:", cmdname);    /* No space after :. */
  26.     if (progname != NULL)
  27.         fprintf(stderr, "%s: ", progname);
  28.     fprintf(stderr, s1, s2);
  29.     if (saverrno != 0)
  30.         fprintf(stderr, " (%s)", strerror(saverrno));
  31.     fprintf(stderr, "\n");
  32.     (void) fflush(stderr);
  33.     errno = 0;
  34. }
  35.