aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tool_formparse.c23
-rw-r--r--src/tool_setopt.c8
2 files changed, 24 insertions, 7 deletions
diff --git a/src/tool_formparse.c b/src/tool_formparse.c
index cf19c0508..fc5162eed 100644
--- a/src/tool_formparse.c
+++ b/src/tool_formparse.c
@@ -347,6 +347,21 @@ static int get_param_part(struct OperationConfig *config, char **str,
return sep & 0xFF;
}
+/* Check if file is "-". If so, use a callback to read OUR stdin (to
+ * workaround Windows DLL file handle caveat).
+ * Else use curl_mime_filedata(). */
+static CURLcode file_or_stdin(curl_mimepart *part, const char *file)
+{
+ CURLcode ret = CURLE_OK;
+
+ if(strcmp(file, "-"))
+ return curl_mime_filedata(part, file);
+
+ return curl_mime_data_cb(part, -1, (curl_read_callback) fread,
+ (curl_seek_callback) fseek, NULL, stdin);
+}
+
+
/***************************************************************************
*
* formparse()
@@ -547,9 +562,9 @@ int formparse(struct OperationConfig *config,
}
/* Setup file in part. */
- res = curl_mime_filedata(part, data);
+ res = file_or_stdin(part, data);
if(res) {
- warnf(config->global, "curl_mime_filedata failed!\n");
+ warnf(config->global, "setting file %s failed!\n", data);
if(res != CURLE_READ_ERROR) {
if(subparts != *mimecurrent)
curl_mime_free(subparts);
@@ -619,9 +634,9 @@ int formparse(struct OperationConfig *config,
}
/* Setup file in part. */
- res = curl_mime_filedata(part, data);
+ res = file_or_stdin(part, data);
if(res) {
- warnf(config->global, "curl_mime_filedata failed!\n");
+ warnf(config->global, "setting file %s failed!\n", data);
if(res != CURLE_READ_ERROR) {
Curl_safefree(contents);
return 22;
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
index 4e25e9e12..19646ea69 100644
--- a/src/tool_setopt.c
+++ b/src/tool_setopt.c
@@ -450,9 +450,11 @@ static CURLcode libcurl_generate_mime(curl_mime *mime, int *mimeno)
filename = part->filename;
}
break;
- case MIMEKIND_FILE:
- /* Can only be stdin in the current context. */
- CODE1("curl_mime_file(part%d, \"-\");", *mimeno);
+ case MIMEKIND_CALLBACK:
+ /* Can only be reading stdin in the current context. */
+ CODE1("curl_mime_data_cb(part%d, -1, (curl_read_callback) fread, \\",
+ *mimeno);
+ CODE0(" (curl_seek_callback) fseek, NULL, stdin);");
break;
case MIMEKIND_DATA:
#ifdef CURL_DOES_CONVERSIONS