+2003-03-31 Bruno Haible <bruno@clisp.org>
+
+ * sh-quote.c (shell_quote_length, shell_quote_copy): Handle empty
+ argument string correctly.
+
2003-03-30 Bruno Haible <bruno@clisp.org>
* progname.c (ISSLASH, HAS_DEVICE, IS_PATH_WITH_DIR,
/* Shell quoting.
- Copyright (C) 2001-2002 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software; you can redistribute it and/or modify
#include "xmalloc.h"
+/* Must quote the program name and arguments since Unix shells interpret
+ characters like " ", "'", "<", ">", "$" etc. in a special way. This
+ kind of quoting should work unless the string contains "\n" and we call
+ csh. But we are lucky: only /bin/sh will be used. */
+
#define SHELL_SPECIAL_CHARS "\t\n !\"#$&'()*;<=>?[\\]`{|}~"
/* Returns the number of bytes needed for the quoted string. */
size_t
shell_quote_length (const char *string)
{
- if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
+ if (string[0] == '\0')
+ return 2;
+ else if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
return strlen (string);
else
{
char *
shell_quote_copy (char *p, const char *string)
{
- if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
+ if (string[0] == '\0')
+ {
+ memcpy (p, "''", 2);
+ return p + 2;
+ }
+ else if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
{
memcpy (p, string, strlen (string));
return p + strlen (string);