From f0337aa4819df5ef097837dc02e9a4746da79467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sat, 20 May 2017 21:03:04 +0200 Subject: Do away with POSIX --- Makefile | 2 +- ell.c | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 34d6309..5ad62ed 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS = -std=gnu99 -Wall -Wextra -ggdb +CFLAGS = -std=c99 -Wall -Wextra -ggdb all: ell ell: ell.c $(CC) $(CFLAGS) $< -o $@ diff --git a/ell.c b/ell.c index c73ba9e..68a5427 100755 --- a/ell.c +++ b/ell.c @@ -17,8 +17,6 @@ * */ -#define _XOPEN_SOURCE 500 - #include #include #include @@ -28,7 +26,6 @@ #include #include #include -#include #include #include @@ -53,12 +50,12 @@ vformat (const char *format, va_list ap) { if (size < 0) return NULL; - char buf[size + 1]; - size = vsnprintf (buf, sizeof buf, format, ap); - if (size < 0) + char *buf = malloc (size + 1); + if (buf && vsnprintf (buf, size + 1, format, ap) < 0) { + free (buf); return NULL; - - return strdup (buf); + } + return buf; } static char * @@ -184,10 +181,7 @@ new_clone_list (const struct item *item) { } static struct item * -new_string (const char *s, ssize_t len) { - if (len < 0) - len = strlen (s); - +new_string (const char *s, size_t len) { struct item *item = calloc (1, sizeof *item + len + 1); if (!item) return NULL; -- cgit v1.2.3