diff --git a/GNUmakefile b/GNUmakefile index 52a30441..eb7b5e93 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.24 2008-06-18 20:11:25 nicm Exp $ +# $Id: GNUmakefile,v 1.25 2008-06-18 20:12:19 nicm Exp $ .PHONY: clean @@ -55,7 +55,7 @@ ifeq ($(shell uname),SunOS) INCDIRS+= -Icompat SRCS+= compat/strtonum.c compat/daemon.c compat/forkpty-sunos.c CFLAGS+= -DNO_STRTONUM -DNO_TREE_H -DNO_PATHS_H -DNO_SETPROCTITLE \ - -DNO_DAEMON -DNO_FORKPTY -DNO_PROGNAME + -DNO_DAEMON -DNO_FORKPTY -DNO_PROGNAME -DNO_ASPRINTF LDFLAGS+= -L/opt/csw/lib LIBS+= -lsocket -lnsl endif diff --git a/compat/asprintf.c b/compat/asprintf.c new file mode 100644 index 00000000..1f157046 --- /dev/null +++ b/compat/asprintf.c @@ -0,0 +1,56 @@ +/* $Id: asprintf.c,v 1.1 2008-06-18 20:12:19 nicm Exp $ */ + +/* + * Copyright (c) 2006 Nicholas Marriott + * + * 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 +#include + +#include "tmux.h" + +int +asprintf(char **ret, const char *format, ...) +{ + va_list ap; + int n; + + va_start(ap, format); + n = vasprintf(ret, format, ap); + va_end(ap); + + return (n); +} + +int +vasprintf(char **ret, const char *format, va_list ap) +{ + int n; + + if ((n = vsnprintf(NULL, 0, format, ap)) < 0) + goto error; + + *ret = xmalloc(n + 1); + if ((n = vsnprintf(*ret, n + 1, format, ap)) < 0) { + xfree(*ret); + goto error; + } + + return (n); + +error: + *ret = NULL; + return (-1); +} diff --git a/tmux.h b/tmux.h index 7305e1a9..f62196fe 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.149 2008-06-18 20:11:25 nicm Exp $ */ +/* $Id: tmux.h,v 1.150 2008-06-18 20:12:19 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -780,6 +780,12 @@ int daemon(int, int); pid_t forkpty(int *, char *, struct termios *, struct winsize *); #endif +#ifdef NO_ASPRINTF +/* asprintf.c */ +int asprintf(char **, const char *, ...); +int vasprintf(char **, const char *, va_list); +#endif + /* tmux.c */ extern volatile sig_atomic_t sigwinch; extern volatile sig_atomic_t sigterm;