summaryrefslogtreecommitdiff
path: root/src/stdbuf.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-06-22 03:37:51 +0100
committerPádraig Brady <P@draigBrady.com>2013-06-22 04:02:19 +0100
commitbc70095df2ea1bc4338ea7331d44b916e0c82258 (patch)
tree78c2d84095471279b6fb0b8c9d3a1a2fd0ede930 /src/stdbuf.c
parentb235223926c23f358df323fab4b368b46d0074af (diff)
downloadcoreutils-bc70095df2ea1bc4338ea7331d44b916e0c82258.tar.xz
stdbuf: make it mandatory to specify a buffering option
This is consistent with the documented interface and avoids any ambiguity in a user thinking that stdbuf without options might reset to a "standard" buffering setup. * src/stdbuf.c (set_libstdbuf_options): Indicate with the return value whether any env variables were actually set. (main): Fail unless some env variables were set. * tests/misc/stdbuf.sh: Ensure this constraint is enforced. * NEWS: Mention the small change in behavior.
Diffstat (limited to 'src/stdbuf.c')
-rw-r--r--src/stdbuf.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/stdbuf.c b/src/stdbuf.c
index 38e9bee7c..2500c3001 100644
--- a/src/stdbuf.c
+++ b/src/stdbuf.c
@@ -248,12 +248,14 @@ set_LD_PRELOAD (void)
}
}
-/* Populate environ with _STDBUF_I=$MODE _STDBUF_O=$MODE _STDBUF_E=$MODE */
+/* Populate environ with _STDBUF_I=$MODE _STDBUF_O=$MODE _STDBUF_E=$MODE.
+ Return TRUE if any environment variables set. */
-static void
+static bool
set_libstdbuf_options (void)
{
- unsigned int i;
+ bool env_set = false;
+ size_t i;
for (i = 0; i < ARRAY_CARDINALITY (stdbuf); i++)
{
@@ -278,8 +280,12 @@ set_libstdbuf_options (void)
_("failed to update the environment with %s"),
quote (var));
}
+
+ env_set = true;
}
}
+
+ return env_set;
}
int
@@ -346,9 +352,11 @@ main (int argc, char **argv)
usage (EXIT_CANCELED);
}
- /* FIXME: Should we mandate at least one option? */
-
- set_libstdbuf_options ();
+ if (! set_libstdbuf_options ())
+ {
+ error (0, 0, _("you must specify a buffering mode option"));
+ usage (EXIT_CANCELED);
+ }
/* Try to preload libstdbuf first from the same path as
stdbuf is running from. */