Move add_to_string to "quote.c" and make it extern.
So that this function may be used in places other than "rsh.c". Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Christian Couder committed
Sep 11, 2006 at 06:59 UTC
86257aa324d04694408ad806989690979456f29a
3 files changed
+36
-30
quote.c
+29
@@ -106,6 +106,35 @@ char *sq_quote_argv(const char** argv, int count)
106
return buf;
107
}
108
109
+/*
110
+ * Append a string to a string buffer, with or without shell quoting.
111
+ * Return true if the buffer overflowed.
112
+ */
113
+int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
114
+{
115
+ char *p = *ptrp;
116
+ int size = *sizep;
117
+ int oc;
118
+ int err = 0;
119
+
120
+ if (quote)
121
+ oc = sq_quote_buf(p, size, str);
122
+ else {
123
+ oc = strlen(str);
124
+ memcpy(p, str, (size <= oc) ? size - 1 : oc);
125
+ }
126
+
127
+ if (size <= oc) {
128
+ err = 1;
129
+ oc = size - 1;
130
+ }
131
+
132
+ *ptrp += oc;
133
+ **ptrp = '\0';
134
+ *sizep -= oc;
135
+ return err;
136
+}
137
+
138
char *sq_dequote(char *arg)
139
{
140
char *dst = arg;
quote.h
+6
@@ -33,6 +33,12 @@ extern void sq_quote_print(FILE *stream, const char *src);
33
extern size_t sq_quote_buf(char *dst, size_t n, const char *src);
34
extern char *sq_quote_argv(const char** argv, int count);
35
36
+/*
37
+ * Append a string to a string buffer, with or without shell quoting.
38
+ * Return true if the buffer overflowed.
39
+ */
40
+extern int add_to_string(char **ptrp, int *sizep, const char *str, int quote);
41
+
42
/* This unwraps what sq_quote() produces in place, but returns
43
* NULL if the input does not look like what sq_quote would have
44
* produced.
rsh.c
+1
-30
@@ -8,36 +8,7 @@
8
9
#define COMMAND_SIZE 4096
10
11
-/*
12
- * Append a string to a string buffer, with or without shell quoting.
13
- * Return true if the buffer overflowed.
14
- */
15
-static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
16
-{
17
- char *p = *ptrp;
18
- int size = *sizep;
19
- int oc;
20
- int err = 0;
21
-
22
- if ( quote ) {
23
- oc = sq_quote_buf(p, size, str);
24
- } else {
25
- oc = strlen(str);
26
- memcpy(p, str, (oc >= size) ? size-1 : oc);
27
- }
28
-
29
- if ( oc >= size ) {
30
- err = 1;
31
- oc = size-1;
32
- }
33
-
34
- *ptrp += oc;
35
- **ptrp = '\0';
36
- *sizep -= oc;
37
- return err;
38
-}
39
-
40
-int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
11
+int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
12
char *url, int rmt_argc, char **rmt_argv)
13
{
14
char *host;