Blame lib/system-quote.h

Packit Service fdd496
/* Quoting for a system command.
Packit Service fdd496
   Copyright (C) 2001-2017 Free Software Foundation, Inc.
Packit Service fdd496
   Written by Bruno Haible <bruno@clisp.org>, 2012.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
#ifndef _SYSTEM_QUOTE_H
Packit Service fdd496
#define _SYSTEM_QUOTE_H
Packit Service fdd496
Packit Service fdd496
/* When passing a command the system's command interpreter, we must quote the
Packit Service fdd496
   program name and arguments, since
Packit Service fdd496
     - Unix shells interpret characters like " ", "'", "<", ">", "$", '*', '?'
Packit Service fdd496
       etc. in a special way,
Packit Service fdd496
     - Windows CreateProcess() interprets characters like ' ', '\t', '\\', '"'
Packit Service fdd496
       etc. (but not '<' and '>') in a special way,
Packit Service fdd496
     - Windows cmd.exe also interprets characters like '<', '>', '&', '%', etc.
Packit Service fdd496
       in a special way.  Note that it is impossible to pass arguments that
Packit Service fdd496
       contain newlines or carriage return characters to programs through
Packit Service fdd496
       cmd.exe.
Packit Service fdd496
     - Windows programs usually perform wildcard expansion when they receive
Packit Service fdd496
       arguments that contain unquoted '*', '?' characters.
Packit Service fdd496
Packit Service fdd496
  With this module, you can build a command that will invoke a program with
Packit Service fdd496
  specific strings as arguments.
Packit Service fdd496
Packit Service fdd496
  Note: If you want wildcard expansion to happen, you have to first do wildcard
Packit Service fdd496
  expansion through the 'glob' module, then quote the resulting strings through
Packit Service fdd496
  this module, and then invoke the system's command interpreter.
Packit Service fdd496
Packit Service fdd496
  Limitations:
Packit Service fdd496
    - When invoking native Windows programs on Windows Vista or newer,
Packit Service fdd496
      wildcard expansion will occur in the invoked program nevertheless.
Packit Service fdd496
    - On native Windows, for SCI_SYSTEM and SCI_WINDOWS_CMD, newlines and
Packit Service fdd496
      carriage return characters are not supported.  Their undesired effect
Packit Service fdd496
      is to truncate the entire command line.
Packit Service fdd496
 */
Packit Service fdd496
Packit Service fdd496
#include <stddef.h>
Packit Service fdd496
Packit Service fdd496
#ifdef __cplusplus
Packit Service fdd496
extern "C" {
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
/* Identifier for the kind of interpreter of the command.  */
Packit Service fdd496
enum system_command_interpreter
Packit Service fdd496
{
Packit Service fdd496
  /* The interpreter used by the system() and popen() functions.
Packit Service fdd496
     This is equivalent to SCI_POSIX_SH on Unix platforms and
Packit Service fdd496
     SCI_WINDOWS_CMD on native Windows platforms.  */
Packit Service fdd496
  SCI_SYSTEM                    = 0
Packit Service fdd496
  /* The POSIX /bin/sh.  */
Packit Service fdd496
  , SCI_POSIX_SH                = 1
Packit Service fdd496
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
Packit Service fdd496
  /* The native Windows CreateProcess() function.  */
Packit Service fdd496
  , SCI_WINDOWS_CREATEPROCESS   = 2
Packit Service fdd496
  /* The native Windows cmd.exe interpreter.  */
Packit Service fdd496
  , SCI_WINDOWS_CMD             = 3
Packit Service fdd496
#endif
Packit Service fdd496
};
Packit Service fdd496
Packit Service fdd496
/* Returns the number of bytes needed for the quoted string.  */
Packit Service fdd496
extern size_t
Packit Service fdd496
       system_quote_length (enum system_command_interpreter interpreter,
Packit Service fdd496
                            const char *string);
Packit Service fdd496
Packit Service fdd496
/* Copies the quoted string to p and returns the incremented p.
Packit Service fdd496
   There must be room for system_quote_length (string) + 1 bytes at p.  */
Packit Service fdd496
extern char *
Packit Service fdd496
       system_quote_copy (char *p,
Packit Service fdd496
                          enum system_command_interpreter interpreter,
Packit Service fdd496
                          const char *string);
Packit Service fdd496
Packit Service fdd496
/* Returns the freshly allocated quoted string.  */
Packit Service fdd496
extern char *
Packit Service fdd496
       system_quote (enum system_command_interpreter interpreter,
Packit Service fdd496
                     const char *string);
Packit Service fdd496
Packit Service fdd496
/* Returns a freshly allocated string containing all argument strings, quoted,
Packit Service fdd496
   separated through spaces.  */
Packit Service fdd496
extern char *
Packit Service fdd496
       system_quote_argv (enum system_command_interpreter interpreter,
Packit Service fdd496
                          char * const *argv);
Packit Service fdd496
Packit Service fdd496
#ifdef __cplusplus
Packit Service fdd496
}
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#endif /* _SYSTEM_QUOTE_H */