#define HAVE_MNTENT_H 1
#define HAVE_NET_ETHERNET_H 1
#define HAVE_SYS_STATFS_H 1
+#define HAVE_PRINTF_PERCENTM 1
#if defined(__UCLIBC__)
# if UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
# undef HAVE_DPRINTF
# undef HAVE_UNLOCKED_STDIO
# undef HAVE_UNLOCKED_LINE_OPS
+# undef HAVE_PRINTF_PERCENTM
#endif
#if defined(__dietlibc__)
# undef HAVE_STRVERSCMP
# undef HAVE_XTABS
# undef HAVE_UNLOCKED_LINE_OPS
+# undef HAVE_PRINTF_PERCENTM
# include <osreldate.h>
# if __FreeBSD_version < 1000029
# undef HAVE_STRCHRNUL /* FreeBSD added strchrnul() between 1000028 and 1000029 */
# undef HAVE_STRVERSCMP
# undef HAVE_UNLOCKED_LINE_OPS
# undef HAVE_NET_ETHERNET_H
+# undef HAVE_PRINTF_PERCENTM
#endif
/*
va_end(ap);
}
+/*
+ * Use '%m' to append error string on platforms that support it, '%s' and
+ * strerror() on those that don't.
+ *
+ * 'fmt' must be a string literal.
+ */
+#ifdef HAVE_PRINTF_PERCENTM
+#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %m", ##__VA_ARGS__)
+#else
+#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %s", ##__VA_ARGS__, strerror(errno))
+#endif
+
static void raise_error_syntax(const char *) NORETURN;
static void
raise_error_syntax(const char *msg)
xtcsetpgrp(int fd, pid_t pgrp)
{
if (tcsetpgrp(fd, pgrp))
- ash_msg_and_raise_error("can't set tty process group (%m)");
+ ash_msg_and_raise_perror("can't set tty process group");
}
/*
err = newfd < 0 ? errno : 0;
if (err != EBADF) {
if (err)
- ash_msg_and_raise_error("%d: %m", from);
+ ash_msg_and_raise_perror("%d", from);
close(from);
fcntl(newfd, F_SETFD, FD_CLOEXEC);
}
newfd = (from != to) ? dup2(from, to) : to;
if (newfd < 0) {
/* Happens when source fd is not open: try "echo >&99" */
- ash_msg_and_raise_error("%d: %m", from);
+ ash_msg_and_raise_perror("%d", from);
}
return newfd;
}
/* "echo >&10" and 10 is a fd opened to a sh script? */
if (is_hidden_fd(sv, right_fd)) {
errno = EBADF; /* as if it is closed */
- ash_msg_and_raise_error("%d: %m", right_fd);
+ ash_msg_and_raise_perror("%d", right_fd);
}
newfd = -1;
} else {
if (newfd >= 0)
close(newfd);
errno = i;
- ash_msg_and_raise_error("%d: %m", fd);
+ ash_msg_and_raise_perror("%d", fd);
/* NOTREACHED */
}
/* EBADF: it is not open - good, remember to close it */