-/**
- * Quotes a string so that the shell (/bin/sh) will interpret the
- * quoted string to mean @unquoted_string. If you pass a filename to
- * the shell, for example, you should first quote it with this
- * function. The return value must be freed with dbus_free(). The
- * quoting style used is undefined (single or double quotes may be
- * used).
- *
- * @unquoted_string: a literal string
- **/
-char*
-_dbus_shell_quote (const char *unquoted_string)
-{
- /* We always use single quotes, because the algorithm is cheesier.
- * We could use double if we felt like it, that might be more
- * human-readable.
- */
-
- const char *p;
- char *ret;
- DBusString dest;
-
- _dbus_string_init (&dest);
-
- p = unquoted_string;
-
- /* could speed this up a lot by appending chunks of text at a
- * time.
- */
- while (*p)
- {
- /* Replace literal ' with a close ', a \', and a open ' */
- if (*p == '\'')
- {
- if (!_dbus_string_append (&dest, "'\\''"))
- {
- _dbus_string_free (&dest);
- return NULL;
- }
- }
- else
- {
- if (!_dbus_string_append_byte (&dest, *p))
- {
- _dbus_string_free (&dest);
- return NULL;
- }
- }
-
- ++p;
- }
-
- /* close the quote */
- if (_dbus_string_append_byte (&dest, '\''))
- {
- ret = _dbus_strdup (_dbus_string_get_data (&dest));
- _dbus_string_free (&dest);
-
- return ret;
- }
-
- _dbus_string_free (&dest);
-
- return NULL;
-}
-