This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] manual: Document %m instead of %a for formatted input.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: Ville Skytta <ville dot skytta at iki dot fi>, libc-alpha at sourceware dot org
- Date: Wed, 19 Feb 2014 14:57:20 +0100
- Subject: Re: [PATCH] manual: Document %m instead of %a for formatted input.
- Authentication-results: sourceware.org; auth=none
- References: <20140211140022 dot GB22794 at domone dot podge> <20140211173249 dot 9BA1174451 at topped-with-meat dot com>
On Tue, Feb 11, 2014 at 09:32:49AM -0800, Roland McGrath wrote:
> > * manual/stdio.texi (Dynamic String Input): Recommend %m modifier instead of %a.
>
> This line is too long.
>
> > +A POSIX.1-2008 extension to formatted input lets you safely
>
> It doesn't make sense to talk about "a POSIX.1-2008 extension", even if
> that were accurate. (Actually it's an ISO C-1990 feature.) Something in
> one of the core standards we implement is not "an extension". The manual
> also needs to continue to document the GNU %a extension, and explain the
> effect of -std mode. %a is also mentioned in @node String Input Conversions
> that needs to be updated too.
Here. As original author thinks its enough it would be better add -std
and differences in separate commit.
* manual/stdio.texi (Dynamic String Input): Recommend %m modifier
instead of %a.
(String Input Conversions): Document m modifier.
diff --git a/manual/stdio.texi b/manual/stdio.texi
index 1161a9a..bec7052 100644
--- a/manual/stdio.texi
+++ b/manual/stdio.texi
@@ -3536,6 +3536,10 @@ successful assignments.
@cindex flag character (@code{scanf})
@item
+An optional flag character @samp{m} (valid with string conversions only)
+which requests allocation of a buffer long enough to store the string in.
+
+@item
An optional flag character @samp{a} (valid with string conversions only)
which requests allocation of a buffer long enough to store the string in.
(This is a GNU extension.)
@@ -3929,18 +3933,21 @@ input with a comprehensible error message, not with a crash.
@node Dynamic String Input
@subsection Dynamically Allocating String Conversions
-A GNU extension to formatted input lets you safely read a string with no
-maximum size. Using this feature, you don't supply a buffer; instead,
-@code{scanf} allocates a buffer big enough to hold the data and gives
-you its address. To use this feature, write @samp{a} as a flag
-character, as in @samp{%as} or @samp{%a[0-9a-z]}.
+Since ISO C-1990 there is feature to safely read a string with no maximum
+size. Using this feature, you don't supply a buffer; instead, @code{scanf}
+allocates a buffer big enough to hold the data and gives you its address.
+To use this feature, write @samp{m} as a flag character, as in
+@samp{%ms}, @samp{%m10c} or @samp{%m[0-9a-z]}.
+
+There is also a GNU extension @samp{a} modifier that works similar
+functionality.
The pointer argument you supply for where to store the input should have
type @code{char **}. The @code{scanf} function allocates a buffer and
stores its address in the word that the argument points to. You should
free the buffer with @code{free} when you no longer need it.
-Here is an example of using the @samp{a} flag with the @samp{%[@dots{}]}
+Here is an example of using the @samp{m} flag with the @samp{%[@dots{}]}
conversion specification to read a ``variable assignment'' of the form
@samp{@var{variable} = @var{value}}.
@@ -3948,7 +3955,7 @@ conversion specification to read a ``variable assignment'' of the form
@{
char *variable, *value;
- if (2 > scanf ("%a[a-zA-Z0-9] = %a[^\n]\n",
+ if (2 > scanf ("%m[a-zA-Z0-9] = %m[^\n]\n",
&variable, &value))
@{
invalid_input_error ();