home *** CD-ROM | disk | FTP | other *** search
- /* perror2 - Like perror(3), but with two string prefixes
- *
- * SYNOPSIS
- * void perror2 (const char *str1, const char *str2) ;
- *
- * DESCRIPTION
- * Prints str1, then a colon and a space, then str2, then a colon and
- * a space, then the error message corresponding to the contents of
- * errno, then a newline on stderr.
- */
-
- static char rcsid[] = "$Id: perror2.c,v 1.2 1992/12/02 03:49:59 tim Exp $";
-
- extern int strlen () ;
-
-
- void perror2 (str1, str2)
- char *str1, *str2 ;
- {
- extern int errno ;
- extern char *sys_errlist[] ;
- extern int sys_nerr ;
- register int save_errno = errno ;
- static char unknown_error[] = "Unknown error" ;
- static char colon_space[2] = {':', ' '} ;
- static char newline = '\n' ;
- char *p ;
-
- if (save_errno < 0 || save_errno >= sys_nerr)
- p = unknown_error ;
- else
- p = sys_errlist[save_errno] ;
- write (2, str1, strlen (str1)) ;
- write (2, colon_space, sizeof (colon_space)) ;
- write (2, str2, strlen (str2)) ;
- write (2, colon_space, sizeof (colon_space)) ;
- write (2, p, strlen (p)) ;
- write (2, &newline, 1) ;
- }
-
-
- #ifdef TEST
-
- int main (argc, argv)
- int argc ;
- char **argv ;
- {
- extern int errno ;
-
- errno = atoi (argv[1]) ;
- perror2 (argv[2], argv[3]) ;
- exit (1) ;
- }
-
- #endif /* TEST */
-