From: Michael Stapelberg Date: Fri, 10 Feb 2012 00:03:18 +0000 (+0000) Subject: Merge branch 'master' into next X-Git-Tag: 4.2~86 X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3;a=commitdiff_plain;h=2daa8d422ae63d55e4b952070e8e894c0963618f;hp=2f8d3d3390e8225fac12b0bde716a836f1fbf963 Merge branch 'master' into next Conflicts: i3-config-wizard/main.c --- diff --git a/i3-config-wizard/main.c b/i3-config-wizard/main.c index 63ebbfa5..bf260c2f 100644 --- a/i3-config-wizard/main.c +++ b/i3-config-wizard/main.c @@ -8,6 +8,19 @@ * keysyms. * */ +#if defined(__FreeBSD__) +#include +#endif + +/* For systems without getline, fall back to fgetln */ +#if defined(__APPLE__) || (defined(__FreeBSD__) && __FreeBSD_version < 800000) +#define USE_FGETLN +#elif defined(__FreeBSD__) +/* Defining this macro before including stdio.h is necessary in order to have + * a prototype for getline in FreeBSD. */ +#define _WITH_GETLINE +#endif + #include #include #include @@ -285,7 +298,7 @@ static void finish() { char *line = NULL; size_t len = 0; -#if !defined(__APPLE__) && (!defined(__FreeBSD__) || __FreeBSD_version >= 800000) +#ifndef USE_FGETLN ssize_t read; #endif bool head_of_file = true; @@ -298,10 +311,16 @@ static void finish() { fputs("# this file and re-run i3-config-wizard(1).\n", ks_config); fputs("#\n", ks_config); -#if defined(__APPLE__) || (defined(__FreeBSD__) && __FreeBSD_version < 800000) - while ((line = fgetln(kc_config, &len)) != NULL) { +#ifdef USE_FGETLN + char *buf = NULL; + while ((buf = fgetln(kc_config, &len)) != NULL) { + /* fgetln does not return null-terminated strings */ + FREE(line); + sasprintf(&line, "%.*s", len, buf); #else - while ((read = getline(&line, &len, kc_config)) != -1) { + size_t linecap = 0; + while ((read = getline(&line, &linecap, kc_config)) != -1) { + len = strlen(line); #endif /* skip the warning block at the beginning of the input file */ if (head_of_file && @@ -338,7 +357,10 @@ static void finish() { fflush(ks_config); fsync(fileno(ks_config)); +#ifndef USE_FGETLN free(line); +#endif + fclose(kc_config); fclose(ks_config);