diff --git a/tools/libtxt/Makefile b/tools/libtxt/Makefile index 39f80b6..cc3dd0d 100644 --- a/tools/libtxt/Makefile +++ b/tools/libtxt/Makefile @@ -13,7 +13,8 @@ LIB = libtxt.a -CFLAGS = -g -Wall +# _GNU_SOURCE for vasprintf +CFLAGS = -g -Wall -D_GNU_SOURCE OBJS = edit.o font.o diff --git a/tools/libtxt/font.c b/tools/libtxt/font.c index 62ec705..e8d68ff 100644 --- a/tools/libtxt/font.c +++ b/tools/libtxt/font.c @@ -11,14 +11,12 @@ */ -#define _GNU_SOURCE /* for vasprintf */ -#include #include #include -#include #include #include +#include "util.h" #include "libtxt.h" @@ -45,28 +43,6 @@ struct font { }; -/* ----- Helper functions -------------------------------------------------- */ - - -static const char *alloc_sprintf(const char *fmt, ...) -{ - va_list ap; - char *tmp, *res; - int n; - - va_start(ap, fmt); - n = vasprintf(&tmp, fmt, ap); - va_end(ap); - if (n < 0) - abort(); - res = malloc(n+1); - if (!res) - abort(); - memcpy(res, tmp, n+1); - return res; -} - - /* ----- XBM image --------------------------------------------------------- */ diff --git a/tools/libtxt/util.h b/tools/libtxt/util.h new file mode 100644 index 0000000..8d77b52 --- /dev/null +++ b/tools/libtxt/util.h @@ -0,0 +1,40 @@ +/* + * tools/libtxt/util.h - Utility functions + * + * Written 2012 by Werner Almesberger + * Copyright 2012 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef UTIL_H +#define UTIL_H + +#include +#include +#include +#include + + +static const char *alloc_sprintf(const char *fmt, ...) +{ + va_list ap; + char *tmp, *res; + int n; + + va_start(ap, fmt); + n = vasprintf(&tmp, fmt, ap); + va_end(ap); + if (n < 0) + abort(); + res = malloc(n+1); + if (!res) + abort(); + memcpy(res, tmp, n+1); + return res; +} + +#endif /* !UTIL_H */