• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
3  * Copyright (c) 2016-2018 The strace developers.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #define perror_msg_and_fail perror_msg_and_fail
30 #define error_msg_and_fail error_msg_and_fail
31 
32 #include "tests.h"
33 #include <errno.h>
34 #include <stdarg.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 
39 void
perror_msg_and_fail(const char * fmt,...)40 perror_msg_and_fail(const char *fmt, ...)
41 {
42 	int err_no = errno;
43 	va_list p;
44 
45 	va_start(p, fmt);
46 	vfprintf(stderr, fmt, p);
47 	if (err_no)
48 		fprintf(stderr, ": %s\n", strerror(err_no));
49 	else
50 		putc('\n', stderr);
51 	exit(1);
52 }
53 
54 void
error_msg_and_fail(const char * fmt,...)55 error_msg_and_fail(const char *fmt, ...)
56 {
57 	va_list p;
58 
59 	va_start(p, fmt);
60 	vfprintf(stderr, fmt, p);
61 	putc('\n', stderr);
62 	exit(1);
63 }
64 
65 void
error_msg_and_skip(const char * fmt,...)66 error_msg_and_skip(const char *fmt, ...)
67 {
68 	va_list p;
69 
70 	va_start(p, fmt);
71 	vfprintf(stderr, fmt, p);
72 	putc('\n', stderr);
73 	exit(77);
74 }
75 
76 void
perror_msg_and_skip(const char * fmt,...)77 perror_msg_and_skip(const char *fmt, ...)
78 {
79 	int err_no = errno;
80 	va_list p;
81 
82 	va_start(p, fmt);
83 	vfprintf(stderr, fmt, p);
84 	if (err_no)
85 		fprintf(stderr, ": %s\n", strerror(err_no));
86 	else
87 		putc('\n', stderr);
88 	exit(77);
89 }
90