/* quotearg.c - quote arguments for output
- Copyright (C) 1998-2002, 2004-2012 Free Software Foundation, Inc.
+ Copyright (C) 1998-2002, 2004-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
if (backslash_escapes
&& quote_string_len
- && i + quote_string_len <= argsize
+ && (i + quote_string_len
+ <= (argsize == SIZE_MAX && 1 < quote_string_len
+ /* Use strlen only if we must: when argsize is SIZE_MAX,
+ and when the quote string is more than 1 byte long.
+ If we do call strlen, save the result. */
+ ? (argsize = strlen (arg)) : argsize))
&& memcmp (arg + i, quote_string, quote_string_len) == 0)
{
if (elide_outer_quotes)
}
-/* The quoting option used by quote_n and quote. */
+/* The quoting option used by the functions of quote.h. */
struct quoting_options quote_quoting_options =
{
locale_quoting_style,
};
char const *
-quote_n (int n, char const *name)
+quote_n_mem (int n, char const *arg, size_t argsize)
{
- return quotearg_n_options (n, name, SIZE_MAX, "e_quoting_options);
+ return quotearg_n_options (n, arg, argsize, "e_quoting_options);
}
char const *
-quote (char const *name)
+quote_mem (char const *arg, size_t argsize)
{
- return quote_n (0, name);
+ return quote_n_mem (0, arg, argsize);
+}
+
+char const *
+quote_n (int n, char const *arg)
+{
+ return quote_n_mem (n, arg, SIZE_MAX);
+}
+
+char const *
+quote (char const *arg)
+{
+ return quote_n (0, arg);
}