aboutsummaryrefslogtreecommitdiff
path: root/src/tool_operhlp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tool_operhlp.c')
-rw-r--r--src/tool_operhlp.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c
index 1a72035f7..5a6a670f9 100644
--- a/src/tool_operhlp.c
+++ b/src/tool_operhlp.c
@@ -152,14 +152,17 @@ char *add_file_name_to_url(CURL *curl, char *url, const char *filename)
}
/* Extracts the name portion of the URL.
- * Returns a heap-allocated string, or NULL if no name part
+ * Returns a pointer to a heap-allocated string or NULL if
+ * no name part, at location indicated by first argument.
*/
-char *get_url_file_name(const char *url)
+CURLcode get_url_file_name(char **filename, const char *url)
{
- char *fn = NULL;
+ const char *pc;
+
+ *filename = NULL;
/* Find and get the remote file name */
- const char *pc = strstr(url, "://");
+ pc = strstr(url, "://");
if(pc)
pc += 3;
else
@@ -169,9 +172,13 @@ char *get_url_file_name(const char *url)
if(pc) {
/* duplicate the string beyond the slash */
pc++;
- fn = *pc ? strdup(pc): NULL;
+ if(*pc) {
+ *filename = strdup(pc);
+ if(!*filename)
+ return CURLE_OUT_OF_MEMORY;
+ }
}
- return fn;
+ return CURLE_OK;
}
/*