Change Details
tools/libtxt/Makefile |
13 | 13 | |
14 | 14 | LIB = libtxt.a |
15 | 15 | |
16 | | CFLAGS = -g -Wall |
| 16 | # _GNU_SOURCE for vasprintf |
| 17 | CFLAGS = -g -Wall -D_GNU_SOURCE |
17 | 18 | |
18 | 19 | OBJS = edit.o font.o |
19 | 20 | |
tools/libtxt/font.c |
11 | 11 | */ |
12 | 12 | |
13 | 13 | |
14 | | #define _GNU_SOURCE /* for vasprintf */ |
15 | | #include <stdarg.h> |
16 | 14 | #include <stdint.h> |
17 | 15 | #include <stdlib.h> |
18 | | #include <stdio.h> |
19 | 16 | #include <string.h> |
20 | 17 | #include <errno.h> |
21 | 18 | |
| 19 | #include "util.h" |
22 | 20 | #include "libtxt.h" |
23 | 21 | |
24 | 22 | |
... | ... | |
45 | 43 | }; |
46 | 44 | |
47 | 45 | |
48 | | /* ----- Helper functions -------------------------------------------------- */ |
49 | | |
50 | | |
51 | | static const char *alloc_sprintf(const char *fmt, ...) |
52 | | { |
53 | | va_list ap; |
54 | | char *tmp, *res; |
55 | | int n; |
56 | | |
57 | | va_start(ap, fmt); |
58 | | n = vasprintf(&tmp, fmt, ap); |
59 | | va_end(ap); |
60 | | if (n < 0) |
61 | | abort(); |
62 | | res = malloc(n+1); |
63 | | if (!res) |
64 | | abort(); |
65 | | memcpy(res, tmp, n+1); |
66 | | return res; |
67 | | } |
68 | | |
69 | | |
70 | 46 | /* ----- XBM image --------------------------------------------------------- */ |
71 | 47 | |
72 | 48 | |
tools/libtxt/util.h |
| 1 | /* |
| 2 | * tools/libtxt/util.h - Utility functions |
| 3 | * |
| 4 | * Written 2012 by Werner Almesberger |
| 5 | * Copyright 2012 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #ifndef UTIL_H |
| 14 | #define UTIL_H |
| 15 | |
| 16 | #include <stdarg.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <stdio.h> |
| 19 | #include <string.h> |
| 20 | |
| 21 | |
| 22 | static const char *alloc_sprintf(const char *fmt, ...) |
| 23 | { |
| 24 | va_list ap; |
| 25 | char *tmp, *res; |
| 26 | int n; |
| 27 | |
| 28 | va_start(ap, fmt); |
| 29 | n = vasprintf(&tmp, fmt, ap); |
| 30 | va_end(ap); |
| 31 | if (n < 0) |
| 32 | abort(); |
| 33 | res = malloc(n+1); |
| 34 | if (!res) |
| 35 | abort(); |
| 36 | memcpy(res, tmp, n+1); |
| 37 | return res; |
| 38 | } |
| 39 | |
| 40 | #endif /* !UTIL_H */ |
Download the corresponding diff file