[augeas-devel] [PATCH] Add --autosave option to augtool (fix ticket #172). Define AUGTOOL_PROMPT as a constant. Do not print (null) lines when using --echo.
David Lutterkort
lutter at redhat.com
Tue Jan 11 00:43:26 UTC 2011
On Sat, 2011-01-08 at 11:16 +0100, Raphaël Pinson wrote:
> On Fri, Jan 7, 2011 at 11:50 PM, David Lutterkort <lutter at redhat.com> wrote:
> >
> > On Wed, 2011-01-05 at 12:52 +0100, raphink at gmail.com wrote:
> >> From: Raphaël Pinson <raphink at gmail.com>
> >>
> >> } else if (isatty(fileno(stdin))) {
> >> - line = readline("augtool> ");
> >> + line = readline(AUGTOOL_PROMPT);
> >> } else {
> >> if (getline(&line, &len, stdin) == -1)
> >> - return ret;
> >> - if (echo)
> >> - printf("augtool> %s", line);
> >> + line = NULL;
> >> + if (echo && line != NULL)
> >> + printf("%s%s", AUGTOOL_PROMPT, line);
> >> }
> >>
> >> - cleanstr(line, '\n');
> >> if (line == NULL) {
> >> - printf("\n");
> >> + if (auto_save) {
> >> + line = "save";
> >
> > This causes compilation to fail for me [1], since we're assigning a
> > const char * to a char *.
>
> Funny, I didn't get a compilation error, although I do see why it
> would^Wshould fail.
Whether you get a compilation error or a warning depends on how you ran
configure, in particular whether you pass
--enable-compile-warnings=error
> >
> > One way to fix this is to write instead
> > strncpy(inputline, "save", sizeof(inputline));
> > line = inputline;
>
> Isn't it possible to do
>
> strncpy(line, "save", sizeof(line));
>
> directly?
IIRC, at that point line == NULL; inputline is a statically allocated
buffer, so we know we can copy into it.
David
More information about the augeas-devel
mailing list