2 * Copyright (c) 1999-2018 The strace developers.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
18 #include "error_prints.h"
20 #ifndef HAVE_PROGRAM_INVOCATION_NAME
21 extern char *program_invocation_name;
25 verror_msg(int err_no, const char *fmt, va_list p)
31 /* We want to print entire message with single fprintf to ensure
32 * message integrity if stderr is shared with other programs.
33 * Thus we use vasprintf + single fprintf.
36 if (vasprintf(&msg, fmt, p) >= 0) {
38 fprintf(stderr, "%s: %s: %s\n",
39 program_invocation_name, msg, strerror(err_no));
41 fprintf(stderr, "%s: %s\n",
42 program_invocation_name, msg);
45 /* malloc in vasprintf failed, try it without malloc */
46 fprintf(stderr, "%s: ", program_invocation_name);
47 vfprintf(stderr, fmt, p);
49 fprintf(stderr, ": %s\n", strerror(err_no));
53 /* We don't switch stderr to buffered, thus fprintf(stderr)
54 * always flushes its output and this is not necessary: */
59 error_msg(const char *fmt, ...)
63 verror_msg(0, fmt, p);
68 error_msg_and_die(const char *fmt, ...)
72 verror_msg(0, fmt, p);
78 error_msg_and_help(const char *fmt, ...)
83 verror_msg(0, fmt, p);
86 fprintf(stderr, "Try '%s -h' for more information.\n",
87 program_invocation_name);
92 perror_msg(const char *fmt, ...)
96 verror_msg(errno, fmt, p);
101 perror_msg_and_die(const char *fmt, ...)
105 verror_msg(errno, fmt, p);