diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | compat.h | 10 | ||||
-rw-r--r-- | compat/cfmakeraw.c | 3 | ||||
-rw-r--r-- | compat/err.c | 97 | ||||
-rw-r--r-- | compat/forkpty-sunos.c | 1 | ||||
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | tmux.c | 1 | ||||
-rw-r--r-- | tmux.h | 2 |
8 files changed, 126 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index f809c131..8bfafd40 100644 --- a/Makefile.am +++ b/Makefile.am @@ -204,6 +204,9 @@ endif if NO_IMSG nodist_tmux_SOURCES += compat/imsg.c compat/imsg-buffer.c endif +if NO_ERR_H +nodist_tmux_SOURCES += compat/err.c +endif if NO_CLOSEFROM nodist_tmux_SOURCES += compat/closefrom.c endif @@ -22,6 +22,7 @@ #include <limits.h> #include <stdio.h> +#include <termios.h> #include <wchar.h> #ifndef __GNUC__ @@ -57,6 +58,15 @@ typedef uint32_t u_int32_t; typedef uint64_t u_int64_t; #endif +#ifdef HAVE_ERR_H +#include <err.h> +#else +void err(int, const char *, ...); +void errx(int, const char *, ...); +void warn(const char *, ...); +void warnx(const char *, ...); +#endif + #ifndef HAVE_PATHS_H #define _PATH_BSHELL "/bin/sh" #define _PATH_TMP "/tmp/" diff --git a/compat/cfmakeraw.c b/compat/cfmakeraw.c index df78ba3f..b481a903 100644 --- a/compat/cfmakeraw.c +++ b/compat/cfmakeraw.c @@ -15,7 +15,10 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <sys/types.h> + #include <string.h> +#include <termios.h> #include "compat.h" diff --git a/compat/err.c b/compat/err.c new file mode 100644 index 00000000..d7f0c0bd --- /dev/null +++ b/compat/err.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> + +#include <errno.h> +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "compat.h" + +void +err(int eval, const char *fmt, ...) +{ + va_list ap; + int saved_errno = errno; + + fprintf(stderr, "%s: ", getprogname()); + + va_start(ap, fmt); + if (fmt != NULL) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } + va_end(ap); + + fprintf(stderr, "%s\n", strerror(saved_errno)); + exit(eval); +} + +void +errx(int eval, const char *fmt, ...) +{ + va_list ap; + + fprintf(stderr, "%s: ", getprogname()); + + va_start(ap, fmt); + if (fmt != NULL) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } + va_end(ap); + + putc('\n', stderr); + exit(eval); +} + +void +warn(const char *fmt, ...) +{ + va_list ap; + int saved_errno = errno; + + fprintf(stderr, "%s: ", getprogname()); + + va_start(ap, fmt); + if (fmt != NULL) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } + va_end(ap); + + fprintf(stderr, "%s\n", strerror(saved_errno)); +} + +void +warnx(const char *fmt, ...) +{ + va_list ap; + + fprintf(stderr, "%s: ", getprogname()); + + va_start(ap, fmt); + if (fmt != NULL) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } + va_end(ap); + + putc('\n', stderr); +} diff --git a/compat/forkpty-sunos.c b/compat/forkpty-sunos.c index 0de36bf5..81109630 100644 --- a/compat/forkpty-sunos.c +++ b/compat/forkpty-sunos.c @@ -21,6 +21,7 @@ #include <stdlib.h> #include <strings.h> #include <stropts.h> +#include <termios.h> #include <unistd.h> #include "compat.h" diff --git a/configure.ac b/configure.ac index acfc5886..79dfcb31 100644 --- a/configure.ac +++ b/configure.ac @@ -350,6 +350,16 @@ if test "x$found_cmsg_data" = xno; then fi AC_SUBST(XOPEN_DEFINES) +# Look for err and friends in err.h. +AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no) +AC_CHECK_FUNC(errx, , found_err_h=no) +AC_CHECK_FUNC(warn, , found_err_h=no) +AC_CHECK_FUNC(warnx, , found_err_h=no) +if test "x$found_err_h" = xyes; then + AC_CHECK_HEADER(err.h, , found_err_h=no) +fi +AM_CONDITIONAL(NO_ERR_H, [test "x$found_err_h" = xno]) + # Look for imsg in libutil. compat/imsg.c is linked by Makefile.am if missing. AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no) if test "x$found_imsg_init" = xyes; then @@ -19,7 +19,6 @@ #include <sys/types.h> #include <sys/stat.h> -#include <err.h> #include <errno.h> #include <event.h> #include <fcntl.h> @@ -55,7 +55,9 @@ struct tmuxpeer; struct tmuxproc; /* Default global configuration file. */ +#ifndef TMUX_CONF #define TMUX_CONF "/etc/tmux.conf" +#endif /* * Minimum layout cell size, NOT including separator line. The scroll region |