summaryrefslogtreecommitdiff
path: root/src/tool_paramhlp.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-12-20 18:44:20 +0100
committerDaniel Stenberg <daniel@haxx.se>2020-12-21 10:52:41 +0100
commita7696c73436f643d5d31ce0c3d48d282c79f4b5d (patch)
treec01a633a45e06f199eba2cd295b60725af7800c0 /src/tool_paramhlp.c
parente1a4647a42b901d88f9629ce98ff56960e342a74 (diff)
downloadcurl-a7696c73436f643d5d31ce0c3d48d282c79f4b5d.tar.gz
curl: add --create-file-mode [mode]
This option sets the (octal) mode to use for the remote file when one is created, using the SFTP, SCP or FILE protocols. When not set, the default is 0644. Closes #6244
Diffstat (limited to 'src/tool_paramhlp.c')
-rw-r--r--src/tool_paramhlp.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c
index 2f43932ec..a2f20cb17 100644
--- a/src/tool_paramhlp.c
+++ b/src/tool_paramhlp.c
@@ -129,14 +129,13 @@ void cleanarg(char *str)
* getparameter a lot, we must check it for NULL before accessing the str
* data.
*/
-
-ParameterError str2num(long *val, const char *str)
+static ParameterError getnum(long *val, const char *str, int base)
{
if(str) {
char *endptr = NULL;
long num;
errno = 0;
- num = strtol(str, &endptr, 10);
+ num = strtol(str, &endptr, base);
if(errno == ERANGE)
return PARAM_NUMBER_TOO_LARGE;
if((endptr != str) && (endptr == str + strlen(str))) {
@@ -147,6 +146,24 @@ ParameterError str2num(long *val, const char *str)
return PARAM_BAD_NUMERIC; /* badness */
}
+ParameterError str2num(long *val, const char *str)
+{
+ return getnum(val, str, 10);
+}
+
+ParameterError oct2nummax(long *val, const char *str, long max)
+{
+ ParameterError result = getnum(val, str, 8);
+ if(result != PARAM_OK)
+ return result;
+ else if(*val > max)
+ return PARAM_NUMBER_TOO_LARGE;
+ else if(*val < 0)
+ return PARAM_NEGATIVE_NUMERIC;
+
+ return PARAM_OK;
+}
+
/*
* Parse the string and write the long in the given address. Return PARAM_OK
* on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
@@ -158,7 +175,7 @@ ParameterError str2num(long *val, const char *str)
ParameterError str2unum(long *val, const char *str)
{
- ParameterError result = str2num(val, str);
+ ParameterError result = getnum(val, str, 10);
if(result != PARAM_OK)
return result;
if(*val < 0)